[PATCH 2/2] AOSP: erofs-utils: add a variable to validate tail block map in block list

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


From: Yue Hu <huyue2 at coolpad.com>

We write the block map directly before the tail, as this applies only to
regular files.  However, the tail block map does not follow the rule.

Therefore, introduce a variable to track whether the tail block is safe
to write before its map if it exists rather than separately check the
file type when mapping.

Signed-off-by: Yue Hu <huyue2 at coolpad.com>
---
 lib/block_list.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/lib/block_list.c b/lib/block_list.c
index a1c719d..e59a8d7 100644
--- a/lib/block_list.c
+++ b/lib/block_list.c
@@ -12,6 +12,7 @@
 #include "erofs/print.h"
 
 static FILE *block_list_fp;
+static bool regular_tail = false;
 
 int erofs_droid_blocklist_fopen(void)
 {
@@ -77,22 +78,23 @@ void erofs_droid_blocklist_write_extent(struct erofs_inode *inode,
 void erofs_droid_blocklist_write(struct erofs_inode *inode,
 				 erofs_blk_t blk_start, erofs_blk_t nblocks)
 {
-	if (!block_list_fp || !cfg.mount_point || !nblocks)
+	if (!block_list_fp || !cfg.mount_point)
 		return;
 
-	blocklist_write(inode->i_srcpath, blk_start, nblocks,
-			true, !inode->idata_size);
+	if (nblocks)
+		blocklist_write(inode->i_srcpath, blk_start, nblocks, true,
+				!inode->idata_size);
+	if (inode->idata_size)
+		regular_tail = true;
 }
 
 void erofs_droid_blocklist_write_tail_end(struct erofs_inode *inode,
 					  erofs_blk_t blkaddr, bool first_block)
 {
-	if (!block_list_fp || !cfg.mount_point)
+	if (!block_list_fp || !cfg.mount_point || !regular_tail)
 		return;
 
-	/* XXX: a bit hacky.. may need a better approach */
-	if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode))
-		return;
+	regular_tail = false;
 
 	if (!first_block) {
 		if (blkaddr == NULL_ADDR)
-- 
2.17.1



More information about the Linux-erofs mailing list