erofs-utils: rebuild: only update dev/i_ino[1] pairs for directories
authorGao Xiang <hsiangkao@linux.alibaba.com>
Tue, 2 Jul 2024 08:31:44 +0000 (16:31 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Tue, 2 Jul 2024 08:35:15 +0000 (16:35 +0800)
Since the underlying dev/i_ino[1] pairs are only useful for merged
sub-directories, don't bother with other types of inodes.

Otherwise, the original i_ino[1] could be overwritten unexpectedly,
which impacts resvsp mode at least..

Fixes: f64d9d02576b ("erofs-utils: introduce incremental builds")
Reported-by: Hongzhen Luo <hongzhen@linux.alibaba.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240702083144.2120808-1-hsiangkao@linux.alibaba.com
lib/rebuild.c

index 8b186eb185b3eb6ec54c6045a681327d874ed699..0b1a6c634023ea2c443b396b6360cccef585b03d 100644 (file)
@@ -464,10 +464,13 @@ static int erofs_rebuild_basedir_dirent_iter(struct erofs_dir_context *ctx)
        } else {
                struct erofs_inode *inode = d->inode;
 
-               list_del(&inode->i_hash);
-               inode->dev = dir->sbi->dev;
-               inode->i_ino[1] = ctx->de_nid;
-               erofs_insert_ihash(inode);
+               /* update sub-directories only for recursively loading */
+               if (S_ISDIR(inode->i_mode)) {
+                       list_del(&inode->i_hash);
+                       inode->dev = dir->sbi->dev;
+                       inode->i_ino[1] = ctx->de_nid;
+                       erofs_insert_ihash(inode);
+               }
        }
        ret = 0;
 out: