@@ -32,6 +32,12 @@ Major new features:
extended attribute functions which take a directory file descriptor
and AT_* flags, like openat.
+* On Linux, the file_getattr and file_setattr functions have been added,
+ along with the <sys/file_attr.h> header. They retrieve and change the
+ extended file attributes (FS_XFLAG_* flags, project ID, and extent size
+ hints) of a file, which were previously only available through the
+ FS_IOC_FSGETXATTR and FS_IOC_FSSETXATTR ioctls.
+
Deprecated and removed features, and other changes affecting compatibility:
* The posix_spawn_file_actions_addchdir and posix_spawn_file_actions_addfchdir
@@ -173,6 +173,7 @@ sysdep_headers += \
sys/epoll.h \
sys/eventfd.h \
sys/fanotify.h \
+ sys/file_attr.h \
sys/fsuid.h \
sys/inotify.h \
sys/kd.h \
@@ -206,6 +207,7 @@ tests += \
tst-fanotify \
tst-fchroot \
tst-fdopendir-o_path \
+ tst-file_attr \
tst-getauxval \
tst-gettid \
tst-gettid-kill \
@@ -345,6 +345,8 @@ libc {
}
GLIBC_2.45 {
fchroot;
+ file_getattr;
+ file_setattr;
getxattrat;
listmount;
listxattrat;
@@ -2776,6 +2776,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -3123,6 +3123,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2537,6 +2537,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2829,6 +2829,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2826,6 +2826,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2813,6 +2813,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2850,6 +2850,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -3033,6 +3033,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2288,6 +2288,8 @@ GLIBC_2.44 write F
GLIBC_2.44 writev F
GLIBC_2.44 wscanf F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2297,6 +2297,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2809,6 +2809,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2976,6 +2976,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2862,6 +2862,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2859,6 +2859,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2939,6 +2939,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2937,6 +2937,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2945,6 +2945,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2847,6 +2847,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2287,6 +2287,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -3166,6 +3166,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -3211,6 +3211,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2920,6 +2920,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2996,6 +2996,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2540,6 +2540,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2740,6 +2740,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2957,6 +2957,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2856,6 +2856,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2853,6 +2853,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -3187,6 +3187,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2823,6 +2823,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
new file mode 100644
@@ -0,0 +1,92 @@
+/* File attributes. Linux version.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#ifndef _SYS_FILE_ATTR_H
+#define _SYS_FILE_ATTR_H 1
+
+#include <features.h>
+#include <bits/types.h>
+#include <stddef.h>
+
+#ifdef __has_include
+# if __has_include ("linux/fs.h")
+# include "linux/fs.h"
+# endif
+#endif
+
+#ifndef FILE_ATTR_SIZE_VER0
+/* Attributes for file_getattr and file_setattr. */
+struct file_attr
+{
+ __uint64_t fa_xflags; /* FS_XFLAG_* flags (get/set). */
+ __uint32_t fa_extsize; /* Extent size hint (get/set). */
+ __uint32_t fa_nextents; /* Number of extents (get). */
+ __uint32_t fa_projid; /* Project identifier (get/set). */
+ __uint32_t fa_cowextsize; /* CoW extent size hint (get/set). */
+};
+# define FILE_ATTR_SIZE_VER0 24
+# define FILE_ATTR_SIZE_LATEST FILE_ATTR_SIZE_VER0
+#endif
+
+/* Flags for the fa_xflags field. */
+#define FS_XFLAG_REALTIME 0x00000001 /* Data in realtime volume. */
+#define FS_XFLAG_PREALLOC 0x00000002 /* Preallocated extents. */
+#define FS_XFLAG_IMMUTABLE 0x00000008 /* File cannot be modified. */
+#define FS_XFLAG_APPEND 0x00000010 /* All writes append. */
+#define FS_XFLAG_SYNC 0x00000020 /* All writes synchronous. */
+#define FS_XFLAG_NOATIME 0x00000040 /* No access time updates. */
+#define FS_XFLAG_NODUMP 0x00000080 /* Not included in backups. */
+#define FS_XFLAG_RTINHERIT 0x00000100 /* Create with rt bit set. */
+#define FS_XFLAG_PROJINHERIT 0x00000200 /* Inherit parent projid. */
+#define FS_XFLAG_NOSYMLINKS 0x00000400 /* No symlink creation. */
+#define FS_XFLAG_EXTSIZE 0x00000800 /* Extent size hint. */
+#define FS_XFLAG_EXTSZINHERIT 0x00001000 /* Inherit extent size. */
+#define FS_XFLAG_NODEFRAG 0x00002000 /* Do not defragment. */
+#define FS_XFLAG_FILESTREAM 0x00004000 /* Filestream allocator. */
+#define FS_XFLAG_DAX 0x00008000 /* Use DAX for IO. */
+#define FS_XFLAG_COWEXTSIZE 0x00010000 /* CoW extent size hint. */
+#define FS_XFLAG_VERITY 0x00020000 /* fs-verity enabled. */
+#define FS_XFLAG_CASEFOLD 0x00040000 /* Case-insensitive lookups
+ (read-only). */
+#define FS_XFLAG_CASENONPRESERVING 0x00080000 /* Case not preserved
+ (read-only). */
+#define FS_XFLAG_HASATTR 0x80000000 /* No DIFLAG for this. */
+
+__BEGIN_DECLS
+
+/* The following functions operate on the file pointed to by PATH, which is
+ relative to the directory DFD (as openat). AT_FLAGS can contain
+ AT_SYMLINK_NOFOLLOW and AT_EMPTY_PATH. With AT_EMPTY_PATH, PATH can be
+ empty or a null pointer to operate on DFD itself. SIZE is the size of
+ the structure pointed to by FATTR. */
+
+/* Store in FATTR the attributes of the file. Return 0 on success, -1 for
+ errors. */
+extern int file_getattr (int __dfd, const char *__path,
+ struct file_attr *__fattr, size_t __size,
+ unsigned int __at_flags) __THROW;
+
+/* Set the attributes of the file to FATTR. Return 0 on success, -1 for
+ errors. */
+extern int file_setattr (int __dfd, const char *__path,
+ const struct file_attr *__fattr, size_t __size,
+ unsigned int __at_flags) __THROW;
+
+__END_DECLS
+
+#endif /* sys/file_attr.h */
@@ -11,6 +11,8 @@ epoll_ctl EXTRA epoll_ctl i:iiip epoll_ctl
eventfd EXTRA eventfd2 i:ii eventfd
execve - execve i:spp __execve execve
fchroot EXTRA fchroot i:iU fchroot
+file_getattr EXTRA file_getattr i:iSpUU file_getattr
+file_setattr EXTRA file_setattr i:iSpUU file_setattr
flock - flock i:ii __flock flock
fsconfig EXTRA fsconfig i:iUsNi fsconfig
fsmount EXTRA fsmount i:iUU fsmount
new file mode 100644
@@ -0,0 +1,89 @@
+/* Basic tests for Linux file_getattr and file_setattr.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/file_attr.h>
+#include <support/check.h>
+#include <support/temp_file.h>
+#include <support/xunistd.h>
+
+_Static_assert (sizeof (struct file_attr) == FILE_ATTR_SIZE_VER0,
+ "sizeof (struct file_attr) != FILE_ATTR_SIZE_VER0");
+
+static int
+do_test (void)
+{
+ char *path;
+ int fd = create_temp_file ("tst-file_attr.", &path);
+ TEST_VERIFY_EXIT (fd != -1);
+
+ struct file_attr fa;
+ if (file_getattr (AT_FDCWD, path, &fa, sizeof (fa), 0) != 0)
+ {
+ if (errno == ENOSYS)
+ FAIL_UNSUPPORTED ("file_getattr is not supported by the kernel");
+ if (errno == EOPNOTSUPP)
+ FAIL_UNSUPPORTED ("file attributes are not supported");
+ FAIL_EXIT1 ("file_getattr: %m");
+ }
+
+ /* The same attributes through the file descriptor. */
+ struct file_attr fa2;
+ TEST_COMPARE (file_getattr (fd, NULL, &fa2, sizeof (fa2), AT_EMPTY_PATH),
+ 0);
+ TEST_COMPARE (fa2.fa_xflags, fa.fa_xflags);
+
+ /* The structure size must cover the first version. */
+ TEST_COMPARE (file_getattr (AT_FDCWD, path, &fa2, FILE_ATTR_SIZE_VER0 - 1,
+ 0), -1);
+ TEST_COMPARE (errno, EINVAL);
+
+ /* Only AT_SYMLINK_NOFOLLOW and AT_EMPTY_PATH are accepted. */
+ TEST_COMPARE (file_getattr (AT_FDCWD, path, &fa2, sizeof (fa2),
+ AT_REMOVEDIR), -1);
+ TEST_COMPARE (errno, EINVAL);
+
+ /* The owner of the file can set FS_XFLAG_NODUMP. */
+ fa.fa_xflags |= FS_XFLAG_NODUMP;
+ if (file_setattr (AT_FDCWD, path, &fa, sizeof (fa), 0) == 0)
+ {
+ TEST_COMPARE (file_getattr (fd, "", &fa2, sizeof (fa2), AT_EMPTY_PATH),
+ 0);
+ TEST_VERIFY (fa2.fa_xflags & FS_XFLAG_NODUMP);
+
+ fa.fa_xflags &= ~FS_XFLAG_NODUMP;
+ TEST_COMPARE (file_setattr (fd, NULL, &fa, sizeof (fa), AT_EMPTY_PATH),
+ 0);
+ TEST_COMPARE (file_getattr (AT_FDCWD, path, &fa2, sizeof (fa2), 0), 0);
+ TEST_VERIFY (!(fa2.fa_xflags & FS_XFLAG_NODUMP));
+ }
+ else
+ {
+ TEST_COMPARE (errno, EOPNOTSUPP);
+ puts ("info: FS_XFLAG_NODUMP is not supported by the file system");
+ }
+
+ xclose (fd);
+ free (path);
+ return 0;
+}
+
+#include <support/test-driver.c>
@@ -2772,6 +2772,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F
@@ -2791,6 +2791,8 @@ GLIBC_2.43 mseal F
GLIBC_2.43 openat2 F
GLIBC_2.43 umaxabs F
GLIBC_2.45 fchroot F
+GLIBC_2.45 file_getattr F
+GLIBC_2.45 file_setattr F
GLIBC_2.45 getxattrat F
GLIBC_2.45 listmount F
GLIBC_2.45 listxattrat F