4 # Test handling of invalid inode modes
6 # Set all possible file type values for different types of files
7 # and verify that xfs_repair detects the correct errors.
9 #-----------------------------------------------------------------------
11 # Copyright (C) 2016 CTERA Networks. All Rights Reserved.
12 # Author: Amir Goldstein <amir73il@gmail.com>
14 # This program is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License as
16 # published by the Free Software Foundation.
18 # This program is distributed in the hope that it would be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write the Free Software Foundation,
25 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #-----------------------------------------------------------------------
30 seqres=$RESULT_DIR/$seq
31 echo "QA output created by $seq"
34 status=1 # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
42 # get standard environment, filters and checks
47 # real QA test starts here
54 _scratch_mkfs >>$seqres.full 2>&1
58 # Create our test files.
59 testdir=$SCRATCH_MNT/test
62 echo 123 > $testdir/DATA
64 ln -s $testdir/DATA $testdir/SYMLINK
65 mknod $testdir/CHRDEV c 1 1
66 mknod $testdir/BLKDEV b 1 1
69 xfs_info $SCRATCH_MNT | grep -q "ftype=1" && FTYPE_FEATURE=1
71 # Record test dir inode for xfs_repair filter
74 pino=$(ls -id $testdir | awk '{print $1}')
75 echo "s/inode $pino/PARENT_INO/" >> $inode_filter
76 echo "s/directory $pino/directory PARENT_INO/" >> $inode_filter
79 # Record inode numbers for xfs_db commands and xfs_repair filter
80 for f in DIR DATA EMPTY SYMLINK CHRDEV BLKDEV FIFO; do
81 ino=$(ls -id $testdir/$f | awk '{print $1}')
83 echo "s/inode $ino/${f}_INO/" >> $inode_filter
88 # Possible mode file type values (mode & S_IFMT) >> 12
89 dtypes="0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17"
90 echo "===== Find inode by file type:"
92 # Set all our test files to dt value
93 for ino in $inodes; do
94 _scratch_xfs_db -c "inode $ino" -c "print core.mode" | \
95 grep -q "0${dt}0...$" && \
96 (echo "dt=$dt => inode $ino" | sed -f $inode_filter)
101 echo "===== Setting dt=$dt to all files:"
102 # Set all our test files to dt value
103 for ino in $inodes; do
104 _scratch_xfs_db -x -c "inode $ino" -c "write core.mode 0${dt}0644"
106 # Repair should detect the inconsistencies
107 # For invalid dt values, all files would have been junked.
108 # For valid dt values, one test file is expected to be valid.
109 # The rest would either have wrong format or non matching dir ftype.
110 _scratch_xfs_repair -n 2>&1 | tee -a $seqres.full | \
111 _filter_repair | grep "^would have junked" | sed -f $inode_filter | sort -u
112 # If ftype feature is enabled, when setting file type to one of the
113 # special types (i.e. FIFO(1), CHRDEV(2),BLKDEV(6),SOCKET(14)),
114 # xfs_repair is expected to detect ftype mismatch error. Otherewise,
115 # xfs_repair is not expected to detect ftype mismatch error.
116 if [ "$FTYPE_FEATURE" = 1 ] && (echo ':1:2:6:14:' | grep -q ":$dt:"); then
117 _scratch_xfs_repair -n 2>&1 | grep -q "^would fix ftype mismatch" || \
118 echo "xfs_repair should fix ftype mismatch"
120 _scratch_xfs_repair -n 2>&1 | grep -q -v "^would fix ftype mismatch" || \
121 echo "xfs_repair should not fix ftype mismatch"
125 # Repair should detect and junk all test files
126 _scratch_xfs_repair 2>&1 >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"