mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-29 05:38:21 +00:00
syscalls: umask
This commit is contained in:
@@ -32,6 +32,7 @@ extern syscall_linkat
|
||||
extern syscall_readlinkat
|
||||
extern syscall_fchmod
|
||||
extern syscall_fchmodat
|
||||
extern syscall_umask
|
||||
syscalltab:
|
||||
dq syscall_print
|
||||
dq syscall_mmap
|
||||
@@ -66,7 +67,8 @@ dq syscall_linkat
|
||||
dq syscall_readlinkat
|
||||
dq syscall_fchmod
|
||||
dq syscall_fchmodat
|
||||
syscallcount equ 33
|
||||
dq syscall_umask
|
||||
syscallcount equ 34
|
||||
section .text
|
||||
global arch_syscall_entry
|
||||
; on entry:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#ifdef SYSCALL_LOGGING
|
||||
|
||||
#define SYSCALL_COUNT 33
|
||||
#define SYSCALL_COUNT 34
|
||||
#define LOGSTR(x) arch_e9_puts(x)
|
||||
|
||||
static char *name[] = {
|
||||
@@ -40,7 +40,8 @@ static char *name[] = {
|
||||
"linkat",
|
||||
"readlinkat",
|
||||
"fchmod",
|
||||
"fchmodat"
|
||||
"fchmodat",
|
||||
"umask"
|
||||
};
|
||||
|
||||
static char *args[] = {
|
||||
@@ -76,7 +77,8 @@ static char *args[] = {
|
||||
"olddirfd %d oldpath %s newdirfd %d oldpath %s flags %d type %d", // linkat
|
||||
"dirfd %d path %s buffer %p buffer length %lu", // readlinkat
|
||||
"fd %d mode %o", // fchmod
|
||||
"dirfd %d path %s mode %o flags %d" // fchmodat
|
||||
"dirfd %d path %s mode %o flags %d", // fchmodat
|
||||
"mode %o" // umask
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -67,6 +67,8 @@ typedef struct proc_t {
|
||||
|
||||
#include <arch/cpu.h>
|
||||
|
||||
#define UMASK(mode) ((mode) & ~_cpu()->thread->proc->umask)
|
||||
|
||||
extern proc_t *sched_initproc;
|
||||
|
||||
void sched_init();
|
||||
|
||||
@@ -11,7 +11,7 @@ static int dochmod(vnode_t *node, mode_t mode) {
|
||||
if (e)
|
||||
return e;
|
||||
|
||||
attr.mode = mode;
|
||||
attr.mode = UMASK(mode);
|
||||
|
||||
return VOP_SETATTR(node, &attr, cred);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,8 @@ syscallret_t syscall_linkat(context_t *, int olddirfd, const char *uoldpath, int
|
||||
|
||||
vattr_t attr = {
|
||||
.gid = _cpu()->thread->proc->cred.gid,
|
||||
.uid = _cpu()->thread->proc->cred.uid
|
||||
.uid = _cpu()->thread->proc->cred.uid,
|
||||
.mode = UMASK(0777)
|
||||
};
|
||||
|
||||
ret.errno = vfs_link(olddirnode, oldpath, newdirnode, newpath, type == 0 ? V_TYPE_REGULAR : V_TYPE_LINK, &attr);
|
||||
|
||||
@@ -26,7 +26,7 @@ syscallret_t syscall_mkdirat(context_t *, int dirfd, const char *upath, mode_t m
|
||||
goto cleanup;
|
||||
|
||||
vattr_t attr = {
|
||||
.mode = mode,
|
||||
.mode = UMASK(mode),
|
||||
.gid = _cpu()->thread->proc->cred.gid,
|
||||
.uid = _cpu()->thread->proc->cred.uid
|
||||
};
|
||||
|
||||
@@ -35,7 +35,7 @@ syscallret_t syscall_openat(context_t *context, int dirfd, const char *path, int
|
||||
|
||||
if (ret.errno == ENOENT && (flags & O_CREAT)) {
|
||||
vattr_t attr = {
|
||||
.mode = mode,
|
||||
.mode = UMASK(mode),
|
||||
.gid = _cpu()->thread->proc->cred.gid,
|
||||
.uid = _cpu()->thread->proc->cred.uid
|
||||
};
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#include <kernel/syscalls.h>
|
||||
#include <arch/cpu.h>
|
||||
|
||||
syscallret_t syscall_umask(context_t *, mode_t mode) {
|
||||
syscallret_t ret = {
|
||||
.errno = 0
|
||||
};
|
||||
|
||||
mode &= 0777;
|
||||
|
||||
ret.ret = __atomic_exchange_n(&_cpu()->thread->proc->umask, mode, __ATOMIC_SEQ_CST);
|
||||
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user