From: Sheng Yong <shengyo...@xiaomi.com>

Signed-off-by: Sheng Yong <shengyo...@xiaomi.com>
---
 tests/f_dentry_bad_hash/README    |  8 +++++
 tests/f_dentry_bad_hash/expect.in |  8 +++++
 tests/f_dentry_bad_hash/script    | 56 +++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)
 create mode 100644 tests/f_dentry_bad_hash/README
 create mode 100644 tests/f_dentry_bad_hash/expect.in
 create mode 100644 tests/f_dentry_bad_hash/script

diff --git a/tests/f_dentry_bad_hash/README b/tests/f_dentry_bad_hash/README
new file mode 100644
index 000000000000..f36c44f7c7bd
--- /dev/null
+++ b/tests/f_dentry_bad_hash/README
@@ -0,0 +1,8 @@
+1. create f2fs image
+2. mount f2fs
+3. create an inline dentry directory, and create a file in it
+4. inject dentry's hash_code of the file
+5. fsck fixes the dentry's hash_code
+6. create a non-inline dentry directory (by converting), and create a file in 
it
+7. inject dentry's hash_code of the file
+8. fsck fixes the dentry's hash_code
diff --git a/tests/f_dentry_bad_hash/expect.in 
b/tests/f_dentry_bad_hash/expect.in
new file mode 100644
index 000000000000..074388fa6849
--- /dev/null
+++ b/tests/f_dentry_bad_hash/expect.in
@@ -0,0 +1,8 @@
+Info: Force to fix corruption
+[ASSERT] (f2fs_check_hash_code:x)  --> Mismatch hash_code for "testfile1" 
[12345:_HASH1_]
+[FIX] (f2fs_check_hash_code:x)  --> Fix hash_code for "testfile1" from 12345 
to _HASH1_
+Info: Force to fix corruption
+Info: Force to fix corruption
+[ASSERT] (f2fs_check_hash_code:x)  --> Mismatch hash_code for "testfile2" 
[12345:_HASH2_]
+[FIX] (f2fs_check_hash_code:x)  --> Fix hash_code for "testfile2" from 12345 
to _HASH2_
+Info: Force to fix corruption
diff --git a/tests/f_dentry_bad_hash/script b/tests/f_dentry_bad_hash/script
new file mode 100644
index 000000000000..4a2d31198e54
--- /dev/null
+++ b/tests/f_dentry_bad_hash/script
@@ -0,0 +1,56 @@
+#!/bin/bash
+
+DESC="dentry with invalid hash_code"
+
+. $TOPDIR/tests/helpers
+
+cleanup
+make_f2fs > $LOG
+
+mkdir $TESTDIR/mntdir
+# inject inline dentry
+safe_mount $MNT_OPTS $META $TESTDIR/mntdir >> $LOG
+mkdir $TESTDIR/mntdir/testdir1
+touch $TESTDIR/mntdir/testdir1/testfile1
+ino=`stat -c "%i" $TESTDIR/mntdir/testdir1/testfile1`
+safe_umount $TESTDIR/mntdir >> $LOG
+
+hash_code=`$INJECT --dry-run --dent --nid $ino --mb d_hash $META | \
+       grep "Info: inject dentry d_hash of nid" | awk '{print $(NF-2)}'`
+echo "ino:$ino hash_code:$hash_code" >> $LOG
+
+$INJECT --dent --nid $ino --mb d_hash --val 0x12345 $META >> $LOG
+$FSCK $FSCK_OPTS -f $META > $OUT
+$FSCK $FSCK_OPTS -f $META >> $OUT
+cat $OUT >> $LOG
+skip_lines=`wc -l $OUT`
+
+HASH_CODE=`printf "%x" $hash_code`
+sed "s/_HASH1_/$HASH_CODE/g" $TESTDIR/expect.in > $TESTDIR/expect
+
+# inject non-inline dentry
+safe_mount $MNT_OPTS $META $TESTDIR/mntdir >> $LOG
+mkdir $TESTDIR/mntdir/testdir2
+i=0
+while [ $i -lt 30 ]; do
+       touch 
$TESTDIR/mntdir/testdir2/loooooooooooooooooooooooooognametestfile$i
+       i=$((i + 1))
+done
+touch $TESTDIR/mntdir/testdir2/testfile2
+ino=`stat -c "%i" $TESTDIR/mntdir/testdir2/testfile2`
+safe_umount $TESTDIR/mntdir >> $LOG
+rm -rf $TESTDIR/mntdir
+
+hash_code=`$INJECT --dry-run --dent --nid $ino --mb d_hash $META | \
+       grep "Info: inject dentry d_hash of nid" | awk '{print $(NF-2)}'`
+echo "ino:$ino hash_code:$hash_code" >> $LOG
+
+$INJECT --dent --nid $ino --mb d_hash --val 0x12345 $META >> $LOG
+$FSCK $FSCK_OPTS -f $META >> $OUT
+$FSCK $FSCK_OPTS -f $META >> $OUT
+cat $OUT | tail -n +$skip_lines >> $LOG
+
+HASH_CODE=`printf "%x" $hash_code`
+sed -i "s/_HASH2_/$HASH_CODE/g" $TESTDIR/expect
+
+check_result
-- 
2.43.0



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to