mirror of
https://github.com/linux-apfs/apfstests.git
synced 2026-05-01 15:01:44 -07:00
generic: listxattr syscall with different buffer sizes
Add test that calls listxattr syscall with different buffer size arguments checking if it fails properly. Signed-off-by: Artem Savkov <asavkov@redhat.com> Reviewed-by: Eryu Guan <eguan@redhat.com> Signed-off-by: Eryu Guan <eguan@redhat.com>
This commit is contained in:
@@ -66,6 +66,7 @@
|
||||
/src/holes
|
||||
/src/holetest
|
||||
/src/itrash
|
||||
/src/listxattr
|
||||
/src/locktest
|
||||
/src/loggen
|
||||
/src/looptest
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
|
||||
stale_handle pwrite_mmap_blocked t_dir_offset2 seek_sanity_test \
|
||||
seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec cloner \
|
||||
renameat2 t_getcwd e4compact test-nextquota punch-alternating \
|
||||
attr-list-by-handle-cursor-test
|
||||
attr-list-by-handle-cursor-test listxattr
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Red Hat, Inc. All Rights Reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation, either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it would be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/xattr.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
size_t bufsize = 0;
|
||||
char *buf = NULL;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "usage: %s <testfile> [bufsize]\n", argv[0]);
|
||||
return 1;
|
||||
};
|
||||
|
||||
if (argc > 2) {
|
||||
bufsize = strtoul(argv[2], NULL, 10);
|
||||
if (bufsize == -1) {
|
||||
perror("buffsize");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (bufsize == 0) {
|
||||
bufsize = listxattr(argv[1], NULL, 0);
|
||||
if (bufsize == -1) {
|
||||
perror("listxattr");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
buf = malloc(bufsize);
|
||||
if (buf == NULL) {
|
||||
perror("buf alloc");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = listxattr(argv[1], buf, bufsize);
|
||||
if (ret < 0) {
|
||||
perror("listxattr");
|
||||
} else {
|
||||
char *l;
|
||||
for (l = buf; l != (buf + bufsize) && *l != '\0';
|
||||
l = strchr(l, '\0') + 1) {
|
||||
printf("xattr: %s\n", l);
|
||||
}
|
||||
}
|
||||
|
||||
free(buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+87
@@ -0,0 +1,87 @@
|
||||
#! /bin/bash
|
||||
# FSQA Test No. 377
|
||||
#
|
||||
# Test listxattr syscall behaviour with different buffer sizes.
|
||||
#
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright (c) 2016 Red Hat, Inc. All Rights Reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation, either version 2 of
|
||||
# the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it would be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
#-----------------------------------------------------------------------
|
||||
#
|
||||
|
||||
seq=`basename $0`
|
||||
seqres=$RESULT_DIR/$seq
|
||||
echo "QA output created by $seq"
|
||||
tmp=/tmp/$$
|
||||
status=1 # failure is the default!
|
||||
trap "_cleanup; exit \$status" 0 1 2 3 15
|
||||
|
||||
_cleanup()
|
||||
{
|
||||
cd /
|
||||
rm -f $tmp.*
|
||||
}
|
||||
|
||||
# get standard environment, filters and checks
|
||||
. ./common/rc
|
||||
. ./common/filter
|
||||
. ./common/attr
|
||||
|
||||
# real QA test starts here
|
||||
_supported_fs generic
|
||||
_supported_os Linux
|
||||
_require_scratch
|
||||
_require_attrs
|
||||
_require_test_program "listxattr"
|
||||
|
||||
listxattr="$here/src/listxattr"
|
||||
|
||||
rm -f $seqres.full
|
||||
|
||||
_scratch_mkfs >>$seqres.full 2>&1
|
||||
_scratch_mount
|
||||
|
||||
# Create a testfile with three xattrs such that the sum of namelengths of the
|
||||
# first two is bigger than the namelength of the third. This is needed for
|
||||
# the 5th testcase that tests one of the cornercases.
|
||||
testfile=${SCRATCH_MNT}/testfile
|
||||
touch $testfile
|
||||
$SETFATTR_PROG -n user.foo -v bar $testfile
|
||||
$SETFATTR_PROG -n user.ping -v pong $testfile
|
||||
$SETFATTR_PROG -n user.hello -v there $testfile
|
||||
|
||||
# 1. Call listxattr without buffer length argument. This should succeed.
|
||||
$listxattr $testfile | sort
|
||||
|
||||
# 2. Calling listxattr on nonexistant file should fail with -ENOENT.
|
||||
$listxattr ""
|
||||
|
||||
# 3. Calling listxattr with buffersize not suffecient for even one xattr
|
||||
# should fail with -ERANGE.
|
||||
$listxattr $testfile 1
|
||||
|
||||
# 4. Calling listxattr with buffersize suffecient for one xattr, but not
|
||||
# sufficient for the whole list should still fail with -ERANGE.
|
||||
$listxattr $testfile 9
|
||||
|
||||
# 5. Calling listxattr with buffersize suffecient for the last xattr, but not
|
||||
# sufficient for the sum of first two. Should fail with -ERANGE.
|
||||
$listxattr $testfile 11
|
||||
|
||||
# 6. Calling listxattr with buffersize bigger than needed should succeed.
|
||||
$listxattr $testfile 500 | sort
|
||||
|
||||
status=0
|
||||
exit
|
||||
@@ -0,0 +1,11 @@
|
||||
QA output created by 377
|
||||
xattr: user.foo
|
||||
xattr: user.hello
|
||||
xattr: user.ping
|
||||
listxattr: No such file or directory
|
||||
listxattr: Numerical result out of range
|
||||
listxattr: Numerical result out of range
|
||||
listxattr: Numerical result out of range
|
||||
xattr: user.foo
|
||||
xattr: user.hello
|
||||
xattr: user.ping
|
||||
@@ -379,3 +379,4 @@
|
||||
374 auto quick clone dedupe
|
||||
375 auto quick acl
|
||||
376 auto quick metadata
|
||||
377 attr auto quick metadata
|
||||
|
||||
Reference in New Issue
Block a user