mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Add chmod(2).
This commit is contained in:
parent
1444683ea8
commit
a11439bc87
3 changed files with 25 additions and 8 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue