diff --git a/kernel/include/kernel/Process.h b/kernel/include/kernel/Process.h index a2b03488..ce719a10 100644 --- a/kernel/include/kernel/Process.h +++ b/kernel/include/kernel/Process.h @@ -119,8 +119,9 @@ namespace Kernel BAN::ErrorOr sys_pread(int fd, void* buffer, size_t count, off_t offset); - BAN::ErrorOr sys_chmod(const char*, mode_t); - BAN::ErrorOr sys_chown(const char*, uid_t, gid_t); + BAN::ErrorOr sys_chmod(const char* path, mode_t mode); + BAN::ErrorOr sys_fchmod(int fildes, mode_t mode); + BAN::ErrorOr sys_chown(const char* path, uid_t uid, gid_t gid); BAN::ErrorOr sys_socket(int domain, int type, int protocol); BAN::ErrorOr sys_getsockname(int socket, sockaddr* address, socklen_t* address_len); diff --git a/kernel/kernel/Process.cpp b/kernel/kernel/Process.cpp index af9e8a28..ffec28f0 100644 --- a/kernel/kernel/Process.cpp +++ b/kernel/kernel/Process.cpp @@ -1103,6 +1103,18 @@ namespace Kernel return 0; } + BAN::ErrorOr Process::sys_fchmod(int fildes, mode_t mode) + { + if (mode & S_IFMASK) + return BAN::Error::from_errno(EINVAL); + + LockGuard _(m_process_lock); + auto inode = TRY(m_open_file_descriptors.inode_of(fildes)); + TRY(inode->chmod(mode)); + + return 0; + } + BAN::ErrorOr Process::sys_chown(const char* path, uid_t uid, gid_t gid) { LockGuard _(m_process_lock); diff --git a/userspace/libraries/LibC/include/sys/syscall.h b/userspace/libraries/LibC/include/sys/syscall.h index 073a3f1e..e4b7afe7 100644 --- a/userspace/libraries/LibC/include/sys/syscall.h +++ b/userspace/libraries/LibC/include/sys/syscall.h @@ -55,6 +55,7 @@ __BEGIN_DECLS O(SYS_TTY_CTRL, tty_ctrl) \ 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) \ diff --git a/userspace/libraries/LibC/sys/stat.cpp b/userspace/libraries/LibC/sys/stat.cpp index 4e6fe002..69e94b26 100644 --- a/userspace/libraries/LibC/sys/stat.cpp +++ b/userspace/libraries/LibC/sys/stat.cpp @@ -13,9 +13,9 @@ int chmod(const char* path, mode_t mode) return syscall(SYS_CHMOD, path, mode); } -int fchmod(int, mode_t) +int fchmod(int fildes, mode_t mode) { - ASSERT_NOT_REACHED(); + return syscall(SYS_FCHMOD, fildes, mode); } int fstat(int fildes, struct stat* buf)