Browse Source

METADATA_CSUM: inode bitmap verification added

pull/11/head
ngkaho1234 9 years ago
parent
commit
3e1d0ec133
  1. 46
      lwext4/ext4_ialloc.c

46
lwext4/ext4_ialloc.c

@ -129,6 +129,34 @@ void ext4_ialloc_set_bitmap_csum(struct ext4_sblock *sb,
} }
#if CONFIG_META_CSUM_ENABLE
static bool
ext4_ialloc_verify_bitmap_csum(struct ext4_sblock *sb,
struct ext4_bgroup *bg,
void *bitmap __unused)
{
if (!ext4_sb_feature_ro_com(sb, EXT4_FRO_COM_METADATA_CSUM))
return true;
int desc_size = ext4_sb_get_desc_size(sb);
uint32_t checksum = ext4_ialloc_bitmap_csum(sb, bitmap);
uint16_t lo_checksum = to_le16(checksum & 0xFFFF),
hi_checksum = to_le16(checksum >> 16);
if (bg->inode_bitmap_csum_lo != lo_checksum)
return false;
if (desc_size == EXT4_MAX_BLOCK_GROUP_DESCRIPTOR_SIZE)
if (bg->inode_bitmap_csum_hi != hi_checksum)
return false;
return true;
}
#else
#define ext4_balloc_verify_bitmap_csum(...) true
#endif
int ext4_ialloc_free_inode(struct ext4_fs *fs, uint32_t index, bool is_dir) int ext4_ialloc_free_inode(struct ext4_fs *fs, uint32_t index, bool is_dir)
{ {
struct ext4_sblock *sb = &fs->sb; struct ext4_sblock *sb = &fs->sb;
@ -150,6 +178,15 @@ int ext4_ialloc_free_inode(struct ext4_fs *fs, uint32_t index, bool is_dir)
if (rc != EOK) if (rc != EOK)
return rc; return rc;
if (!ext4_ialloc_verify_bitmap_csum(sb,
bg_ref.block_group,
bitmap_block.data)) {
ext4_dbg(DEBUG_IALLOC,
DBG_WARN "Bitmap checksum failed."
"Group: %" PRIu32"\n",
bg_ref.index);
}
/* Free i-node in the bitmap */ /* Free i-node in the bitmap */
uint32_t index_in_group = ext4_ialloc_inode2index_in_group(sb, index); uint32_t index_in_group = ext4_ialloc_inode2index_in_group(sb, index);
ext4_bmap_bit_clr(bitmap_block.data, index_in_group); ext4_bmap_bit_clr(bitmap_block.data, index_in_group);
@ -242,6 +279,15 @@ int ext4_ialloc_alloc_inode(struct ext4_fs *fs, uint32_t *index, bool is_dir)
return rc; return rc;
} }
if (!ext4_ialloc_verify_bitmap_csum(sb,
bg_ref.block_group,
bitmap_block.data)) {
ext4_dbg(DEBUG_IALLOC,
DBG_WARN "Bitmap checksum failed."
"Group: %" PRIu32"\n",
bg_ref.index);
}
/* Try to allocate i-node in the bitmap */ /* Try to allocate i-node in the bitmap */
uint32_t inodes_in_group = uint32_t inodes_in_group =
ext4_inodes_in_group_cnt(sb, bgid); ext4_inodes_in_group_cnt(sb, bgid);

Loading…
Cancel
Save