diff --git a/tsk/fs/ext2fs.c b/tsk/fs/ext2fs.c index 93b4d06a311dc85cdd5c4db1c23193190f2ae10b..d40a64be90e95f0c4e21f18f12efdcde809b759d 100644 --- a/tsk/fs/ext2fs.c +++ b/tsk/fs/ext2fs.c @@ -85,23 +85,27 @@ test_root(uint32_t a, uint32_t b) } /** \internal - ext2fs_bg_has_super - wrapper around test_root - Adapted from E2fsprogs sparse.c - @return 1 if block group has superblock, otherwise 0 + * Test if block group has a super block in it. + * + * @return 1 if block group has superblock, otherwise 0 */ static uint32_t -ext2fs_bg_has_super(uint32_t feature_ro_compat, uint32_t group_block) +ext2fs_is_super_bg(uint32_t feature_ro_compat, uint32_t group_block) { + // if no sparse feature, then it has super block if (!(feature_ro_compat & EXT2FS_FEATURE_RO_COMPAT_SPARSE_SUPER)) return 1; + // group 0 always has super block if (group_block == 0) return 1; - // Super blocks are only in block groups that are powers of 3,5, and 7 - if (test_root(group_block, 3) || (test_root(group_block, 5)) || - test_root(group_block, 7)) + // Sparse FS put super blocks in groups that are powers of 3, 5, 7 + if (test_root(group_block, 3) || + (test_root(group_block, 5)) || + (test_root(group_block, 7))) { return 1; + } return 0; } @@ -1769,8 +1773,6 @@ ext4_fsstat_datablock_helper(TSK_FS_INFO * fs, FILE * hFile, ", gpfbg: %d, ibpg: %d \n", cg_base, gpfbg, ibpg); #endif /*If this is the 1st bg in a flex bg then it contains the bitmaps and inode tables */ - //if(ext2fs_bg_has_super(tsk_getu32(fs->endian,sb->s_feature_ro_compat),i)) - //{ if (i % gpfbg == 0) { if (curr_flex_bg == (num_flex_bg - 1)) { unsigned int num_groups = 0; @@ -1812,7 +1814,7 @@ ext4_fsstat_datablock_helper(TSK_FS_INFO * fs, FILE * hFile, } tsk_fprintf(hFile, " Data Blocks: "); db_offset = 0; - if (ext2fs_bg_has_super(tsk_getu32(fs->endian, + if (ext2fs_is_super_bg(tsk_getu32(fs->endian, sb->s_feature_ro_compat), i)) { db_offset = cg_base + (gpfbg * 2) //To account for the bitmaps + (ibpg * gpfbg) //Combined inode tables @@ -1829,7 +1831,7 @@ ext4_fsstat_datablock_helper(TSK_FS_INFO * fs, FILE * hFile, else { tsk_fprintf(hFile, " Data Blocks: "); db_offset = 0; - if (ext2fs_bg_has_super(tsk_getu32(fs->endian, + if (ext2fs_is_super_bg(tsk_getu32(fs->endian, sb->s_feature_ro_compat), i)) { db_offset = cg_base + tsk_getu16(fs->endian, ext2fs->fs->pad_or_gdt.s_reserved_gdt_blocks) + gd_blocks //group descriptors + 1; //superblock @@ -2252,7 +2254,7 @@ ext2fs_fsstat(TSK_FS_INFO * fs, FILE * hFile) */ #ifdef Ext4_DBG printf("DEBUG: ext2fs_super: %d\n", - ext2fs_bg_has_super(tsk_getu32(fs->endian, + ext2fs_is_super_bg(tsk_getu32(fs->endian, sb->s_feature_ro_compat), i)); #endif /* if (((tsk_getu32(fs->endian, ext2fs->fs->s_feature_ro_compat) & @@ -2263,7 +2265,7 @@ ext2fs_fsstat(TSK_FS_INFO * fs, FILE * hFile) ext2fs->fs->s_feature_ro_compat) & EXT2FS_FEATURE_RO_COMPAT_SPARSE_SUPER) == 0)) { */ - if (ext2fs_bg_has_super(tsk_getu32(fs->endian, + if (ext2fs_is_super_bg(tsk_getu32(fs->endian, sb->s_feature_ro_compat), i)) { TSK_OFF_T boff; @@ -2364,7 +2366,7 @@ ext2fs_fsstat(TSK_FS_INFO * fs, FILE * hFile) tsk_fprintf(hFile, " Data Blocks: "); // BC: Commented out from Ext4 commit because it produced // bad data on Ext2 test image. - //if (ext2fs_bg_has_super(tsk_getu32(fs->endian, + //if (ext2fs_is_super_bg(tsk_getu32(fs->endian, // sb->s_feature_ro_compat), i)) { if ((tsk_getu32(fs->endian, ext2fs->fs->s_feature_ro_compat) & EXT2FS_FEATURE_RO_COMPAT_SPARSE_SUPER) &&