2 * linux/fs/ext4/bitmap.c
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)
10 #include <linux/buffer_head.h>
11 #include <linux/jbd2.h>
14 unsigned int ext4_count_free(char *bitmap, unsigned int numchars)
16 return numchars * BITS_PER_BYTE - memweight(bitmap, numchars);
19 int ext4_inode_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
20 struct ext4_group_desc *gdp,
21 struct buffer_head *bh, int sz)
24 __u32 provided, calculated;
25 struct ext4_sb_info *sbi = EXT4_SB(sb);
27 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
28 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
31 provided = le16_to_cpu(gdp->bg_inode_bitmap_csum_lo);
32 calculated = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
33 if (sbi->s_desc_size >= EXT4_BG_INODE_BITMAP_CSUM_HI_END) {
34 hi = le16_to_cpu(gdp->bg_inode_bitmap_csum_hi);
35 provided |= (hi << 16);
39 return provided == calculated;
42 void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
43 struct ext4_group_desc *gdp,
44 struct buffer_head *bh, int sz)
47 struct ext4_sb_info *sbi = EXT4_SB(sb);
49 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
50 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
53 csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
54 gdp->bg_inode_bitmap_csum_lo = cpu_to_le16(csum & 0xFFFF);
55 if (sbi->s_desc_size >= EXT4_BG_INODE_BITMAP_CSUM_HI_END)
56 gdp->bg_inode_bitmap_csum_hi = cpu_to_le16(csum >> 16);
59 int ext4_block_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
60 struct ext4_group_desc *gdp,
61 struct buffer_head *bh, int sz)
64 __u32 provided, calculated;
65 struct ext4_sb_info *sbi = EXT4_SB(sb);
67 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
68 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
71 provided = le16_to_cpu(gdp->bg_block_bitmap_csum_lo);
72 calculated = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
73 if (sbi->s_desc_size >= EXT4_BG_BLOCK_BITMAP_CSUM_HI_END) {
74 hi = le16_to_cpu(gdp->bg_block_bitmap_csum_hi);
75 provided |= (hi << 16);
79 if (provided == calculated)
82 ext4_error(sb, "Bad block bitmap checksum: block_group = %u", group);
86 void ext4_block_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
87 struct ext4_group_desc *gdp,
88 struct buffer_head *bh, int sz)
91 struct ext4_sb_info *sbi = EXT4_SB(sb);
93 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
94 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
97 csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
98 gdp->bg_block_bitmap_csum_lo = cpu_to_le16(csum & 0xFFFF);
99 if (sbi->s_desc_size >= EXT4_BG_BLOCK_BITMAP_CSUM_HI_END)
100 gdp->bg_block_bitmap_csum_hi = cpu_to_le16(csum >> 16);