lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon,  4 Jul 2022 12:36:53 +0530
From:   Ritesh Harjani <ritesh.list@...il.com>
To:     Theodore Ts'o <tytso@....edu>
Cc:     Harshad Shirwadkar <harshadshirwadkar@...il.com>,
        Andreas Dilger <adilger@...ger.ca>,
        linux-ext4 <linux-ext4@...r.kernel.org>,
        Wang Shilong <wshilong@....com>,
        Ritesh Harjani <ritesh.list@...il.com>
Subject: [RFC 04/13] ext2fs/bitmaps: Add merge bitmaps library abstraction changes

From: Wang Shilong <wshilong@....com>

Add merge bitmaps library abstraction changes.

Signed-off-by: Wang Shilong <wshilong@....com>
Signed-off-by: Ritesh Harjani <ritesh.list@...il.com>
---
 lib/ext2fs/bitmaps.c      |  9 +++++++++
 lib/ext2fs/bmap64.h       |  5 +++++
 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 834a3962..23072a11 100644
--- a/lib/ext2fs/bitmaps.c
+++ b/lib/ext2fs/bitmaps.c
@@ -45,6 +45,15 @@ 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 dst,
+							  ext2fs_generic_bitmap dup,
+							  ext2fs_generic_bitmap dup_allowed)
+{
+	return ext2fs_merge_generic_bmap(src, dst, 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..4c254892 100644
--- a/lib/ext2fs/bmap64.h
+++ b/lib/ext2fs/bmap64.h
@@ -100,6 +100,11 @@ struct ext2_bitmap_ops {
 	 * May be NULL, in which case a generic function is used. */
 	errcode_t (*find_first_set)(ext2fs_generic_bitmap_64 bitmap,
 				    __u64 start, __u64 end, __u64 *out);
+
+	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);
 };
 
 extern struct ext2_bitmap_ops ext2fs_blkmap64_bitarray;
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index 68f9c1fe..c18849d7 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -867,6 +867,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 dst,
+							  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);
@@ -1455,6 +1459,10 @@ errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic,
 				    ext2fs_generic_bitmap *ret);
 errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap src,
 				   ext2fs_generic_bitmap *dest);
+extern errcode_t ext2fs_merge_generic_bmap(ext2fs_generic_bitmap gen_src,
+							  ext2fs_generic_bitmap gen_dst,
+							  ext2fs_generic_bitmap gen_dup,
+							  ext2fs_generic_bitmap gen_dup_allowed);
 void ext2fs_clear_generic_bmap(ext2fs_generic_bitmap bitmap);
 errcode_t ext2fs_fudge_generic_bmap_end(ext2fs_generic_bitmap bitmap,
 					errcode_t neq,
diff --git a/lib/ext2fs/gen_bitmap64.c b/lib/ext2fs/gen_bitmap64.c
index 90c700ca..eea100b0 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_dst,
+							  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 dst = (ext2fs_generic_bitmap_64) gen_dst;
+	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 || !dst)
+		return EINVAL;
+
+	if (!EXT2FS_IS_64_BITMAP(src) || !EXT2FS_IS_64_BITMAP(dst) ||
+	   (dup && !EXT2FS_IS_64_BITMAP(dup)) ||
+	   (dup_allowed && !EXT2FS_IS_64_BITMAP(dup_allowed)))
+		return EINVAL;
+
+	if (src->bitmap_ops != dst->bitmap_ops ||
+		(dup && dup->bitmap_ops != src->bitmap_ops) ||
+		(dup_allowed && dup_allowed->bitmap_ops != src->bitmap_ops))
+		return EINVAL;
+
+	if (!src->bitmap_ops->merge_bmap)
+		return EOPNOTSUPP;
+
+	return src->bitmap_ops->merge_bmap(src, dst, dup, dup_allowed);
+}
+
 errcode_t ext2fs_resize_generic_bmap(ext2fs_generic_bitmap gen_bmap,
 				     __u64 new_end,
 				     __u64 new_real_end)
-- 
2.35.3

Powered by blists - more mailing lists