Add GPL license plate to SGI's files.
[xfstests-dev.git] / 020
1 #! /bin/sh
2 # FS QA Test No. 020
3 #
4 # extended attributes
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #
22 #-----------------------------------------------------------------------
23 #
24 # creator
25 owner=dxm@sgi.com
26
27 seq=`basename $0`
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=0        # success is the default!
33 trap "_cleanup; rm -f $tmp.* $testfile; exit \$status" 0 1 2 3 15
34
35 # get standard environment, filters and checks
36 . ./common.rc
37 . ./common.filter
38
39 _cleanup()
40 {
41     _cleanup_testdir
42 }
43
44 _filter()
45 {
46     sed "s#$testdir[^ :]*#<TESTFILE>#g; 
47             s#$tmp[^ :]*#<TMPFILE>#g" $1
48 }
49
50 _attr()
51 {
52     attr $* 2>$tmp.err >$tmp.out
53     exit=$?
54     _filter $tmp.out
55     _filter $tmp.err 1>&2
56     return $exit
57 }
58
59 _getfattr()
60 {
61     getfattr $* 2>$tmp.err >$tmp.out
62     exit=$?
63     _filter $tmp.out
64     _filter $tmp.err 1>&2
65     return $exit
66 }
67
68 _attr_list()
69 {
70     file=$1
71     
72     echo "   *** print attributes"
73     if ! _getfattr -d -e text --absolute-names $file
74     then
75         echo "      !!! error return"
76         return 1
77     fi
78 }
79
80
81 # real QA test starts here
82 _supported_fs xfs udf
83 _supported_os Linux
84
85 [ -x /usr/bin/attr ] || _notrun "attr is not installed"
86 [ -x /usr/bin/getfattr ] || _notrun "getfattr is not installed"
87
88 _setup_testdir
89
90 rm -f $seq.full
91
92 testfile=$testdir/attribute_$$
93
94 echo "*** list non-existant file"
95 _attr_list $testfile
96
97 echo "*** list empty file"
98 touch $testfile
99 _attr_list $testfile
100
101 echo "*** query non-existant attribute"
102 _attr -g "nonexistant" $testfile 2>&1
103
104 echo "*** one attribute"
105 echo "fish" | _attr -s fish $testfile
106 _attr_list $testfile
107
108 echo "*** replace attribute"
109 echo "fish3" | _attr -s fish $testfile
110 _attr_list $testfile
111
112 echo "*** add attribute"
113 echo "fish2" | _attr -s snrub $testfile
114 _attr_list $testfile
115
116 echo "*** remove attribute"
117 _attr -r fish $testfile
118 _attr_list $testfile
119
120 echo "*** add lots of attributes"
121 v=0
122 while [ $v -lt 1000 ]
123 do
124     echo "value_$v" | attr -s "attribute_$v" $testfile >>$seq.full
125     if [ $? -ne 0 ]
126     then
127         echo "!!! failed to add \"attribute_$v\""
128         exit 1
129     fi
130     
131     let "v = v + 1"
132 done
133
134 echo "*** check"
135 # don't print it all out...
136 getfattr --absolute-names $testfile \
137     | tee -a $seq.full \
138     | $AWK_PROG '
139         /^#/ { next }
140         /^[     ]*$/ { next }
141         { l++ } 
142         END {print "   *** " (l - 1) " attribute(s)" }'
143
144 echo "*** remove lots of attributes"
145 v=0
146 while [ $v -lt 1000 ]
147 do
148     if ! attr -r "attribute_$v" $testfile >>$seq.full
149     then
150         echo "!!! failed to remove \"attribute_$v\""
151         exit 1
152     fi
153     
154     let "v = v + 1"
155 done
156
157 _attr_list $testfile
158
159 echo "*** really long value"
160 dd if=/dev/zero bs=1024 count=100 2>/dev/null \
161     | _attr -s "long_attr" $testfile >/dev/null
162     
163 _attr -g "long_attr" $testfile | tail -n +2 | od -t x1
164 _attr -r "long_attr" $testfile >/dev/null
165
166
167 echo "*** set/get/remove really long names (expect failure)"
168 short="XXXXXXXXXX"
169 long="$short$short$short$short$short$short$short$short$short$short"
170 vlong="$long$long$long"
171
172 _attr -s $vlong -V fish $testfile 2>&1 >/dev/null
173 _attr -g $vlong $testfile 2>&1 >/dev/null
174 _attr -r $vlong $testfile 2>&1 >/dev/null
175
176 echo "*** check final"
177
178 _attr_list $testfile
179
180 echo "*** delete"
181 rm -f $testfile
182
183 exit