fsck.f2fs: fix to repair hash_code only if c.fix_on is true
PATCH 1/1 fsck.f2fs: fix to repair hash_code only if c.fix_on is true
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 <[email protected]>
--- fsck/fsck.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
fsck/fsck.c +12 -5
@@ -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 ; }
Signature · 8 lines
2.49.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel