Test that fsync/sync force file size changes to disk.
[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" $1
34 }
35
36 _attr()
37 {
38     attr $* 2>$tmp.err >$tmp.out
39     exit=$?
40     _filter $tmp.out
41     _filter $tmp.err 1>&2
42     return $exit
43 }
44
45 _getfattr()
46 {
47     getfattr $* 2>$tmp.err >$tmp.out
48     exit=$?
49     _filter $tmp.out
50     _filter $tmp.err 1>&2
51     return $exit
52 }
53
54 _attr_list()
55 {
56     file=$1
57     
58     echo "   *** print attributes"
59     if ! _getfattr -d -e text --absolute-names $file
60     then
61         echo "      !!! error return"
62         return 1
63     fi
64 }
65
66
67 # real QA test starts here
68 _supported_fs xfs udf
69 _supported_os Linux
70
71 [ -x /usr/bin/attr ] || _notrun "attr is not installed"
72 [ -x /usr/bin/getfattr ] || _notrun "getfattr is not installed"
73
74 _setup_testdir
75
76 rm -f $seq.full
77
78 testfile=$testdir/attribute_$$
79
80 echo "*** list non-existant file"
81 _attr_list $testfile
82
83 echo "*** list empty file"
84 touch $testfile
85 _attr_list $testfile
86
87 echo "*** query non-existant attribute"
88 _attr -g "nonexistant" $testfile 2>&1
89
90 echo "*** one attribute"
91 echo "fish" | _attr -s fish $testfile
92 _attr_list $testfile
93
94 echo "*** replace attribute"
95 echo "fish3" | _attr -s fish $testfile
96 _attr_list $testfile
97
98 echo "*** add attribute"
99 echo "fish2" | _attr -s snrub $testfile
100 _attr_list $testfile
101
102 echo "*** remove attribute"
103 _attr -r fish $testfile
104 _attr_list $testfile
105
106 echo "*** add lots of attributes"
107 v=0
108 while [ $v -lt 1000 ]
109 do
110     echo "value_$v" | attr -s "attribute_$v" $testfile >>$seq.full
111     if [ $? -ne 0 ]
112     then
113         echo "!!! failed to add \"attribute_$v\""
114         exit 1
115     fi
116     
117     let "v = v + 1"
118 done
119
120 echo "*** check"
121 # don't print it all out...
122 getfattr --absolute-names $testfile \
123     | tee -a $seq.full \
124     | $AWK_PROG '
125         /^#/ { next }
126         /^[     ]*$/ { next }
127         { l++ } 
128         END {print "   *** " (l - 1) " attribute(s)" }'
129
130 echo "*** remove lots of attributes"
131 v=0
132 while [ $v -lt 1000 ]
133 do
134     if ! attr -r "attribute_$v" $testfile >>$seq.full
135     then
136         echo "!!! failed to remove \"attribute_$v\""
137         exit 1
138     fi
139     
140     let "v = v + 1"
141 done
142
143 _attr_list $testfile
144
145 echo "*** really long value"
146 dd if=/dev/zero bs=1024 count=100 2>/dev/null \
147     | _attr -s "long_attr" $testfile >/dev/null
148     
149 _attr -g "long_attr" $testfile | tail -n +2 | od -t x1
150 _attr -r "long_attr" $testfile >/dev/null
151
152
153 echo "*** set/get/remove really long names (expect failure)"
154 short="XXXXXXXXXX"
155 long="$short$short$short$short$short$short$short$short$short$short"
156 vlong="$long$long$long"
157
158 _attr -s $vlong -V fish $testfile 2>&1 >/dev/null
159 _attr -g $vlong $testfile 2>&1 >/dev/null
160 _attr -r $vlong $testfile 2>&1 >/dev/null
161
162 echo "*** check final"
163
164 _attr_list $testfile
165
166 echo "*** delete"
167 rm -f $testfile
168
169 exit