From d88ee5c9eefb65545aacbb6c523bbee11650db7b Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 17 Sep 2024 15:55:53 +0300 Subject: [PATCH] Kernel/LibC: Implement `creat` with `open` This allows getting rid of unnecessary SYS_CREATE. Directory creation still has its own syscall, but I could combine it with SYS_OPEN also. --- kernel/include/kernel/Process.h | 1 - kernel/kernel/Process.cpp | 8 -------- userspace/libraries/LibC/fcntl.cpp | 3 +-- userspace/libraries/LibC/include/sys/syscall.h | 1 - 4 files changed, 1 insertion(+), 12 deletions(-) diff --git a/kernel/include/kernel/Process.h b/kernel/include/kernel/Process.h index c1567aa7..49a2fb49 100644 --- a/kernel/include/kernel/Process.h +++ b/kernel/include/kernel/Process.h @@ -109,7 +109,6 @@ namespace Kernel BAN::ErrorOr sys_read(int fd, void* buffer, size_t count); BAN::ErrorOr sys_write(int fd, const void* buffer, size_t count); BAN::ErrorOr sys_access(const char* path, int amode); - BAN::ErrorOr sys_create(const char*, mode_t); BAN::ErrorOr sys_create_dir(const char*, mode_t); BAN::ErrorOr sys_unlink(const char*); BAN::ErrorOr readlink_impl(BAN::RefPtr, char* buffer, size_t bufsize); diff --git a/kernel/kernel/Process.cpp b/kernel/kernel/Process.cpp index 45ac4c97..2229d3ef 100644 --- a/kernel/kernel/Process.cpp +++ b/kernel/kernel/Process.cpp @@ -970,14 +970,6 @@ namespace Kernel return 0; } - BAN::ErrorOr Process::sys_create(const char* path, mode_t mode) - { - LockGuard _(m_process_lock); - TRY(validate_string_access(path)); - TRY(create_file_or_dir(VirtualFileSystem::get().root_file(), path, mode)); - return 0; - } - BAN::ErrorOr Process::sys_create_dir(const char* path, mode_t mode) { LockGuard _(m_process_lock); diff --git a/userspace/libraries/LibC/fcntl.cpp b/userspace/libraries/LibC/fcntl.cpp index bbfc8459..809f2c99 100644 --- a/userspace/libraries/LibC/fcntl.cpp +++ b/userspace/libraries/LibC/fcntl.cpp @@ -1,12 +1,11 @@ #include -#include #include #include #include int creat(const char* path, mode_t mode) { - return syscall(SYS_CREATE, path, S_IFREG | __UMASKED_MODE(mode)); + return open(path, O_WRONLY | O_CREAT | O_TRUNC, mode); } int open(const char* path, int oflag, ...) diff --git a/userspace/libraries/LibC/include/sys/syscall.h b/userspace/libraries/LibC/include/sys/syscall.h index e4b7afe7..1746c153 100644 --- a/userspace/libraries/LibC/include/sys/syscall.h +++ b/userspace/libraries/LibC/include/sys/syscall.h @@ -56,7 +56,6 @@ __BEGIN_DECLS O(SYS_POWEROFF, poweroff) \ O(SYS_CHMOD, chmod) \ O(SYS_FCHMOD, fchmod) \ - O(SYS_CREATE, create) \ O(SYS_CREATE_DIR, create_dir) \ O(SYS_UNLINK, unlink) \ O(SYS_READLINK, readlink) \