[PATCH] erofs-utils: fix the current rebuild mode

Gao Xiang hsiangkao at linux.alibaba.com
Wed Jun 12 12:16:17 AEST 2024


`inode->with_diskbuf` can be false in the rebuild mode since
inode data has been mapped before.

Fixes: 203c847cc7d1 ("erofs-utils: unify the tree traversal for the rebuild mode")
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
 lib/inode.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lib/inode.c b/lib/inode.c
index 3c29bd2..09bf76b 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -1148,7 +1148,7 @@ static int erofs_mkfs_handle_nondirectory(struct erofs_mkfs_job_ndir_ctx *ctx)
 		ret = erofs_write_file_from_buffer(inode, symlink);
 		free(symlink);
 		inode->i_link = NULL;
-	} else if (inode->i_size) {
+	} else if (inode->i_size && ctx->fd >= 0) {
 		ret = erofs_mkfs_job_write_file(ctx);
 	}
 	if (ret)
@@ -1484,10 +1484,11 @@ static int erofs_rebuild_handle_inode(struct erofs_inode *inode)
 		return ret;
 
 	if (!S_ISDIR(inode->i_mode)) {
-		struct erofs_mkfs_job_ndir_ctx ctx = { .inode = inode };
+		struct erofs_mkfs_job_ndir_ctx ctx =
+			{ .inode = inode, .fd = -1 };
 
-		if (!S_ISLNK(inode->i_mode) && inode->i_size) {
-			DBG_BUGON(!inode->with_diskbuf);
+		if (!S_ISLNK(inode->i_mode) && inode->i_size &&
+		    inode->with_diskbuf) {
 			ctx.fd = erofs_diskbuf_getfd(inode->i_diskbuf, &ctx.fpos);
 			if (ctx.fd < 0)
 				return ret;
-- 
2.39.3



More information about the Linux-erofs mailing list