Update for message about the number of entries processed.
[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 _create_test_bed()
63 {
64         echo "*** create test bed"
65         touch $SCRATCH_MNT/reg
66         mkdir -p $SCRATCH_MNT/dir
67         ln -s $SCRATCH_MNT/dir $SCRATCH_MNT/lnk
68         mkdir $SCRATCH_MNT/dev
69         mknod $SCRATCH_MNT/dev/b b 0 0
70         mknod $SCRATCH_MNT/dev/c c 0 0
71         mknod $SCRATCH_MNT/dev/p p
72         # sanity check
73         find $SCRATCH_MNT | LC_COLLATE=POSIX sort
74 }
75
76 getfattr()
77 {
78         /usr/bin/getfattr $@ | sed -e \
79                 "s/$SCRATCH_MNT/SCRATCH_MNT/g"
80 }
81
82 setfattr()
83 {
84         /usr/bin/setfattr $@ | sed -e \
85                 "s/$SCRATCH_MNT/SCRATCH_MNT/g"
86 }
87
88 _require_scratch
89 [ -x /usr/bin/getfattr ] || _notrun "getfattr is not installed"
90 [ -x /usr/bin/setfattr ] || _notrun "setfattr is not installed"
91 rm -f $tmp.backup1 $tmp.backup2 $seq.full
92
93 # real QA test starts here
94 mkfs -t xfs -f $SCRATCH_DEV | _filter_mkfs 2>$tmp.mkfs
95 mount -t xfs $SCRATCH_DEV $SCRATCH_MNT || _fail "mount failed"
96 _create_test_bed
97
98 for nsp in user xfsroot; do
99         for inode in reg dir lnk dev/b dev/c dev/p; do
100
101                 echo; echo "=== TYPE $inode; NAMESPACE $nsp"; echo
102
103                 echo "*** set/get one initially empty attribute"
104                 setfattr -l -n $nsp.name $SCRATCH_MNT/$inode
105                 getfattr -al -d $SCRATCH_MNT/$inode
106
107                 echo "*** overwrite empty, set several new attributes"
108                 setfattr -l -n $nsp.name -v 0xbabe $SCRATCH_MNT/$inode
109                 setfattr -l -n $nsp.name2 -v 0xdeadbeef $SCRATCH_MNT/$inode
110                 setfattr -l -n $nsp.name3 -v 0xdeface $SCRATCH_MNT/$inode
111
112                 echo "*** fetch several attribute names and values (hex)"
113                 getfattr -al -d -e hex $SCRATCH_MNT/$inode
114
115                 echo "*** fetch several attribute names and values (base64)"
116                 getfattr -al -d -e base64 $SCRATCH_MNT/$inode
117
118                 echo "*** shrink value of an existing attribute"
119                 setfattr -l -n $nsp.name2 -v 0xdeaf $SCRATCH_MNT/$inode
120                 getfattr -al -d -e hex $SCRATCH_MNT/$inode
121
122                 echo "*** grow value of existing attribute"
123                 setfattr -l -n $nsp.name2 -v 0xdecade $SCRATCH_MNT/$inode
124                 getfattr -al -d -e hex $SCRATCH_MNT/$inode
125
126                 echo "*** set an empty value for second attribute"
127                 setfattr -l -n $nsp.name2 $SCRATCH_MNT/$inode
128                 getfattr -al -d -n $nsp.name2 $SCRATCH_MNT/$inode
129
130                 echo "*** overwrite empty value"
131                 setfattr -l -n $nsp.name2 -v 0xcafe $SCRATCH_MNT/$inode
132                 getfattr -al -d -e hex -n $nsp.name2 $SCRATCH_MNT/$inode
133
134                 echo "*** remove attribute"
135                 setfattr -l -x $nsp.name2 $SCRATCH_MNT/$inode
136                 getfattr -al -d -n $nsp.name2 $SCRATCH_MNT/$inode
137
138                 echo "*** final list (strings, type=$inode, nsp=$nsp)"
139                 getfattr -als -d $SCRATCH_MNT/$inode
140         done
141 done
142
143
144
145 # Test the directory descent code
146
147 echo; echo
148
149 _extend_test_bed()
150 {
151         echo "*** extend test bed"
152         # must set some descents' attributes to be useful
153         mkdir -p $SCRATCH_MNT/here/up/ascend
154         mkdir -p $SCRATCH_MNT/descend/down/here
155         find $SCRATCH_MNT/descend | xargs setfattr -n user.x -v yz
156         find $SCRATCH_MNT/descend | xargs setfattr -n user.1 -v 23
157         find $SCRATCH_MNT/here | xargs setfattr -n root.a -v bc
158         find $SCRATCH_MNT/here | xargs setfattr -n root.9 -v 87
159         # whack a symlink in the middle, just to be difficult
160         ln -s $SCRATCH_MNT/here/up $SCRATCH_MNT/descend/and
161         # dump out our new starting point
162         find $SCRATCH_MNT | LC_COLLATE=POSIX sort
163 }
164
165 _extend_test_bed
166
167 echo
168 echo "*** forward directory descent with us following symlinks"
169 getfattr -L -R -adls -e hex $SCRATCH_MNT
170
171 echo
172 echo "*** reverse directory descent with us following symlinks"
173 getfattr -L -R -5 -adls -e hex $SCRATCH_MNT
174
175 echo
176 echo "*** forward directory descent without following symlinks"
177 getfattr -P -R -adls -e hex $SCRATCH_MNT
178
179 echo
180 echo "*** reverse directory descent without following symlinks"
181 getfattr -P -R -5 -adls -e hex $SCRATCH_MNT
182
183
184
185 # Test the backup/restore code
186
187 echo; echo
188
189 _backup()
190 {
191         getfattr -a -sdlR $SCRATCH_MNT >$1
192         echo BACKUP $1 >>$seq.full
193         cat $1 >> $seq.full
194         [ ! -s $1 ] && echo "warning: $1 (backup file) is empty"
195 }
196
197 echo "*** backup everything"
198 _backup $tmp.backup1
199
200 echo "*** clear out the scratch device"
201 rm -fr $SCRATCH_MNT/*
202 echo "AFTER REMOVE" >>$seq.full
203 getfattr -L -R -adls $SCRATCH_MNT >>$seq.full
204
205 echo "*** reset test bed with no extended attributes"
206 _create_test_bed
207 _extend_test_bed
208
209 echo "*** restore everything"
210 setfattr -lB $tmp.backup1
211 _backup $tmp.backup2
212
213 echo "AFTER RESTORE" >>$seq.full
214 getfattr -L -R -adls $SCRATCH_MNT >>$seq.full
215
216 echo "*** compare before and after backups"
217 diff $tmp.backup1 $tmp.backup2
218 if [ $? -ne 0 ]; then
219         echo "urk, failed - creating $seq.backup1 and $seq.backup2"
220         cp $tmp.backup1 $seq.backup1 && cp $tmp.backup2 $seq.backup2
221         status=1
222         exit
223 fi
224
225 # success, all done
226 status=0
227 exit