common/fuzzy: try to clear blocking flags first in _scratch_fuzz_modify
[xfstests-dev.git] / tests / generic / 020
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 020
6 #
7 # extended attributes
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=0        # success is the default!
16 trap "rm -f $tmp.* $testfile; exit \$status" 0 1 2 3 15
17
18 # get standard environment, filters and checks
19 . ./common/rc
20 . ./common/filter
21 . ./common/attr
22
23 _filter()
24 {
25     sed "s#$TEST_DIR[^ :]*#<TESTFILE>#g; 
26             s#$tmp[^ :]*#<TMPFILE>#g" $1
27 }
28
29 _attr()
30 {
31     $ATTR_PROG $* 2>$tmp.err >$tmp.out
32     exit=$?
33     _filter $tmp.out
34     _filter $tmp.err 1>&2
35     return $exit
36 }
37
38 do_getfattr()
39 {
40     _getfattr $* 2>$tmp.err >$tmp.out
41     exit=$?
42     _filter $tmp.out
43     _filter $tmp.err 1>&2
44     return $exit
45 }
46
47 _attr_list()
48 {
49     file=$1
50     
51     echo "   *** print attributes"
52     if ! do_getfattr -d -e text --absolute-names $file
53     then
54         echo "      !!! error return"
55         return 1
56     fi
57 }
58
59 # real QA test starts here
60 _supported_fs generic
61 _supported_os Linux
62
63 _require_test
64 _require_attrs
65
66 rm -f $seqres.full
67
68 testfile=$TEST_DIR/attribute_$$
69
70 echo "*** list non-existant file"
71 _attr_list $testfile
72
73 echo "*** list empty file"
74 touch $testfile
75 _attr_list $testfile
76
77 echo "*** query non-existant attribute"
78 _attr -g "nonexistant" $testfile 2>&1
79
80 echo "*** one attribute"
81 echo "fish" | _attr -s fish $testfile
82 _attr_list $testfile
83
84 echo "*** replace attribute"
85 echo "fish3" | _attr -s fish $testfile
86 _attr_list $testfile
87
88 echo "*** add attribute"
89 echo "fish2" | _attr -s snrub $testfile
90 _attr_list $testfile
91
92 echo "*** remove attribute"
93 _attr -r fish $testfile
94 _attr_list $testfile
95
96 echo "*** add lots of attributes"
97 v=0
98
99 while [ $v -lt $MAX_ATTRS ]
100 do
101     echo -n "value_$v" | attr -s "attribute_$v" $testfile >>$seqres.full
102     if [ $? -ne 0 ]
103     then
104         echo "!!! failed to add \"attribute_$v\""
105         exit 1
106     fi
107     
108     let "v = v + 1"
109 done
110
111 echo "*** check"
112 # don't print it all out...
113 _getfattr --absolute-names $testfile \
114     | tee -a $seqres.full \
115     | $AWK_PROG '
116         /^#/ { next }
117         /^[     ]*$/ { next }
118         { l++ } 
119         END {print "   *** " (l - 1) " attribute(s)" }' \
120     | sed s/$MAX_ATTRS/MAX_ATTRS/
121
122 echo "*** remove lots of attributes"
123 v=0
124 while [ $v -lt $MAX_ATTRS ]
125 do
126     if ! $ATTR_PROG -r "attribute_$v" $testfile >>$seqres.full
127     then
128         echo "!!! failed to remove \"attribute_$v\""
129         exit 1
130     fi
131     
132     let "v = v + 1"
133 done
134
135 _attr_list $testfile
136
137 echo "*** really long value"
138 dd if=/dev/zero bs=1 count=$MAX_ATTRVAL_SIZE 2>/dev/null \
139     | _attr -s "long_attr" $testfile >/dev/null
140
141 OCTAL_SIZE=`echo "obase=8; $MAX_ATTRVAL_SIZE" | bc`
142 _attr -q -g "long_attr" $testfile | od -t x1 | sed -e "s/^0*$OCTAL_SIZE$/ATTRSIZE/"    
143 _attr -r "long_attr" $testfile >/dev/null
144
145 echo "*** set/get/remove really long names (expect failure)"
146 short="XXXXXXXXXX"
147 long="$short$short$short$short$short$short$short$short$short$short"
148 vlong="$long$long$long"
149
150 _attr -s $vlong -V fish $testfile 2>&1 >/dev/null
151 _attr -g $vlong $testfile 2>&1 >/dev/null
152 _attr -r $vlong $testfile 2>&1 >/dev/null
153
154 echo "*** check final"
155
156 _attr_list $testfile
157
158 echo "*** delete"
159 rm -f $testfile
160
161 exit