erofs-utils: fix the current rebuild mode
authorGao Xiang <hsiangkao@linux.alibaba.com>
Wed, 12 Jun 2024 02:16:17 +0000 (10:16 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Wed, 12 Jun 2024 03:09:17 +0000 (11:09 +0800)
`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@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240612021617.4025762-1-hsiangkao@linux.alibaba.com
lib/inode.c

index 14bd00aee8452a3aee411b42a11eb7b6989198a7..7d4ccc4193a677d39825b0623275075791f5978d 100644 (file)
@@ -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;