bitmap.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #include <linux/buffer_head.h>
  10. #include <linux/jbd2.h>
  11. #include "ext4.h"
  12. static const int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0};
  13. unsigned int ext4_count_free(char *bitmap, unsigned int numchars)
  14. {
  15. unsigned int i, sum = 0;
  16. for (i = 0; i < numchars; i++)
  17. sum += nibblemap[bitmap[i] & 0xf] +
  18. nibblemap[(bitmap[i] >> 4) & 0xf];
  19. return sum;
  20. }
  21. int ext4_inode_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
  22. struct ext4_group_desc *gdp,
  23. struct buffer_head *bh, int sz)
  24. {
  25. __u32 hi;
  26. __u32 provided, calculated;
  27. struct ext4_sb_info *sbi = EXT4_SB(sb);
  28. if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
  29. EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
  30. return 1;
  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);
  36. } else
  37. calculated &= 0xFFFF;
  38. return provided == calculated;
  39. }
  40. void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
  41. struct ext4_group_desc *gdp,
  42. struct buffer_head *bh, int sz)
  43. {
  44. __u32 csum;
  45. struct ext4_sb_info *sbi = EXT4_SB(sb);
  46. if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
  47. EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
  48. return;
  49. csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
  50. gdp->bg_inode_bitmap_csum_lo = cpu_to_le16(csum & 0xFFFF);
  51. if (sbi->s_desc_size >= EXT4_BG_INODE_BITMAP_CSUM_HI_END)
  52. gdp->bg_inode_bitmap_csum_hi = cpu_to_le16(csum >> 16);
  53. }