2 # SPDX-License-Identifier: GPL-2.0+
3 # Copyright (c) 2016 Red Hat, Inc. All Rights Reserved.
7 # Test listxattr syscall behaviour with different buffer sizes.
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
13 status=1 # failure is the default!
14 trap "_cleanup; exit \$status" 0 1 2 3 15
22 # get standard environment, filters and checks
27 # real QA test starts here
31 _require_test_program "listxattr"
33 listxattr="$here/src/listxattr"
37 _scratch_mkfs >>$seqres.full 2>&1
40 # Create a testfile with three xattrs such that the sum of namelengths of the
41 # first two is bigger than the namelength of the third. This is needed for
42 # the 5th testcase that tests one of the cornercases.
43 testfile=${SCRATCH_MNT}/testfile
45 $SETFATTR_PROG -n user.foo -v bar $testfile
46 $SETFATTR_PROG -n user.ping -v pong $testfile
47 $SETFATTR_PROG -n user.hello -v there $testfile
49 # 1. Call listxattr without buffer length argument. This should succeed.
50 $listxattr $testfile | grep '^xattr: user\.' | sort
52 # 2. Calling listxattr on nonexistant file should fail with -ENOENT.
55 # 3. Calling listxattr with buffersize not suffecient for even one xattr
56 # should fail with -ERANGE.
57 $listxattr $testfile 1
59 # 4. Calling listxattr with buffersize suffecient for one xattr, but not
60 # sufficient for the whole list should still fail with -ERANGE.
61 $listxattr $testfile 9
63 # 5. Calling listxattr with buffersize suffecient for the last xattr, but not
64 # sufficient for the sum of first two. Should fail with -ERANGE.
65 $listxattr $testfile 11
67 # 6. Calling listxattr with buffersize bigger than needed should succeed.
68 $listxattr $testfile 500 | grep '^xattr: user\.' | sort