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

Signed-off-by: Sheng Yong <shengyo...@xiaomi.com>
---
 tests/f_nat_bad_ino/README    |  4 ++++
 tests/f_nat_bad_ino/expect.in | 12 ++++++++++++
 tests/f_nat_bad_ino/script    | 31 +++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+)
 create mode 100644 tests/f_nat_bad_ino/README
 create mode 100644 tests/f_nat_bad_ino/expect.in
 create mode 100644 tests/f_nat_bad_ino/script

diff --git a/tests/f_nat_bad_ino/README b/tests/f_nat_bad_ino/README
new file mode 100644
index 000000000000..b97015297b25
--- /dev/null
+++ b/tests/f_nat_bad_ino/README
@@ -0,0 +1,4 @@
+1. create f2fs image
+2. mount f2fs and create a regular file
+3. inject ino in nat entry with value 0x12345 of the regular file
+4. fsck fixes the nat entry by nullifying it
diff --git a/tests/f_nat_bad_ino/expect.in b/tests/f_nat_bad_ino/expect.in
new file mode 100644
index 000000000000..4a70b0b27cff
--- /dev/null
+++ b/tests/f_nat_bad_ino/expect.in
@@ -0,0 +1,12 @@
+Info: Force to fix corruption
+[ASSERT] (sanity_check_nid: x)  --> nid[_INO_] nat_entry->ino[0x12345] 
footer.ino[_INO_]
+[FIX] (__chk_dentries:x)  --> Unlink [_INO_] - testfile len[0x8], type[0x1]
+[fsck_chk_quota_files:x] Fixing Quota file ([  0] ino [0x4])
+[FIX] (nullify_nat_entry:x)  --> Remove nid [0x4] in NAT
+[fsck_chk_quota_files:x] Fixing Quota file ([  1] ino [0x5])
+[FIX] (nullify_nat_entry:x)  --> Remove nid [0x5] in NAT
+[fsck_chk_quota_files:x] Fixing Quota file ([  2] ino [0x6])
+[FIX] (nullify_nat_entry:x)  --> Remove nid [0x6] in NAT
+NID[_INO_] is unreachable, blkaddr:_BLK_
+[FIX] (nullify_nat_entry:x)  --> Remove nid [_INO_] in NAT
+Info: Force to fix corruption
diff --git a/tests/f_nat_bad_ino/script b/tests/f_nat_bad_ino/script
new file mode 100644
index 000000000000..ded5b2a602fb
--- /dev/null
+++ b/tests/f_nat_bad_ino/script
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+DESC="nat entry with invalid ino"
+
+. $TOPDIR/tests/helpers
+
+cleanup
+make_f2fs > $LOG
+
+mkdir $TESTDIR/mntdir
+safe_mount $MNT_OPTS $META $TESTDIR/mntdir >> $LOG
+touch $TESTDIR/mntdir/testfile
+ino=`stat -c "%i" $TESTDIR/mntdir/testfile`
+safe_umount $TESTDIR/mntdir >> $LOG
+rm -rf $TESTDIR/mntdir
+
+blk=`$DUMP $DUMP_OPTS -i $ino -d 1 $META | grep nat_entry.block_addr | \
+       sed 
's/.*nat_entry\.block_addr[[:space:]]*\[\(0x[0-9a-f]\{1,\}\)\]/\1/g'`
+
+echo "ino:$ino blk:$blk" >> $LOG
+
+$INJECT --nat 0 --nid $ino --mb ino --val 0x12345 $META >> $LOG
+$FSCK $FSCK_OPTS -f $META > $OUT
+$FSCK $FSCK_OPTS -f $META >> $OUT
+cat $OUT >> $LOG
+
+INO=`printf "0x%x" $ino`
+sed "s/_INO_/$INO/g" $TESTDIR/expect.in > $TESTDIR/expect
+sed -i "s/_BLK_/$blk/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