[PATCH 1/2 v2] AOSP: erofs-utils: pass a parameter to write tail end in block list

Yue Hu zbestahu at gmail.com
Tue Aug 15 14:55:24 AEST 2023


From: Yue Hu <huyue2 at coolpad.com>

We can determine whether the tail block is the first one or not during
the writing process.  Therefore, instead of internally checking the
block number for the tail block map, just simply pass the flag.

Also, add the missing sbi argument to macro erofs_blknr.

Signed-off-by: Yue Hu <huyue2 at coolpad.com>
---
v2: change commit message a bit

 include/erofs/block_list.h | 4 ++--
 lib/block_list.c           | 5 ++---
 lib/inode.c                | 9 +++++++--
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/include/erofs/block_list.h b/include/erofs/block_list.h
index 78fab44..e0dced8 100644
--- a/include/erofs/block_list.h
+++ b/include/erofs/block_list.h
@@ -19,7 +19,7 @@ void erofs_droid_blocklist_fclose(void);
 void erofs_droid_blocklist_write(struct erofs_inode *inode,
 				 erofs_blk_t blk_start, erofs_blk_t nblocks);
 void erofs_droid_blocklist_write_tail_end(struct erofs_inode *inode,
-					  erofs_blk_t blkaddr);
+					  erofs_blk_t blkaddr, bool first_block);
 void erofs_droid_blocklist_write_extent(struct erofs_inode *inode,
 					erofs_blk_t blk_start, erofs_blk_t nblocks,
 					bool first_extent, bool last_extent);
@@ -28,7 +28,7 @@ static inline void erofs_droid_blocklist_write(struct erofs_inode *inode,
 				 erofs_blk_t blk_start, erofs_blk_t nblocks) {}
 static inline void
 erofs_droid_blocklist_write_tail_end(struct erofs_inode *inode,
-					  erofs_blk_t blkaddr) {}
+				     erofs_blk_t blkaddr, bool first_block) {}
 static inline void
 erofs_droid_blocklist_write_extent(struct erofs_inode *inode,
 				   erofs_blk_t blk_start, erofs_blk_t nblocks,
diff --git a/lib/block_list.c b/lib/block_list.c
index 896fb01..a1c719d 100644
--- a/lib/block_list.c
+++ b/lib/block_list.c
@@ -85,7 +85,7 @@ void erofs_droid_blocklist_write(struct erofs_inode *inode,
 }
 
 void erofs_droid_blocklist_write_tail_end(struct erofs_inode *inode,
-					  erofs_blk_t blkaddr)
+					  erofs_blk_t blkaddr, bool first_block)
 {
 	if (!block_list_fp || !cfg.mount_point)
 		return;
@@ -94,8 +94,7 @@ void erofs_droid_blocklist_write_tail_end(struct erofs_inode *inode,
 	if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode))
 		return;
 
-	/* XXX: another hack, which means it has been outputed before */
-	if (erofs_blknr(inode->i_size)) {
+	if (!first_block) {
 		if (blkaddr == NULL_ADDR)
 			fprintf(block_list_fp, "\n");
 		else
diff --git a/lib/inode.c b/lib/inode.c
index c4d1476..7cd3e69 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -734,12 +734,15 @@ static int erofs_write_tail_end(struct erofs_inode *inode)
 {
 	struct erofs_sb_info *sbi = inode->sbi;
 	struct erofs_buffer_head *bh, *ibh;
+	bool first_block;
 
 	bh = inode->bh_data;
 
 	if (!inode->idata_size)
 		goto out;
 
+	first_block = !erofs_blknr(sbi, inode->i_size);
+
 	/* have enough room to inline data */
 	if (inode->bh_inline) {
 		ibh = inode->bh_inline;
@@ -747,7 +750,8 @@ static int erofs_write_tail_end(struct erofs_inode *inode)
 		ibh->fsprivate = erofs_igrab(inode);
 		ibh->op = &erofs_write_inline_bhops;
 
-		erofs_droid_blocklist_write_tail_end(inode, NULL_ADDR);
+		erofs_droid_blocklist_write_tail_end(inode, NULL_ADDR,
+						     first_block);
 	} else {
 		int ret;
 		erofs_off_t pos, zero_pos;
@@ -801,7 +805,8 @@ static int erofs_write_tail_end(struct erofs_inode *inode)
 		free(inode->idata);
 		inode->idata = NULL;
 
-		erofs_droid_blocklist_write_tail_end(inode, erofs_blknr(sbi, pos));
+		erofs_droid_blocklist_write_tail_end(inode, erofs_blknr(sbi, pos),
+						     first_block);
 	}
 out:
 	/* now bh_data can drop directly */
-- 
2.17.1



More information about the Linux-erofs mailing list