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 --absolute-names -dh $@ 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 $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 -h -n $nsp.name $SCRATCH_MNT/$inode
106 getfattr -m $nsp $SCRATCH_MNT/$inode
108 echo "*** overwrite empty, set several new attributes"
109 setfattr -h -n $nsp.name -v 0xbabe $SCRATCH_MNT/$inode
110 setfattr -h -n $nsp.name2 -v 0xdeadbeef $SCRATCH_MNT/$inode
111 setfattr -h -n $nsp.name3 -v 0xdeface $SCRATCH_MNT/$inode
113 echo "*** fetch several attribute names and values (hex)"
114 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
116 echo "*** fetch several attribute names and values (base64)"
117 getfattr -m $nsp -e base64 $SCRATCH_MNT/$inode
119 echo "*** shrink value of an existing attribute"
120 setfattr -h -n $nsp.name2 -v 0xdeaf $SCRATCH_MNT/$inode
121 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
123 echo "*** grow value of existing attribute"
124 setfattr -h -n $nsp.name2 -v 0xdecade $SCRATCH_MNT/$inode
125 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
127 echo "*** set an empty value for second attribute"
128 setfattr -h -n $nsp.name2 $SCRATCH_MNT/$inode
129 getfattr -m $nsp -n $nsp.name2 $SCRATCH_MNT/$inode
131 echo "*** overwrite empty value"
132 setfattr -h -n $nsp.name2 -v 0xcafe $SCRATCH_MNT/$inode
133 getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode
135 echo "*** remove attribute"
136 setfattr -h -x $nsp.name2 $SCRATCH_MNT/$inode
137 getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode
139 echo "*** final list (strings, type=$inode, nsp=$nsp)"
140 getfattr -m '^user|^xfsroot' -e hex $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 "*** directory descent with us following symlinks"
170 getfattr -h -L -R -m '^user|^xfsroot' -e hex $SCRATCH_MNT
173 echo "*** directory descent without following symlinks"
174 getfattr -h -P -R -m '^user|^xfsroot' -e hex $SCRATCH_MNT
178 # Test the backup/restore code
184 # NB: no filtering of scratch here... (need to restore too)
185 /usr/bin/getfattr --absolute-names -dh -R -m '^user|^system' $SCRATCH_MNT >$1
186 echo BACKUP $1 >>$seq.full
188 [ ! -s $1 ] && echo "warning: $1 (backup file) is empty"
191 echo "*** backup everything"
194 echo "*** clear out the scratch device"
195 rm -fr $SCRATCH_MNT/*
196 echo "AFTER REMOVE" >>$seq.full
197 getfattr -L -R -m '^user|^xfsroot' $SCRATCH_MNT >>$seq.full
199 echo "*** reset test bed with no extended attributes"
203 echo "*** restore everything"
204 setfattr -h --restore=$tmp.backup1
207 echo "AFTER RESTORE" >>$seq.full
208 getfattr -L -R -m '^user|^xfsroot' $SCRATCH_MNT >>$seq.full
210 echo "*** compare before and after backups"
211 diff $tmp.backup1 $tmp.backup2
212 if [ $? -ne 0 ]; then
213 echo "urk, failed - creating $seq.backup1 and $seq.backup2"
214 cp $tmp.backup1 $seq.backup1 && cp $tmp.backup2 $seq.backup2