Add fchmod(2).

This commit is contained in:
Jonas 'Sortie' Termansen 2012-10-25 00:17:43 +02:00
parent c1280bedb0
commit f21462bf18
3 changed files with 17 additions and 8 deletions

View File

@ -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 <sys/types.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <errno.h>
// 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);
}

View File

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

View File

@ -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<Descriptor> 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);