netfilter: remove unnecessary goto statement for error recovery
[cascardo/linux.git] / fs / ext4 / bitmap.c
1 /*
2  *  linux/fs/ext4/bitmap.c
3  *
4  * Copyright (C) 1992, 1993, 1994, 1995
5  * Remy Card (card@masi.ibp.fr)
6  * Laboratoire MASI - Institut Blaise Pascal
7  * Universite Pierre et Marie Curie (Paris VI)
8  */
9
10 #include <linux/buffer_head.h>
11 #include <linux/jbd2.h>
12 #include "ext4.h"
13
14 static const int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0};
15
16 unsigned int ext4_count_free(char *bitmap, unsigned int numchars)
17 {
18         unsigned int i, sum = 0;
19
20         for (i = 0; i < numchars; i++)
21                 sum += nibblemap[bitmap[i] & 0xf] +
22                         nibblemap[(bitmap[i] >> 4) & 0xf];
23         return sum;
24 }
25
26 int ext4_inode_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
27                                   struct ext4_group_desc *gdp,
28                                   struct buffer_head *bh, int sz)
29 {
30         __u32 hi;
31         __u32 provided, calculated;
32         struct ext4_sb_info *sbi = EXT4_SB(sb);
33
34         if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
35                                         EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
36                 return 1;
37
38         provided = le16_to_cpu(gdp->bg_inode_bitmap_csum_lo);
39         calculated = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
40         if (sbi->s_desc_size >= EXT4_BG_INODE_BITMAP_CSUM_HI_END) {
41                 hi = le16_to_cpu(gdp->bg_inode_bitmap_csum_hi);
42                 provided |= (hi << 16);
43         } else
44                 calculated &= 0xFFFF;
45
46         return provided == calculated;
47 }
48
49 void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
50                                 struct ext4_group_desc *gdp,
51                                 struct buffer_head *bh, int sz)
52 {
53         __u32 csum;
54         struct ext4_sb_info *sbi = EXT4_SB(sb);
55
56         if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
57                                         EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
58                 return;
59
60         csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
61         gdp->bg_inode_bitmap_csum_lo = cpu_to_le16(csum & 0xFFFF);
62         if (sbi->s_desc_size >= EXT4_BG_INODE_BITMAP_CSUM_HI_END)
63                 gdp->bg_inode_bitmap_csum_hi = cpu_to_le16(csum >> 16);
64 }
65
66 int ext4_block_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
67                                   struct ext4_group_desc *gdp,
68                                   struct buffer_head *bh, int sz)
69 {
70         __u32 hi;
71         __u32 provided, calculated;
72         struct ext4_sb_info *sbi = EXT4_SB(sb);
73
74         if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
75                                         EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
76                 return 1;
77
78         provided = le16_to_cpu(gdp->bg_block_bitmap_csum_lo);
79         calculated = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
80         if (sbi->s_desc_size >= EXT4_BG_BLOCK_BITMAP_CSUM_HI_END) {
81                 hi = le16_to_cpu(gdp->bg_block_bitmap_csum_hi);
82                 provided |= (hi << 16);
83         } else
84                 calculated &= 0xFFFF;
85
86         if (provided == calculated)
87                 return 1;
88
89         ext4_error(sb, "Bad block bitmap checksum: block_group = %u", group);
90         return 0;
91 }
92
93 void ext4_block_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
94                                 struct ext4_group_desc *gdp,
95                                 struct buffer_head *bh, int sz)
96 {
97         __u32 csum;
98         struct ext4_sb_info *sbi = EXT4_SB(sb);
99
100         if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
101                         EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
102                 return;
103
104         csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
105         gdp->bg_block_bitmap_csum_lo = cpu_to_le16(csum & 0xFFFF);
106         if (sbi->s_desc_size >= EXT4_BG_BLOCK_BITMAP_CSUM_HI_END)
107                 gdp->bg_block_bitmap_csum_hi = cpu_to_le16(csum >> 16);
108 }