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 _begin_fstest attr auto quick metadata
12 # Import common functions.
16 # real QA test starts here
20 _require_test_program "listxattr"
22 listxattr="$here/src/listxattr"
24 _scratch_mkfs >>$seqres.full 2>&1
27 # Create a testfile with three xattrs such that the sum of namelengths of the
28 # first two is bigger than the namelength of the third. This is needed for
29 # the 5th testcase that tests one of the cornercases.
30 testfile=${SCRATCH_MNT}/testfile
32 $SETFATTR_PROG -n user.foo -v bar $testfile
33 $SETFATTR_PROG -n user.ping -v pong $testfile
34 $SETFATTR_PROG -n user.hello -v there $testfile
36 # 1. Call listxattr without buffer length argument. This should succeed.
37 $listxattr $testfile | grep '^xattr: user\.' | sort
39 # 2. Calling listxattr on nonexistant file should fail with -ENOENT.
42 # 3. Calling listxattr with buffersize not suffecient for even one xattr
43 # should fail with -ERANGE.
44 $listxattr $testfile 1
46 # 4. Calling listxattr with buffersize suffecient for one xattr, but not
47 # sufficient for the whole list should still fail with -ERANGE.
48 $listxattr $testfile 9
50 # 5. Calling listxattr with buffersize suffecient for the last xattr, but not
51 # sufficient for the sum of first two. Should fail with -ERANGE.
52 $listxattr $testfile 11
54 # 6. Calling listxattr with buffersize bigger than needed should succeed.
55 $listxattr $testfile 500 | grep '^xattr: user\.' | sort