]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
vfs: uapi: retire octal and hex numbers in favor of (1 << n) for O_ flags
authorJori Koolstra <jkoolstra@xs4all.nl>
Thu, 4 Jun 2026 22:24:05 +0000 (00:24 +0200)
committerChristian Brauner <brauner@kernel.org>
Sat, 6 Jun 2026 13:34:03 +0000 (15:34 +0200)
A recent build failure[1] exposed the diffculty of working with the
current octal and hex definitions of O_ flags when trying to find a gap
for a new flag. This difficulty is compounded by the fact that O_ flags
may have architectural specific values.

Replace the hex/octal #defines, which are hard to parse when looking for
free bits, with explicit bit shifts like (1 << 11). Also, add comments
that identify which architectures redefine some of the seemingly free
("cursed") bits in uapi/asm-generic/fcntl.h. These should not be used to
define new O_ flags (for now, at least).

The translastion was done with Claude Opus 4.8, and verified with a
(non-AI) gawk script. The accounting of which architectures claim
which bit-gaps in uapi/asm-generic/fcntl.h is also done by hand.

[1]: https://lore.kernel.org/all/agruPPybCx8q2XcJ@sirena.org.uk/

Assisted-by: Claude:Opus 4.8
Signed-off-by: Jori Koolstra <jkoolstra@xs4all.nl>
Link: https://patch.msgid.link/20260604222405.5382-1-jkoolstra@xs4all.nl
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
arch/alpha/include/uapi/asm/fcntl.h
arch/arm/include/uapi/asm/fcntl.h
arch/arm64/include/uapi/asm/fcntl.h
arch/m68k/include/uapi/asm/fcntl.h
arch/mips/include/uapi/asm/fcntl.h
arch/parisc/include/uapi/asm/fcntl.h
arch/powerpc/include/uapi/asm/fcntl.h
arch/sparc/include/uapi/asm/fcntl.h
include/uapi/asm-generic/fcntl.h

index 50bdc8e8a271b2a22f8b4d9c92585df1ce8578f4..c7e1c5cf646d5009e88540fe2877cb25ff177bbc 100644 (file)
@@ -2,20 +2,20 @@
 #ifndef _ALPHA_FCNTL_H
 #define _ALPHA_FCNTL_H
 
-#define O_CREAT                 01000  /* not fcntl */
-#define O_TRUNC                 02000  /* not fcntl */
-#define O_EXCL          04000  /* not fcntl */
-#define O_NOCTTY       010000  /* not fcntl */
-
-#define O_NONBLOCK      00004
-#define O_APPEND        00010
-#define O_DSYNC                040000  /* used to be O_SYNC, see below */
-#define O_DIRECTORY    0100000 /* must be a directory */
-#define O_NOFOLLOW     0200000 /* don't follow links */
-#define O_LARGEFILE    0400000 /* will be set by the kernel on every open */
-#define O_DIRECT       02000000 /* direct disk access - should check with OSF/1 */
-#define O_NOATIME      04000000
-#define O_CLOEXEC      010000000 /* set close_on_exec */
+#define O_CREAT                (1 << 9)        /* not fcntl */
+#define O_TRUNC                (1 << 10)       /* not fcntl */
+#define O_EXCL         (1 << 11)       /* not fcntl */
+#define O_NOCTTY       (1 << 12)       /* not fcntl */
+
+#define O_NONBLOCK     (1 << 2)
+#define O_APPEND       (1 << 3)
+#define O_DSYNC                (1 << 14)       /* used to be O_SYNC, see below */
+#define O_DIRECTORY    (1 << 15)       /* must be a directory */
+#define O_NOFOLLOW     (1 << 16)       /* don't follow links */
+#define O_LARGEFILE    (1 << 17)       /* will be set by the kernel on every open */
+#define O_DIRECT       (1 << 19)       /* direct disk access - should check with OSF/1 */
+#define O_NOATIME      (1 << 20)
+#define O_CLOEXEC      (1 << 21)       /* set close_on_exec */
 /*
  * Before Linux 2.6.33 only O_DSYNC semantics were implemented, but using
  * the O_SYNC flag.  We continue to use the existing numerical value
  *
  * Note: __O_SYNC must never be used directly.
  */
-#define __O_SYNC       020000000
+#define __O_SYNC       (1 << 22)
 #define O_SYNC         (__O_SYNC|O_DSYNC)
 
-#define O_PATH         040000000
-#define __O_TMPFILE    0100000000
+#define O_PATH         (1 << 23)
+#define __O_TMPFILE    (1 << 24)
 
 #define F_GETLK                7
 #define F_SETLK                8
index e6b5d7141c05b2bd0fd4b2f245ba32a192f04e6a..b576ff00beb2d6202ee40f3e6738ce0e50ce30bd 100644 (file)
@@ -2,10 +2,10 @@
 #ifndef _ARM_FCNTL_H
 #define _ARM_FCNTL_H
 
-#define O_DIRECTORY     040000 /* must be a directory */
-#define O_NOFOLLOW     0100000 /* don't follow links */
-#define O_DIRECT       0200000 /* direct disk access hint - currently ignored */
-#define O_LARGEFILE    0400000
+#define O_DIRECTORY    (1 << 14)       /* must be a directory */
+#define O_NOFOLLOW     (1 << 15)       /* don't follow links */
+#define O_DIRECT       (1 << 16)       /* direct disk access hint - currently ignored */
+#define O_LARGEFILE    (1 << 17)
 
 #include <asm-generic/fcntl.h>
 
index f8db34f2622d3cdd4e2d638334e3b061c2948af9..e503fdb74ecbc5b5d258b41cb88cfeea657f8037 100644 (file)
 /*
  * Using our own definitions for AArch32 (compat) support.
  */
-#define O_DIRECTORY     040000 /* must be a directory */
-#define O_NOFOLLOW     0100000 /* don't follow links */
-#define O_DIRECT       0200000 /* direct disk access hint - currently ignored */
-#define O_LARGEFILE    0400000
+#define O_DIRECTORY    (1 << 14)       /* must be a directory */
+#define O_NOFOLLOW     (1 << 15)       /* don't follow links */
+#define O_DIRECT       (1 << 16)       /* direct disk access hint - currently ignored */
+#define O_LARGEFILE    (1 << 17)
 
 #include <asm-generic/fcntl.h>
 
index c6861e6ee31309ee6539cf2fc5b70bcc88603a08..66c0e55151056390d5eaba4b2de0dc73bd295dc4 100644 (file)
@@ -2,10 +2,10 @@
 #ifndef _M68K_FCNTL_H
 #define _M68K_FCNTL_H
 
-#define O_DIRECTORY    040000  /* must be a directory */
-#define O_NOFOLLOW     0100000 /* don't follow links */
-#define O_DIRECT       0200000 /* direct disk access hint - currently ignored */
-#define O_LARGEFILE    0400000
+#define O_DIRECTORY    (1 << 14)       /* must be a directory */
+#define O_NOFOLLOW     (1 << 15)       /* don't follow links */
+#define O_DIRECT       (1 << 16)       /* direct disk access hint - currently ignored */
+#define O_LARGEFILE    (1 << 17)
 
 #include <asm-generic/fcntl.h>
 
index 0369a38e3d4f274dc9c92138ae08ee5130885ee1..549fc65d849db4c782115c574d29208c1f946bfd 100644 (file)
 
 #include <asm/sgidefs.h>
 
-#define O_APPEND       0x0008
-#define O_DSYNC                0x0010  /* used to be O_SYNC, see below */
-#define O_NONBLOCK     0x0080
-#define O_CREAT                0x0100  /* not fcntl */
-#define O_TRUNC                0x0200  /* not fcntl */
-#define O_EXCL         0x0400  /* not fcntl */
-#define O_NOCTTY       0x0800  /* not fcntl */
-#define FASYNC         0x1000  /* fcntl, for BSD compatibility */
-#define O_LARGEFILE    0x2000  /* allow large file opens */
+#define O_APPEND       (1 << 3)
+#define O_DSYNC                (1 << 4)        /* used to be O_SYNC, see below */
+#define O_NONBLOCK     (1 << 7)
+#define O_CREAT                (1 << 8)        /* not fcntl */
+#define O_TRUNC                (1 << 9)        /* not fcntl */
+#define O_EXCL         (1 << 10)       /* not fcntl */
+#define O_NOCTTY       (1 << 11)       /* not fcntl */
+#define FASYNC         (1 << 12)       /* fcntl, for BSD compatibility */
+#define O_LARGEFILE    (1 << 13)       /* allow large file opens */
 /*
  * Before Linux 2.6.33 only O_DSYNC semantics were implemented, but using
  * the O_SYNC flag.  We continue to use the existing numerical value
@@ -33,9 +33,9 @@
  *
  * Note: __O_SYNC must never be used directly.
  */
-#define __O_SYNC       0x4000
+#define __O_SYNC       (1 << 14)
 #define O_SYNC         (__O_SYNC|O_DSYNC)
-#define O_DIRECT       0x8000  /* direct disk access hint */
+#define O_DIRECT       (1 << 15)       /* direct disk access hint */
 
 #define F_GETLK                14
 #define F_SETLK                6
index 03dee816cb136c94d697df53858ace8f9624f417..2e1bb18eefb8efc9b7a53ecec6b1660adab889fb 100644 (file)
@@ -2,23 +2,23 @@
 #ifndef _PARISC_FCNTL_H
 #define _PARISC_FCNTL_H
 
-#define O_APPEND       000000010
-#define O_CREAT                000000400 /* not fcntl */
-#define O_EXCL         000002000 /* not fcntl */
-#define O_LARGEFILE    000004000
-#define __O_SYNC       000100000
+#define O_APPEND       (1 << 3)
+#define O_CREAT                (1 << 8)        /* not fcntl */
+#define O_EXCL         (1 << 10)       /* not fcntl */
+#define O_LARGEFILE    (1 << 11)
+#define __O_SYNC       (1 << 15)
 #define O_SYNC         (__O_SYNC|O_DSYNC)
-#define O_NONBLOCK     000200000
-#define O_NOCTTY       000400000 /* not fcntl */
-#define O_DSYNC                001000000
-#define O_NOATIME      004000000
-#define O_CLOEXEC      010000000 /* set close_on_exec */
+#define O_NONBLOCK     (1 << 16)
+#define O_NOCTTY       (1 << 17)       /* not fcntl */
+#define O_DSYNC                (1 << 18)
+#define O_NOATIME      (1 << 20)
+#define O_CLOEXEC      (1 << 21)       /* set close_on_exec */
 
-#define O_DIRECTORY    000010000 /* must be a directory */
-#define O_NOFOLLOW     000000200 /* don't follow links */
+#define O_DIRECTORY    (1 << 12)       /* must be a directory */
+#define O_NOFOLLOW     (1 << 7)        /* don't follow links */
 
-#define O_PATH         020000000
-#define __O_TMPFILE    040000000
+#define O_PATH         (1 << 22)
+#define __O_TMPFILE    (1 << 23)
 
 #define F_GETLK64      8
 #define F_SETLK64      9
index 65ce08322a89b3563b017f2b356e11c386dac94a..003bc5ea78e117712090161a44f1b2374244f402 100644 (file)
@@ -2,10 +2,10 @@
 #ifndef _ASM_FCNTL_H
 #define _ASM_FCNTL_H
 
-#define O_DIRECTORY      040000        /* must be a directory */
-#define O_NOFOLLOW      0100000        /* don't follow links */
-#define O_LARGEFILE     0200000
-#define O_DIRECT       0400000 /* direct disk access hint */
+#define O_DIRECTORY    (1 << 14)       /* must be a directory */
+#define O_NOFOLLOW     (1 << 15)       /* don't follow links */
+#define O_LARGEFILE    (1 << 16)
+#define O_DIRECT       (1 << 17)       /* direct disk access hint */
 
 #include <asm-generic/fcntl.h>
 
index 67dae75e5274d469b162a4ec51bffc9205b1c932..29c5639bc3fa3f6270b4da4fe4a6635134a8fb36 100644 (file)
@@ -2,23 +2,23 @@
 #ifndef _SPARC_FCNTL_H
 #define _SPARC_FCNTL_H
 
-#define O_APPEND       0x0008
-#define FASYNC         0x0040  /* fcntl, for BSD compatibility */
-#define O_CREAT                0x0200  /* not fcntl */
-#define O_TRUNC                0x0400  /* not fcntl */
-#define O_EXCL         0x0800  /* not fcntl */
-#define O_DSYNC                0x2000  /* used to be O_SYNC, see below */
-#define O_NONBLOCK     0x4000
+#define O_APPEND       (1 << 3)
+#define FASYNC         (1 << 6)        /* fcntl, for BSD compatibility */
+#define O_CREAT                (1 << 9)        /* not fcntl */
+#define O_TRUNC                (1 << 10)       /* not fcntl */
+#define O_EXCL         (1 << 11)       /* not fcntl */
+#define O_DSYNC                (1 << 13)       /* used to be O_SYNC, see below */
+#define O_NONBLOCK     (1 << 14)
 #if defined(__sparc__) && defined(__arch64__)
-#define O_NDELAY       0x0004
+#define O_NDELAY       (1 << 2)
 #else
-#define O_NDELAY       (0x0004 | O_NONBLOCK)
+#define O_NDELAY       ((1 << 2) | O_NONBLOCK)
 #endif
-#define O_NOCTTY       0x8000  /* not fcntl */
-#define O_LARGEFILE    0x40000
-#define O_DIRECT        0x100000 /* direct disk access hint */
-#define O_NOATIME      0x200000
-#define O_CLOEXEC      0x400000
+#define O_NOCTTY       (1 << 15)       /* not fcntl */
+#define O_LARGEFILE    (1 << 18)
+#define O_DIRECT       (1 << 20)       /* direct disk access hint */
+#define O_NOATIME      (1 << 21)
+#define O_CLOEXEC      (1 << 22)
 /*
  * Before Linux 2.6.33 only O_DSYNC semantics were implemented, but using
  * the O_SYNC flag.  We continue to use the existing numerical value
  *
  * Note: __O_SYNC must never be used directly.
  */
-#define __O_SYNC       0x800000
+#define __O_SYNC       (1 << 23)
 #define O_SYNC         (__O_SYNC|O_DSYNC)
 
-#define O_PATH         0x1000000
-#define __O_TMPFILE    0x2000000
+#define O_PATH         (1 << 24)
+#define __O_TMPFILE    (1 << 25)
 
 #define F_GETOWN       5       /*  for sockets. */
 #define F_SETOWN       6       /*  for sockets. */
index 613475285643b3354c31b3b2567ccf8bccbd7148..359622b083d5eba1d216ef5aff01d8caaa54c17f 100644 (file)
  * When introducing new O_* bits, please check its uniqueness in fcntl_init().
  */
 
-#define O_ACCMODE      00000003
-#define O_RDONLY       00000000
-#define O_WRONLY       00000001
-#define O_RDWR         00000002
+#define O_ACCMODE      3
+#define O_RDONLY       0
+#define O_WRONLY       (1 << 0)
+#define O_RDWR         (1 << 1)
+/* (1 << 2) must not be used -- it collides with flags on alpha, sparc */
+/* (1 << 3) must not be used -- it collides with flags on alpha, mips, parisc, sparc */
+/* (1 << 4) must not be used -- it collides with flags on mips */
+/* (1 << 5) is free */
 #ifndef O_CREAT
-#define O_CREAT                00000100        /* not fcntl */
+#define O_CREAT                (1 << 6)        /* not fcntl */
 #endif
 #ifndef O_EXCL
-#define O_EXCL         00000200        /* not fcntl */
+#define O_EXCL         (1 << 7)        /* not fcntl */
 #endif
 #ifndef O_NOCTTY
-#define O_NOCTTY       00000400        /* not fcntl */
+#define O_NOCTTY       (1 << 8)        /* not fcntl */
 #endif
 #ifndef O_TRUNC
-#define O_TRUNC                00001000        /* not fcntl */
+#define O_TRUNC                (1 << 9)        /* not fcntl */
 #endif
 #ifndef O_APPEND
-#define O_APPEND       00002000
+#define O_APPEND       (1 << 10)
 #endif
 #ifndef O_NONBLOCK
-#define O_NONBLOCK     00004000
+#define O_NONBLOCK     (1 << 11)
 #endif
 #ifndef O_DSYNC
-#define O_DSYNC                00010000        /* used to be O_SYNC, see below */
+#define O_DSYNC                (1 << 12)       /* used to be O_SYNC, see below */
 #endif
 #ifndef FASYNC
-#define FASYNC         00020000        /* fcntl, for BSD compatibility */
+#define FASYNC         (1 << 13)       /* fcntl, for BSD compatibility */
 #endif
 #ifndef O_DIRECT
-#define O_DIRECT       00040000        /* direct disk access hint */
+#define O_DIRECT       (1 << 14)       /* direct disk access hint */
 #endif
 #ifndef O_LARGEFILE
-#define O_LARGEFILE    00100000
+#define O_LARGEFILE    (1 << 15)
 #endif
 #ifndef O_DIRECTORY
-#define O_DIRECTORY    00200000        /* must be a directory */
+#define O_DIRECTORY    (1 << 16)       /* must be a directory */
 #endif
 #ifndef O_NOFOLLOW
-#define O_NOFOLLOW     00400000        /* don't follow links */
+#define O_NOFOLLOW     (1 << 17)       /* don't follow links */
 #endif
 #ifndef O_NOATIME
-#define O_NOATIME      01000000
+#define O_NOATIME      (1 << 18)
 #endif
 #ifndef O_CLOEXEC
-#define O_CLOEXEC      02000000        /* set close_on_exec */
+#define O_CLOEXEC      (1 << 19)       /* set close_on_exec */
 #endif
 
 /*
  * Note: __O_SYNC must never be used directly.
  */
 #ifndef O_SYNC
-#define __O_SYNC       04000000
+#define __O_SYNC       (1 << 20)
 #define O_SYNC         (__O_SYNC|O_DSYNC)
 #endif
 
 #ifndef O_PATH
-#define O_PATH         010000000
+#define O_PATH         (1 << 21)
 #endif
 
 #ifndef __O_TMPFILE
-#define __O_TMPFILE    020000000
+#define __O_TMPFILE    (1 << 22)
 #endif
 
 /* a horrid kludge trying to make sure that this will fail on old kernels */
 #define O_NDELAY       O_NONBLOCK
 #endif
 
+/* (1 << 23) must not be used -- it collides with flags on alpha, parisc, sparc */
+/* (1 << 24) must not be used -- it collides with flags on alpha, sparc */
+/* (1 << 25) must not be used -- it collides with flags on sparc */
+
 #define F_DUPFD                0       /* dup */
 #define F_GETFD                1       /* get close_on_exec */
 #define F_SETFD                2       /* set/clear close_on_exec */