Signed-off-by: Sheng Yong <shengy...@oppo.com> --- tests/f_dentry_dup_dots/README | 11 +++ tests/f_dentry_dup_dots/expect.in | 150 ++++++++++++++++++++++++++++++ tests/f_dentry_dup_dots/script | 58 ++++++++++++ 3 files changed, 219 insertions(+) create mode 100644 tests/f_dentry_dup_dots/README create mode 100644 tests/f_dentry_dup_dots/expect.in create mode 100644 tests/f_dentry_dup_dots/script
diff --git a/tests/f_dentry_dup_dots/README b/tests/f_dentry_dup_dots/README new file mode 100644 index 000000000000..54304051d548 --- /dev/null +++ b/tests/f_dentry_dup_dots/README @@ -0,0 +1,11 @@ +1. create f2fs image +2. mount f2fs +3. create a directory, and create a file in it +4. inject dot dentry in the directory by changing its d_ino to the dotdot's ino +5. fsck fixes the dot's d_ino +6. inject dotdot dentry in the directory by changing its d_ino to the dot's ino +7. fsck fixes the dotdot's d_ino +8. inject dot dentry in the directory by changing its filename to ".." +9. fsck fixes it by deleting duplicated dotdot dentry and adding a new dot dentry +10. inject dotdot dentry in the directory by changing its filename to the "." +11. fsck fixes it by deleting duplicated dot dentry and adding a new dotdot dentry diff --git a/tests/f_dentry_dup_dots/expect.in b/tests/f_dentry_dup_dots/expect.in new file mode 100644 index 000000000000..ce2a45c09080 --- /dev/null +++ b/tests/f_dentry_dup_dots/expect.in @@ -0,0 +1,150 @@ +Info: Force to fix corruption +Info: checkpoint state = x : nat_bits crc compacted_summary unmount +[ASSERT] (__chk_dots_dentries:x) --> Bad inode number[_PINO_HEX_] for '.', parent_ino is [_INO_HEX_] + + +[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 [Fail] +Info: Duplicate valid checkpoint to mirror position x -> x +Info: Write valid nat_bits in checkpoint +Info: write_checkpoint() cur_cp: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..] + +Info: Force to fix corruption +Info: checkpoint state = x : allow_nocrc nat_bits unmount +[ASSERT] (__chk_dots_dentries:x) --> Bad inode number[_INO_HEX_] for '..', parent parent ino is [_PINO_HEX_] + + +[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 [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..] + +Info: Force to fix corruption +Info: checkpoint state = x : allow_nocrc nat_bits unmount +[ASSERT] (__chk_dots_dentries:x) --> Bad inode number[_INO_HEX_] for '..', parent parent ino is [_PINO_HEX_] + +[ASSERT] (__chk_dentries:x) --> More than one '..', should delete the extra one, i: 1, ino:_PINO_DEC_ +[ASSERT] (fsck_chk_inode_blk:x) --> ino: _INO_HEX_ has no '.' and/or '..' dirents, dot: 0, dotdot: 1 +[FIX] (fsck_chk_inode_blk:x) --> convert inline dentry ino: _INO_DEC_, pino: _PINO_DEC_, ret: 0 +[FIX] (fsck_chk_inode_blk:x) --> add missing '.' dirent in ino: _INO_DEC_, pino: _PINO_DEC_, ret:0 + +[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 [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..] + +Info: Force to fix corruption +Info: checkpoint state = x : allow_nocrc nat_bits unmount +[ASSERT] (__chk_dots_dentries:x) --> Bad inode number[_PINO_HEX_] for '.', parent_ino is [_INO_HEX_] + +[ASSERT] (__chk_dentries:x) --> More than one '.', should delete the extra one, i: 1, ino:_INO_DEC_ +[ASSERT] (fsck_chk_inode_blk:x) --> ino: _INO_HEX_ has no '.' and/or '..' dirents, dot: 1, dotdot: 0 +[FIX] (fsck_chk_inode_blk:x) --> convert inline dentry ino: _INO_DEC_, pino: _PINO_DEC_, ret: 0 +[FIX] (fsck_chk_inode_blk:x) --> add missing '..' dirent in ino: _INO_DEC_, pino: _PINO_DEC_, ret:0 + +[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 [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..] + diff --git a/tests/f_dentry_dup_dots/script b/tests/f_dentry_dup_dots/script new file mode 100644 index 000000000000..6f6a92cb2843 --- /dev/null +++ b/tests/f_dentry_dup_dots/script @@ -0,0 +1,58 @@ +#!/bin/bash + +DESC="directory duplicated dot or dotdot" + +. $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 +mkdir $TESTDIR/mntdir/testdir +touch $TESTDIR/mntdir/testdir/testfile +ino=`stat -c "%i" $TESTDIR/mntdir/testdir` +pino=`stat -c "%i" $TESTDIR/mntdir/testdir/..` +safe_umount $TESTDIR/mntdir >> $LOG 2>&1 +if [ $? -ne 0 ]; then + echo "cannot umount f2fs image" + exit +fi +rm -rf $TESTDIR/mntdir + +echo "ino:$ino pino:$pino" >> $LOG + +# inject dot's d_ino +$INJECT --dent --nid $ino --mb d_ino --dots 1 --val $pino $META >> $LOG 2>&1 +$FSCK $FSCK_OPTS -f $META > $OUT 2>&1 +$FSCK $FSCK_OPTS -f $META >> $OUT 2>&1 + +# inject dotdot's d_ino +$INJECT --dent --nid $ino --mb d_ino --dots 2 --val $ino $META >> $LOG 2>&1 +$FSCK $FSCK_OPTS -f $META >> $OUT 2>&1 +$FSCK $FSCK_OPTS -f $META >> $OUT 2>&1 + +# inject dot's filename +$INJECT --dent --nid $ino --mb filename --dots 1 --str ".." $META >> $LOG 2>&1 +$FSCK $FSCK_OPTS -f $META >> $OUT 2>&1 +$FSCK $FSCK_OPTS -f $META >> $OUT 2>&1 + +# inject dotdot's filename +$INJECT --dent --nid $ino --mb filename --dots 2 --str "." $META >> $LOG 2>&1 +$FSCK $FSCK_OPTS -f $META >> $OUT 2>&1 +$FSCK $FSCK_OPTS -f $META >> $OUT 2>&1 +cat $OUT >> $LOG + +INO_HEX=`printf "0x%x" $ino` +PINO_HEX=`printf "0x%x" $pino` +sed "s/_INO_DEC_/$ino/g" $TESTDIR/expect.in > $TESTDIR/expect +sed -i "s/_PINO_DEC_/$pino/g" $TESTDIR/expect +sed -i "s/_INO_HEX_/$INO_HEX/g" $TESTDIR/expect +sed -i "s/_PINO_HEX_/$PINO_HEX/g" $TESTDIR/expect + +check_result +cleanup post >> $LOG 2>&1 -- 2.40.1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel