new file mode 100644
@@ -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
new file mode 100644
@@ -0,0 +1,38 @@
+Info: Force to fix corruption
+Info: checkpoint state = x : nat_bits crc compacted_summary unmount
+[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) --> [0x4] i_blocks=0x00000202 -> 0x201
+
+[FSCK] Unreachable nat entries [Ok..] [x]
+[FSCK] SIT valid block bitmap checking [Fail]
+[FSCK] Hard link checking for regular file [Ok..] [x]
+[FSCK] valid_block_count matching with CP [Fail] [x]
+[FSCK] valid_node_count matching with CP (de lookup) [Ok..] [x]
+[FSCK] valid_node_count matching with CP (nat lookup) [Ok..] [x]
+[FSCK] valid_inode_count matched with CP [Ok..] [x]
+[FSCK] free segment_count matched with CP [Ok..] [x]
+[FSCK] next block offset is free [Ok..]
+[FSCK] fixing SIT types
+[FSCK] other corrupted bugs [Fail]
+Info: Duplicate valid checkpoint to mirror position x -> x
+Info: Write valid nat_bits in checkpoint
+Info: fix_checkpoint() cur_cp:x
+
+Info: Force to fix corruption
+Info: checkpoint state = x : allow_nocrc nat_bits unmount
+
+[FSCK] Unreachable nat entries [Ok..] [x]
+[FSCK] SIT valid block bitmap checking [Ok..]
+[FSCK] Hard link checking for regular file [Ok..] [x]
+[FSCK] valid_block_count matching with CP [Ok..] [x]
+[FSCK] valid_node_count matching with CP (de lookup) [Ok..] [x]
+[FSCK] valid_node_count matching with CP (nat lookup) [Ok..] [x]
+[FSCK] valid_inode_count matched with CP [Ok..] [x]
+[FSCK] free segment_count matched with CP [Ok..] [x]
+[FSCK] next block offset is free [Ok..]
+[FSCK] fixing SIT types
+[FSCK] other corrupted bugs [Ok..]
+
new file mode 100644
@@ -0,0 +1,58 @@
+#!/bin/sh
+
+DESC="inode with invalid i_addr"
+
+. $TOPDIR/tests/helpers
+
+cleanup pre > $LOG 2>&1
+make_f2fs >> $LOG 2>&1
+
+mkdir $TESTDIR/mntdir
+safe_mount $MNT_OPTS $META $TESTDIR/mntdir >> $LOG 2>&1
+if [ $? -ne 0 ]; then
+ echo "cannot mount f2fs image"
+ exit
+fi
+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 2>&1
+if [ $? -ne 0 ]; then
+ echo "cannot umount f2fs image"
+ exit
+fi
+rm -rf $TESTDIR/mntdir
+
+$DUMP $DUMP_OPTS -i $ino $META >> $LOG 2>&1
+blkaddr=`$DUMP $DUMP_OPTS -i $ino $META | grep "\[0x100\]" | sed 's/i_addr\[0x100\].*: \([0-9]*\)\]$/\1/g'`
+ext=`$DUMP $DUMP_OPTS -i $ino $META | grep i_ext:`
+pgofs=`echo $ext | sed 's/.*fofs:\([0-9]\+\).*/0x\1/g'`
+blk=`echo $ext | sed 's/.*blkaddr:\([0-9]\+\).*/0x\1/g'`
+len=`echo $ext | sed 's/.*len:\([0-9]\+\).*/0x\1/g'`
+echo "ino:$ino blkaddr:$blkaddr ext:$ext" >> $LOG
+
+$INJECT --node --nid $ino --mb i_addr --idx $((0x100)) --val 0x12345 $META >> $LOG 2>&1
+$FSCK $FSCK_OPTS -f $META > $OUT 2>&1
+$FSCK $FSCK_OPTS -f $META >> $OUT 2>&1
+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
+
+$DUMP $DUMP_OPTS -i $ino $META >> $LOG 2>&1
+new_blkaddr=`$DUMP $DUMP_OPTS -i $ino $META | grep "\[0x100\]" | sed 's/i_addr\[0x100\].*: \([0-9]*\)\]$/\1/g'`
+
+# 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
+cleanup post >> $LOG 2>&1
Signed-off-by: Sheng Yong <shengyong@oppo.com> --- tests/f_inode_bad_iaddr/README | 6 ++++ tests/f_inode_bad_iaddr/expect.in | 38 ++++++++++++++++++++ tests/f_inode_bad_iaddr/script | 58 +++++++++++++++++++++++++++++++ 3 files changed, 102 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