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.
This commit is contained in:
Bananymous 2024-09-17 15:55:53 +03:00
parent d4ea720239
commit d88ee5c9ee
4 changed files with 1 additions and 12 deletions

View File

@ -109,7 +109,6 @@ namespace Kernel
BAN::ErrorOr<long> sys_read(int fd, void* buffer, size_t count);
BAN::ErrorOr<long> sys_write(int fd, const void* buffer, size_t count);
BAN::ErrorOr<long> sys_access(const char* path, int amode);
BAN::ErrorOr<long> sys_create(const char*, mode_t);
BAN::ErrorOr<long> sys_create_dir(const char*, mode_t);
BAN::ErrorOr<long> sys_unlink(const char*);
BAN::ErrorOr<long> readlink_impl(BAN::RefPtr<Inode>, char* buffer, size_t bufsize);

View File

@ -970,14 +970,6 @@ namespace Kernel
return 0;
}
BAN::ErrorOr<long> 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<long> Process::sys_create_dir(const char* path, mode_t mode)
{
LockGuard _(m_process_lock);

View File

@ -1,12 +1,11 @@
#include <fcntl.h>
#include <errno.h>
#include <stdarg.h>
#include <sys/syscall.h>
#include <unistd.h>
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, ...)

View File

@ -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) \