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

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

diff --git a/tests/f_sit_bad_vblocks/README b/tests/f_sit_bad_vblocks/README
new file mode 100644
index 000000000000..4ca21c766b2d
--- /dev/null
+++ b/tests/f_sit_bad_vblocks/README
@@ -0,0 +1,5 @@
+1. create f2fs image
+2. mount f2fs and create a regular file and write data
+3. get a block address by dumping the inode
+4. inject vblocks in the sit entry of the blkaddr by subtracting 1
+5. fsck fixes the vblocks
diff --git a/tests/f_sit_bad_vblocks/expect.in 
b/tests/f_sit_bad_vblocks/expect.in
new file mode 100644
index 000000000000..9e31f38c458b
--- /dev/null
+++ b/tests/f_sit_bad_vblocks/expect.in
@@ -0,0 +1,3 @@
+Info: Force to fix corruption
+[ASSERT] (check_block_count:x)  --> Wrong SIT valid blocks: segno=_SEGNO_, 511 
vs. 512
+Info: Force to fix corruption
diff --git a/tests/f_sit_bad_vblocks/script b/tests/f_sit_bad_vblocks/script
new file mode 100644
index 000000000000..6dd684555011
--- /dev/null
+++ b/tests/f_sit_bad_vblocks/script
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+DESC="sit entry with invalid vblocks"
+
+. $TOPDIR/tests/helpers
+
+cleanup
+make_f2fs > $LOG
+
+mkdir $TESTDIR/mntdir
+safe_mount $MNT_OPTS $META $TESTDIR/mntdir >> $LOG
+dd if=/dev/zero of=$TESTDIR/mntdir/testfile bs=4K count=513 status=none
+ino=`stat -c "%i" $TESTDIR/mntdir/testfile`
+safe_umount $TESTDIR/mntdir >> $LOG
+rm -rf $TESTDIR/mntdir
+
+node=`$DUMP $DUMP_OPTS -i $ino $META`
+echo "$node" >> $LOG
+blkaddr=`get_mb_val "$node" 'i_addr\[0x100\]'`
+echo "ino:$ino blkaddr:$blkaddr" >> $LOG
+
+SIT_VBLOCKS_SHIFT=10
+SIT_VBLOCKS_MASK=$(((1 << SIT_VBLOCKS_SHIFT) - 1))
+val=`$INJECT --dry-run --sit 0 --blk $blkaddr --mb vblocks $META | \
+       grep "inject sit entry vblocks" | awk '{print $(NF-2)}'`
+vblocks=$((val & SIT_VBLOCKS_MASK))
+val=$(((val & ~SIT_VBLOCKS_MASK) | (vblocks - 1)))
+
+$INJECT --sit 0 --blk $blkaddr --mb vblocks --val $val $META >> $LOG
+$FSCK $FSCK_OPTS -f $META > $OUT
+$FSCK $FSCK_OPTS -f $META >> $OUT
+cat $OUT >> $LOG
+
+segno=`get_segno $blkaddr`
+SEGNO=`printf "0x%x" $segno`
+sed "s/_SEGNO_/$SEGNO/g" $TESTDIR/expect.in > $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