On Fri, Aug 16, 2019 at 03:49:14AM +0000, Dongyang Li wrote: > Fix a bug in handle_bad_blocks(), don't covert the bad block to > cluster when marking it as used, the bitmap is still a block bitmap, > will be coverted to cluster bitmap later. Please separate the bug fix into a separate commit. > Note: in kernel the overhead is the s_overhead_clusters field from > struct ext4_super_block, it's named s_overhead_blocks in e2fsprogs Please fix up the field name in e2fsprogs, again in a separate commit. > +errcode_t ext2fs_convert_subcluster_bitmap_overhead(ext2_filsys fs, > + ext2fs_block_bitmap *bitmap, > + badblocks_list bb_list, > + unsigned int *count); So I really hate this abstraction which you've proposed. It's very mke2fs specific, and mixing the bb_list abstraction into bitmap is just really ugly. Instead let me suggest the following: 1) Have mke2fs unset the blocks in bb_list from the block bitmap. 2) Then have mke2fs call ext2fs_convert_subcluster_bitmap() 3) Create an abstraction which counts the number of clusters in the bitmap, by using find_first_set() and first_first_zero(). 4) Let mke2fs call that function defined in (3) above on the converted cluster bitmap() to get the overhead in clusters 5) Iterate over the bb_list to set the clusters in the converted cluster-granularity allocation map. The abstraction in (3) is much less mke2fs specific, and if you make the abstraction take a starting and ending block count, there are potentially other use cases (for example, counting the number of clusters in use in a block group). Cheers, - Ted