fix _require_scratch test for extN, resierfs, gfs2, and btrfs
[xfstests-dev.git] / 062
1 #! /bin/sh
2 # FS QA Test No. 062
3 #
4 # Exercises the getfattr/setfattr tools
5 # Derived from tests originally written by Andreas Gruenbacher for ext2
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #
23 #-----------------------------------------------------------------------
24 #
25 # creator
26 owner=nathans@sgi.com
27
28 seq=`basename $0`
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34
35 # get standard environment, filters and checks
36 . ./common.rc
37 . ./common.filter
38
39 _cleanup()
40 {
41         cd /
42         echo; echo "*** unmount"
43         umount $SCRATCH_MNT 2>/dev/null
44         rm -f $tmp.*
45 }
46 trap "_cleanup; exit \$status" 0 1 2 3 15
47
48 _filter_scratch()
49 {
50             sed -e "s,$SCRATCH_MNT,SCRATCH_MNT,g"
51 }
52
53 _linux_attr_calls()
54 {
55     echo "*** set/get one initially empty attribute"
56     setfattr -h -n $nsp.name $SCRATCH_MNT/$inode
57     getfattr -m $nsp $SCRATCH_MNT/$inode
58
59     echo "*** overwrite empty, set several new attributes"
60     setfattr -h -n $nsp.name -v 0xbabe $SCRATCH_MNT/$inode
61     setfattr -h -n $nsp.name2 -v 0xdeadbeef $SCRATCH_MNT/$inode
62     setfattr -h -n $nsp.name3 -v 0xdeface $SCRATCH_MNT/$inode
63
64     echo "*** fetch several attribute names and values (hex)"
65     getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
66
67     echo "*** fetch several attribute names and values (base64)"
68     getfattr -m $nsp -e base64 $SCRATCH_MNT/$inode
69
70     echo "*** shrink value of an existing attribute"
71     setfattr -h -n $nsp.name2 -v 0xdeaf $SCRATCH_MNT/$inode
72     getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
73
74     echo "*** grow value of existing attribute"
75     setfattr -h -n $nsp.name2 -v 0xdecade $SCRATCH_MNT/$inode
76     getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
77
78     echo "*** set an empty value for second attribute"
79     setfattr -h -n $nsp.name2 $SCRATCH_MNT/$inode
80     getfattr -m $nsp -n $nsp.name2 $SCRATCH_MNT/$inode
81
82     echo "*** overwrite empty value"
83     setfattr -h -n $nsp.name2 -v 0xcafe $SCRATCH_MNT/$inode
84     getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode
85
86     echo "*** remove attribute"
87     setfattr -h -x $nsp.name2 $SCRATCH_MNT/$inode
88     getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode
89
90     echo "*** final list (strings, type=$inode, nsp=$nsp)"
91     getfattr -m '.' -e hex $SCRATCH_MNT/$inode
92 }
93
94 getfattr()
95 {
96     /usr/bin/getfattr --absolute-names -dh $@ 2>&1 | _filter_scratch
97 }
98
99 setfattr()
100 {
101     /usr/bin/setfattr $@ 2>&1 | _filter_scratch
102 }
103
104 _create_test_bed()
105 {
106         echo "*** create test bed"
107         touch $SCRATCH_MNT/reg
108         mkdir -p $SCRATCH_MNT/dir
109         ln -s $SCRATCH_MNT/dir $SCRATCH_MNT/lnk
110         mkdir $SCRATCH_MNT/dev
111         mknod $SCRATCH_MNT/dev/b b 0 0
112         mknod $SCRATCH_MNT/dev/c c 0 0
113         mknod $SCRATCH_MNT/dev/p p
114         # sanity check
115         find $SCRATCH_MNT | LC_COLLATE=POSIX sort | _filter_scratch
116 }
117
118 # real QA test starts here
119 _supported_fs xfs udf nfs
120 _supported_os Linux
121
122 _require_scratch
123 rm -f $tmp.backup1 $tmp.backup2 $seq.full
124
125 # real QA test starts here
126 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
127 _scratch_mount || _fail "mount failed"
128 _create_test_bed
129
130 if [ "$USE_ATTR_SECURE" = yes ]; then
131     ATTR_MODES="user security trusted"
132 else
133     ATTR_MODES="user trusted"
134 fi
135 for nsp in $ATTR_MODES; do
136         for inode in reg dir lnk dev/b dev/c dev/p; do
137
138                 echo; echo "=== TYPE $inode; NAMESPACE $nsp"; echo
139                 echo "*** set/get one initially empty attribute"
140     
141                 setfattr -h -n $nsp.name $SCRATCH_MNT/$inode
142                 getfattr -m $nsp $SCRATCH_MNT/$inode
143
144                 echo "*** overwrite empty, set several new attributes"
145                 setfattr -h -n $nsp.name -v 0xbabe $SCRATCH_MNT/$inode
146                 setfattr -h -n $nsp.name2 -v 0xdeadbeef $SCRATCH_MNT/$inode
147                 setfattr -h -n $nsp.name3 -v 0xdeface $SCRATCH_MNT/$inode
148
149                 echo "*** fetch several attribute names and values (hex)"
150                 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
151
152                 echo "*** fetch several attribute names and values (base64)"
153                 getfattr -m $nsp -e base64 $SCRATCH_MNT/$inode
154                 
155                 echo "*** shrink value of an existing attribute"
156                 setfattr -h -n $nsp.name2 -v 0xdeaf $SCRATCH_MNT/$inode
157                 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
158
159                 echo "*** grow value of existing attribute"
160                 setfattr -h -n $nsp.name2 -v 0xdecade $SCRATCH_MNT/$inode
161                 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
162                 
163                 echo "*** set an empty value for second attribute"
164                 setfattr -h -n $nsp.name2 $SCRATCH_MNT/$inode
165                 getfattr -m $nsp -n $nsp.name2 $SCRATCH_MNT/$inode
166
167                 echo "*** overwrite empty value"
168                 setfattr -h -n $nsp.name2 -v 0xcafe $SCRATCH_MNT/$inode
169                 getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode
170
171                 echo "*** remove attribute"
172                 setfattr -h -x $nsp.name2 $SCRATCH_MNT/$inode
173                 getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode
174
175                 echo "*** final list (strings, type=$inode, nsp=$nsp)"
176                 getfattr -m '.' -e hex $SCRATCH_MNT/$inode
177         
178         done
179 done
180
181
182
183 # Test the directory descent code
184
185 echo; echo
186
187 _extend_test_bed()
188 {
189         echo "*** extend test bed"
190         # must set some descents' attributes to be useful
191         mkdir -p $SCRATCH_MNT/here/up/ascend
192         mkdir -p $SCRATCH_MNT/descend/down/here
193         find $SCRATCH_MNT/descend | xargs setfattr -n user.x -v yz
194         find $SCRATCH_MNT/descend | xargs setfattr -n user.1 -v 23
195         find $SCRATCH_MNT/here | xargs setfattr -n trusted.a -v bc
196         find $SCRATCH_MNT/here | xargs setfattr -n trusted.9 -v 87
197         # whack a symlink in the middle, just to be difficult
198         ln -s $SCRATCH_MNT/here/up $SCRATCH_MNT/descend/and
199         # dump out our new starting point
200         find $SCRATCH_MNT | LC_COLLATE=POSIX sort | _filter_scratch
201 }
202
203 _extend_test_bed
204
205 echo
206 echo "*** directory descent with us following symlinks"
207 getfattr -h -L -R -m '.' -e hex $SCRATCH_MNT
208
209 echo
210 echo "*** directory descent without following symlinks"
211 getfattr -h -P -R -m '.' -e hex $SCRATCH_MNT
212
213
214
215 # Test the backup/restore code
216
217 echo; echo
218
219 _backup()
220 {
221         # NB: no filtering of scratch here... (need to restore too)
222         /usr/bin/getfattr --absolute-names -dh -R -m '.' $SCRATCH_MNT >$1
223         echo BACKUP $1 >>$seq.full
224         cat $1 >> $seq.full
225         [ ! -s $1 ] && echo "warning: $1 (backup file) is empty"
226 }
227
228 echo "*** backup everything"
229 _backup $tmp.backup1
230
231 echo "*** clear out the scratch device"
232 rm -fr $SCRATCH_MNT/*
233 echo "AFTER REMOVE" >>$seq.full
234 getfattr -L -R -m '.' $SCRATCH_MNT >>$seq.full
235
236 echo "*** reset test bed with no extended attributes"
237 _create_test_bed
238 _extend_test_bed
239
240 echo "*** restore everything"
241 setfattr -h --restore=$tmp.backup1
242 _backup $tmp.backup2
243
244 echo "AFTER RESTORE" >>$seq.full
245 getfattr -L -R -m '.' $SCRATCH_MNT >>$seq.full
246
247 echo "*** compare before and after backups"
248 diff $tmp.backup1 $tmp.backup2
249 if [ $? -ne 0 ]; then
250         echo "urk, failed - creating $seq.backup1 and $seq.backup2"
251         cp $tmp.backup1 $seq.backup1 && cp $tmp.backup2 $seq.backup2
252         status=1
253         exit
254 fi
255
256 # success, all done
257 status=0
258 exit