[PATCH] erofs-utils: use the BLK_ROUND_UP directly

Yue Hu zbestahu at gmail.com
Mon Aug 8 13:20:49 AEST 2022


Just simplify the code.

Signed-off-by: Yue Hu <huyue2 at coolpad.com>
---
 fsck/main.c    | 6 ++----
 lib/compress.c | 4 ++--
 lib/data.c     | 2 +-
 lib/zmap.c     | 2 +-
 4 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/fsck/main.c b/fsck/main.c
index 8ed3fc5..410e756 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -483,10 +483,8 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)
 	}
 
 	if (fsckcfg.print_comp_ratio) {
-		fsckcfg.logical_blocks +=
-			DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ);
-		fsckcfg.physical_blocks +=
-			DIV_ROUND_UP(pchunk_len, EROFS_BLKSIZ);
+		fsckcfg.logical_blocks += BLK_ROUND_UP(inode->i_size);
+		fsckcfg.physical_blocks += BLK_ROUND_UP(pchunk_len);
 	}
 out:
 	if (raw)
diff --git a/lib/compress.c b/lib/compress.c
index ee3b856..4bd0958 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -303,7 +303,7 @@ nocompression:
 
 			tailused = ret & (EROFS_BLKSIZ - 1);
 			padding = 0;
-			ctx->compressedblks = DIV_ROUND_UP(ret, EROFS_BLKSIZ);
+			ctx->compressedblks = BLK_ROUND_UP(ret);
 			DBG_BUGON(ctx->compressedblks * EROFS_BLKSIZ >= count);
 
 			/* zero out garbage trailing data for non-0padding */
@@ -584,7 +584,7 @@ void z_erofs_drop_inline_pcluster(struct erofs_inode *inode)
 		u8 *out;
 
 		eofs = inode->extent_isize -
-			(4 << (DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ) & 1));
+			(4 << (BLK_ROUND_UP(inode->i_size) & 1));
 		base = round_down(eofs, 8);
 		pos = 16 /* encodebits */ * ((eofs - base) / 4);
 		out = inode->compressmeta + base;
diff --git a/lib/data.c b/lib/data.c
index 6bc554d..ad7b2cb 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -22,7 +22,7 @@ static int erofs_map_blocks_flatmode(struct erofs_inode *inode,
 
 	trace_erofs_map_blocks_flatmode_enter(inode, map, flags);
 
-	nblocks = DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ);
+	nblocks = BLK_ROUND_UP(inode->i_size);
 	lastblk = nblocks - tailendpacking;
 
 	/* there is no hole in flatmode */
diff --git a/lib/zmap.c b/lib/zmap.c
index 95745c5..abe0d31 100644
--- a/lib/zmap.c
+++ b/lib/zmap.c
@@ -325,7 +325,7 @@ static int compacted_load_cluster_from_disk(struct z_erofs_maprecorder *m,
 	const erofs_off_t ebase = round_up(iloc(vi->nid) + vi->inode_isize +
 					   vi->xattr_isize, 8) +
 		sizeof(struct z_erofs_map_header);
-	const unsigned int totalidx = DIV_ROUND_UP(vi->i_size, EROFS_BLKSIZ);
+	const unsigned int totalidx = BLK_ROUND_UP(vi->i_size);
 	unsigned int compacted_4b_initial, compacted_2b;
 	unsigned int amortizedshift;
 	erofs_off_t pos;
-- 
2.17.1



More information about the Linux-erofs mailing list