diff --git a/libc/fchmod.cpp b/libc/fchmod.cpp index bef33d39..fecc59c8 100644 --- a/libc/fchmod.cpp +++ b/libc/fchmod.cpp @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + Copyright(C) Jonas 'Sortie' Termansen 2012. This file is part of the Sortix C Library. @@ -22,15 +22,13 @@ *******************************************************************************/ +#include #include #include -#include -// TODO: Implement this in the kernel. +DEFN_SYSCALL2(int, sys_fchmod, SYSCALL_FCHMOD, int, mode_t); + extern "C" int fchmod(int fd, mode_t mode) { - (void) fd; - (void) mode; - errno = ENOSYS; - return -1; + return sys_fchmod(fd, mode); } diff --git a/sortix/include/sortix/syscallnum.h b/sortix/include/sortix/syscallnum.h index 60cce093..27907bd6 100644 --- a/sortix/include/sortix/syscallnum.h +++ b/sortix/include/sortix/syscallnum.h @@ -89,6 +89,7 @@ #define SYSCALL_TRUNCATEAT 65 #define SYSCALL_FCHOWNAT 66 #define SYSCALL_FCHOWN 67 -#define SYSCALL_MAX_NUM 68 /* index of highest constant + 1 */ +#define SYSCALL_FCHMOD 68 +#define SYSCALL_MAX_NUM 69 /* index of highest constant + 1 */ #endif diff --git a/sortix/io.cpp b/sortix/io.cpp index 146128a8..0c6b300b 100644 --- a/sortix/io.cpp +++ b/sortix/io.cpp @@ -384,6 +384,15 @@ static int sys_chown(const char* path, uid_t owner, gid_t group) return sys_fchownat(AT_FDCWD, path, owner, group, 0); } +static int sys_fchmod(int fd, mode_t mode) +{ + Ref desc = CurrentProcess()->GetDescriptor(fd); + if ( !desc ) + return -1; + ioctx_t ctx; SetupUserIOCtx(&ctx); + return desc->chmod(&ctx, mode); +} + static int sys_chmod(const char* path, mode_t mode) { char* pathcopy = GetStringFromUser(path); @@ -478,6 +487,7 @@ void Init() Syscall::Register(SYSCALL_DUP2, (void*) sys_dup2); Syscall::Register(SYSCALL_FACCESSAT, (void*) sys_faccessat); Syscall::Register(SYSCALL_FCHDIR, (void*) sys_fchdir); + Syscall::Register(SYSCALL_FCHMOD, (void*) sys_fchmod); Syscall::Register(SYSCALL_FCHOWNAT, (void*) sys_fchownat); Syscall::Register(SYSCALL_FCHOWN, (void*) sys_fchown); Syscall::Register(SYSCALL_FCNTL, (void*) sys_fcntl);