5 # Exercises the getfattr/setfattr tools
6 # Derived from tests originally written by Andreas Gruenbacher for ext2
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2001 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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.
30 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
31 # Mountain View, CA 94043, or:
35 # For further information regarding this notice, see:
37 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
38 #-----------------------------------------------------------------------
44 echo "QA output created by $seq"
48 status=1 # failure is the default!
50 # get standard environment, filters and checks
56 echo; echo "*** unmount"
57 umount $SCRATCH_MNT 2>/dev/null
60 trap "_cleanup; exit \$status" 0 1 2 3 15
64 sed -e "s,$SCRATCH_MNT,SCRATCH_MNT,g"
69 /usr/bin/getfattr -adl $@ 2>&1 | _filter_scratch
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
88 find $SCRATCH_MNT | LC_COLLATE=POSIX sort | _filter_scratch
92 rm -f $tmp.backup1 $tmp.backup2 $seq.full
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"
99 for nsp in user xfsroot; do
100 for inode in reg dir lnk dev/b dev/c dev/p; do
102 echo; echo "=== TYPE $inode; NAMESPACE $nsp"; echo
104 echo "*** set/get one initially empty attribute"
105 setfattr -l -n $nsp.name $SCRATCH_MNT/$inode
106 getfattr -r $nsp $SCRATCH_MNT/$inode
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
113 echo "*** fetch several attribute names and values (hex)"
114 getfattr -r $nsp -e hex $SCRATCH_MNT/$inode
116 echo "*** fetch several attribute names and values (base64)"
117 getfattr -r $nsp -e base64 $SCRATCH_MNT/$inode
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
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
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
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
135 echo "*** remove attribute"
136 setfattr -l -x $nsp.name2 $SCRATCH_MNT/$inode
137 getfattr -r $nsp -n $nsp.name2 $SCRATCH_MNT/$inode
139 echo "*** final list (strings, type=$inode, nsp=$nsp)"
140 getfattr -r '^user|^xfsroot' $SCRATCH_MNT/$inode
146 # Test the directory descent code
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
169 echo "*** forward directory descent with us following symlinks"
170 getfattr -L -R -r '^user|^xfsroot' -e hex $SCRATCH_MNT
173 echo "*** reverse directory descent with us following symlinks"
174 getfattr -L -R -5 -r '^user|^xfsroot' -e hex $SCRATCH_MNT
177 echo "*** forward directory descent without following symlinks"
178 getfattr -P -R -r '^user|^xfsroot' -e hex $SCRATCH_MNT
181 echo "*** reverse directory descent without following symlinks"
182 getfattr -P -R -5 -r '^user|^xfsroot' -e hex $SCRATCH_MNT
186 # Test the backup/restore code
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
196 [ ! -s $1 ] && echo "warning: $1 (backup file) is empty"
199 echo "*** backup everything"
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
207 echo "*** reset test bed with no extended attributes"
211 echo "*** restore everything"
212 setfattr -lB $tmp.backup1
215 echo "AFTER RESTORE" >>$seq.full
216 getfattr -L -R -r '^user|^xfsroot' $SCRATCH_MNT >>$seq.full
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