@@ -1738,11 +1738,18 @@ static int f2fs_check_hash_code(int encoding, int casefolded,
char new[F2FS_PRINT_NAMELEN];
pretty_print_filename(name, len, new, enc_name);
- FIX_MSG("Mismatch hash_code for \"%s\" [%x:%x]",
- new, le32_to_cpu(dentry->hash_code),
- hash_code);
- dentry->hash_code = cpu_to_le32(hash_code);
- return 1;
+
+ ASSERT_MSG("Mismatch hash_code for \"%s\" [%x:%x]",
+ new, le32_to_cpu(dentry->hash_code),
+ hash_code);
+ if (c.fix_on) {
+ FIX_MSG("Fix hash_code for \"%s\" from %x to %x",
+ new, le32_to_cpu(dentry->hash_code),
+ hash_code);
+ dentry->hash_code = cpu_to_le32(hash_code);
+ return 1;
+ }
+ return 0;
}
return 0;
}
w/ below testcase, fsck will fix image accidently: mkfs.f2fs -f /dev/vdb mount -t f2fs -o noinline_dentry /dev/vdb /mnt/f2fs mkdir /mnt/f2fs/dir/ touch /mnt/f2fs/dir/file umount /mnt/f2fs inject.f2fs --dent --mb d_hash --nid 5 --val 0x9a2ea068 /dev/vdb fsck.f2fs -d 1 /dev/vdb output: [FIX] (f2fs_check_hash_code:1741) --> Mismatch hash_code for "file" [9a2ea068:53fcf74e] [fsck_chk_dentry_blk:2124] [ 2] Dentry Block [0x4401] Fixed hash_codes In f2fs_check_hash_code(), we should only fix hash code and return 1 if c.fix_on is true, otherwise, caller will update fixed value to dentry block directly. Signed-off-by: Chao Yu <chao@kernel.org> --- fsck/fsck.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)