From 24e8f648bb8040f9fc07b4ba3a4819e322462281 Mon Sep 17 00:00:00 2001 From: Matheus Date: Mon, 27 May 2024 21:55:04 -0300 Subject: [PATCH] open syscall: O_EXCL support --- kernel-src/sys/syscalls/open.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel-src/sys/syscalls/open.c b/kernel-src/sys/syscalls/open.c index 07ab4fc0..3e911dfe 100644 --- a/kernel-src/sys/syscalls/open.c +++ b/kernel-src/sys/syscalls/open.c @@ -28,6 +28,7 @@ syscallret_t syscall_openat(context_t *context, int dirfd, const char *path, int ret.errno = dirfd_enter(pathbuf, dirfd, &dirfile, &dirnode); + retry_open: file_t *newfile = NULL; int newfd; ret.errno = fd_new(flags & O_CLOEXEC, &newfile, &newfd); @@ -36,6 +37,10 @@ syscallret_t syscall_openat(context_t *context, int dirfd, const char *path, int vnode_t *vnode = NULL; ret.errno = vfs_open(dirnode, pathbuf, fileflagstovnodeflags(flags), &vnode); + if (ret.errno == 0 && (flags & O_CREAT) && (flags & O_EXCL)) { + ret.errno = EEXIST; + return ret; + } if (ret.errno == ENOENT && (flags & O_CREAT)) { vattr_t attr = { @@ -45,6 +50,8 @@ syscallret_t syscall_openat(context_t *context, int dirfd, const char *path, int }; ret.errno = vfs_create(dirnode, pathbuf, &attr, V_TYPE_REGULAR, &vnode); + if (ret.errno == EEXIST && (flags & O_EXCL) == 0) + goto retry_open; } if (ret.errno)