From 2080d1f2b769916a247bb49e1c64ef75f1d9e30e Mon Sep 17 00:00:00 2001 From: EnderIce2 Date: Fri, 21 Mar 2025 01:58:14 +0000 Subject: [PATCH] feat(kernel/syscalls): add fcntl() syscall Signed-off-by: EnderIce2 --- Kernel/include/interface/syscalls.h | 22 ++++++++++++++++++++++ Kernel/syscalls/native.cpp | 2 ++ 2 files changed, 24 insertions(+) diff --git a/Kernel/include/interface/syscalls.h b/Kernel/include/interface/syscalls.h index 3c0fbcc4..1d75bd71 100644 --- a/Kernel/include/interface/syscalls.h +++ b/Kernel/include/interface/syscalls.h @@ -830,6 +830,25 @@ typedef enum * - #EINVAL if the request is invalid */ SYS_IOCTL, + /** + * @brief Function control + * + * @code + * int fcntl(int fd, int cmd, void *arg); + * @endcode + * + * @details Manipulates the underlying parameters of a device. + * + * @param fd File descriptor referring to the device + * @param cmd Device-specific request code + * @param arg Argument for the request + * + * @return + * - #EOK on success + * - #EBADF if `fd` is not valid + * - #EINVAL if the request is invalid + */ + SYS_FCNTL, /* File Status */ @@ -1678,6 +1697,9 @@ typedef enum /** @copydoc SYS_IOCTL */ #define call_ioctl(fd, request, argp) syscall3(SYS_IOCTL, (scarg)fd, (scarg)request, (scarg)argp) +/** @copydoc SYS_FCNTL */ +#define call_fcntl(fd, cmd, arg) syscall3(SYS_FCNTL, (scarg)fd, (scarg)cmd, (scarg)arg) + /* File Status */ /** @copydoc SYS_STAT */ diff --git a/Kernel/syscalls/native.cpp b/Kernel/syscalls/native.cpp index b7ab94c7..9de911bd 100644 --- a/Kernel/syscalls/native.cpp +++ b/Kernel/syscalls/native.cpp @@ -135,6 +135,7 @@ static int sys_close(SysFrm *Frame, int fd) } static int sys_ioctl(SysFrm *Frame, int fd, unsigned long request, void *argp) { return -ENOSYS; } +static int sys_fcntl(SysFrm *Frame, int fd, int cmd, void *arg) { return -ENOSYS; } static int sys_stat(SysFrm *Frame, const char *pathname, struct stat *statbuf) { return -ENOSYS; } static int sys_fstat(SysFrm *Frame, int fd, struct stat *statbuf) { return -ENOSYS; } static int sys_lstat(SysFrm *Frame, const char *pathname, struct stat *statbuf) { return -ENOSYS; } @@ -275,6 +276,7 @@ __constructor void __init_native_syscalls(void) scTbl[SYS_OPEN] = {"SYS_OPEN", (void *)sys_open}; scTbl[SYS_CLOSE] = {"SYS_CLOSE", (void *)sys_close}; scTbl[SYS_IOCTL] = {"SYS_IOCTL", (void *)sys_ioctl}; + scTbl[SYS_FCNTL] = {"SYS_FCNTL", (void *)sys_fcntl}; /* File Status */ scTbl[SYS_STAT] = {"SYS_STAT", (void *)sys_stat};