xfs: force file creation to the data device for certain layout tests
[xfstests-dev.git] / tests / xfs / 504
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0+
3 # Copyright (c) 2019, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 504
6 #
7 # Create a filesystem label with emoji and confusing unicode characters
8 # to make sure that these special things actually work on xfs.  In
9 # theory it should allow this (labels are a sequence of arbitrary bytes)
10 # even if the user implications are horrifying.
11 #
12 seq=`basename "$0"`
13 seqres="$RESULT_DIR/$seq"
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1    # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         cd /
24         rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30
31 _supported_fs xfs
32 _require_scratch_nocheck
33 _require_xfs_io_command 'label'
34
35 echo "Silence is golden."
36
37 want_scrub=
38 _check_xfs_scrub_does_unicode "$SCRATCH_MNT" "$SCRATCH_DEV" && want_scrub=yes
39
40 filter_scrub() {
41         grep 'Unicode' | sed -e 's/^.*Duplicate/Duplicate/g'
42 }
43
44 maybe_scrub() {
45         test "$want_scrub" = "yes" || return
46
47         output="$(LC_ALL="C.UTF-8" ${XFS_SCRUB_PROG} -v -n "${SCRATCH_MNT}" 2>&1)"
48         echo "xfs_scrub output:" >> $seqres.full
49         echo "$output" >> $seqres.full
50         echo "$output" >> $tmp.scrub
51 }
52
53 testlabel() {
54         local label="$(echo -e "$1")"
55         local expected_label="label = \"$label\""
56
57         echo "Formatting label '$1'." >> $seqres.full
58         # First, let's see if we can recover the label when we set it
59         # with mkfs.
60         _scratch_mkfs -L "$label" >> $seqres.full 2>&1
61         _scratch_mount >> $seqres.full 2>&1
62         blkid -s LABEL $SCRATCH_DEV | _filter_scratch | sed -e "s/ $//g" >> $seqres.full
63         blkid -d -s LABEL $SCRATCH_DEV | _filter_scratch | sed -e "s/ $//g" >> $seqres.full
64
65         # Did it actually stick?
66         local actual_label="$($XFS_IO_PROG -c label $SCRATCH_MNT)"
67         echo "$actual_label" >> $seqres.full
68
69         if [ "${actual_label}" != "${expected_label}" ]; then
70                 echo "Saw '${expected_label}', expected '${actual_label}'."
71         fi
72         maybe_scrub
73         _scratch_unmount
74
75         # Now let's try setting the label online to see what happens.
76         echo "Setting label '$1'." >> $seqres.full
77         _scratch_mkfs >> $seqres.full 2>&1
78         _scratch_mount >> $seqres.full 2>&1
79         $XFS_IO_PROG -c "label -s $label" $SCRATCH_MNT >> $seqres.full
80         blkid -s LABEL $SCRATCH_DEV | _filter_scratch | sed -e "s/ $//g" >> $seqres.full
81         blkid -d -s LABEL $SCRATCH_DEV | _filter_scratch | sed -e "s/ $//g" >> $seqres.full
82         _scratch_cycle_mount
83
84         # Did it actually stick?
85         local actual_label="$($XFS_IO_PROG -c label $SCRATCH_MNT)"
86         echo "$actual_label" >> $seqres.full
87
88         if [ "${actual_label}" != "${expected_label}" ]; then
89                 echo "Saw '${expected_label}'; expected '${actual_label}'."
90         fi
91         maybe_scrub
92         _scratch_unmount
93 }
94
95 # Simple test
96 testlabel "simple"
97
98 # Two different renderings of the same label
99 testlabel "caf\xc3\xa9.fs"
100 testlabel "cafe\xcc\x81.fs"
101
102 # Arabic code point can expand into a muuuch longer series
103 testlabel "xfs_\xef\xb7\xba.fs"
104
105 # Fake slash?
106 testlabel "urk\xc0\xafmoo"
107
108 # Emoji: octopus butterfly owl giraffe
109 testlabel "\xf0\x9f\xa6\x91\xf0\x9f\xa6\x8b\xf0\x9f\xa6\x89"
110
111 # unicode rtl widgets too...
112 testlabel "mo\xe2\x80\xaegnp.txt"
113 testlabel "motxt.png"
114
115 # mixed-script confusables
116 testlabel "mixed_t\xce\xbfp"
117 testlabel "mixed_top"
118
119 # single-script spoofing
120 testlabel "a\xe2\x80\x90b.fs"
121 testlabel "a-b.fs"
122
123 testlabel "dz_dze.fs"
124 testlabel "dz_\xca\xa3e.fs"
125
126 # symbols
127 testlabel "_Rs.fs"
128 testlabel "_\xe2\x82\xa8.fs"
129
130 # zero width joiners
131 testlabel "moocow.fs"
132 testlabel "moo\xe2\x80\x8dcow.fs"
133
134 # combining marks
135 testlabel "\xe1\x80\x9c\xe1\x80\xad\xe1\x80\xaf.fs"
136 testlabel "\xe1\x80\x9c\xe1\x80\xaf\xe1\x80\xad.fs"
137
138 # fake dotdot entry
139 testlabel ".\xe2\x80\x8d"
140 testlabel "..\xe2\x80\x8d"
141
142 # Did scrub choke on anything?
143 if [ "$want_scrub" = "yes" ]; then
144         grep -q "^Warning.*gnp.txt.*suspicious text direction" $tmp.scrub || \
145                 echo "No complaints about direction overrides?"
146         grep -q "^Warning.*control characters" $tmp.scrub || \
147                 echo "No complaints about control characters?"
148 fi
149
150 # success, all done
151 status=0
152 exit