ext4: pass a char * to ext4_count_free() instead of a buffer_head ptr
[deliverable/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 #ifdef EXT4FS_DEBUG
15
16 static const int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0};
17
18 unsigned int ext4_count_free(char *bitmap, unsigned int numchars)
19 {
20 unsigned int i, sum = 0;
21
22 for (i = 0; i < numchars; i++)
23 sum += nibblemap[bitmap[i] & 0xf] +
24 nibblemap[(bitmap[i] >> 4) & 0xf];
25 return sum;
26 }
27
28 #endif /* EXT4FS_DEBUG */
29
30 int ext4_inode_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
31 struct ext4_group_desc *gdp,
32 struct buffer_head *bh, int sz)
33 {
34 __u32 hi;
35 __u32 provided, calculated;
36 struct ext4_sb_info *sbi = EXT4_SB(sb);
37
38 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
39 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
40 return 1;
41
42 provided = le16_to_cpu(gdp->bg_inode_bitmap_csum_lo);
43 calculated = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
44 if (sbi->s_desc_size >= EXT4_BG_INODE_BITMAP_CSUM_HI_END) {
45 hi = le16_to_cpu(gdp->bg_inode_bitmap_csum_hi);
46 provided |= (hi << 16);
47 } else
48 calculated &= 0xFFFF;
49
50 return provided == calculated;
51 }
52
53 void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
54 struct ext4_group_desc *gdp,
55 struct buffer_head *bh, int sz)
56 {
57 __u32 csum;
58 struct ext4_sb_info *sbi = EXT4_SB(sb);
59
60 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
61 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
62 return;
63
64 csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
65 gdp->bg_inode_bitmap_csum_lo = cpu_to_le16(csum & 0xFFFF);
66 if (sbi->s_desc_size >= EXT4_BG_INODE_BITMAP_CSUM_HI_END)
67 gdp->bg_inode_bitmap_csum_hi = cpu_to_le16(csum >> 16);
68 }
69
70 int ext4_block_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
71 struct ext4_group_desc *gdp,
72 struct buffer_head *bh, int sz)
73 {
74 __u32 hi;
75 __u32 provided, calculated;
76 struct ext4_sb_info *sbi = EXT4_SB(sb);
77
78 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
79 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
80 return 1;
81
82 provided = le16_to_cpu(gdp->bg_block_bitmap_csum_lo);
83 calculated = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
84 if (sbi->s_desc_size >= EXT4_BG_BLOCK_BITMAP_CSUM_HI_END) {
85 hi = le16_to_cpu(gdp->bg_block_bitmap_csum_hi);
86 provided |= (hi << 16);
87 } else
88 calculated &= 0xFFFF;
89
90 if (provided == calculated)
91 return 1;
92
93 ext4_error(sb, "Bad block bitmap checksum: block_group = %u", group);
94 return 0;
95 }
96
97 void ext4_block_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
98 struct ext4_group_desc *gdp,
99 struct buffer_head *bh, int sz)
100 {
101 __u32 csum;
102 struct ext4_sb_info *sbi = EXT4_SB(sb);
103
104 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
105 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
106 return;
107
108 csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
109 gdp->bg_block_bitmap_csum_lo = cpu_to_le16(csum & 0xFFFF);
110 if (sbi->s_desc_size >= EXT4_BG_BLOCK_BITMAP_CSUM_HI_END)
111 gdp->bg_block_bitmap_csum_hi = cpu_to_le16(csum >> 16);
112 }
This page took 0.033916 seconds and 5 git commands to generate.