On Nov 7, 2022, at 5:21 AM, Ritesh Harjani (IBM) <ritesh.list@xxxxxxxxx> wrote: > > From: Wang Shilong <wshilong@xxxxxxx> > > This adds the support in libext2fs to query whether the block range is > valid or not (within range) given the block bitmap. > Also to avoid duplicate warning messages in case of invalid blocks. > > This will be later used in pass1 of e2fsck is_blocks_used() function to > check whether the given block range is valid or not to avoid duplicate > warning resulting from ext2fs_test_block_bitmap_range2() > > Signed-off-by: Wang Shilong <wshilong@xxxxxxx> > Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@xxxxxxxxx> I don't think this patch is correct? > --- > diff --git a/lib/ext2fs/gen_bitmap64.c b/lib/ext2fs/gen_bitmap64.c > index c31f942f..a9637cb5 100644 > --- a/lib/ext2fs/gen_bitmap64.c > +++ b/lib/ext2fs/gen_bitmap64.c > @@ -731,6 +731,39 @@ int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap gen_bmap, > return bmap->bitmap_ops->test_clear_bmap_extent(bmap, block, num); > } > > +int ext2fs_test_block_bitmap_range2_valid(ext2fs_block_bitmap bitmap, > + blk64_t block, unsigned int num) > +{ > + ext2fs_generic_bitmap_64 bmap = (ext2fs_generic_bitmap_64)bitmap; > + __u64 end = block + num; > + > + if (!bmap) > + return 0; > + > + if (EXT2FS_IS_32_BITMAP(bmap)) { > + if ((block & ~0xffffffffULL) || > + ((block+num-1) & ~0xffffffffULL)) { > + return 0; > + } > + } This is bailing out early if the requested bit is > 2^32, but that is before cluster conversion below. However, I think the bitmap is actually stored in clusters, so the 2^32 check seems premature? > + > + if (!EXT2FS_IS_64_BITMAP(bmap)) > + return 0; > + > + /* convert to clusters if necessary */ > + block >>= bmap->cluster_bits; > + end += (1 << bmap->cluster_bits) - 1; > + end >>= bmap->cluster_bits; > + num = end - block; > + > + if ((block < bmap->start) || (block > bmap->end) || > + (block+num-1 > bmap->end)) > + return 0; > + > + return 1; > +} Cheers, Andreas
Attachment:
signature.asc
Description: Message signed with OpenPGP