2 #-----------------------------------------------------------------------
3 # Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 # Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
20 # Mountain View, CA 94043, USA, or: http://www.sgi.com
21 #-----------------------------------------------------------------------
22 # common extended attribute and ACL support
24 # filesystems that want to test maximum supported acl counts need to
30 # CRC format filesystems have much larger ACL counts. The actual
31 # number is into the thousands, but testing that meany takes too
32 # long, so just test well past the old limit of 25.
33 xfs_info $TEST_DIR | _filter_mkfs > /dev/null 2> $tmp.info
36 if [ $_fs_has_crcs -eq 0 ]; then
46 _fs_options $TEST_DEV | grep "inline_xattr" >/dev/null 2>&1
59 _require_acl_get_max()
61 if [ $(_acl_get_max) -eq 0 ]; then
62 _notrun "$FSTYP does not define maximum ACL count"
66 # pick three unused user/group ids, store them as $acl[1-3]
70 eval `(_cat_passwd; _cat_group) | awk -F: '
74 for(i=1; i<1000000 && j<=3;i++){
76 printf "acl%d=%d;", j, i;
83 # filter for the acl ids selected above
88 -e "s/u:$acl1/u:id1/" \
89 -e "s/u:$acl2/u:id2/" \
90 -e "s/u:$acl3/u:id3/" \
91 -e "s/g:$acl1/g:id1/" \
92 -e "s/g:$acl2/g:id2/" \
93 -e "s/g:$acl3/g:id3/" \
94 -e "s/ $acl1 / id1 /" \
95 -e "s/ $acl2 / id2 /" \
102 -e "s/user:$acl1/user:id1/" \
103 -e "s/user:$acl2/user:id2/" \
104 -e "s/user:$acl3/user:id3/" \
105 -e "s/group:$acl1/group:id1/" \
106 -e "s/group:$acl2/group:id2/" \
107 -e "s/group:$acl3/group:id3/" \
108 -e "s/: $acl1/: id1/" \
109 -e "s/: $acl2/: id2/" \
110 -e "s/: $acl3/: id3/"
117 _ls_l -n $* | awk '{ print $1, $3, $4, $NF }' | _acl_filter_id
120 # create an ACL with n ACEs in it
125 acl='u::rwx,g::rwx,o::rwx,m::rwx' # 4 ace acl start
126 while [ $n -ne 0 ]; do
133 # filter user ace names to user ids
137 tmp_file=`mktemp /tmp/ace.XXXXXX`
139 (_cat_passwd; _cat_group) > $tmp_file
141 $AWK_PROG -v tmpfile=$tmp_file '
144 while ( getline <tmpfile > 0 ) {
148 /^user/ { if ($2 in idlist) sub($2, idlist[$2]); print; next}
149 /^u/ { if ($2 in idlist) sub($2, idlist[$2]); print; next}
150 /^default:user/ { if ($3 in idlist) sub($3, idlist[$3]); print; next}
156 _filter_aces_notypes()
158 tr '\[' '\012' | tr ']' '\012' | tr ',' '\012' | _filter_aces|\
159 sed -e 's/u:/user:/' -e 's/g:/group:/' -e 's/o:/other:/' -e 's/m:/mask:/'
164 [ -n "$CHACL_PROG" ] || _notrun "chacl command not found"
167 # Test if chacl is able to list ACLs on the target filesystems. On really
168 # old kernels the system calls might not be implemented at all, but the
169 # more common case is that the tested filesystem simply doesn't support
172 touch $TEST_DIR/syscalltest
173 chacl -l $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
174 cat $TEST_DIR/syscalltest.out >> $seqres.full
176 if grep -q 'Function not implemented' $TEST_DIR/syscalltest.out; then
177 _notrun "kernel does not support ACLs"
179 if grep -q 'Operation not supported' $TEST_DIR/syscalltest.out; then
180 _notrun "ACLs not supported by this filesystem type: $FSTYP"
183 rm -f $TEST_DIR/syscalltest.out
190 ls -dD $file | _acl_filter_id
195 [ -n "$ATTR_PROG" ] || _notrun "attr command not found"
196 [ -n "$GETFATTR_PROG" ] || _notrun "getfattr command not found"
197 [ -n "$SETFATTR_PROG" ] || _notrun "setfattr command not found"
200 # Test if chacl is able to write an attribute on the target filesystems.
201 # On really old kernels the system calls might not be implemented at all,
202 # but the more common case is that the tested filesystem simply doesn't
203 # support attributes. Note that we can't simply list attributes as
204 # various security modules generate synthetic attributes not actually
207 touch $TEST_DIR/syscalltest
208 attr -s "user.xfstests" -V "attr" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
209 cat $TEST_DIR/syscalltest.out >> $seqres.full
211 if grep -q 'Function not implemented' $TEST_DIR/syscalltest.out; then
212 _notrun "kernel does not support attrs"
214 if grep -q 'Operation not supported' $TEST_DIR/syscalltest.out; then
215 _notrun "attrs not supported by this filesystem type: $FSTYP"
218 rm -f $TEST_DIR/syscalltest.out
223 _scratch_mkfs_xfs_supported -i attr=1 >/dev/null 2>&1 \
224 || _notrun "attr v1 not supported on $SCRATCH_DEV"
227 # check if we support the noattr2 mount option
230 _scratch_mkfs_xfs > /dev/null 2>&1 \
231 || _fail "_scratch_mkfs_xfs failed on $SCRATCH_DEV"
232 _scratch_mount -o noattr2 > /dev/null 2>&1 \
233 || _notrun "noattr2 mount option not supported on $SCRATCH_DEV"
237 # getfattr -R returns info in readdir order which varies from fs to fs.
238 # This sorts the output by filename
239 _sort_getfattr_output()
241 awk '{a[FNR]=$0}END{n = asort(a); for(i=1; i <= n; i++) print a[i]"\n"}' RS=''
244 # set maximum total attr space based on fs type
246 xfs|udf|pvfs2|9p|ceph)
250 # Assume max ~1 block of attrs
251 BLOCK_SIZE=`_get_block_size $TEST_DIR`
252 # user.attribute_XXX="value.XXX" is about 32 bytes; leave some overhead
253 let MAX_ATTRS=$BLOCK_SIZE/40
258 # Set max attr value size based on fs type
264 MAX_ATTRVAL_SIZE=8192
267 MAX_ATTRVAL_SIZE=65536
270 # Assume max ~1 block of attrs
271 BLOCK_SIZE=`_get_block_size $TEST_DIR`
272 # leave a little overhead
273 let MAX_ATTRVAL_SIZE=$BLOCK_SIZE-256
276 export MAX_ATTRVAL_SIZE
277 # make sure this script returns success