[RFC PATCH v3 0/2] vfs: add O_CREAT|O_DIRECTORY to open*(2)
From: Jori Koolstra
Date: Sun May 17 2026 - 13:04:14 EST
This series implements new semantics for the O_CREAT|O_DIRECTORY flag
combination for open*(2): perform a mkdir and open the resulting
directory, and return a pinning fd (which mkdir does not).
Feedback on the v2 rfc of this patch was to not introduce a new syscall
(mkdirat2) but implement this functionality as O_CREAT|O_DIRECTORY in
open*(2).
Two comments from me upfront:
- This patch just EINVAL bans O_CREAT|O_DIRECTORY for filesystems that
define atomic_open(). I figure it is better to (dis)allow on a fs per
fs basis. So feedback per filesystem on what is the appropriate course
of action on receiving O_CREAT|O_DIRECTORY would be very useful.
- If we create a regular file with mknod, before creation
security_path_mknod() is called, and after creation
security_path_post_mknod(). If we create a regular file using O_CREAT
(and this is also pre-patch) only security_path_mknod() is called. Is
this the correct behaviour?
Jori Koolstra (2):
vfs: add O_CREAT|O_DIRECTORY to open*(2)
selftest: add tests for open*(O_CREAT|O_DIRECTORY)
fs/namei.c | 186 +++++++++++-------
fs/open.c | 23 +--
include/uapi/asm-generic/fcntl.h | 2 +
.../testing/selftests/filesystems/.gitignore | 1 +
tools/testing/selftests/filesystems/Makefile | 4 +-
tools/testing/selftests/filesystems/fclog.c | 1 +
.../filesystems/open_o_creat_o_directory.c | 147 ++++++++++++++
7 files changed, 283 insertions(+), 81 deletions(-)
create mode 100644 tools/testing/selftests/filesystems/open_o_creat_o_directory.c
--
2.54.0