From afd9d8d3a00e42b57ec399e06331dbdadb2d50b1 Mon Sep 17 00:00:00 2001 From: Matheus Date: Tue, 14 Jul 2026 16:37:48 -0300 Subject: [PATCH] rename: RENAME_NOREPLACE --- kernel-src/fs/ext2.c | 6 ++++++ kernel-src/fs/fat/fatfs.c | 6 ++++++ kernel-src/fs/tmpfs.c | 3 +++ kernel-src/include/kernel/abi.h | 2 ++ kernel-src/sys/syscalls/renameat.c | 6 ++++-- patches/mlibc/jinx-working-patch.patch | 17 +++++++++++++++++ 6 files changed, 38 insertions(+), 2 deletions(-) diff --git a/kernel-src/fs/ext2.c b/kernel-src/fs/ext2.c index 76dfd6c7..5a46cad7 100644 --- a/kernel-src/fs/ext2.c +++ b/kernel-src/fs/ext2.c @@ -1871,6 +1871,12 @@ static int ext2_rename(vnode_t *sourcedir, vnode_t *source, char *oldname, vnode ext2node_t *ext2_replaced_node = (ext2node_t *)replaced_vnode; if (replaced_vnode) { + if (flags & RENAME_NOREPLACE) { + VOP_UNLOCK(replaced_vnode); + VOP_RELEASE(replaced_vnode); + return EEXIST; + } + // we are replacing an existing link // do some checks expected by posix if (source->type != V_TYPE_DIR && replaced_vnode->type == V_TYPE_DIR) { diff --git a/kernel-src/fs/fat/fatfs.c b/kernel-src/fs/fat/fatfs.c index 24519324..7eaf3fa5 100644 --- a/kernel-src/fs/fat/fatfs.c +++ b/kernel-src/fs/fat/fatfs.c @@ -738,6 +738,12 @@ static int fatfs_rename(vnode_t *vsource_dir, vnode_t *vsource, char *old_name, target = (fatnode_t *)vtarget; if (target) { + if (flags & RENAME_NOREPLACE) { + VOP_UNLOCK(vtarget); + VOP_RELEASE(vtarget); + return EEXIST; + } + // we are replacing an existing link // do some checks expected by posix if (vsource->type != V_TYPE_DIR && vtarget->type == V_TYPE_DIR) { diff --git a/kernel-src/fs/tmpfs.c b/kernel-src/fs/tmpfs.c index 043c7c01..0464a08f 100644 --- a/kernel-src/fs/tmpfs.c +++ b/kernel-src/fs/tmpfs.c @@ -352,6 +352,9 @@ static int tmpfs_rename(vnode_t *source, vnode_t *sourcefile, char *oldname, vno oldnode = v; if (oldnode) { + if (flags & RENAME_NOREPLACE) + return EEXIST; + // we are replacing an existing link // do some checks expected by posix if (sourcefile->type != V_TYPE_DIR && oldnode->type == V_TYPE_DIR) diff --git a/kernel-src/include/kernel/abi.h b/kernel-src/include/kernel/abi.h index 3a1c1a96..e8a4ed84 100644 --- a/kernel-src/include/kernel/abi.h +++ b/kernel-src/include/kernel/abi.h @@ -84,6 +84,8 @@ typedef struct { #define AT_SYMLINK_NOFOLLOW 0x100 #define AT_EMPTY_PATH 0x1000 +#define RENAME_NOREPLACE 0x1 + #define AF_LOCAL 1 #define AF_INET 2 diff --git a/kernel-src/sys/syscalls/renameat.c b/kernel-src/sys/syscalls/renameat.c index 35214363..39776706 100644 --- a/kernel-src/sys/syscalls/renameat.c +++ b/kernel-src/sys/syscalls/renameat.c @@ -3,13 +3,15 @@ #include #include +#define RENAMEAT_KNOWN_FLAGS RENAME_NOREPLACE + syscallret_t syscall_renameat(context_t *context, int olddirfd, char *uoldpath, int newdirfd, char *unewpath, unsigned int flags) { syscallret_t ret = { .ret = -1 }; - if (flags) - printf("renameat: unknown %x\n", flags); + if (flags & ~RENAMEAT_KNOWN_FLAGS) + printf("renameat: unknown %x\n", flags & ~RENAMEAT_KNOWN_FLAGS); size_t oldpathlen; size_t newpathlen; diff --git a/patches/mlibc/jinx-working-patch.patch b/patches/mlibc/jinx-working-patch.patch index bd2573f7..864759c1 100644 --- a/patches/mlibc/jinx-working-patch.patch +++ b/patches/mlibc/jinx-working-patch.patch @@ -286,6 +286,23 @@ index 8592ea5..94ceba1 100644 + } + return 0; } +diff --git mlibc-clean/options/posix/include/bits/posix/posix_stdio.h mlibc-workdir/options/posix/include/bits/posix/posix_stdio.h +index f0d6edd..ab57b6b 100644 +--- mlibc-clean/options/posix/include/bits/posix/posix_stdio.h ++++ mlibc-workdir/options/posix/include/bits/posix/posix_stdio.h +@@ -63,6 +63,7 @@ char *fgetln(FILE *__stream, size_t *__size); + #endif /* !__MLIBC_ABI_ONLY */ + + #if defined(_GNU_SOURCE) ++#define RENAME_NOREPLACE (1 << 0) + #define RENAME_EXCHANGE (1 << 1) + + /* GNU extensions */ +@@ -97,4 +98,3 @@ FILE *fopencookie(void *__restrict __cookie, const char *__restrict __mode, cook + + #endif /* _MLIBC_POSIX_STDIO_H */ + +- diff --git mlibc-clean/options/rtld/x86_64/runtime.S mlibc-workdir/options/rtld/x86_64/runtime.S index ba9a520..b958ef3 100644 --- mlibc-clean/options/rtld/x86_64/runtime.S