[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <728edcaf0eb7fca7e347183799b5dca743236db0.1667822611.git.ritesh.list@gmail.com>
Date: Mon, 7 Nov 2022 17:50:51 +0530
From: "Ritesh Harjani (IBM)" <ritesh.list@...il.com>
To: Theodore Ts'o <tytso@....edu>
Cc: linux-ext4@...r.kernel.org,
Harshad Shirwadkar <harshadshirwadkar@...il.com>,
Wang Shilong <wshilong@....com>,
Andreas Dilger <adilger.kernel@...ger.ca>,
Li Xi <lixi@....com>,
"Ritesh Harjani (IBM)" <ritesh.list@...il.com>
Subject: [RFCv1 03/72] blkmap64_ba: Add common helper for bits size calculation
Just a quick common helper for bits size calculation.
Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@...il.com>
---
lib/ext2fs/blkmap64_ba.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/lib/ext2fs/blkmap64_ba.c b/lib/ext2fs/blkmap64_ba.c
index 5d8f1548..4e7007f0 100644
--- a/lib/ext2fs/blkmap64_ba.c
+++ b/lib/ext2fs/blkmap64_ba.c
@@ -40,6 +40,13 @@ struct ext2fs_ba_private_struct {
typedef struct ext2fs_ba_private_struct *ext2fs_ba_private;
+#define ba_bits_size(start, end) ((((end) - (start)) / 8 + 1))
+
+static size_t ba_bitmap_size(ext2fs_generic_bitmap_64 bitmap)
+{
+ return (size_t) ba_bits_size(bitmap->start, bitmap->real_end);
+}
+
static errcode_t ba_alloc_private_data (ext2fs_generic_bitmap_64 bitmap)
{
ext2fs_ba_private bp;
@@ -56,7 +63,7 @@ static errcode_t ba_alloc_private_data (ext2fs_generic_bitmap_64 bitmap)
if (retval)
return retval;
- size = (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1);
+ size = ba_bitmap_size(bitmap);
retval = ext2fs_get_mem(size, &bp->bitarray);
if (retval) {
@@ -80,7 +87,7 @@ static errcode_t ba_new_bmap(ext2_filsys fs EXT2FS_ATTR((unused)),
return retval;
bp = (ext2fs_ba_private) bitmap->private;
- size = (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1);
+ size = ba_bitmap_size(bitmap);
memset(bp->bitarray, 0, size);
return 0;
@@ -115,7 +122,7 @@ static errcode_t ba_copy_bmap(ext2fs_generic_bitmap_64 src,
dest_bp = (ext2fs_ba_private) dest->private;
- size = (size_t) (((src->real_end - src->start) / 8) + 1);
+ size = ba_bitmap_size(src);
memcpy (dest_bp->bitarray, src_bp->bitarray, size);
return 0;
@@ -145,8 +152,8 @@ static errcode_t ba_resize_bmap(ext2fs_generic_bitmap_64 bmap,
return 0;
}
- size = ((bmap->real_end - bmap->start) / 8) + 1;
- new_size = ((new_real_end - bmap->start) / 8) + 1;
+ size = ba_bitmap_size(bmap);
+ new_size = ba_bits_size(new_real_end, bmap->start);
if (size != new_size) {
retval = ext2fs_resize_mem(size, new_size, &bp->bitarray);
@@ -306,8 +313,7 @@ static void ba_clear_bmap(ext2fs_generic_bitmap_64 bitmap)
{
ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private;
- memset(bp->bitarray, 0,
- (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1));
+ memset(bp->bitarray, 0, ba_bitmap_size(bitmap));
}
#ifdef ENABLE_BMAP_STATS
--
2.37.3
Powered by blists - more mailing lists