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