From: Sheng Yong <shengyo...@xiaomi.com> Signed-off-by: Sheng Yong <shengyo...@xiaomi.com> --- tests/f_inode_bad_iaddr/README | 6 ++++ tests/f_inode_bad_iaddr/expect.in | 13 ++++++++ tests/f_inode_bad_iaddr/script | 50 +++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 tests/f_inode_bad_iaddr/README create mode 100644 tests/f_inode_bad_iaddr/expect.in create mode 100644 tests/f_inode_bad_iaddr/script
diff --git a/tests/f_inode_bad_iaddr/README b/tests/f_inode_bad_iaddr/README new file mode 100644 index 000000000000..5ada3226ab5d --- /dev/null +++ b/tests/f_inode_bad_iaddr/README @@ -0,0 +1,6 @@ +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 i_addr[0x100] of the inode with an invalid value +5. fsck fixes the inode by nullify i_addr[0x100] +6. check if i_addr[0x100] is 0 diff --git a/tests/f_inode_bad_iaddr/expect.in b/tests/f_inode_bad_iaddr/expect.in new file mode 100644 index 000000000000..4a79f671a651 --- /dev/null +++ b/tests/f_inode_bad_iaddr/expect.in @@ -0,0 +1,13 @@ +Info: Force to fix corruption +[ASSERT] (fsck_chk_data_blk:x) --> blkaddress is not valid. [0x12345] +[FIX] (fsck_chk_inode_blk:x) --> [_INO_] i_addr[256] = NULL_ADDR +[ASSERT] (fsck_chk_inode_blk:x) --> ino: _INO_ has wrong ext: [pgofs:_PGOFS_, blk:_BLK_, len:_LEN_] +[ASSERT] (fsck_chk_inode_blk:x) --> ino: _INO_ has i_blocks: 0x00000202, but has 0x201 blocks +[FIX] (fsck_chk_inode_blk:x) --> [_INO_] i_blocks=0x00000202 -> 0x201 +[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 +Info: Force to fix corruption diff --git a/tests/f_inode_bad_iaddr/script b/tests/f_inode_bad_iaddr/script new file mode 100644 index 000000000000..7c9e67d0eccc --- /dev/null +++ b/tests/f_inode_bad_iaddr/script @@ -0,0 +1,50 @@ +#!/bin/bash + +DESC="inode with invalid i_addr" + +. $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\]'` +ext=`get_mb "$node" 'i_ext:'` +pgofs=`echo $ext | sed 's/.*fofs:\([0-9a-fA-F]\{1,\}\).*/0x\1/g'` +blk=`echo $ext | sed 's/.*blkaddr:\([0-9a-fA-F]\{1,\}\).*/0x\1/g'` +len=`echo $ext | sed 's/.*len:\([0-9a-fA-F]\{1,\}\).*/0x\1/g'` +echo "ino:$ino blkaddr:$blkaddr ext:$ext" >> $LOG + +$INJECT --node --nid $ino --mb i_addr --idx 0x100 --val 0x12345 $META >> $LOG +$FSCK $FSCK_OPTS -f $META > $OUT +$FSCK $FSCK_OPTS -f $META >> $OUT +cat $OUT >> $LOG + +INO=`printf "0x%x" $ino` +PGOFS=$((pgofs)) +BLK=$((blk)) +LEN=$((len)) +sed "s/_INO_/$INO/g" $TESTDIR/expect.in > $TESTDIR/expect +sed -i "s/_PGOFS_/$PGOFS/g" $TESTDIR/expect +sed -i "s/_BLK_/$BLK/g" $TESTDIR/expect +sed -i "s/_LEN_/$LEN/g" $TESTDIR/expect + +node=`$DUMP $DUMP_OPTS -i $ino $META` +echo "$node" >> $LOG +new_blkaddr=`get_mb_val "$node" 'i_addr\[0x100\]'` + +# if i_addr is 0, dump.f2fs hides this i_addr slot +if [ x"$new_blkaddr" != x"" ]; then + echo "old_blkaddr: $blkaddr" >> $OUT + echo "new_blkaddr: $new_blkaddr" >> $OUT +fi + +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