syscalls: fchmod and fchmodat

This commit is contained in:
Matheus
2023-07-06 20:58:17 -03:00
parent a94d8f7389
commit e29d75580a
4 changed files with 106 additions and 8 deletions
+5 -1
View File
@@ -30,6 +30,8 @@ extern syscall_mkdirat
extern syscall_clockget
extern syscall_linkat
extern syscall_readlinkat
extern syscall_fchmod
extern syscall_fchmodat
syscalltab:
dq syscall_print
dq syscall_mmap
@@ -62,7 +64,9 @@ dq syscall_mkdirat
dq syscall_clockget
dq syscall_linkat
dq syscall_readlinkat
syscallcount equ 31
dq syscall_fchmod
dq syscall_fchmodat
syscallcount equ 33
section .text
global arch_syscall_entry
; on entry:
+7 -3
View File
@@ -4,7 +4,7 @@
#ifdef SYSCALL_LOGGING
#define SYSCALL_COUNT 30
#define SYSCALL_COUNT 33
#define LOGSTR(x) arch_e9_puts(x)
static char *name[] = {
@@ -38,7 +38,9 @@ static char *name[] = {
"mkdirat",
"clockget",
"linkat",
"readlinkat"
"readlinkat",
"fchmod",
"fchmodat"
};
static char *args[] = {
@@ -72,7 +74,9 @@ static char *args[] = {
"dirfd %d path %s mode %o", // mkdirat
"clockid %d timespec %p", // clockget
"olddirfd %d oldpath %s newdirfd %d oldpath %s flags %d type %d", // linkat
"dirfd %d path %s buffer %p buffer length %lu" // readlinkat
"dirfd %d path %s buffer %p buffer length %lu", // readlinkat
"fd %d mode %o", // fchmod
"dirfd %d path %s mode %o flags %d" // fchmodat
};
#endif
+74
View File
@@ -0,0 +1,74 @@
#include <kernel/syscalls.h>
#include <kernel/alloc.h>
#include <kernel/file.h>
#include <kernel/vfs.h>
#include <arch/cpu.h>
static int dochmod(vnode_t *node, mode_t mode) {
vattr_t attr;
cred_t *cred = &_cpu()->thread->proc->cred;
int e = VOP_GETATTR(node, &attr, cred);
if (e)
return e;
attr.mode = mode;
return VOP_SETATTR(node, &attr, cred);
}
syscallret_t syscall_fchmodat(context_t *, int dirfd, const char *upath, mode_t mode, int flags) {
syscallret_t ret = {
.ret = -1
};
char *path = alloc(strlen(upath) + 1);
if (path == NULL) {
ret.errno = ENOMEM;
return ret;
}
strcpy(path, upath);
file_t *file = NULL;
vnode_t *dirnode = NULL;
vnode_t *node = NULL;
ret.errno = dirfd_enter(path, dirfd, &file, &dirnode);
if (ret.errno)
goto cleanup;
ret.errno = vfs_lookup(&node, dirnode, path, NULL, (flags & AT_SYMLINK_NOFOLLOW) ? VFS_LOOKUP_NOLINK : 0);
if (ret.errno)
goto cleanup;
ret.errno = dochmod(node, mode);
ret.ret = ret.errno ? -1 : 0;
cleanup:
if (node)
VOP_RELEASE(node);
if (dirnode)
dirfd_leave(dirnode, file);
free(path);
return ret;
}
syscallret_t syscall_fchmod(context_t *, int fd, mode_t mode) {
syscallret_t ret = {
.ret = -1
};
file_t *file = fd_get(fd);
if (file == NULL) {
ret.errno = EBADF;
return ret;
}
ret.errno = dochmod(file->vnode, mode);
ret.ret = ret.errno ? -1 : 0;
return ret;
}