syscalls: mkdirat and gethostname + uname stubs in mlibc

This commit is contained in:
Matheus
2023-07-05 21:06:38 -03:00
parent f76046a56b
commit 4b38f6d26b
6 changed files with 150 additions and 8 deletions
+3 -1
View File
@@ -26,6 +26,7 @@ extern syscall_isatty
extern syscall_faccessat
extern syscall_unlinkat
extern syscall_ioctl
extern syscall_mkdirat
syscalltab:
dq syscall_print
dq syscall_mmap
@@ -54,7 +55,8 @@ dq syscall_isatty
dq syscall_faccessat
dq syscall_unlinkat
dq syscall_ioctl
syscallcount equ 27
dq syscall_mkdirat
syscallcount equ 28
section .text
global arch_syscall_entry
; on entry:
+7 -3
View File
@@ -4,7 +4,7 @@
#ifdef SYSCALL_LOGGING
#define SYSCALL_COUNT 25
#define SYSCALL_COUNT 28
#define LOGSTR(x) arch_e9_puts(x)
static char *name[] = {
@@ -33,7 +33,9 @@ static char *name[] = {
"pipe2",
"isatty",
"faccessat",
"unlinkat"
"unlinkat",
"ioctl",
"mkdirat"
};
static char *args[] = {
@@ -62,7 +64,9 @@ static char *args[] = {
"flags %d", // pipe2
"fd %d", // isatty
"dirfd %d pathname %s mode %d flags %d", // faccessat
"dirfd %d pathname %d flags %d" // unlinkat
"dirfd %d pathname %d flags %d", // unlinkat
"fd %d request %lu argument %d", // ioctl
"dirfd %d path %s mode %o" // mkdirat
};
#endif
+1
View File
@@ -238,6 +238,7 @@ static void ctor(scache_t *cache, void *obj) {
node->attr.inode = ++currentinode;
EVENT_INIT(&node->writeevent);
EVENT_INIT(&node->readevent);
node->vnode.type = V_TYPE_FIFO;
}
void pipefs_init() {
+62
View File
@@ -0,0 +1,62 @@
#include <kernel/syscalls.h>
#include <kernel/file.h>
#include <kernel/vfs.h>
#include <kernel/alloc.h>
#include <kernel/abi.h>
#include <arch/cpu.h>
syscallret_t syscall_mkdirat(context_t *, int dirfd, const char *upath, mode_t mode) {
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;
}
}
vattr_t attr = {
.mode = mode,
.gid = _cpu()->thread->proc->cred.gid,
.uid = _cpu()->thread->proc->cred.uid
};
ret.errno = vfs_create(dirnode, path, &attr, V_TYPE_DIR, NULL);
ret.ret = ret.errno ? -1 : 0;
cleanup:
if (file)
fd_release(file);
else
VOP_RELEASE(dirnode);
free(path);
return ret;
}