[RFC PATCH v2 0/2] vfs: syscalls: add mkdirat2() that returns an O_DIRECTORY fd

Jori Koolstra
2026-04-12T13:55:55Z

This series implements the mkdirat2() syscall that was suggested over
at the UAPI group kernel feature page [1] with some tests.

Obviously, we probably also want to implement equivalent mknodeat2() and
symlinkat2() syscalls, but their implementation can be done quite similar
I believe.

This has been compiled and tested on x86 only.

[1]: https://github.com/uapi-group/kernel-features?tab=readme-ov-file#race-free-creation-and-opening-of-non-file-inodes

v2:
- Use AT_* flags.
- Ensure an fd is allocated only if mkdir and open_dentry succeed.
- The returned fd gets O_CLOEXEC by default.
- Renamed syscall from mkdirat_fd() to mkdirat2().

Jori Koolstra (2):
vfs: syscalls: add mkdirat2() that returns an O_DIRECTORY fd
selftest: add tests for mkdirat2()

arch/x86/entry/syscalls/syscall_64.tbl | 1 +
fs/internal.h | 2 +
fs/namei.c | 44 +++++-
include/linux/syscalls.h | 2 +
include/uapi/asm-generic/unistd.h | 5 +-
scripts/syscall.tbl | 1 +
tools/include/uapi/asm-generic/unistd.h | 5 +-
.../testing/selftests/filesystems/.gitignore | 1 +
tools/testing/selftests/filesystems/Makefile | 4 +-
.../selftests/filesystems/mkdirat_fd_test.c | 143 ++++++++++++++++++
10 files changed, 200 insertions(+), 8 deletions(-)
create mode 100644 tools/testing/selftests/filesystems/mkdirat_fd_test.c

--
2.53.0