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.
9 #-----------------------------------------------------------------------
15 echo "QA output created by $seq"
19 status=1 # failure is the default!
21 # get standard environment, filters and checks
28 echo; echo "*** unmount"
29 umount $SCRATCH_MNT 2>/dev/null
32 trap "_cleanup; exit \$status" 0 1 2 3 15
36 sed -e "s,$SCRATCH_MNT,SCRATCH_MNT,g"
41 echo "*** set/get one initially empty attribute"
42 setfattr -h -n $nsp.name $SCRATCH_MNT/$inode
43 getfattr -m $nsp $SCRATCH_MNT/$inode
45 echo "*** overwrite empty, set several new attributes"
46 setfattr -h -n $nsp.name -v 0xbabe $SCRATCH_MNT/$inode
47 setfattr -h -n $nsp.name2 -v 0xdeadbeef $SCRATCH_MNT/$inode
48 setfattr -h -n $nsp.name3 -v 0xdeface $SCRATCH_MNT/$inode
50 echo "*** fetch several attribute names and values (hex)"
51 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
53 echo "*** fetch several attribute names and values (base64)"
54 getfattr -m $nsp -e base64 $SCRATCH_MNT/$inode
56 echo "*** shrink value of an existing attribute"
57 setfattr -h -n $nsp.name2 -v 0xdeaf $SCRATCH_MNT/$inode
58 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
60 echo "*** grow value of existing attribute"
61 setfattr -h -n $nsp.name2 -v 0xdecade $SCRATCH_MNT/$inode
62 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
64 echo "*** set an empty value for second attribute"
65 setfattr -h -n $nsp.name2 $SCRATCH_MNT/$inode
66 getfattr -m $nsp -n $nsp.name2 $SCRATCH_MNT/$inode
68 echo "*** overwrite empty value"
69 setfattr -h -n $nsp.name2 -v 0xcafe $SCRATCH_MNT/$inode
70 getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode
72 echo "*** remove attribute"
73 setfattr -h -x $nsp.name2 $SCRATCH_MNT/$inode
74 getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode
76 echo "*** final list (strings, type=$inode, nsp=$nsp)"
77 getfattr -m '.' -e hex $SCRATCH_MNT/$inode
82 /usr/bin/getfattr --absolute-names -dh $@ 2>&1 | _filter_scratch
92 echo "*** create test bed"
93 touch $SCRATCH_MNT/reg
94 mkdir -p $SCRATCH_MNT/dir
95 ln -s $SCRATCH_MNT/dir $SCRATCH_MNT/lnk
96 mkdir $SCRATCH_MNT/dev
97 mknod $SCRATCH_MNT/dev/b b 0 0
98 mknod $SCRATCH_MNT/dev/c c 0 0
99 mknod $SCRATCH_MNT/dev/p p
101 find $SCRATCH_MNT | LC_COLLATE=POSIX sort | _filter_scratch
104 # real QA test starts here
105 _supported_fs xfs udf nfs
109 rm -f $tmp.backup1 $tmp.backup2 $seq.full
111 # real QA test starts here
112 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
113 _scratch_mount || _fail "mount failed"
116 if [ "$USE_ATTR_SECURE" = yes ]; then
117 ATTR_MODES="user security trusted"
119 ATTR_MODES="user trusted"
121 for nsp in $ATTR_MODES; do
122 for inode in reg dir lnk dev/b dev/c dev/p; do
124 echo; echo "=== TYPE $inode; NAMESPACE $nsp"; echo
125 echo "*** set/get one initially empty attribute"
127 setfattr -h -n $nsp.name $SCRATCH_MNT/$inode
128 getfattr -m $nsp $SCRATCH_MNT/$inode
130 echo "*** overwrite empty, set several new attributes"
131 setfattr -h -n $nsp.name -v 0xbabe $SCRATCH_MNT/$inode
132 setfattr -h -n $nsp.name2 -v 0xdeadbeef $SCRATCH_MNT/$inode
133 setfattr -h -n $nsp.name3 -v 0xdeface $SCRATCH_MNT/$inode
135 echo "*** fetch several attribute names and values (hex)"
136 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
138 echo "*** fetch several attribute names and values (base64)"
139 getfattr -m $nsp -e base64 $SCRATCH_MNT/$inode
141 echo "*** shrink value of an existing attribute"
142 setfattr -h -n $nsp.name2 -v 0xdeaf $SCRATCH_MNT/$inode
143 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
145 echo "*** grow value of existing attribute"
146 setfattr -h -n $nsp.name2 -v 0xdecade $SCRATCH_MNT/$inode
147 getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
149 echo "*** set an empty value for second attribute"
150 setfattr -h -n $nsp.name2 $SCRATCH_MNT/$inode
151 getfattr -m $nsp -n $nsp.name2 $SCRATCH_MNT/$inode
153 echo "*** overwrite empty value"
154 setfattr -h -n $nsp.name2 -v 0xcafe $SCRATCH_MNT/$inode
155 getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode
157 echo "*** remove attribute"
158 setfattr -h -x $nsp.name2 $SCRATCH_MNT/$inode
159 getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode
161 echo "*** final list (strings, type=$inode, nsp=$nsp)"
162 getfattr -m '.' -e hex $SCRATCH_MNT/$inode
169 # Test the directory descent code
175 echo "*** extend test bed"
176 # must set some descents' attributes to be useful
177 mkdir -p $SCRATCH_MNT/here/up/ascend
178 mkdir -p $SCRATCH_MNT/descend/down/here
179 find $SCRATCH_MNT/descend | xargs setfattr -n user.x -v yz
180 find $SCRATCH_MNT/descend | xargs setfattr -n user.1 -v 23
181 find $SCRATCH_MNT/here | xargs setfattr -n trusted.a -v bc
182 find $SCRATCH_MNT/here | xargs setfattr -n trusted.9 -v 87
183 # whack a symlink in the middle, just to be difficult
184 ln -s $SCRATCH_MNT/here/up $SCRATCH_MNT/descend/and
185 # dump out our new starting point
186 find $SCRATCH_MNT | LC_COLLATE=POSIX sort | _filter_scratch
192 echo "*** directory descent with us following symlinks"
193 getfattr -h -L -R -m '.' -e hex $SCRATCH_MNT
196 echo "*** directory descent without following symlinks"
197 getfattr -h -P -R -m '.' -e hex $SCRATCH_MNT
201 # Test the backup/restore code
207 # NB: no filtering of scratch here... (need to restore too)
208 /usr/bin/getfattr --absolute-names -dh -R -m '.' $SCRATCH_MNT >$1
209 echo BACKUP $1 >>$seq.full
211 [ ! -s $1 ] && echo "warning: $1 (backup file) is empty"
214 echo "*** backup everything"
217 echo "*** clear out the scratch device"
218 rm -fr $SCRATCH_MNT/*
219 echo "AFTER REMOVE" >>$seq.full
220 getfattr -L -R -m '.' $SCRATCH_MNT >>$seq.full
222 echo "*** reset test bed with no extended attributes"
226 echo "*** restore everything"
227 setfattr -h --restore=$tmp.backup1
230 echo "AFTER RESTORE" >>$seq.full
231 getfattr -L -R -m '.' $SCRATCH_MNT >>$seq.full
233 echo "*** compare before and after backups"
234 diff $tmp.backup1 $tmp.backup2
235 if [ $? -ne 0 ]; then
236 echo "urk, failed - creating $seq.backup1 and $seq.backup2"
237 cp $tmp.backup1 $seq.backup1 && cp $tmp.backup2 $seq.backup2