[LTP] [PATCH 3/6] fs: add file_setattr/file_getattr fallback definitions
Andrea Cervesato
andrea.cervesato@suse.de
Mon Aug 4 20:09:21 CEST 2025
From: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
compile_flags.txt | 5 +++
configure.ac | 1 +
include/lapi/fs.h | 32 +++++++++++++++
testcases/kernel/syscalls/getxattr/getxattr06.c | 53 +++++++++++++++++++++++++
4 files changed, 91 insertions(+)
diff --git a/compile_flags.txt b/compile_flags.txt
new file mode 100644
index 0000000000000000000000000000000000000000..21b8cc301c9958663d74909396aa5dd21e45e911
--- /dev/null
+++ b/compile_flags.txt
@@ -0,0 +1,5 @@
+-Iinclude/
+-Iinclude/old
+-Itestcases/kernel/syscalls/utils
+-Itestcases/kernel/mem/hugetlb/lib
+-Itestcases/kernel/mem/include
diff --git a/configure.ac b/configure.ac
index 9bd139f602b9f174e5314171f8f03338c06f3df4..3ddea62b57270662fe8f24d52d697874ee8768ef 100644
--- a/configure.ac
+++ b/configure.ac
@@ -263,6 +263,7 @@ AC_CHECK_TYPES([struct mnt_id_req],,,[#include <sys/mount.h>])
AC_CHECK_TYPES([struct statmount],,,[#include <sys/mount.h>])
AC_CHECK_TYPES([struct pidfd_info],,,[#include <sys/pidfd.h>])
+AC_CHECK_TYPES([struct file_attr],,,[#include <linux/fs.h>])
AC_CHECK_TYPES([struct fsxattr],,,[#include <linux/fs.h>])
diff --git a/include/lapi/fs.h b/include/lapi/fs.h
index 23b58edf9621726f94727cc6286b9b4b67226035..e0a55d1ab963c07e1bd7a6dc9d92097af90018e1 100644
--- a/include/lapi/fs.h
+++ b/include/lapi/fs.h
@@ -14,10 +14,13 @@
# include <linux/fs.h>
#endif
+#include <stddef.h>
#include <stdint.h>
#include <sys/user.h>
#include <limits.h>
+#include "tst_test.h"
#include "lapi/abisize.h"
+#include "lapi/syscalls.h"
#ifndef HAVE_STRUCT_FSXATTR
struct fsxattr {
@@ -88,4 +91,33 @@ static inline long long tst_max_lfs_filesize(void)
#endif
}
+#ifndef HAVE_STRUCT_FILE_ATTR
+struct file_attr {
+ uint64_t fa_xflags; /* xflags field value (get/set) */
+ uint32_t fa_extsize; /* extsize field value (get/set)*/
+ uint32_t fa_nextents; /* nextents field value (get) */
+ uint32_t fa_projid; /* project identifier (get/set) */
+ uint32_t fa_cowextsize; /* CoW extsize field value (get/set) */
+};
+#endif
+
+#define FILE_ATTR_SIZE_VER0 24
+#define FILE_ATTR_SIZE_LATEST FILE_ATTR_SIZE_VER0
+
+static inline int file_getattr(int dfd, const char *filename,
+ struct file_attr *ufattr, size_t usize,
+ unsigned int at_flags)
+{
+ return tst_syscall(__NR_file_getattr, dfd, filename, ufattr, usize,
+ at_flags);
+}
+
+static inline int file_setattr(int dfd, const char *filename,
+ struct file_attr *ufattr, size_t usize,
+ unsigned int at_flags)
+{
+ return tst_syscall(__NR_file_setattr, dfd, filename, ufattr, usize,
+ at_flags);
+}
+
#endif /* LAPI_FS_H__ */
diff --git a/testcases/kernel/syscalls/getxattr/getxattr06.c b/testcases/kernel/syscalls/getxattr/getxattr06.c
new file mode 100644
index 0000000000000000000000000000000000000000..e1f7bb6aae5335b6bb22cba61eb826aa829b14a8
--- /dev/null
+++ b/testcases/kernel/syscalls/getxattr/getxattr06.c
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2012 Red Hat, Inc.
+ * Copyright (c) 2023 Marius Kittler <mkittler@suse.de>
+ */
+
+/*\
+ * An empty buffer of size zero can be passed into getxattr(2) to
+ * return the current size of the named extended attribute.
+ */
+
+#include "config.h"
+#include "tst_test.h"
+
+#include <sys/xattr.h>
+#include "tst_safe_macros.h"
+
+#define MNTPOINT "mntpoint"
+#define FNAME MNTPOINT"/getxattr03testfile"
+#define XATTR_TEST_KEY "user.testkey"
+#define XATTR_TEST_VALUE "test value"
+#define XATTR_TEST_VALUE_SIZE (sizeof(XATTR_TEST_VALUE) - 1)
+
+static void run(void)
+{
+ TST_EXP_VAL(getxattr(FNAME, XATTR_TEST_KEY, NULL, 0),
+ XATTR_TEST_VALUE_SIZE);
+}
+
+static void setup(void)
+{
+ SAFE_TOUCH(FNAME, 0644, NULL);
+ SAFE_SETXATTR(FNAME, XATTR_TEST_KEY, XATTR_TEST_VALUE,
+ XATTR_TEST_VALUE_SIZE, XATTR_CREATE);
+}
+
+static struct tst_test test = {
+ .timeout = 14,
+ .all_filesystems = 1,
+ .needs_root = 1,
+ .mntpoint = MNTPOINT,
+ .mount_device = 1,
+ .skip_filesystems = (const char *const []) {
+ "exfat",
+ "tmpfs",
+ "ramfs",
+ "nfs",
+ "vfat",
+ NULL
+ },
+ .setup = setup,
+ .test_all = run,
+};
--
2.50.1
More information about the ltp
mailing list