From 925ed6cc2b17e20a5915aa5f26a0bbac0161e80e Mon Sep 17 00:00:00 2001 From: Gao Xiang Date: Wed, 12 Jun 2024 10:16:17 +0800 Subject: [PATCH] erofs-utils: fix the current rebuild mode `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 Link: https://lore.kernel.org/r/20240612021617.4025762-1-hsiangkao@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 14bd00a..7d4ccc4 100644 --- a/lib/inode.c +++ b/lib/inode.c @@ -1161,7 +1161,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) @@ -1492,10 +1492,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.34.1