On Nov 7, 2022, at 06:23, Ritesh Harjani (IBM) <ritesh.list@xxxxxxxxx> wrote: > > From: Wang Shilong <wshilong@xxxxxxx> > > Signed-off-by: Li Xi <lixi@xxxxxxx> > Signed-off-by: Wang Shilong <wshilong@xxxxxxx> > [Note: splitted rb merge tree logic patch such that we > seperate out libext2fs changes from e2fsck specific changes] > Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@xxxxxxxxx> Reviewed-by: Andreas Dilger <adilger@xxxxxxxxx> > --- > lib/ext2fs/bitmaps.c | 10 ++++++++++ > lib/ext2fs/bmap64.h | 4 ++++ > lib/ext2fs/ext2fs.h | 8 ++++++++ > lib/ext2fs/gen_bitmap64.c | 29 +++++++++++++++++++++++++++++ > 4 files changed, 51 insertions(+) > > diff --git a/lib/ext2fs/bitmaps.c b/lib/ext2fs/bitmaps.c > index 8bfa24b1..9437331e 100644 > --- a/lib/ext2fs/bitmaps.c > +++ b/lib/ext2fs/bitmaps.c > @@ -45,6 +45,16 @@ errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src, > { > return (ext2fs_copy_generic_bmap(src, dest)); > } > + > +errcode_t ext2fs_merge_bitmap(ext2fs_generic_bitmap src, > + ext2fs_generic_bitmap dest, > + ext2fs_generic_bitmap dup, > + ext2fs_generic_bitmap dup_allowed) > +{ > + return ext2fs_merge_generic_bmap(src, dest, dup, > + dup_allowed); > +} > + > void ext2fs_set_bitmap_padding(ext2fs_generic_bitmap map) > { > ext2fs_set_generic_bmap_padding(map); > diff --git a/lib/ext2fs/bmap64.h b/lib/ext2fs/bmap64.h > index de334548..555193ee 100644 > --- a/lib/ext2fs/bmap64.h > +++ b/lib/ext2fs/bmap64.h > @@ -72,6 +72,10 @@ struct ext2_bitmap_ops { > void (*free_bmap)(ext2fs_generic_bitmap_64 bitmap); > errcode_t (*copy_bmap)(ext2fs_generic_bitmap_64 src, > ext2fs_generic_bitmap_64 dest); > + errcode_t (*merge_bmap)(ext2fs_generic_bitmap_64 src, > + ext2fs_generic_bitmap_64 dest, > + ext2fs_generic_bitmap_64 dup, > + ext2fs_generic_bitmap_64 dup_allowed); > errcode_t (*resize_bmap)(ext2fs_generic_bitmap_64 bitmap, > __u64 new_end, > __u64 new_real_end); > diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h > index 443f93d2..54aed5d1 100644 > --- a/lib/ext2fs/ext2fs.h > +++ b/lib/ext2fs/ext2fs.h > @@ -870,6 +870,10 @@ extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap); > extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap); > extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src, > ext2fs_generic_bitmap *dest); > +extern errcode_t ext2fs_merge_bitmap(ext2fs_generic_bitmap src, > + ext2fs_generic_bitmap dest, > + ext2fs_generic_bitmap dup, > + ext2fs_generic_bitmap dup_allowed); > extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs, > const char *descr, > ext2fs_block_bitmap *ret); > @@ -1467,6 +1471,10 @@ void ext2fs_set_generic_bmap_padding(ext2fs_generic_bitmap bmap); > errcode_t ext2fs_resize_generic_bmap(ext2fs_generic_bitmap bmap, > __u64 new_end, > __u64 new_real_end); > +errcode_t ext2fs_merge_generic_bmap(ext2fs_generic_bitmap gen_src, > + ext2fs_generic_bitmap gen_dest, > + ext2fs_generic_bitmap gen_dup, > + ext2fs_generic_bitmap dup_allowed); > errcode_t ext2fs_compare_generic_bmap(errcode_t neq, > ext2fs_generic_bitmap bm1, > ext2fs_generic_bitmap bm2); > diff --git a/lib/ext2fs/gen_bitmap64.c b/lib/ext2fs/gen_bitmap64.c > index f7710afd..c31f942f 100644 > --- a/lib/ext2fs/gen_bitmap64.c > +++ b/lib/ext2fs/gen_bitmap64.c > @@ -346,6 +346,35 @@ errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap gen_src, > return 0; > } > > +errcode_t ext2fs_merge_generic_bmap(ext2fs_generic_bitmap gen_src, > + ext2fs_generic_bitmap gen_dest, > + ext2fs_generic_bitmap gen_dup, > + ext2fs_generic_bitmap gen_dup_allowed) > +{ > + ext2fs_generic_bitmap_64 src = (ext2fs_generic_bitmap_64)gen_src; > + ext2fs_generic_bitmap_64 dest = (ext2fs_generic_bitmap_64)gen_dest; > + ext2fs_generic_bitmap_64 dup = (ext2fs_generic_bitmap_64)gen_dup; > + ext2fs_generic_bitmap_64 dup_allowed = (ext2fs_generic_bitmap_64)gen_dup_allowed; > + > + if (!src || !dest) > + return EINVAL; > + > + if (!EXT2FS_IS_64_BITMAP(src) || !EXT2FS_IS_64_BITMAP(dest) || > + (dup && !EXT2FS_IS_64_BITMAP(dup)) || > + (dup_allowed && !EXT2FS_IS_64_BITMAP(dup_allowed))) > + return EINVAL; > + > + if (src->bitmap_ops != dest->bitmap_ops || > + (dup && src->bitmap_ops != dup->bitmap_ops) || > + (dup_allowed && src->bitmap_ops != dup_allowed->bitmap_ops)) > + return EINVAL; > + > + if (src->bitmap_ops->merge_bmap == NULL) > + return EOPNOTSUPP; > + > + return src->bitmap_ops->merge_bmap(src, dest, dup, dup_allowed); > +} > + > errcode_t ext2fs_resize_generic_bmap(ext2fs_generic_bitmap gen_bmap, > __u64 new_end, > __u64 new_real_end) > -- > 2.37.3 >