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