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
42 _require_acl_get_max()
44 if [ $(_acl_get_max) -eq 0 ]; then
45 _notrun "$FSTYP does not define maximum ACL count"
49 # pick three unused user/group ids, store them as $acl[1-3]
53 eval `(_cat_passwd; _cat_group) | awk -F: '
57 for(i=1; i<1000000 && j<=3;i++){
59 printf "acl%d=%d;", j, i;
66 # filter for the acl ids selected above
71 -e "s/u:$acl1/u:id1/" \
72 -e "s/u:$acl2/u:id2/" \
73 -e "s/u:$acl3/u:id3/" \
74 -e "s/g:$acl1/g:id1/" \
75 -e "s/g:$acl2/g:id2/" \
76 -e "s/g:$acl3/g:id3/" \
77 -e "s/ $acl1 / id1 /" \
78 -e "s/ $acl2 / id2 /" \
85 -e "s/user:$acl1/user:id1/" \
86 -e "s/user:$acl2/user:id2/" \
87 -e "s/user:$acl3/user:id3/" \
88 -e "s/group:$acl1/group:id1/" \
89 -e "s/group:$acl2/group:id2/" \
90 -e "s/group:$acl3/group:id3/" \
91 -e "s/: $acl1/: id1/" \
92 -e "s/: $acl2/: id2/" \
100 _ls_l -n $* | awk '{ print $1, $3, $4, $NF }' | _acl_filter_id
103 # create an ACL with n ACEs in it
108 acl='u::rwx,g::rwx,o::rwx,m::rwx' # 4 ace acl start
109 while [ $n -ne 0 ]; do
116 # filter user ace names to user ids
120 tmp_file=`mktemp /tmp/ace.XXXXXX`
122 (_cat_passwd; _cat_group) > $tmp_file
124 $AWK_PROG -v tmpfile=$tmp_file '
127 while ( getline <tmpfile > 0 ) {
131 /^user/ { if ($2 in idlist) sub($2, idlist[$2]); print; next}
132 /^u/ { if ($2 in idlist) sub($2, idlist[$2]); print; next}
133 /^default:user/ { if ($3 in idlist) sub($3, idlist[$3]); print; next}
139 _filter_aces_notypes()
141 tr '\[' '\012' | tr ']' '\012' | tr ',' '\012' | _filter_aces|\
142 sed -e 's/u:/user:/' -e 's/g:/group:/' -e 's/o:/other:/' -e 's/m:/mask:/'
147 [ -n "$CHACL_PROG" ] || _notrun "chacl command not found"
150 # Test if chacl is able to list ACLs on the target filesystems. On really
151 # old kernels the system calls might not be implemented at all, but the
152 # more common case is that the tested filesystem simply doesn't support
155 touch $TEST_DIR/syscalltest
156 chacl -l $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
157 cat $TEST_DIR/syscalltest.out >> $seqres.full
159 if grep -q 'Function not implemented' $TEST_DIR/syscalltest.out; then
160 _notrun "kernel does not support ACLs"
162 if grep -q 'Operation not supported' $TEST_DIR/syscalltest.out; then
163 _notrun "ACLs not supported by this filesystem type: $FSTYP"
166 rm -f $TEST_DIR/syscalltest.out
173 ls -dD $file | _acl_filter_id
178 [ -n "$ATTR_PROG" ] || _notrun "attr command not found"
179 [ -n "$GETFATTR_PROG" ] || _notrun "getfattr command not found"
180 [ -n "$SETFATTR_PROG" ] || _notrun "setfattr command not found"
183 # Test if chacl is able to write an attribute on the target filesystems.
184 # On really old kernels the system calls might not be implemented at all,
185 # but the more common case is that the tested filesystem simply doesn't
186 # support attributes. Note that we can't simply list attributes as
187 # various security modules generate synthetic attributes not actually
190 touch $TEST_DIR/syscalltest
191 attr -s "user.xfstests" -V "attr" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
192 cat $TEST_DIR/syscalltest.out >> $seqres.full
194 if grep -q 'Function not implemented' $TEST_DIR/syscalltest.out; then
195 _notrun "kernel does not support attrs"
197 if grep -q 'Operation not supported' $TEST_DIR/syscalltest.out; then
198 _notrun "attrs not supported by this filesystem type: $FSTYP"
201 rm -f $TEST_DIR/syscalltest.out
206 _scratch_mkfs_xfs_supported -i attr=1 >/dev/null 2>&1 \
207 || _notrun "attr v1 not supported on $SCRATCH_DEV"
210 # check if we support the noattr2 mount option
213 _scratch_mkfs_xfs > /dev/null 2>&1 \
214 || _fail "_scratch_mkfs_xfs failed on $SCRATCH_DEV"
215 _try_scratch_mount -o noattr2 > /dev/null 2>&1 \
216 || _notrun "noattr2 mount option not supported on $SCRATCH_DEV"
220 # getfattr -R returns info in readdir order which varies from fs to fs.
221 # This sorts the output by filename
222 _sort_getfattr_output()
224 awk '{a[FNR]=$0}END{n = asort(a); for(i=1; i <= n; i++) print a[i]"\n"}' RS=''
227 # Previously, when getfattr dumps values of all extended attributes, it prints
228 # empty attr as 'user.name', but new getfattr (since attr-2.4.48) prints it as
229 # 'user.name=""'. Filter out the ending '=""' so that both old and new getfattr
230 # pints the same output.
232 # Note: This function returns the getfattr command result.
235 $GETFATTR_PROG "$@" | sed -e 's/=\"\"//'
236 return ${PIPESTATUS[0]}
239 # set maximum total attr space based on fs type
241 xfs|udf|pvfs2|9p|ceph)
245 # Assume max ~1 block of attrs
246 BLOCK_SIZE=`_get_block_size $TEST_DIR`
247 # user.attribute_XXX="value.XXX" is about 32 bytes; leave some overhead
248 let MAX_ATTRS=$BLOCK_SIZE/40
253 # Set max attr value size based on fs type
259 MAX_ATTRVAL_SIZE=8192
262 MAX_ATTRVAL_SIZE=65536
265 # Assume max ~1 block of attrs
266 BLOCK_SIZE=`_get_block_size $TEST_DIR`
267 # leave a little overhead
268 let MAX_ATTRVAL_SIZE=$BLOCK_SIZE-256
271 export MAX_ATTRVAL_SIZE
272 # make sure this script returns success