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
32 _require_test_program "listxattr"
34 listxattr="$here/src/listxattr"
38 _scratch_mkfs >>$seqres.full 2>&1
41 # Create a testfile with three xattrs such that the sum of namelengths of the
42 # first two is bigger than the namelength of the third. This is needed for
43 # the 5th testcase that tests one of the cornercases.
44 testfile=${SCRATCH_MNT}/testfile
46 $SETFATTR_PROG -n user.foo -v bar $testfile
47 $SETFATTR_PROG -n user.ping -v pong $testfile
48 $SETFATTR_PROG -n user.hello -v there $testfile
50 # 1. Call listxattr without buffer length argument. This should succeed.
51 $listxattr $testfile | sort
53 # 2. Calling listxattr on nonexistant file should fail with -ENOENT.
56 # 3. Calling listxattr with buffersize not suffecient for even one xattr
57 # should fail with -ERANGE.
58 $listxattr $testfile 1
60 # 4. Calling listxattr with buffersize suffecient for one xattr, but not
61 # sufficient for the whole list should still fail with -ERANGE.
62 $listxattr $testfile 9
64 # 5. Calling listxattr with buffersize suffecient for the last xattr, but not
65 # sufficient for the sum of first two. Should fail with -ERANGE.
66 $listxattr $testfile 11
68 # 6. Calling listxattr with buffersize bigger than needed should succeed.
69 $listxattr $testfile 500 | sort