Switch to always using get/setxattr rather than a separate projid call on IRIX.
[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 #
10 # creator
11 owner=dxm@sgi.com
12
13 seq=`basename $0`
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=0        # success is the default!
19 trap "_cleanup; rm -f $tmp.* $testfile; exit \$status" 0 1 2 3 15
20
21 # get standard environment, filters and checks
22 . ./common.rc
23 . ./common.filter
24
25 _cleanup()
26 {
27     _cleanup_testdir
28 }
29
30 _filter()
31 {
32     sed "s#$testdir[^ :]*#<TESTFILE>#g; 
33             s#$tmp[^ :]*#<TMPFILE>#g;
34             s#/proc[^ :]*#<PROCFILE>#g" $1
35 }
36
37 _attr()
38 {
39     attr $* 2>$tmp.err >$tmp.out
40     exit=$?
41     _filter $tmp.out
42     _filter $tmp.err 1>&2
43     return $exit
44 }
45
46 _getfattr()
47 {
48     getfattr $* 2>$tmp.err >$tmp.out
49     exit=$?
50     _filter $tmp.out
51     _filter $tmp.err 1>&2
52     return $exit
53 }
54
55 _attr_list()
56 {
57     file=$1
58     
59     echo "   *** print attributes"
60     if ! _getfattr -d -e text --absolute-names $file
61     then
62         echo "      !!! error return"
63         return 1
64     fi
65 }
66
67
68 # real QA test starts here
69 _supported_fs xfs udf
70 _supported_os Linux
71
72 [ -x /usr/bin/attr ] || _notrun "attr is not installed"
73 [ -x /usr/bin/getfattr ] || _notrun "getfattr is not installed"
74
75 _setup_testdir
76
77 rm -f $seq.full
78
79 testfile=$testdir/attribute_$$
80
81 echo "*** list non-existant file"
82 _attr_list $testfile
83
84 echo "*** list non-xfs file (in /proc)"
85 _attr_list /proc/devices
86
87 echo "*** list empty file"
88 touch $testfile
89 _attr_list $testfile
90
91 echo "*** query non-existant attribute"
92 _attr -g "nonexistant" $testfile 2>&1
93
94 echo "*** one attribute"
95 echo "fish" | _attr -s fish $testfile
96 _attr_list $testfile
97
98 echo "*** replace attribute"
99 echo "fish3" | _attr -s fish $testfile
100 _attr_list $testfile
101
102 echo "*** add attribute"
103 echo "fish2" | _attr -s snrub $testfile
104 _attr_list $testfile
105
106 echo "*** remove attribute"
107 _attr -r fish $testfile
108 _attr_list $testfile
109
110 echo "*** add lots of attributes"
111 v=0
112 while [ $v -lt 1000 ]
113 do
114     echo "value_$v" | attr -s "attribute_$v" $testfile >>$seq.full
115     if [ $? -ne 0 ]
116     then
117         echo "!!! failed to add \"attribute_$v\""
118         exit 1
119     fi
120     
121     let "v = v + 1"
122 done
123
124 echo "*** check"
125 # don't print it all out...
126 getfattr --absolute-names $testfile \
127     | tee -a $seq.full \
128     | $AWK_PROG '
129         /^#/ { next }
130         /^[     ]*$/ { next }
131         { l++ } 
132         END {print "   *** " (l - 1) " attribute(s)" }'
133
134 echo "*** remove lots of attributes"
135 v=0
136 while [ $v -lt 1000 ]
137 do
138     if ! attr -r "attribute_$v" $testfile >>$seq.full
139     then
140         echo "!!! failed to remove \"attribute_$v\""
141         exit 1
142     fi
143     
144     let "v = v + 1"
145 done
146
147 _attr_list $testfile
148
149 echo "*** really long value"
150 dd if=/dev/zero bs=1024 count=100 2>/dev/null \
151     | _attr -s "long_attr" $testfile >/dev/null
152     
153 _attr -g "long_attr" $testfile | tail -n +2 | od -t x1
154 _attr -r "long_attr" $testfile >/dev/null
155
156
157 echo "*** set/get/remove really long names (expect failure)"
158 short="XXXXXXXXXX"
159 long="$short$short$short$short$short$short$short$short$short$short"
160 vlong="$long$long$long"
161
162 _attr -s $vlong -V fish $testfile 2>&1 >/dev/null
163 _attr -g $vlong $testfile 2>&1 >/dev/null
164 _attr -r $vlong $testfile 2>&1 >/dev/null
165
166 echo "*** check final"
167
168 _attr_list $testfile
169
170 echo "*** delete"
171 rm -f $testfile
172
173 exit