mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-29 13:48:21 +00:00
syscalls: faccessat
This commit is contained in:
@@ -23,6 +23,7 @@ extern syscall_fcntl
|
||||
extern syscall_chdir
|
||||
extern syscall_pipe2
|
||||
extern syscall_isatty
|
||||
extern syscall_faccessat
|
||||
syscalltab:
|
||||
dq syscall_print
|
||||
dq syscall_mmap
|
||||
@@ -48,7 +49,8 @@ dq syscall_fcntl
|
||||
dq syscall_chdir
|
||||
dq syscall_pipe2
|
||||
dq syscall_isatty
|
||||
syscallcount equ 24
|
||||
dq syscall_faccessat
|
||||
syscallcount equ 25
|
||||
section .text
|
||||
global arch_syscall_entry
|
||||
; on entry:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <arch/e9.h>
|
||||
#include <arch/cpu.h>
|
||||
|
||||
#define SYSCALL_COUNT 24
|
||||
#define SYSCALL_COUNT 25
|
||||
#define LOGSTR(x) arch_e9_puts(x)
|
||||
|
||||
static char *name[] = {
|
||||
@@ -29,7 +29,8 @@ static char *name[] = {
|
||||
"fcntl",
|
||||
"chdir",
|
||||
"pipe2",
|
||||
"isatty"
|
||||
"isatty",
|
||||
"faccessat"
|
||||
};
|
||||
|
||||
static char *args[] = {
|
||||
@@ -57,6 +58,7 @@ static char *args[] = {
|
||||
"path %s", // chdir
|
||||
"flags %d", // pipe2
|
||||
"fd %d", // isatty
|
||||
"dirfd %d pathname %s mode %d flags %d" // faccessat
|
||||
};
|
||||
|
||||
__attribute__((no_caller_saved_registers)) void arch_syscall_log(int syscall, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, uint64_t a6) {
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
#include <kernel/syscalls.h>
|
||||
#include <kernel/file.h>
|
||||
#include <kernel/alloc.h>
|
||||
#include <kernel/vfs.h>
|
||||
#include <arch/cpu.h>
|
||||
#include <string.h>
|
||||
|
||||
#define AT_SYMLINK_NOFOLLOW 0x100
|
||||
|
||||
syscallret_t syscall_faccessat(context_t *, int dirfd, const char *upath, int mode, int flags) {
|
||||
syscallret_t ret = {
|
||||
.ret = -1
|
||||
};
|
||||
|
||||
char *path = alloc(strlen(upath) + 1);
|
||||
if (path == NULL) {
|
||||
ret.errno = ENOMEM;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// TODO safe strcopy
|
||||
strcpy(path, upath);
|
||||
|
||||
vnode_t *dirnode = NULL;
|
||||
file_t *file = NULL;
|
||||
if (*path == '/') {
|
||||
dirnode = sched_getroot();
|
||||
} else if (dirfd == AT_FDCWD) {
|
||||
dirnode = sched_getcwd();
|
||||
} else {
|
||||
file = fd_get(dirfd);
|
||||
if (file == NULL) {
|
||||
ret.errno = EBADF;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
dirnode = file->vnode;
|
||||
|
||||
if (dirnode->type != V_TYPE_DIR) {
|
||||
ret.errno = ENOTDIR;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
vnode_t *node = NULL;
|
||||
ret.errno = vfs_lookup(&node, dirnode, path, NULL, flags & AT_SYMLINK_NOFOLLOW ? VFS_LOOKUP_NOLINK : 0);
|
||||
if (ret.errno)
|
||||
goto cleanup;
|
||||
|
||||
ret.errno = VOP_ACCESS(node, mode, &_cpu()->thread->proc->cred);
|
||||
ret.ret = 0;
|
||||
|
||||
cleanup:
|
||||
if (node)
|
||||
VOP_RELEASE(node);
|
||||
|
||||
if (file)
|
||||
fd_release(file);
|
||||
else
|
||||
VOP_RELEASE(dirnode);
|
||||
|
||||
free(path);
|
||||
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user