generic: listxattr syscall with different buffer sizes
[xfstests-dev.git] / tests / generic / 377
1 #! /bin/bash
2 # FSQA Test No. 377
3 #
4 # Test listxattr syscall behaviour with different buffer sizes.
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2016 Red Hat, Inc.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation, either version 2 of
12 # the License, or (at your option) any later version.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #-----------------------------------------------------------------------
22 #
23
24 seq=`basename $0`
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
27 tmp=/tmp/$$
28 status=1        # failure is the default!
29 trap "_cleanup; exit \$status" 0 1 2 3 15
30
31 _cleanup()
32 {
33         cd /
34         rm -f $tmp.*
35 }
36
37 # get standard environment, filters and checks
38 . ./common/rc
39 . ./common/filter
40 . ./common/attr
41
42 # real QA test starts here
43 _supported_fs generic
44 _supported_os Linux
45 _require_scratch
46 _require_attrs
47 _require_test_program "listxattr"
48
49 listxattr="$here/src/listxattr"
50
51 rm -f $seqres.full
52
53 _scratch_mkfs >>$seqres.full 2>&1
54 _scratch_mount
55
56 # Create a testfile with three xattrs such that the sum of namelengths of the
57 # first two is bigger than the namelength of the third. This is needed for
58 # the 5th testcase that tests one of the cornercases.
59 testfile=${SCRATCH_MNT}/testfile
60 touch $testfile
61 $SETFATTR_PROG -n user.foo -v bar $testfile
62 $SETFATTR_PROG -n user.ping -v pong $testfile
63 $SETFATTR_PROG -n user.hello -v there $testfile
64
65 # 1. Call listxattr without buffer length argument. This should succeed.
66 $listxattr $testfile | sort
67
68 # 2. Calling listxattr on nonexistant file should fail with -ENOENT.
69 $listxattr ""
70
71 # 3. Calling listxattr with buffersize not suffecient for even one xattr
72 # should fail with -ERANGE.
73 $listxattr $testfile 1
74
75 # 4. Calling listxattr with buffersize suffecient for one xattr, but not
76 # sufficient for the whole list should still fail with -ERANGE.
77 $listxattr $testfile 9
78
79 # 5. Calling listxattr with buffersize suffecient for the last xattr, but not
80 # sufficient for the sum of first two. Should fail with -ERANGE.
81 $listxattr $testfile 11
82
83 # 6. Calling listxattr with buffersize bigger than needed should succeed.
84 $listxattr $testfile 500 | sort
85
86 status=0
87 exit