[PATCH v3 04/25] Add new constants from Linux 7.2 and 7.3 to bits/fcntl-linux.h

Adhemerval Zanella adhemerval.zanella@linaro.org
Mon Nov 16 19:42:17 GMT 2026


Add the O_EMPTYPATH open flag (commit
31cf44efa6df72a524b40adefb80539f3a4e13ba, Linux 7.2), which allows
openat and openat2 to open the file referred to by the descriptor
argument when the file name is empty, and FD_FAILFS_ROOT (commit
cdf930a00949af72fbe9a22da2a8efa77981baa7, Linux 7.3).

O_EMPTYPATH has the same value on all architectures, so there is no
need for architecture-specific definitions.  The manual documents the
new open flag.
---
 manual/filesys.texi                        |  3 ++-
 manual/llio.texi                           | 13 +++++++++++++
 sysdeps/unix/sysv/linux/bits/fcntl-linux.h |  5 +++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/manual/filesys.texi b/manual/filesys.texi
index f49d7d75728..bbe9f6405f5 100644
--- a/manual/filesys.texi
+++ b/manual/filesys.texi
@@ -300,7 +300,8 @@ file name resolution.  On Linux, this allows operations on descriptors
 opened with the @code{O_PATH} flag.  For regular descriptors (opened
 without @code{O_PATH}), the same functionality is also available through
 the plain descriptor-based functions (for example, @code{fstat} instead
-of @code{fstatat}).
+of @code{fstatat}).  The @code{openat} and @code{openat2} functions use
+the @code{O_EMPTYPATH} open flag instead (@pxref{Open-time Flags}).
 
 This is a GNU extension.
 @end itemize
diff --git a/manual/llio.texi b/manual/llio.texi
index c055ea61b6a..90c6a53da74 100644
--- a/manual/llio.texi
+++ b/manual/llio.texi
@@ -4115,6 +4115,19 @@ refers to a symbolic link.  The @code{errno} variable is set to
 @code{ELOOP} for this error condition.
 @end deftypevr
 
+@deftypevr Macro int O_EMPTYPATH
+@standards{Linux, fcntl.h}
+If set, @code{openat} and @code{openat2} accept an empty file name
+@code{""}, and open the file referred to by the descriptor argument
+itself.  This can be used to obtain a regular descriptor for a file
+from a descriptor opened with @code{O_PATH}, with the access mode given
+in the flags.  @xref{Descriptor-Relative Access}.
+
+Kernels older than Linux 7.2 do not support this flag, so @code{openat}
+ignores it and fails with @code{ENOENT} for an empty file name, and
+@code{openat2} fails with @code{EINVAL}.
+@end deftypevr
+
 @deftypevr Macro int O_TMPFILE
 @standards{GNU, fcntl.h}
 If this flag is specified, functions in the @code{open} family create an
diff --git a/sysdeps/unix/sysv/linux/bits/fcntl-linux.h b/sysdeps/unix/sysv/linux/bits/fcntl-linux.h
index 6aaa6cc4e7f..765cabd21b0 100644
--- a/sysdeps/unix/sysv/linux/bits/fcntl-linux.h
+++ b/sysdeps/unix/sysv/linux/bits/fcntl-linux.h
@@ -97,6 +97,9 @@
 #ifndef __O_TMPFILE
 # define __O_TMPFILE   (020000000 | __O_DIRECTORY)
 #endif
+#ifndef __O_EMPTYPATH
+# define __O_EMPTYPATH 0400000000
+#endif
 
 #ifndef F_GETLK
 # if !defined __USE_FILE_OFFSET64 && __TIMESIZE != 64
@@ -147,6 +150,7 @@
 # define O_NOATIME	__O_NOATIME	/* Do not set atime.  */
 # define O_PATH		__O_PATH	/* Resolve pathname but do not open file.  */
 # define O_TMPFILE	__O_TMPFILE	/* Atomically create nameless file.  */
+# define O_EMPTYPATH	__O_EMPTYPATH	/* Allow empty file name.  */
 #endif
 
 /* For now, Linux has no separate synchronicity options for read
@@ -222,6 +226,7 @@
 #ifdef __USE_GNU
 # define FD_PIDFS_ROOT	-10002	/* Root of the pidfs filesystem */
 # define FD_NSFS_ROOT	-10003	/* Root of the nsfs filesystem */
+# define FD_FAILFS_ROOT	-10004	/* Root of the failfs filesystem */
 #endif
 
 #ifndef F_RDLCK
-- 
2.53.0



More information about the Libc-alpha mailing list