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 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
73 find $SCRATCH_MNT | LC_COLLATE=POSIX sort
77 [ -x /usr/bin/getfattr ] || _notrun "getfattr is not installed"
78 [ -x /usr/bin/setfattr ] || _notrun "setfattr is not installed"
79 rm -f $tmp.backup1 $tmp.backup2 $seq.full
81 # real QA test starts here
82 mkfs -t xfs -f $SCRATCH_DEV | _filter_mkfs 2>$tmp.mkfs
83 mount -t xfs $SCRATCH_DEV $SCRATCH_MNT || _fail "mount failed"
86 for nsp in user root; do
87 for inode in reg dir lnk dev/b dev/c dev/p; do
89 echo; echo "=== TYPE $inode; NAMESPACE $nsp"; echo
91 echo "*** set/get one initially empty attribute"
92 setfattr -l -N $nsp -n name $SCRATCH_MNT/$inode
93 getfattr -al -N $nsp -d $SCRATCH_MNT/$inode
95 echo "*** overwrite empty, set several new attributes"
96 setfattr -l -N $nsp -n name -v 0xbabe $SCRATCH_MNT/$inode
97 setfattr -l -N $nsp -n name2 -v 0xdeadbeef $SCRATCH_MNT/$inode
98 setfattr -l -N $nsp -n name3 -v 0xdeface $SCRATCH_MNT/$inode
100 echo "*** fetch several attribute names and values (hex)"
101 getfattr -al -N $nsp -d -e hex $SCRATCH_MNT/$inode
103 echo "*** fetch several attribute names and values (base64)"
104 getfattr -al -N $nsp -d -e base64 $SCRATCH_MNT/$inode
106 echo "*** shrink value of an existing attribute"
107 setfattr -l -N $nsp -n name2 -v 0xdeaf $SCRATCH_MNT/$inode
108 getfattr -al -N $nsp -d -e hex $SCRATCH_MNT/$inode
110 echo "*** grow value of existing attribute"
111 setfattr -l -N $nsp -n name2 -v 0xdecade $SCRATCH_MNT/$inode
112 getfattr -al -N $nsp -d -e hex $SCRATCH_MNT/$inode
114 echo "*** set an empty value for second attribute"
115 setfattr -l -N $nsp -n name2 $SCRATCH_MNT/$inode
116 getfattr -al -N $nsp -d -n name2 $SCRATCH_MNT/$inode
118 echo "*** overwrite empty value"
119 setfattr -l -N $nsp -n name2 -v 0xcafe $SCRATCH_MNT/$inode
120 getfattr -al -N $nsp -d -e hex -n name2 $SCRATCH_MNT/$inode
122 echo "*** remove attribute"
123 setfattr -l -N $nsp -x name2 $SCRATCH_MNT/$inode
124 getfattr -al -N $nsp -d -n name2 $SCRATCH_MNT/$inode
126 echo "*** final list (strings, type=$inode, nsp=$nsp)"
127 getfattr -als -d $SCRATCH_MNT/$inode
133 # Test the directory descent code
139 echo "*** extend test bed"
140 # must set some descents' attributes to be useful
141 mkdir -p $SCRATCH_MNT/here/up/ascend
142 mkdir -p $SCRATCH_MNT/descend/down/here
143 find $SCRATCH_MNT/descend | xargs setfattr -N user -n x -v yz
144 find $SCRATCH_MNT/descend | xargs setfattr -N user -n 1 -v 23
145 find $SCRATCH_MNT/here | xargs setfattr -N root -n a -v bc
146 find $SCRATCH_MNT/here | xargs setfattr -N root -n 9 -v 87
147 # whack a symlink in the middle, just to be difficult
148 ln -s $SCRATCH_MNT/here/up $SCRATCH_MNT/descend/and
149 # dump out our new starting point
150 find $SCRATCH_MNT | LC_COLLATE=POSIX sort
156 echo "*** forward directory descent with us following symlinks"
157 getfattr -L -R -adls -e hex $SCRATCH_MNT
160 echo "*** reverse directory descent with us following symlinks"
161 getfattr -L -R -5 -adls -e hex $SCRATCH_MNT
164 echo "*** forward directory descent without following symlinks"
165 getfattr -P -R -adls -e hex $SCRATCH_MNT
168 echo "*** reverse directory descent without following symlinks"
169 getfattr -P -R -5 -adls -e hex $SCRATCH_MNT
173 # Test the backup/restore code
179 getfattr -a -sdlR $SCRATCH_MNT >$1
180 echo BACKUP $1 >>$seq.full
182 [ ! -s $1 ] && echo "warning: $1 (backup file) is empty"
185 echo "*** backup everything"
188 echo "*** clear out the scratch device"
189 rm -fr $SCRATCH_MNT/*
190 echo "AFTER REMOVE" >>$seq.full
191 getfattr -L -R -adls $SCRATCH_MNT >>$seq.full
193 echo "*** reset test bed with no extended attributes"
197 echo "*** restore everything"
198 setfattr -lB $tmp.backup1
201 echo "AFTER RESTORE" >>$seq.full
202 getfattr -L -R -adls $SCRATCH_MNT >>$seq.full
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