Skip to contentSkip to conversation

vfs: uapi: retire octal and hex numbers in favor of (1 << n) for O_ flags

PATCH Applied Jori Koolstra 5 participants 7 messages Jun 4 – Jun 17

Subsystems (10)
Arm (32-bit) VFS PowerPC MIPS +6 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfs: uapi: retire octal and hex numbers in favor of (1 << n) for O_ flags

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/[email protected]/

Assisted-by Claude:Opus 4.8

---

The following gawk script outputs:

Mismatch in arch/sparc/include/uapi/asm/fcntl.h, flag O_NDELAY changed: 1212 -> 4

which is because O_NDELAY in sparc is not defined in the standard "#define O_BLABLA number" form. This one was checked by hand to be sure.

function num(x) { gsub(/[^0-9xXa-fA-F]/, "", x); return strtonum(x) }
function val(s, a) { sub(/\/[*/].*/, "", s)

		     if (s ~ /<</) { split(s, a, /<</); return lshift(num(a[1]), num(a[2])) }
		     return num(s) }

/^\+\+\+ / { f = $2; sub(/^[ab]\//, "", f); next }
/^(---|@@)/ { next }
/^-#define/ { v=""; for (i=3; i<=NF; i++) v = v $i" "; old[f SUBSEP $2] = val(v) }
/^\+#define/ { v=""; for (i=3; i<=NF; i++) v = v $i" "; new[f SUBSEP $2] = val(v) }

function diff_old( k, p, file, flag, o, n) {

	for (k in old) {
		split(k, p, SUBSEP)
		file = p[1]; flag = p[2]
		if (k in new) {
			o = old[k]; n = new[k]
			if (o != n)
				printf "Mismatch in %s, flag %s changed: %d -> %d\n", file, flag, o, n
			delete new[k]
		} else
			printf "Flag %s is -'ed but not +'ed in %s\n", flag, file
	}
}

function diff_new( k, p, file, flag) {

	for (k in new) {
		split(k, p, SUBSEP)
		file = p[1]; flag = p[2]
		printf "Flag %s is +'ed but not -'ed in %s\n", flag, file
	}
}

END { diff_old(); diff_new() }

---
 arch/alpha/include/uapi/asm/fcntl.h   | 34 +++++++++---------
 arch/arm/include/uapi/asm/fcntl.h     |  8 ++---
 arch/arm64/include/uapi/asm/fcntl.h   |  8 ++---
 arch/m68k/include/uapi/asm/fcntl.h    |  8 ++---
 arch/mips/include/uapi/asm/fcntl.h    | 22 ++++++------
 arch/parisc/include/uapi/asm/fcntl.h  | 28 +++++++--------
 arch/powerpc/include/uapi/asm/fcntl.h |  8 ++---
 arch/sparc/include/uapi/asm/fcntl.h   | 34 +++++++++---------
 include/uapi/asm-generic/fcntl.h      | 50 ++++++++++++++++-----------
 9 files changed, 104 insertions(+), 96 deletions(-)
arch/alpha/include/uapi/asm/fcntl.h +17 -17
index 50bdc8e8a271..c7e1c5cf646d 100644
@@ -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
@@ -29,11 +29,11 @@
  *
  * 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
arch/arm/include/uapi/asm/fcntl.h +4 -4
index e6b5d7141c05..b576ff00beb2 100644
@@ -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>
 
arch/arm64/include/uapi/asm/fcntl.h +4 -4
index f8db34f2622d..e503fdb74ecb 100644
@@ -20,10 +20,10 @@
 /*
  * 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>
 
arch/m68k/include/uapi/asm/fcntl.h +4 -4
index c6861e6ee313..66c0e5515105 100644
@@ -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>
 
arch/mips/include/uapi/asm/fcntl.h +11 -11
index 0369a38e3d4f..549fc65d849d 100644
@@ -11,15 +11,15 @@
 
 #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
arch/parisc/include/uapi/asm/fcntl.h +14 -14
index 03dee816cb13..2e1bb18eefb8 100644
@@ -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
arch/powerpc/include/uapi/asm/fcntl.h +4 -4
index 65ce08322a89..003bc5ea78e1 100644
@@ -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>
 
arch/sparc/include/uapi/asm/fcntl.h +17 -17
index 67dae75e5274..29c5639bc3fa 100644
@@ -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
@@ -32,11 +32,11 @@
  *
  * 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. */
include/uapi/asm-generic/fcntl.h +29 -21

102 lines not on this page · raw message

base-commit: 6a08076f009e3d9460bebae9f209c1dc1d8a46b7

Signature · 1 line
2.54.0
maintainer Applied
#1 lore raw
Quoted 5 lines · Jori Koolstra

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.

Quoted 7 lines

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).

[...]

Applied to the vfs-7.2.misc branch of the vfs/vfs.git tree. Patches in the vfs-7.2.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-7.2.misc

[1/1] vfs: uapi: retire octal and hex numbers in favor of (1 << n) for O_ flags

      https://git.kernel.org/vfs/vfs/c/0da79c259ad0
#2 lore raw
In reply to Jori Koolstra

Hi Jori,

Quoted 11 lines

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).

Quoted 8 lines

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/[email protected]/

Assisted-by Claude:Opus 4.8

Thanks for your patch, which is now commit 0da79c259ad0554b ("vfs:
uapi: retire octal and hex numbers in favor of (1 << n) for O_ flags").

Quoted 4 lines
include/uapi/asm-generic/fcntl.h +0 -0
@@ -15,51 +15,55 @@
  * When introducing new O_* bits, please check its uniqueness in fcntl_init().

include/uapi/asm-generic/fcntl.h line 21

Quoted 10 lines
include/uapi/asm-generic/fcntl.h +4 -4
  */
 
-#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)

And suddenly all these constants became signed? Can't that cause subtle issues, especially for uapi headers?

	#define O_ACCMODE	3U
	#define O_RDONLY	0
	#define O_WRONLY	(1U << 0)
	#define O_RDWR		(1U << 1)

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#3 lore raw
In reply to Jori Koolstra

Hi Jori,

Quoted 11 lines

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).

Quoted 8 lines

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/[email protected]/

Assisted-by Claude:Opus 4.8

Thanks for your patch, which is now commit 0da79c259ad0554b ("vfs:
uapi: retire octal and hex numbers in favor of (1 << n) for O_ flags").

Quoted 4 lines
include/uapi/asm-generic/fcntl.h +0 -0
@@ -15,51 +15,55 @@
  * When introducing new O_* bits, please check its uniqueness in fcntl_init().

include/uapi/asm-generic/fcntl.h line 21

Quoted 10 lines
include/uapi/asm-generic/fcntl.h +4 -4
  */
 
-#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)

And suddenly all these constants became signed? Can't that cause subtle issues, especially for uapi headers?

	#define O_ACCMODE	3U
	#define O_RDONLY	0
	#define O_WRONLY	(1U << 0)
	#define O_RDWR		(1U << 1)

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#4 lore raw

Dag Geert,

Quoted 35 lines

Op 16-06-2026 12:22 CEST schreef Geert Uytterhoeven <[email protected]>:

Hi Jori,

Quoted 11 lines

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).

Quoted 8 lines

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/[email protected]/

Assisted-by Claude:Opus 4.8

Thanks for your patch, which is now commit 0da79c259ad0554b ("vfs:
uapi: retire octal and hex numbers in favor of (1 << n) for O_ flags").

Quoted 6 lines
include/uapi/asm-generic/fcntl.h +0 -0
@@ -15,51 +15,55 @@
  * When introducing new O_* bits, please check its uniqueness in fcntl_init().
  */
 
Quoted 11 lines

include/uapi/asm-generic/fcntl.h line 21

Quoted 8 lines
include/uapi/asm-generic/fcntl.h +4 -4
-#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)

And suddenly all these constants became signed? Can't that cause subtle issues, especially for uapi headers?

Isn't 00000003 already singed? I am by no means a C language expert, but what I can find in the C99 standard is:

The type of an integer constant is the first of the corresponding list in which its value can be represented.

and for octal and hex constants this list starts with "int"

Quoted 8 lines
	#define O_ACCMODE	3U
	#define O_RDONLY	0
	#define O_WRONLY	(1U << 0)
	#define O_RDWR		(1U << 1)

Gr{oetje,eeting}s,

Quoted 8 lines

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

Groet,
Jori.

#5 lore raw

Hoi Jori,

Quoted 43 lines · Jori Koolstra
Quoted 31 lines

Op 16-06-2026 12:22 CEST schreef Geert Uytterhoeven <[email protected]>:

Quoted 11 lines

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).

Quoted 8 lines

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/[email protected]/

Assisted-by Claude:Opus 4.8

Thanks for your patch, which is now commit 0da79c259ad0554b ("vfs:
uapi: retire octal and hex numbers in favor of (1 << n) for O_ flags").

Quoted 6 lines
include/uapi/asm-generic/fcntl.h +0 -0
@@ -15,51 +15,55 @@
  * When introducing new O_* bits, please check its uniqueness in fcntl_init().
  */
 
Quoted 11 lines

include/uapi/asm-generic/fcntl.h line 21

Quoted 8 lines
include/uapi/asm-generic/fcntl.h +4 -4
-#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)

And suddenly all these constants became signed? Can't that cause subtle issues, especially for uapi headers?

Quoted 7 lines

Isn't 00000003 already singed? I am by no means a C language expert, but what I can find in the C99 standard is:

The type of an integer constant is the first of the corresponding list in which its value can be represented.

and for octal and hex constants this list starts with "int"

Sorry, I indeed misremembered[1] that hexadecimal and octal constants are always unsigned. Instead, they are only unsigned if they no longer fit in the corresponding signed type.

So "(1 << n)" has the same signedness as the old octal constants, unless n is 31 (shifting into the sign bit), or n > 31 (needs an ULL-suffix for 64-bit). But your patch has no such cases.

[1] https://lore.kernel.org/all/CAHk-=wgcv_YewP0rgwR1+gj3YF-7Jz8WPVzDgndx0DVMVKzV=Q@mail.gmail.com

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#6 lore raw
In reply to Geert Uytterhoeven
Quoted 32 lines · On Tue, 16 Jun 2026 12:22:50 +0200 Geert Uytterhoeven…

Hi Jori,

Quoted 11 lines

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).

Quoted 8 lines

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/[email protected]/

Assisted-by Claude:Opus 4.8

Thanks for your patch, which is now commit 0da79c259ad0554b ("vfs:
uapi: retire octal and hex numbers in favor of (1 << n) for O_ flags").

Quoted 6 lines
include/uapi/asm-generic/fcntl.h +0 -0
@@ -15,51 +15,55 @@
  * When introducing new O_* bits, please check its uniqueness in fcntl_init().
  */
 
Quoted 8 lines

include/uapi/asm-generic/fcntl.h line 21

Quoted 8 lines
include/uapi/asm-generic/fcntl.h +4 -4
-#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)  

I'm not 100% that changing these uapi constants might not generate compile error for userspace that has duplicate definitions that are currently fine because the definitions exactly match.

David

Quoted 20 lines

And suddenly all these constants became signed? Can't that cause subtle issues, especially for uapi headers?

	#define O_ACCMODE	3U
	#define O_RDONLY	0
	#define O_WRONLY	(1U << 0)
	#define O_RDWR		(1U << 1)

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds