4 # Exercises the getfattr/setfattr tools
5 # Derived from tests originally written by Andreas Gruenbacher for ext2
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2001-2002 Silicon Graphics, Inc. All Rights Reserved.
10 # This program is free software; you can redistribute it and/or modify it
11 # under the terms of version 2 of the GNU General Public License as
12 # published by the Free Software Foundation.
14 # This program is distributed in the hope that it would be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 # Further, this software is distributed without any warranty that it is
19 # free of the rightful claim of any third person regarding infringement
20 # or the like. Any license provided herein, whether implied or
21 # otherwise, applies only to this software file. Patent licenses, if
22 # any, provided herein do not apply to combinations of this program with
23 # other software, or any other product whatsoever.
25 # You should have received a copy of the GNU General Public License along
26 # with this program; if not, write the Free Software Foundation, Inc., 59
27 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
29 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
30 # Mountain View, CA 94043, or:
34 # For further information regarding this notice, see:
36 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
37 #-----------------------------------------------------------------------
43 echo "QA output created by $seq"
47 status=1 # failure is the default!
49 # get standard environment, filters and checks
55 echo; echo "*** unmount"
56 umount $SCRATCH_MNT 2>/dev/null
59 trap "_cleanup; exit \$status" 0 1 2 3 15
63 sed -e "s,$SCRATCH_MNT,SCRATCH_MNT,g"
68 /usr/bin/getfattr --absolute-names -dh $@ 2>&1 | _filter_scratch
78 echo "*** create test bed"
79 touch $SCRATCH_MNT/reg
80 mkdir -p $SCRATCH_MNT/dir
81 ln -s $SCRATCH_MNT/dir $SCRATCH_MNT/lnk
82 mkdir $SCRATCH_MNT/dev
83 mknod $SCRATCH_MNT/dev/b b 0 0
84 mknod $SCRATCH_MNT/dev/c c 0 0
85 mknod $SCRATCH_MNT/dev/p p
87 find $SCRATCH_MNT | LC_COLLATE=POSIX sort | _filter_scratch
91 rm -f $tmp.backup1 $tmp.backup2 $seq.full
93 # real QA test starts here
94 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
95 _scratch_mount || _fail "mount failed"
98 if [ "$USE_ATTR_SECURE" = yes ]; then
99 ATTR_MODES="user security trusted"
101 ATTR_MODES="user trusted"
103 for nsp in $ATTR_MODES; do
104 for inode in reg dir lnk dev/b dev/c dev/p; do
106 echo; echo "=== TYPE $inode; NAMESPACE $nsp"; echo
108 echo "*** set/get one initially empty attribute"
109 setfattr -h -n $nsp.name $SCRATCH_MNT/$inode
110 getfattr -m $nsp $SCRATCH_MNT/$inode
112 echo "*** overwrite empty, set several new attributes"
113 setfattr -h -n $nsp.name -v 0xbabe $SCRATCH_MNT/$inode
114 setfattr -h -n $nsp.name2 -v 0xdeadbeef $SCRATCH_MNT/$inode
115 setfattr -h -n $nsp.name3 -v 0xdeface $SCRATCH_MNT/$inode
117 echo "*** fetch several attribute names and values (hex)"
118 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
120 echo "*** fetch several attribute names and values (base64)"
121 getfattr -m $nsp -e base64 $SCRATCH_MNT/$inode
123 echo "*** shrink value of an existing attribute"
124 setfattr -h -n $nsp.name2 -v 0xdeaf $SCRATCH_MNT/$inode
125 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
127 echo "*** grow value of existing attribute"
128 setfattr -h -n $nsp.name2 -v 0xdecade $SCRATCH_MNT/$inode
129 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
131 echo "*** set an empty value for second attribute"
132 setfattr -h -n $nsp.name2 $SCRATCH_MNT/$inode
133 getfattr -m $nsp -n $nsp.name2 $SCRATCH_MNT/$inode
135 echo "*** overwrite empty value"
136 setfattr -h -n $nsp.name2 -v 0xcafe $SCRATCH_MNT/$inode
137 getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode
139 echo "*** remove attribute"
140 setfattr -h -x $nsp.name2 $SCRATCH_MNT/$inode
141 getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode
143 echo "*** final list (strings, type=$inode, nsp=$nsp)"
144 getfattr -m '.' -e hex $SCRATCH_MNT/$inode
150 # Test the directory descent code
156 echo "*** extend test bed"
157 # must set some descents' attributes to be useful
158 mkdir -p $SCRATCH_MNT/here/up/ascend
159 mkdir -p $SCRATCH_MNT/descend/down/here
160 find $SCRATCH_MNT/descend | xargs setfattr -n user.x -v yz
161 find $SCRATCH_MNT/descend | xargs setfattr -n user.1 -v 23
162 find $SCRATCH_MNT/here | xargs setfattr -n trusted.a -v bc
163 find $SCRATCH_MNT/here | xargs setfattr -n trusted.9 -v 87
164 # whack a symlink in the middle, just to be difficult
165 ln -s $SCRATCH_MNT/here/up $SCRATCH_MNT/descend/and
166 # dump out our new starting point
167 find $SCRATCH_MNT | LC_COLLATE=POSIX sort | _filter_scratch
173 echo "*** directory descent with us following symlinks"
174 getfattr -h -L -R -m '.' -e hex $SCRATCH_MNT
177 echo "*** directory descent without following symlinks"
178 getfattr -h -P -R -m '.' -e hex $SCRATCH_MNT
182 # Test the backup/restore code
188 # NB: no filtering of scratch here... (need to restore too)
189 /usr/bin/getfattr --absolute-names -dh -R -m '.' $SCRATCH_MNT >$1
190 echo BACKUP $1 >>$seq.full
192 [ ! -s $1 ] && echo "warning: $1 (backup file) is empty"
195 echo "*** backup everything"
198 echo "*** clear out the scratch device"
199 rm -fr $SCRATCH_MNT/*
200 echo "AFTER REMOVE" >>$seq.full
201 getfattr -L -R -m '.' $SCRATCH_MNT >>$seq.full
203 echo "*** reset test bed with no extended attributes"
207 echo "*** restore everything"
208 setfattr -h --restore=$tmp.backup1
211 echo "AFTER RESTORE" >>$seq.full
212 getfattr -L -R -m '.' $SCRATCH_MNT >>$seq.full
214 echo "*** compare before and after backups"
215 diff $tmp.backup1 $tmp.backup2
216 if [ $? -ne 0 ]; then
217 echo "urk, failed - creating $seq.backup1 and $seq.backup2"
218 cp $tmp.backup1 $seq.backup1 && cp $tmp.backup2 $seq.backup2