Add chmod(2).

This commit is contained in:
Jonas 'Sortie' Termansen 2012-10-23 19:55:54 +02:00
parent 1444683ea8
commit a11439bc87
3 changed files with 25 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,14 @@
*******************************************************************************/
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <errno.h>
#include <unistd.h>
DEFN_SYSCALL2(int, sys_chmod, SYSCALL_CHMOD, const char*, mode_t);
// TODO: Implement this in the kernel.
extern "C" int chmod(const char* path, mode_t mode)
{
(void) path;
(void) mode;
errno = ENOSYS;
return -1;
return sys_chmod(path, mode);
}

View File

@ -78,6 +78,7 @@
#define SYSCALL_OPENAT 54
#define SYSCALL_DISPMSG_ISSUE 55
#define SYSCALL_FSTATAT 56
#define SYSCALL_MAX_NUM 57 /* index of highest constant + 1 */
#define SYSCALL_CHMOD 57
#define SYSCALL_MAX_NUM 58 /* index of highest constant + 1 */
#endif

View File

@ -317,6 +317,22 @@ static int sys_chdir(const char* path)
return 0;
}
static int sys_chmod(const char* path, mode_t mode)
{
char* pathcopy = GetStringFromUser(path);
if ( !pathcopy )
return -1;
ioctx_t ctx; SetupUserIOCtx(&ctx);
const char* relpath = pathcopy;
Ref<Descriptor> from = PrepareLookup(&relpath);
Ref<Descriptor> desc = from->open(&ctx, relpath, O_WRONLY);
from.Reset();
delete[] pathcopy;
if ( !desc )
return -1;
return desc->chmod(&ctx, mode);
}
static int sys_settermmode(int fd, unsigned mode)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
@ -357,6 +373,7 @@ void Init()
{
Syscall::Register(SYSCALL_ACCESS, (void*) sys_access);
Syscall::Register(SYSCALL_CHDIR, (void*) sys_chdir);
Syscall::Register(SYSCALL_CHMOD, (void*) sys_chmod);
Syscall::Register(SYSCALL_CLOSE, (void*) sys_close);
Syscall::Register(SYSCALL_DUP, (void*) sys_dup);
Syscall::Register(SYSCALL_FCNTL, (void*) sys_fcntl);