2 # SPDX-License-Identifier: GPL-2.0+
3 # Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
5 # common extended attribute and ACL support
7 # filesystems that want to test maximum supported acl counts need to
13 # CRC format filesystems have much larger ACL counts. The actual
14 # number is into the thousands, but testing that meany takes too
15 # long, so just test well past the old limit of 25.
16 $XFS_INFO_PROG $TEST_DIR | _filter_mkfs > /dev/null 2> $tmp.info
19 if [ $_fs_has_crcs -eq 0 ]; then
29 _fs_options $TEST_DEV | grep "inline_xattr" >/dev/null 2>&1
45 _require_acl_get_max()
47 if [ $(_acl_get_max) -eq 0 ]; then
48 _notrun "$FSTYP does not define maximum ACL count"
52 # pick three unused user/group ids, store them as $acl[1-3]
56 eval `(_cat_passwd; _cat_group) | awk -F: '
60 for(i=1; i<1000000 && j<=3;i++){
62 printf "acl%d=%d;", j, i;
69 # filter for the acl ids selected above
74 -e "s/u:$acl1/u:id1/" \
75 -e "s/u:$acl2/u:id2/" \
76 -e "s/u:$acl3/u:id3/" \
77 -e "s/g:$acl1/g:id1/" \
78 -e "s/g:$acl2/g:id2/" \
79 -e "s/g:$acl3/g:id3/" \
80 -e "s/ $acl1 / id1 /" \
81 -e "s/ $acl2 / id2 /" \
88 -e "s/user:$acl1/user:id1/" \
89 -e "s/user:$acl2/user:id2/" \
90 -e "s/user:$acl3/user:id3/" \
91 -e "s/group:$acl1/group:id1/" \
92 -e "s/group:$acl2/group:id2/" \
93 -e "s/group:$acl3/group:id3/" \
94 -e "s/: $acl1/: id1/" \
95 -e "s/: $acl2/: id2/" \
103 _ls_l -n $* | awk '{ print $1, $3, $4, $NF }' | _acl_filter_id
106 # create an ACL with n ACEs in it
111 acl='u::rwx,g::rwx,o::rwx,m::rwx' # 4 ace acl start
112 while [ $n -ne 0 ]; do
119 # filter user ace names to user ids
123 tmp_file=`mktemp /tmp/ace.XXXXXX`
125 (_cat_passwd; _cat_group) > $tmp_file
127 $AWK_PROG -v tmpfile=$tmp_file '
130 while ( getline <tmpfile > 0 ) {
134 /^user/ { if ($2 in idlist) sub($2, idlist[$2]); print; next}
135 /^u/ { if ($2 in idlist) sub($2, idlist[$2]); print; next}
136 /^default:user/ { if ($3 in idlist) sub($3, idlist[$3]); print; next}
142 _filter_aces_notypes()
144 tr '\[' '\012' | tr ']' '\012' | tr ',' '\012' | _filter_aces|\
145 sed -e 's/u:/user:/' -e 's/g:/group:/' -e 's/o:/other:/' -e 's/m:/mask:/'
150 [ -n "$CHACL_PROG" ] || _notrun "chacl command not found"
153 # Test if chacl is able to list ACLs on the target filesystems. On really
154 # old kernels the system calls might not be implemented at all, but the
155 # more common case is that the tested filesystem simply doesn't support
158 touch $TEST_DIR/syscalltest
159 chacl -l $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
160 cat $TEST_DIR/syscalltest.out >> $seqres.full
162 if grep -q 'Function not implemented' $TEST_DIR/syscalltest.out; then
163 _notrun "kernel does not support ACLs"
165 if grep -q 'Operation not supported' $TEST_DIR/syscalltest.out; then
166 _notrun "ACLs not supported by this filesystem type: $FSTYP"
169 rm -f $TEST_DIR/syscalltest.out
176 ls -dD $file | _acl_filter_id
184 if [ $# -eq 0 ]; then
190 [ -n "$ATTR_PROG" ] || _notrun "attr command not found"
191 [ -n "$GETFATTR_PROG" ] || _notrun "getfattr command not found"
192 [ -n "$SETFATTR_PROG" ] || _notrun "setfattr command not found"
196 # Test if chacl is able to write an attribute on the target
197 # filesystems. On really old kernels the system calls might
198 # not be implemented at all, but the more common case is that
199 # the tested filesystem simply doesn't support attributes.
200 # Note that we can't simply list attributes as various security
201 # modules generate synthetic attributes not actually stored on
204 touch $TEST_DIR/syscalltest
205 $SETFATTR_PROG -n "$nsp.xfstests" -v "attr" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
206 cat $TEST_DIR/syscalltest.out >> $seqres.full
208 if grep -q 'Function not implemented' $TEST_DIR/syscalltest.out; then
209 _notrun "kernel does not support attrs"
211 if grep -q 'Operation not supported' $TEST_DIR/syscalltest.out; then
212 _notrun "attr namespace $nsp not supported by this filesystem type: $FSTYP"
215 rm -f $TEST_DIR/syscalltest.out
221 _scratch_mkfs_xfs_supported -i attr=1 >/dev/null 2>&1 \
222 || _notrun "attr v1 not supported on $SCRATCH_DEV"
225 # check if we support the noattr2 mount option
228 _scratch_mkfs_xfs > /dev/null 2>&1 \
229 || _fail "_scratch_mkfs_xfs failed on $SCRATCH_DEV"
230 _try_scratch_mount -o noattr2 > /dev/null 2>&1 \
231 || _notrun "noattr2 mount option not supported on $SCRATCH_DEV"
235 # getfattr -R returns info in readdir order which varies from fs to fs.
236 # This sorts the output by filename
237 _sort_getfattr_output()
239 awk '{a[FNR]=$0}END{n = asort(a); for(i=1; i <= n; i++) print a[i]"\n"}' RS=''
242 # Previously, when getfattr dumps values of all extended attributes, it prints
243 # empty attr as 'user.name', but new getfattr (since attr-2.4.48) prints it as
244 # 'user.name=""'. Filter out the ending '=""' so that both old and new getfattr
245 # pints the same output.
247 # Note: This function returns the getfattr command result.
250 $GETFATTR_PROG "$@" | sed -e 's/=\"\"//'
251 return ${PIPESTATUS[0]}
254 # set maximum total attr space based on fs type
256 xfs|udf|pvfs2|9p|ceph|nfs)
260 # Assume max ~1 block of attrs
261 BLOCK_SIZE=`_get_block_size $TEST_DIR`
262 # user.attribute_XXX="value.XXX" is about 32 bytes; leave some overhead
263 let MAX_ATTRS=$BLOCK_SIZE/40
268 # Set max attr value size based on fs type
274 MAX_ATTRVAL_SIZE=8192
277 MAX_ATTRVAL_SIZE=65536
280 MAX_ATTRVAL_SIZE=1024
283 # Assume max ~1 block of attrs
284 BLOCK_SIZE=`_get_block_size $TEST_DIR`
285 # leave a little overhead
286 let MAX_ATTRVAL_SIZE=$BLOCK_SIZE-256
289 export MAX_ATTRVAL_SIZE
290 # make sure this script returns success