42cfdab0e39a8aee61f1ba70fcf64be43639c8fd
[xfstests-dev.git] / tests / xfs / 148
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0-or-newer
3 # Copyright (c) 2019, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 148
6 #
7 # See if we catch corrupt directory names or attr names with nulls or slashes
8 # in them.
9
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1    # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         $UMOUNT_PROG $mntpt > /dev/null 2>&1
23         test -n "$loopdev" && _destroy_loop_device $loopdev > /dev/null 2>&1
24         rm -r -f $imgfile $mntpt $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30 . ./common/attr
31
32 # real QA test starts here
33 _supported_fs xfs
34 _supported_os Linux
35 _require_test
36 _require_attrs
37 _require_xfs_mkfs_crc
38 _disable_dmesg_check
39
40 rm -f $seqres.full
41
42 imgfile=$TEST_DIR/img-$seq
43 mntpt=$TEST_DIR/mount-$seq
44 testdir=$mntpt/testdir
45 testfile=$mntpt/testfile
46 nullstr="too_many_beans"
47 slashstr="are_bad_for_you"
48 test_names=("something" "$nullstr" "$slashstr" "another")
49
50 # Format image file w/o crcs so we can sed the image file
51 $XFS_IO_PROG -f -c 'truncate 40m' $imgfile
52 loopdev=$(_create_loop_device $imgfile)
53 MKFS_OPTIONS="-m crc=0" _mkfs_dev $loopdev >> $seqres.full
54
55 # Mount image file
56 mkdir -p $mntpt
57 _mount $loopdev $mntpt
58
59 echo "creating entries" >> $seqres.full
60
61 # Create directory entries
62 mkdir -p $testdir
63 for name in "${test_names[@]}"; do
64         touch "$testdir/f_$name"
65 done
66
67 # Create attrs
68 touch $testfile
69 for name in "${test_names[@]}"; do
70         $ATTR_PROG -s "a_$name" -V heh $testfile >> $seqres.full
71 done
72
73 # Now put in the first part of the garbage names to make sure we can't
74 # access those directly
75 test_names+=("too_many" "are_bad/for_you")
76
77 access_stuff() {
78         ls $testdir
79         $ATTR_PROG -l $testfile
80
81         for name in "${test_names[@]}"; do
82                 ls "$testdir/f_$name"
83                 $ATTR_PROG -g "a_$name" $testfile
84         done
85 }
86
87 # Does it work?
88 echo "++ ACCESSING GOOD METADATA" | tee -a $seqres.full
89 access_stuff > $tmp.log 2>&1
90 cat $tmp.log >> $seqres.full
91 cat $tmp.log | _filter_test_dir
92
93 # Corrupt the entries
94 $UMOUNT_PROG $mntpt
95 _destroy_loop_device $loopdev
96 cp $imgfile $imgfile.old
97 sed -b \
98         -e "s/$nullstr/too_many\x00beans/g" \
99         -e "s/$slashstr/are_bad\/for_you/g" \
100         -i $imgfile
101 test "$(md5sum < $imgfile)" != "$(md5sum < $imgfile.old)" ||
102         _fail "sed failed to change the image file?"
103 rm -f $imgfile.old
104 loopdev=$(_create_loop_device $imgfile)
105 _mount $loopdev $mntpt
106
107 # Try to access the corrupt metadata
108 echo "++ ACCESSING BAD METADATA" | tee -a $seqres.full
109 access_stuff > $tmp.log 2>&1
110 cat $tmp.log >> $seqres.full
111 cat $tmp.log | _filter_test_dir | sed -e '/Could not list/d'
112
113 echo "does scrub complain?" >> $seqres.full
114
115 # Does scrub complain about this?
116 if _supports_xfs_scrub $mntpt $loopdev; then
117         $XFS_SCRUB_PROG -n $mntpt >> $seqres.full 2>&1
118         res=$?
119         test $((res & 1)) -eq 0 && \
120                 echo "scrub failed to report corruption ($res)"
121 fi
122
123 echo "does repair complain?" >> $seqres.full
124
125 # Does repair complain about this?
126 $UMOUNT_PROG $mntpt
127 $XFS_REPAIR_PROG -n $loopdev >> $seqres.full 2>&1
128 res=$?
129 test $res -eq 1 || \
130         echo "repair failed to report corruption ($res)"
131
132 _destroy_loop_device $loopdev
133 loopdev=
134
135 # success, all done
136 status=0
137 exit