- // get the block group descriptor
- gdesc_bno = (vol->sb->s_first_data_block + 1) + groupno / gdesc_per_block;
+
+ // Calculate the block number which contains the block group descriptor we look for
+ if(vol->sb->s_feature_incompat & EXT4_FEATURE_INCOMPAT_META_BG && groupno >= vol->sb->s_first_meta_bg)
+ {
+ // If option meta_bg is set, the block group descriptor is in meta block group...
+ metabg_of_gdesc = (fsw_u32)(groupno / gdesc_per_block) * gdesc_per_block;
+ gdesc_bno = fsw_ext4_group_first_block_no(vol->sb, metabg_of_gdesc);
+ // We need to know if the block group in questition has a super block, if yes, the
+ // block group descriptors are in the next block number
+ if(!(vol->sb->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) || fsw_ext4_group_sparse(metabg_of_gdesc))
+ gdesc_bno += 1;
+ }
+ else
+ {
+ // All group descriptors follow the super block (+1)
+ gdesc_bno = (vol->sb->s_first_data_block + 1) + groupno / gdesc_per_block;
+ }