xfstests: remove dead code in test 062
[xfstests-dev.git] / 062
1 #! /bin/bash
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 . ./common.attr
39
40 _cleanup()
41 {
42         cd /
43         echo; echo "*** unmount"
44         umount $SCRATCH_MNT 2>/dev/null
45         rm -f $tmp.*
46 }
47 trap "_cleanup; exit \$status" 0 1 2 3 15
48
49 getfattr()
50 {
51     $GETFATTR_PROG --absolute-names -dh $@ 2>&1 | _filter_scratch
52 }
53
54 setfattr()
55 {
56     $SETFATTR_PROG $@ 2>&1 | _filter_scratch
57 }
58
59 _create_test_bed()
60 {
61         echo "*** create test bed"
62         touch $SCRATCH_MNT/reg
63         mkdir -p $SCRATCH_MNT/dir
64         ln -s $SCRATCH_MNT/dir $SCRATCH_MNT/lnk
65         mkdir $SCRATCH_MNT/dev
66         mknod $SCRATCH_MNT/dev/b b 0 0
67         mknod $SCRATCH_MNT/dev/c c 0 0
68         mknod $SCRATCH_MNT/dev/p p
69         # sanity check
70         find $SCRATCH_MNT | LC_COLLATE=POSIX sort | _filter_scratch
71 }
72
73 # real QA test starts here
74 _supported_fs xfs udf nfs
75 _supported_os Linux
76
77 _require_scratch
78 _require_attrs
79
80 rm -f $tmp.backup1 $tmp.backup2 $seq.full
81
82 # real QA test starts here
83 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
84 _scratch_mount || _fail "mount failed"
85 _create_test_bed
86
87 if [ "$USE_ATTR_SECURE" = yes ]; then
88     ATTR_MODES="user security trusted"
89 else
90     ATTR_MODES="user trusted"
91 fi
92 for nsp in $ATTR_MODES; do
93         for inode in reg dir lnk dev/b dev/c dev/p; do
94
95                 echo; echo "=== TYPE $inode; NAMESPACE $nsp"; echo
96                 echo "*** set/get one initially empty attribute"
97     
98                 setfattr -h -n $nsp.name $SCRATCH_MNT/$inode
99                 getfattr -m $nsp $SCRATCH_MNT/$inode
100
101                 echo "*** overwrite empty, set several new attributes"
102                 setfattr -h -n $nsp.name -v 0xbabe $SCRATCH_MNT/$inode
103                 setfattr -h -n $nsp.name2 -v 0xdeadbeef $SCRATCH_MNT/$inode
104                 setfattr -h -n $nsp.name3 -v 0xdeface $SCRATCH_MNT/$inode
105
106                 echo "*** fetch several attribute names and values (hex)"
107                 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
108
109                 echo "*** fetch several attribute names and values (base64)"
110                 getfattr -m $nsp -e base64 $SCRATCH_MNT/$inode
111                 
112                 echo "*** shrink value of an existing attribute"
113                 setfattr -h -n $nsp.name2 -v 0xdeaf $SCRATCH_MNT/$inode
114                 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
115
116                 echo "*** grow value of existing attribute"
117                 setfattr -h -n $nsp.name2 -v 0xdecade $SCRATCH_MNT/$inode
118                 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
119                 
120                 echo "*** set an empty value for second attribute"
121                 setfattr -h -n $nsp.name2 $SCRATCH_MNT/$inode
122                 getfattr -m $nsp -n $nsp.name2 $SCRATCH_MNT/$inode
123
124                 echo "*** overwrite empty value"
125                 setfattr -h -n $nsp.name2 -v 0xcafe $SCRATCH_MNT/$inode
126                 getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode
127
128                 echo "*** remove attribute"
129                 setfattr -h -x $nsp.name2 $SCRATCH_MNT/$inode
130                 getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode
131
132                 echo "*** final list (strings, type=$inode, nsp=$nsp)"
133                 getfattr -m '.' -e hex $SCRATCH_MNT/$inode
134         
135         done
136 done
137
138
139
140 # Test the directory descent code
141
142 echo; echo
143
144 _extend_test_bed()
145 {
146         echo "*** extend test bed"
147         # must set some descents' attributes to be useful
148         mkdir -p $SCRATCH_MNT/here/up/ascend
149         mkdir -p $SCRATCH_MNT/descend/down/here
150         find $SCRATCH_MNT/descend | xargs setfattr -n user.x -v yz
151         find $SCRATCH_MNT/descend | xargs setfattr -n user.1 -v 23
152         find $SCRATCH_MNT/here | xargs setfattr -n trusted.a -v bc
153         find $SCRATCH_MNT/here | xargs setfattr -n trusted.9 -v 87
154         # whack a symlink in the middle, just to be difficult
155         ln -s $SCRATCH_MNT/here/up $SCRATCH_MNT/descend/and
156         # dump out our new starting point
157         find $SCRATCH_MNT | LC_COLLATE=POSIX sort | _filter_scratch
158 }
159
160 _extend_test_bed
161
162 echo
163 echo "*** directory descent with us following symlinks"
164 getfattr -h -L -R -m '.' -e hex $SCRATCH_MNT
165
166 echo
167 echo "*** directory descent without following symlinks"
168 getfattr -h -P -R -m '.' -e hex $SCRATCH_MNT
169
170
171
172 # Test the backup/restore code
173
174 echo; echo
175
176 _backup()
177 {
178         # NB: no filtering of scratch here... (need to restore too)
179         $GETFATTR_PROG --absolute-names -dh -R -m '.' $SCRATCH_MNT >$1
180         echo BACKUP $1 >>$seq.full
181         cat $1 >> $seq.full
182         [ ! -s $1 ] && echo "warning: $1 (backup file) is empty"
183 }
184
185 echo "*** backup everything"
186 _backup $tmp.backup1
187
188 echo "*** clear out the scratch device"
189 rm -fr $SCRATCH_MNT/*
190 echo "AFTER REMOVE" >>$seq.full
191 getfattr -L -R -m '.' $SCRATCH_MNT >>$seq.full
192
193 echo "*** reset test bed with no extended attributes"
194 _create_test_bed
195 _extend_test_bed
196
197 echo "*** restore everything"
198 setfattr -h --restore=$tmp.backup1
199 _backup $tmp.backup2
200
201 echo "AFTER RESTORE" >>$seq.full
202 getfattr -L -R -m '.' $SCRATCH_MNT >>$seq.full
203
204 echo "*** compare before and after backups"
205 diff $tmp.backup1 $tmp.backup2
206 if [ $? -ne 0 ]; then
207         echo "urk, failed - creating $seq.backup1 and $seq.backup2"
208         cp $tmp.backup1 $seq.backup1 && cp $tmp.backup2 $seq.backup2
209         status=1
210         exit
211 fi
212
213 # success, all done
214 status=0
215 exit