asm-generic/fcntl.h vs bits/fcntl.h

DJ Delorie dj@redhat.com
Fri Jan 16 19:45:00 GMT 2026


Florian Weimer <fw@deneb.enyo.de> writes:
> No, it contains too much other stuff, and more importantly, it's not
> architecture-specific.  We can't make this file architecture-specific
> as is, it has too many independent parts init, so this would be bad
> from a maintenance perspective.

So I worked on this for a while, trying to "do it right", and discovered
the following:

* The new mount API functions added in 2022 require more of fcntl.h than
  just O_CLOEXEC.  All the AT_* constants, for example.

* The man pages document that fcntl.h must be included manually.

* sysdeps/unix/sysv/linux/tst-mount.c does not include fcntl.h.

* Even fixed, the original conflict occurs if you need to use the NEW
  mount APIs, because fcntl.h itself conflicts wrt its typedefs.

* Those files are very messy.

I ended up writing a patch that split bits/fcntl.h into three
categories: O_ flags, F_/FN_ flags, and "everything else".  I added
those conditionals to all the sysdeps files (which are already
arch-specific), and made them allow themselves to be included by
sys/mount.h as well as fcntl.h, and pulled just the O_ flags into
mount.h.  I also moved the F_*LCK constants a bit to organize them
better and reduce clutter.

It seems to work (attached, probably has bugs, for discussion only ;).

However, at the other end of the effort curve, I could have added a
dozen or so sysdep/*/o_cloexec.h files for just that one flag.  That
seemed like bad forward planning to me.

Thoughts?


diff --git a/bits/fcntl.h b/bits/fcntl.h
index ed14c22625..eed5766f2b 100644
--- a/bits/fcntl.h
+++ b/bits/fcntl.h
@@ -16,11 +16,12 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#ifndef	_FCNTL_H
+#if !defined(_FCNTL_H) && !defined(_SYS_MOUNT_H)
 #error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
 #endif
 
 
+#ifdef __FCNTL_H_INCLUDE_O_FLAGS
 /* File access modes for `open' and `fcntl'.  */
 #define	O_RDONLY	0	/* Open read-only.  */
 #define	O_WRONLY	1	/* Open write-only.  */
@@ -78,7 +79,9 @@
 /* Mask for file access modes.  This is system-dependent in case
    some system ever wants to define some other flavor of access.  */
 #define	O_ACCMODE	(O_RDONLY|O_WRONLY|O_RDWR)
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_F_FLAGS
 /* Values for the second argument to `fcntl'.  */
 #define	F_DUPFD	  	0	/* Duplicate file descriptor.  */
 #define	F_GETFD		1	/* Get file descriptor flags.  */
@@ -104,7 +107,14 @@
 /* File descriptor flags used with F_GETFD and F_SETFD.  */
 #define	FD_CLOEXEC	1	/* Close on exec.  */
 
+/* Values for the `l_type' field of a `struct flock'.  */
+#define	F_RDLCK	1	/* Read lock.  */
+#define	F_WRLCK	2	/* Write lock.  */
+#define	F_UNLCK	3	/* Remove lock.  */
+#endif
+
 
+#ifdef __FCNTL_H_INCLUDE_MISC
 #include <bits/types.h>
 
 /* The structure describing an advisory lock.  This is the type of the third
@@ -130,11 +140,6 @@ struct flock64
   };
 #endif
 
-/* Values for the `l_type' field of a `struct flock'.  */
-#define	F_RDLCK	1	/* Read lock.  */
-#define	F_WRLCK	2	/* Write lock.  */
-#define	F_UNLCK	3	/* Remove lock.  */
-
 /* Advise to `posix_fadvise'.  */
 #ifdef __USE_XOPEN2K
 # define POSIX_FADV_NORMAL	0 /* No further special treatment.  */
@@ -144,3 +149,4 @@ struct flock64
 # define POSIX_FADV_DONTNEED	4 /* Don't need these pages.  */
 # define POSIX_FADV_NOREUSE	5 /* Data will be accessed once.  */
 #endif
+#endif
diff --git a/io/fcntl.h b/io/fcntl.h
index d0ad4d6652..2376330020 100644
--- a/io/fcntl.h
+++ b/io/fcntl.h
@@ -32,7 +32,13 @@ __BEGIN_DECLS
 
 /* Get the definitions of O_*, F_*, FD_*: all the
    numbers and flag bits for `open', `fcntl', et al.  */
+#define __FCNTL_H_INCLUDE_O_FLAGS
+#define __FCNTL_H_INCLUDE_F_FLAGS
+#define __FCNTL_H_INCLUDE_MISC
 #include <bits/fcntl.h>
+#undef __FCNTL_H_INCLUDE_O_FLAGS
+#undef __FCNTL_H_INCLUDE_F_FLAGS
+#undef __FCNTL_H_INCLUDE_MISC
 
 /* Detect if open needs mode as a third argument (or for openat as a fourth
    argument).  */
diff --git a/sysdeps/mach/hurd/bits/fcntl.h b/sysdeps/mach/hurd/bits/fcntl.h
index faa45a1e77..aeb50ae3e1 100644
--- a/sysdeps/mach/hurd/bits/fcntl.h
+++ b/sysdeps/mach/hurd/bits/fcntl.h
@@ -16,7 +16,7 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#ifndef _FCNTL_H
+#if !defined(_FCNTL_H) && !defined(_SYS_MOUNT_H)
 # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
 #endif
 
@@ -28,6 +28,8 @@
    `file_name_lookup'; and are returned by `fcntl' with the F_GETFL
    command.  */
 
+#ifdef __FCNTL_H_INCLUDE_O_FLAGS
+
 /* In GNU, read and write are bits (unlike BSD).  */
 #ifdef __USE_GNU
 # define O_READ		O_RDONLY /* Open for reading.  */
@@ -137,7 +139,6 @@
 /* `open' never assigns a controlling terminal in GNU.  */
 #define	O_NOCTTY	0	/* Don't assign a controlling terminal.  */
 
-
 #ifdef __USE_MISC
 /* Flags for TIOCFLUSH.  */
 # define FREAD		O_RDONLY
@@ -156,7 +157,10 @@
 # define FNDELAY	O_NDELAY
 #endif
 
+#endif
+
 
+#ifdef __FCNTL_H_INCLUDE_F_FLAGS
 /* Values for the second argument to `fcntl'.  */
 #define	F_DUPFD	  	0	/* Duplicate file descriptor.  */
 #define	F_GETFD		1	/* Get file descriptor flags.  */
@@ -197,6 +201,9 @@
 #define	F_WRLCK	2	/* Write lock.  */
 #define	F_UNLCK	3	/* Remove lock.  */
 
+#endif
+
+#ifdef __FCNTL_H_INCLUDE_MISC
 /* Advise to `posix_fadvise'.  */
 #ifdef __USE_XOPEN2K
 # define POSIX_FADV_NORMAL	0 /* No further special treatment.  */
@@ -206,3 +213,4 @@
 # define POSIX_FADV_DONTNEED	4 /* Don't need these pages.  */
 # define POSIX_FADV_NOREUSE	5 /* Data will be accessed once.  */
 #endif
+#endif
diff --git a/sysdeps/unix/sysv/linux/aarch64/bits/fcntl.h b/sysdeps/unix/sysv/linux/aarch64/bits/fcntl.h
index 500c594f9f..0423aba1db 100644
--- a/sysdeps/unix/sysv/linux/aarch64/bits/fcntl.h
+++ b/sysdeps/unix/sysv/linux/aarch64/bits/fcntl.h
@@ -17,20 +17,25 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#ifndef	_FCNTL_H
+#if !defined(_FCNTL_H) && !defined(_SYS_MOUNT_H)
 # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
 #endif
 
+#ifdef __FCNTL_H_INCLUDE_O_FLAGS
 #define __O_DIRECTORY	 040000
 #define __O_NOFOLLOW	0100000
 #define __O_DIRECT	0200000
 
 #define __O_LARGEFILE	0
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_F_FLAGS
 #define F_GETLK64	5
 #define F_SETLK64	6
 #define F_SETLKW64	7
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_MISC
 struct flock
   {
     short int l_type;	/* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.	*/
@@ -50,6 +55,7 @@ struct flock64
     __pid_t l_pid;	/* Process holding the lock.  */
   };
 #endif
+#endif
 
 /* Include generic Linux declarations.  */
 #include <bits/fcntl-linux.h>
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/fcntl.h b/sysdeps/unix/sysv/linux/alpha/bits/fcntl.h
index 1bb58423b2..671b2ba682 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/fcntl.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/fcntl.h
@@ -16,10 +16,11 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#ifndef	_FCNTL_H
+#if !defined(_FCNTL_H) && !defined(_SYS_MOUNT_H)
 # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
 #endif
 
+#ifdef __FCNTL_H_INCLUDE_O_FLAGS
 #define O_CREAT		 01000	/* not fcntl */
 #define O_TRUNC		 02000	/* not fcntl */
 #define O_EXCL		 04000	/* not fcntl */
@@ -42,7 +43,9 @@
 #define __O_LARGEFILE	0
 
 #define __O_DSYNC	040000	/* Synchronize data.  */
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_F_FLAGS
 #define F_GETLK		7	/* Get record locking info.  */
 #define F_SETLK		8	/* Set record locking info (non-blocking).  */
 #define F_SETLKW	9	/* Set record locking info (blocking).  */
@@ -61,7 +64,9 @@
 /* for old implementation of bsd flock () */
 #define F_EXLCK		16	/* or 3 */
 #define F_SHLCK		32	/* or 4 */
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_MISC
 /* We don't need to support __USE_FILE_OFFSET64.  */
 struct flock
   {
@@ -82,6 +87,7 @@ struct flock64
     __pid_t l_pid;	/* Process holding the lock.  */
   };
 #endif
+#endif
 
 /* Include generic Linux declarations.  */
 #include <bits/fcntl-linux.h>
diff --git a/sysdeps/unix/sysv/linux/arm/bits/fcntl.h b/sysdeps/unix/sysv/linux/arm/bits/fcntl.h
index 0bd4784df6..a40ec2a1dc 100644
--- a/sysdeps/unix/sysv/linux/arm/bits/fcntl.h
+++ b/sysdeps/unix/sysv/linux/arm/bits/fcntl.h
@@ -16,15 +16,18 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#ifndef	_FCNTL_H
+#if !defined(_FCNTL_H) && !defined(_SYS_MOUNT_H)
 # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
 #endif
 
+#ifdef __FCNTL_H_INCLUDE_O_FLAGS
 #define __O_DIRECTORY	 040000	/* Must be a directory.	 */
 #define __O_NOFOLLOW	0100000	/* Do not follow links.	 */
 #define __O_DIRECT	0200000	/* Direct disk access.	*/
 #define __O_LARGEFILE	0400000
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_MISC
 struct flock
   {
     short int l_type;	/* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.	*/
@@ -49,6 +52,7 @@ struct flock64
     __pid_t l_pid;	/* Process holding the lock.  */
   };
 #endif
+#endif
 
 /* Include generic Linux declarations.  */
 #include <bits/fcntl-linux.h>
diff --git a/sysdeps/unix/sysv/linux/bits/fcntl-linux-fortify.h b/sysdeps/unix/sysv/linux/bits/fcntl-linux-fortify.h
index 4c8f3a874e..ad28a00fba 100644
--- a/sysdeps/unix/sysv/linux/bits/fcntl-linux-fortify.h
+++ b/sysdeps/unix/sysv/linux/bits/fcntl-linux-fortify.h
@@ -16,10 +16,11 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#ifndef	_FCNTL_H
+#if !defined(_FCNTL_H) && !defined(_SYS_MOUNT_H)
 # error "Never include <bits/fcntl-linux-fortify.h> directly; use <fcntl.h> instead."
 #endif
 
+#ifdef __FCNTL_H_INCLUDE_MISC
 #ifdef __USE_GNU
 
 extern int __REDIRECT (__openat2_alias, (int __dfd, const char *__filename,
@@ -47,3 +48,4 @@ openat2 (int __dfd, const char *__filename, const struct open_how *__how,
 }
 
 #endif /* use GNU */
+#endif /* __FCNTL_H_INCLUDE_MISC */
diff --git a/sysdeps/unix/sysv/linux/bits/fcntl-linux.h b/sysdeps/unix/sysv/linux/bits/fcntl-linux.h
index ad7f7c98c6..1e1ae16322 100644
--- a/sysdeps/unix/sysv/linux/bits/fcntl-linux.h
+++ b/sysdeps/unix/sysv/linux/bits/fcntl-linux.h
@@ -16,7 +16,7 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#ifndef	_FCNTL_H
+#if !defined(_FCNTL_H) && !defined(_SYS_MOUNT_H)
 # error "Never use <bits/fcntl-linux.h> directly; include <fcntl.h> instead."
 #endif
 
@@ -38,6 +38,7 @@
 # include <bits/types/struct_iovec.h>
 #endif
 
+#ifdef __FCNTL_H_INCLUDE_O_FLAGS
 /* open/fcntl.  */
 #define O_ACCMODE	   0003
 #define O_RDONLY	     00
@@ -99,7 +100,9 @@
 #ifndef __O_TMPFILE
 # define __O_TMPFILE   (020000000 | __O_DIRECTORY)
 #endif
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_F_FLAGS
 #ifndef F_GETLK
 # if !defined __USE_FILE_OFFSET64 && __TIMESIZE != 64
 #  define F_GETLK	5	/* Get record locking info.  */
@@ -116,6 +119,7 @@
 # define F_SETLK64	13	/* Set record locking info (non-blocking).  */
 # define F_SETLKW64	14	/* Set record locking info (blocking).  */
 #endif
+#endif
 
 /* open file description locks.
 
@@ -128,12 +132,15 @@
    like BSD (flock) locks, and they are only released automatically when the
    last reference to the the file description against which they were acquired
    is put. */
+#ifdef __FCNTL_H_INCLUDE_F_FLAGS
 #ifdef __USE_GNU
 # define F_OFD_GETLK	36
 # define F_OFD_SETLK	37
 # define F_OFD_SETLKW	38
 #endif
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_O_FLAGS
 #ifdef __USE_LARGEFILE64
 # define O_LARGEFILE __O_LARGEFILE
 #endif
@@ -162,7 +169,9 @@
 #  define O_RSYNC	O_SYNC		/* Synchronize read operations.  */
 # endif
 #endif
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_F_FLAGS
 /* Values for the second argument to `fcntl'.  */
 #define F_DUPFD		0	/* Duplicate file descriptor.  */
 #define F_GETFD		1	/* Get file descriptor flags.  */
@@ -236,7 +245,9 @@
 # define F_EXLCK		4	/* or 3 */
 # define F_SHLCK		8	/* or 4 */
 #endif
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_MISC
 #ifdef __USE_MISC
 /* Operations for BSD flock, also used by the kernel implementation.  */
 # define LOCK_SH	1	/* Shared lock.  */
@@ -282,7 +293,9 @@ struct f_owner_ex
     __pid_t pid;		/* ID of owner.  */
   };
 #endif
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_F_FLAGS
 #ifdef __USE_GNU
 /* Types of seals.  */
 # define F_SEAL_SEAL	0x0001	/* Prevent further seals from being set.  */
@@ -293,7 +306,9 @@ struct f_owner_ex
 					   mapped.  */
 # define F_SEAL_EXEC	0x0020	/* Prevent chmod modifying exec bits. */
 #endif
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_MISC
 #ifdef __USE_GNU
 /* Hint values for F_{GET,SET}_RW_HINT.  */
 # define RWH_WRITE_LIFE_NOT_SET	0
@@ -487,6 +502,7 @@ extern int openat2 (int __dfd, const char * __filename,
      __nonnull ((2, 3));
 
 #endif	/* use GNU */
+#endif
 
 #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
 # include <bits/fcntl-linux-fortify.h>
diff --git a/sysdeps/unix/sysv/linux/bits/fcntl.h b/sysdeps/unix/sysv/linux/bits/fcntl.h
index f626eef80d..d514043740 100644
--- a/sysdeps/unix/sysv/linux/bits/fcntl.h
+++ b/sysdeps/unix/sysv/linux/bits/fcntl.h
@@ -16,16 +16,19 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#ifndef	_FCNTL_H
+#if !defined(_FCNTL_H) && !defined(_SYS_MOUNT_H)
 # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
 #endif
 
 #include <bits/wordsize.h>
 
+#ifdef __FCNTL_H_INCLUDE_O_FLAGS
 #if __WORDSIZE == 64
 # define __O_LARGEFILE	0
 #endif
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_MISC
 struct flock
   {
     short int l_type;	/* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.	*/
@@ -50,6 +53,7 @@ struct flock64
     __pid_t l_pid;	/* Process holding the lock.  */
   };
 #endif
+#endif
 
 /* Include generic Linux declarations.  */
 #include <bits/fcntl-linux.h>
diff --git a/sysdeps/unix/sysv/linux/hppa/bits/fcntl.h b/sysdeps/unix/sysv/linux/hppa/bits/fcntl.h
index a99067c141..2e75097f2b 100644
--- a/sysdeps/unix/sysv/linux/hppa/bits/fcntl.h
+++ b/sysdeps/unix/sysv/linux/hppa/bits/fcntl.h
@@ -16,10 +16,11 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#ifndef	_FCNTL_H
+#if !defined(_FCNTL_H) && !defined(_SYS_MOUNT_H)
 # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
 #endif
 
+#ifdef __FCNTL_H_INCLUDE_O_FLAGS
 #define O_CREAT		00000400 /* not fcntl */
 #define O_EXCL		00002000 /* not fcntl */
 #define O_NOCTTY	00400000 /* not fcntl */
@@ -37,7 +38,9 @@
 #define __O_TMPFILE     040010000 /* Atomically create nameless file. */
 
 #define __O_LARGEFILE	00004000
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_F_FLAGS
 #define F_GETLK64	8	/* Get record locking info.  */
 #define F_SETLK64	9	/* Set record locking info (non-blocking).  */
 #define F_SETLKW64	10	/* Set record locking info (blocking).  */
@@ -52,7 +55,9 @@
 #define F_RDLCK		1	/* Read lock.  */
 #define F_WRLCK		2	/* Write lock.  */
 #define F_UNLCK		3	/* Remove lock.  */
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_MISC
 struct flock
   {
     short int l_type;	/* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.	*/
@@ -77,6 +82,7 @@ struct flock64
     __pid_t l_pid;	/* Process holding the lock.  */
   };
 #endif
+#endif
 
 /* Include generic Linux declarations.  */
 #include <bits/fcntl-linux.h>
diff --git a/sysdeps/unix/sysv/linux/loongarch/bits/fcntl.h b/sysdeps/unix/sysv/linux/loongarch/bits/fcntl.h
index 0b16aaf592..b18ec35a46 100644
--- a/sysdeps/unix/sysv/linux/loongarch/bits/fcntl.h
+++ b/sysdeps/unix/sysv/linux/loongarch/bits/fcntl.h
@@ -16,7 +16,7 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#ifndef _FCNTL_H
+#if !defined(_FCNTL_H) && !defined(_SYS_MOUNT_H)
 #error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
 #endif
 
@@ -25,13 +25,18 @@
 /* In 64-bit ISA files are always with 64bit off_t and F_*LK64 are the same as
    non-64-bit versions.  It will need to be revised for 128-bit.  */
 #if __WORDSIZE == 64
+#ifdef __FCNTL_H_INCLUDE_O_FLAGS
 #define __O_LARGEFILE 0
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_F_FLAGS
 #define F_GETLK64 5  /* Get record locking info.  */
 #define F_SETLK64 6  /* Set record locking info (non-blocking).  */
 #define F_SETLKW64 7 /* Set record locking info (blocking).  */
 #endif
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_MISC
 struct flock
 {
   short int l_type;   /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
@@ -56,6 +61,7 @@ struct flock64
   __pid_t l_pid;      /* Process holding the lock.  */
 };
 #endif
+#endif
 
 /* Include generic Linux declarations.  */
 #include <bits/fcntl-linux.h>
diff --git a/sysdeps/unix/sysv/linux/m68k/bits/fcntl.h b/sysdeps/unix/sysv/linux/m68k/bits/fcntl.h
index 9946516151..cc11f97dc6 100644
--- a/sysdeps/unix/sysv/linux/m68k/bits/fcntl.h
+++ b/sysdeps/unix/sysv/linux/m68k/bits/fcntl.h
@@ -16,15 +16,18 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#ifndef	_FCNTL_H
+#if !defined(_FCNTL_H) && !defined(_SYS_MOUNT_H)
 # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
 #endif
 
+#ifdef __FCNTL_H_INCLUDE_O_FLAGS
 #define __O_DIRECTORY	 040000	/* Must be a directory.	 */
 #define __O_NOFOLLOW	0100000	/* Do not follow links.	 */
 #define __O_DIRECT	0200000	/* Direct disk access.	*/
 #define __O_LARGEFILE	0400000
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_MISC
 struct flock
   {
     short int l_type;	/* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.	*/
@@ -49,6 +52,7 @@ struct flock64
     __pid_t l_pid;	/* Process holding the lock.  */
   };
 #endif
+#endif
 
 /* Include generic Linux declarations.  */
 #include <bits/fcntl-linux.h>
diff --git a/sysdeps/unix/sysv/linux/microblaze/bits/fcntl.h b/sysdeps/unix/sysv/linux/microblaze/bits/fcntl.h
index 5c1ae009a7..c5d98166b9 100644
--- a/sysdeps/unix/sysv/linux/microblaze/bits/fcntl.h
+++ b/sysdeps/unix/sysv/linux/microblaze/bits/fcntl.h
@@ -16,10 +16,11 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#ifndef	_FCNTL_H
+#if !defined(_FCNTL_H) && !defined(_SYS_MOUNT_H)
 # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
 #endif
 
+#ifdef __FCNTL_H_INCLUDE_O_FLAGS
 #define O_CREAT	 00000100	/* not fcntl.  */
 #define O_TRUNC	 00001000	/* not fcntl.  */
 #define O_EXCL		 00000200	/* not fcntl.  */
@@ -41,7 +42,9 @@
 #define __O_LARGEFILE	00100000
 
 #define __O_DSYNC	00010000	/* Synchronize data.  */
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_F_FLAGS
 #define F_GETLK	5	/* Get record locking info.  */
 #define F_SETLK	6	/* Set record locking info (non-blocking).  */
 #define F_SETLKW	7	/* Set record locking info (blocking).  */
@@ -60,7 +63,9 @@
 /* for old implementation of bsd flock ().  */
 #define F_EXLCK	4	/* or 3.  */
 #define F_SHLCK	8	/* or 4.  */
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_MISC
 /* We don't need to support __USE_FILE_OFFSET64.  */
 struct flock
   {
@@ -81,6 +86,7 @@ struct flock64
     __pid_t l_pid;		/* Process holding the lock.  */
   };
 #endif
+#endif
 
 /* Include generic Linux declarations.  */
 #include <bits/fcntl-linux.h>
diff --git a/sysdeps/unix/sysv/linux/mips/bits/fcntl.h b/sysdeps/unix/sysv/linux/mips/bits/fcntl.h
index 60be660b63..7a6c3675d6 100644
--- a/sysdeps/unix/sysv/linux/mips/bits/fcntl.h
+++ b/sysdeps/unix/sysv/linux/mips/bits/fcntl.h
@@ -16,12 +16,13 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#ifndef	_FCNTL_H
+#if !defined(_FCNTL_H) && !defined(_SYS_MOUNT_H)
 # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
 #endif
 
 #include <sgidefs.h>
 
+#ifdef __FCNTL_H_INCLUDE_O_FLAGS
 #define O_APPEND	 0x0008
 #define O_SYNC		 0x4010
 #define O_NONBLOCK	 0x0080
@@ -40,7 +41,9 @@
 #else
 # define __O_LARGEFILE	0x2000	/* Allow large file opens.  */
 #endif
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_F_FLAGS
 #ifndef __USE_FILE_OFFSET64
 # define F_GETLK	14	/* Get record locking info.  */
 # define F_SETLK	6	/* Set record locking info (non-blocking).  */
@@ -63,7 +66,9 @@
 
 #define __F_SETOWN	24	/* Get owner (process receiving SIGIO).  */
 #define __F_GETOWN	23	/* Set owner (process receiving SIGIO).  */
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_MISC
 struct flock
   {
     short int l_type;	/* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.	*/
@@ -99,6 +104,7 @@ struct flock64
     __pid_t l_pid;	/* Process holding the lock.  */
   };
 #endif
+#endif
 
 /* Include generic Linux declarations.  */
 #include <bits/fcntl-linux.h>
diff --git a/sysdeps/unix/sysv/linux/powerpc/bits/fcntl.h b/sysdeps/unix/sysv/linux/powerpc/bits/fcntl.h
index badad12135..40c799a955 100644
--- a/sysdeps/unix/sysv/linux/powerpc/bits/fcntl.h
+++ b/sysdeps/unix/sysv/linux/powerpc/bits/fcntl.h
@@ -16,12 +16,13 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#ifndef	_FCNTL_H
+#if !defined(_FCNTL_H) && !defined(_SYS_MOUNT_H)
 # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
 #endif
 
 #include <bits/wordsize.h>
 
+#ifdef __FCNTL_H_INCLUDE_O_FLAGS
 #define __O_DIRECTORY	 040000	/* Must be a directory.	 */
 #define __O_NOFOLLOW	0100000	/* Do not follow links.	 */
 #define __O_DIRECT	0400000	/* Direct disk access.	*/
@@ -32,13 +33,17 @@
 #else
 # define __O_LARGEFILE	0200000
 #endif
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_F_FLAGS
 #if __WORDSIZE == 64 && !defined __USE_FILE_OFFSET64
 # define F_GETLK	5
 # define F_SETLK	6
 # define F_SETLKW	7
 #endif
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_MISC
 struct flock
   {
     short int l_type;	/* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.	*/
@@ -63,6 +68,7 @@ struct flock64
     __pid_t l_pid;	/* Process holding the lock.  */
   };
 #endif
+#endif
 
 /* Include generic Linux declarations.  */
 #include <bits/fcntl-linux.h>
diff --git a/sysdeps/unix/sysv/linux/riscv/bits/fcntl.h b/sysdeps/unix/sysv/linux/riscv/bits/fcntl.h
index 6116ab0acc..b916ef9ebc 100644
--- a/sysdeps/unix/sysv/linux/riscv/bits/fcntl.h
+++ b/sysdeps/unix/sysv/linux/riscv/bits/fcntl.h
@@ -17,7 +17,7 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#ifndef	_FCNTL_H
+#if !defined(_FCNTL_H) && !defined(_SYS_MOUNT_H)
 # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
 #endif
 
@@ -26,13 +26,18 @@
 /* In 64-bit ISA files are always with 64bit off_t and F_*LK64 are the same as
    non-64-bit versions.  It will need to be revised for 128-bit.  */
 #if __WORDSIZE == 64
+#ifdef __FCNTL_H_INCLUDE_O_FLAGS
 # define __O_LARGEFILE	0
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_F_FLAGS
 # define F_GETLK64	5	/* Get record locking info.  */
 # define F_SETLK64	6	/* Set record locking info (non-blocking).  */
 # define F_SETLKW64	7	/* Set record locking info (blocking).	*/
 #endif
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_MISC
 struct flock
   {
     short int l_type;   /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
@@ -57,6 +62,7 @@ struct flock64
     __pid_t l_pid;      /* Process holding the lock.  */
   };
 #endif
+#endif
 
 /* Include generic Linux declarations.  */
 #include <bits/fcntl-linux.h>
diff --git a/sysdeps/unix/sysv/linux/s390/bits/fcntl.h b/sysdeps/unix/sysv/linux/s390/bits/fcntl.h
index 75ea4e23c6..649925530d 100644
--- a/sysdeps/unix/sysv/linux/s390/bits/fcntl.h
+++ b/sysdeps/unix/sysv/linux/s390/bits/fcntl.h
@@ -16,24 +16,29 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#ifndef	_FCNTL_H
+#if !defined(_FCNTL_H) && !defined(_SYS_MOUNT_H)
 # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
 #endif
 
 #include <bits/wordsize.h>
 
+#ifdef __FCNTL_H_INCLUDE_O_FLAGS
 #if __WORDSIZE == 64
 /* Not necessary, files are always with 64bit off_t.  */
 # define __O_LARGEFILE	0
 #endif
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_F_FLAGS
 #if __WORDSIZE == 64
 /* Not necessary, we always have 64-bit offsets.  */
 # define F_GETLK64	5	/* Get record locking info.  */
 # define F_SETLK64	6	/* Set record locking info (non-blocking).  */
 # define F_SETLKW64	7	/* Set record locking info (blocking).	*/
 #endif
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_MISC
 struct flock
   {
     short int l_type;	/* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.	*/
@@ -66,6 +71,7 @@ struct flock64
 # define __POSIX_FADV_DONTNEED	4 /* Don't need these pages.  */
 # define __POSIX_FADV_NOREUSE	5 /* Data will be accessed once.  */
 #endif
+#endif
 
 /* Include generic Linux declarations.  */
 #include <bits/fcntl-linux.h>
diff --git a/sysdeps/unix/sysv/linux/sh/bits/fcntl.h b/sysdeps/unix/sysv/linux/sh/bits/fcntl.h
index 6c5650b6ec..e380b62baf 100644
--- a/sysdeps/unix/sysv/linux/sh/bits/fcntl.h
+++ b/sysdeps/unix/sysv/linux/sh/bits/fcntl.h
@@ -16,11 +16,12 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#ifndef	_FCNTL_H
+#if !defined(_FCNTL_H) && !defined(_SYS_MOUNT_H)
 # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
 #endif
 
 
+#ifdef __FCNTL_H_INCLUDE_MISC
 struct flock
   {
     short int l_type;	/* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.	*/
@@ -45,6 +46,7 @@ struct flock64
     __pid_t l_pid;	/* Process holding the lock.  */
   };
 #endif
+#endif
 
 /* Include generic Linux declarations.  */
 #include <bits/fcntl-linux.h>
diff --git a/sysdeps/unix/sysv/linux/sparc/bits/fcntl.h b/sysdeps/unix/sysv/linux/sparc/bits/fcntl.h
index f990fbb9fd..e01b093475 100644
--- a/sysdeps/unix/sysv/linux/sparc/bits/fcntl.h
+++ b/sysdeps/unix/sysv/linux/sparc/bits/fcntl.h
@@ -16,12 +16,13 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#ifndef _FCNTL_H
+#if !defined(_FCNTL_H) && !defined(_SYS_MOUNT_H)
 # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
 #endif
 
 #include <bits/wordsize.h>
 
+#ifdef __FCNTL_H_INCLUDE_O_FLAGS
 #define O_APPEND	0x0008
 #define O_ASYNC		0x0040
 #define O_CREAT		0x0200	/* not fcntl */
@@ -48,8 +49,10 @@
 #endif
 
 #define __O_DSYNC	0x2000	/* Synchronize data.  */
+#endif
 
 
+#ifdef __FCNTL_H_INCLUDE_F_FLAGS
 #define __F_GETOWN	5	/* Get owner (process receiving SIGIO).  */
 #define __F_SETOWN	6	/* Set owner (process receiving SIGIO).  */
 
@@ -69,7 +72,9 @@
 #define F_RDLCK		1	/* Read lock.  */
 #define F_WRLCK		2	/* Write lock.  */
 #define F_UNLCK		3	/* Remove lock.  */
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_MISC
 struct flock
   {
     short int l_type;	/* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
@@ -96,6 +101,7 @@ struct flock64
     short int __glibc_reserved;
   };
 #endif
+#endif
 
 /* Include generic Linux declarations.  */
 #include <bits/fcntl-linux.h>
diff --git a/sysdeps/unix/sysv/linux/sys/mount.h b/sysdeps/unix/sysv/linux/sys/mount.h
index 457d8dcff2..9a24eb36e2 100644
--- a/sysdeps/unix/sysv/linux/sys/mount.h
+++ b/sysdeps/unix/sysv/linux/sys/mount.h
@@ -21,8 +21,15 @@
 #ifndef _SYS_MOUNT_H
 #define _SYS_MOUNT_H	1
 
-#include <fcntl.h>
 #include <features.h>
+
+#define __FCNTL_H_INCLUDE_O_FLAGS
+/* We only need O_CLOEXEC. */
+__BEGIN_DECLS
+#include <bits/fcntl.h>
+__END_DECLS
+#undef __FCNTL_H_INCLUDE_O_FLAGS
+
 #include <stdint.h>
 #include <stddef.h>
 #include <sys/ioctl.h>
diff --git a/sysdeps/unix/sysv/linux/tst-mount.c b/sysdeps/unix/sysv/linux/tst-mount.c
index 8e3ffbd56f..cefaaa4b49 100644
--- a/sysdeps/unix/sysv/linux/tst-mount.c
+++ b/sysdeps/unix/sysv/linux/tst-mount.c
@@ -20,6 +20,7 @@
 #include <support/check.h>
 #include <support/xunistd.h>
 #include <support/namespace.h>
+#include <fcntl.h>
 #include <sys/mount.h>
 
 _Static_assert (sizeof (struct mount_attr) == MOUNT_ATTR_SIZE_VER0,
diff --git a/sysdeps/unix/sysv/linux/x86/bits/fcntl.h b/sysdeps/unix/sysv/linux/x86/bits/fcntl.h
index a0991f421b..bf3fbf821b 100644
--- a/sysdeps/unix/sysv/linux/x86/bits/fcntl.h
+++ b/sysdeps/unix/sysv/linux/x86/bits/fcntl.h
@@ -16,22 +16,27 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#ifndef _FCNTL_H
+#if !defined(_FCNTL_H) && !defined(_SYS_MOUNT_H)
 # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
 #endif
 
+#ifdef __FCNTL_H_INCLUDE_O_FLAGS
 #ifdef __x86_64__
 # define __O_LARGEFILE	0
 #endif
+#endif
 
+#ifdef __FCNTL_H_INCLUDE_F_FLAGS
 #ifdef __x86_64__
 /* Not necessary, we always have 64-bit offsets.  */
 # define F_GETLK64	5	/* Get record locking info.  */
 # define F_SETLK64	6	/* Set record locking info (non-blocking).  */
 # define F_SETLKW64	7	/* Set record locking info (blocking).	*/
 #endif
+#endif
 
 
+#ifdef __FCNTL_H_INCLUDE_MISC
 struct flock
   {
     short int l_type;	/* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.	*/
@@ -56,6 +61,7 @@ struct flock64
     __pid_t l_pid;	/* Process holding the lock.  */
   };
 #endif
+#endif
 
 /* Include generic Linux declarations.  */
 #include <bits/fcntl-linux.h>



More information about the Libc-alpha mailing list