xfs/530: skip test if user MKFS_OPTIONS screw up formatting
[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 . ./common/preamble
11 _begin_fstest auto quick fuzzers
12
13 # Override the default cleanup function.
14 _cleanup()
15 {
16         cd /
17         $UMOUNT_PROG $mntpt > /dev/null 2>&1
18         test -n "$loopdev" && _destroy_loop_device $loopdev > /dev/null 2>&1
19         rm -r -f $imgfile $mntpt $tmp.*
20 }
21
22 # Import common functions.
23 . ./common/filter
24 . ./common/attr
25
26 # real QA test starts here
27 _supported_fs xfs
28 _require_test
29 _require_attrs
30 _require_xfs_mkfs_crc
31 _disable_dmesg_check
32
33 imgfile=$TEST_DIR/img-$seq
34 mntpt=$TEST_DIR/mount-$seq
35 testdir=$mntpt/testdir
36 testfile=$mntpt/testfile
37 nullstr="too_many_beans"
38 slashstr="are_bad_for_you"
39 test_names=("something" "$nullstr" "$slashstr" "another")
40
41 # Format image file w/o crcs so we can sed the image file
42 $XFS_IO_PROG -f -c 'truncate 40m' $imgfile
43 loopdev=$(_create_loop_device $imgfile)
44 MKFS_OPTIONS="-m crc=0" _mkfs_dev $loopdev >> $seqres.full
45
46 # Mount image file
47 mkdir -p $mntpt
48 _mount $loopdev $mntpt
49
50 echo "creating entries" >> $seqres.full
51
52 # Create directory entries
53 mkdir -p $testdir
54 for name in "${test_names[@]}"; do
55         touch "$testdir/f_$name"
56 done
57
58 # Create attrs
59 touch $testfile
60 for name in "${test_names[@]}"; do
61         $ATTR_PROG -s "a_$name" -V heh $testfile >> $seqres.full
62 done
63
64 # Now put in the first part of the garbage names to make sure we can't
65 # access those directly
66 test_names+=("too_many" "are_bad/for_you")
67
68 access_stuff() {
69         ls $testdir
70         $ATTR_PROG -l $testfile | grep 'a_' | sort
71
72         for name in "${test_names[@]}"; do
73                 ls "$testdir/f_$name"
74                 $ATTR_PROG -g "a_$name" $testfile
75         done
76 }
77
78 # Does it work?
79 echo "++ ACCESSING GOOD METADATA" | tee -a $seqres.full
80 access_stuff > $tmp.log 2>&1
81 cat $tmp.log >> $seqres.full
82 cat $tmp.log | _filter_test_dir
83
84 # Corrupt the entries
85 $UMOUNT_PROG $mntpt
86 _destroy_loop_device $loopdev
87 cp $imgfile $imgfile.old
88 sed -b \
89         -e "s/$nullstr/too_many\x00beans/g" \
90         -e "s/$slashstr/are_bad\/for_you/g" \
91         -i $imgfile
92 test "$(md5sum < $imgfile)" != "$(md5sum < $imgfile.old)" ||
93         _fail "sed failed to change the image file?"
94 rm -f $imgfile.old
95 loopdev=$(_create_loop_device $imgfile)
96 _mount $loopdev $mntpt
97
98 # Try to access the corrupt metadata
99 echo "++ ACCESSING BAD METADATA" | tee -a $seqres.full
100 access_stuff > $tmp.log 2>&1
101 cat $tmp.log >> $seqres.full
102 cat $tmp.log | _filter_test_dir | sed -e '/Could not list/d'
103
104 echo "does scrub complain?" >> $seqres.full
105
106 # Does scrub complain about this?
107 if _supports_xfs_scrub $mntpt $loopdev; then
108         $XFS_SCRUB_PROG -n $mntpt >> $seqres.full 2>&1
109         res=$?
110         test $((res & 1)) -eq 0 && \
111                 echo "scrub failed to report corruption ($res)"
112 fi
113
114 echo "does repair complain?" >> $seqres.full
115
116 # Does repair complain about this?
117 $UMOUNT_PROG $mntpt
118 $XFS_REPAIR_PROG -n $loopdev >> $seqres.full 2>&1
119 res=$?
120 test $res -eq 1 || \
121         echo "repair failed to report corruption ($res)"
122
123 _destroy_loop_device $loopdev
124 loopdev=
125
126 # success, all done
127 status=0
128 exit