erofs-utils: mkfs: make output stable
authorJooyung Han <jooyung@google.com>
Tue, 3 Dec 2024 07:45:31 +0000 (16:45 +0900)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Tue, 3 Dec 2024 07:51:53 +0000 (15:51 +0800)
The iteration order of opendir/readdir depends on filesystem
implementation. Initializng inode->i_ino[0] in the loop causes the
output unstable even though the entries are sorted in
erofs_prepare_dir_file().

In this change,  inode->i_ino[0] is initialized in
erofs_prepare_inode_buffer() instead to make the output stable. (not
affected by readdir())

  # should generate the same output

Test: mkfs.erofs ... inputdir(ext3)
Test: mkfs.erofs ... inputdir(tmpfs)
Signed-off-by: Jooyung Han <jooyung@google.com>
Link: https://lore.kernel.org/r/20241203074531.3728133-1-jooyung@google.com
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
lib/inode.c

index e2888a4394848ba3e1272ed89433c521159fe64c..7e5c58165e04783d1c75fa4ef30ce3ee42ecb5b3 100644 (file)
@@ -821,6 +821,7 @@ noinline:
        bh->fsprivate = erofs_igrab(inode);
        bh->op = &erofs_write_inode_bhops;
        inode->bh = bh;
+       inode->i_ino[0] = ++inode->sbi->inos;  /* inode serial number */
        return 0;
 }
 
@@ -1114,7 +1115,6 @@ struct erofs_inode *erofs_new_inode(struct erofs_sb_info *sbi)
                return ERR_PTR(-ENOMEM);
 
        inode->sbi = sbi;
-       inode->i_ino[0] = sbi->inos++;  /* inode serial number */
        inode->i_count = 1;
        inode->datalayout = EROFS_INODE_FLAT_PLAIN;