syscalls: mknodat

This commit is contained in:
Matheus
2024-08-11 14:44:53 -03:00
parent 40693d8ca0
commit b6ed9c1bac
5 changed files with 101 additions and 8 deletions
+3 -1
View File
@@ -77,6 +77,7 @@ extern syscall_pause
extern syscall_ppoll
extern syscall_pread
extern syscall_pwrite
extern syscall_mknodat
syscalltab:
dq syscall_print
dq syscall_mmap
@@ -156,7 +157,8 @@ dq syscall_pause
dq syscall_ppoll
dq syscall_pread
dq syscall_pwrite
syscallcount equ 78
dq syscall_mknodat
syscallcount equ 79
section .text
global arch_syscall_entry
; on entry:
+5 -3
View File
@@ -5,7 +5,7 @@
#ifdef SYSCALL_LOGGING
#define SYSCALL_COUNT 78
#define SYSCALL_COUNT 79
#define LOGSTR(x) arch_e9_puts(x)
static char *name[] = {
@@ -86,7 +86,8 @@ static char *name[] = {
"pause",
"ppoll",
"pread",
"pwrite"
"pwrite",
"mknodat"
};
static char *args[] = {
@@ -165,9 +166,10 @@ static char *args[] = {
"fd %d addr %p addrlen %p", // getpeername
"path %s", // chroot
"N/A", // pause
"fds %p nfds %d timeout %p sigmask %p" // ppoll
"fds %p nfds %d timeout %p sigmask %p", // ppoll
"fd %d buffer %p count %lu offset %lu\n", // pread
"fd %d buffer %p count %lu offset %lu\n", // pwrite
"dirfd %d path %s mode %o dev %x\n" // mknodat
};
#endif
+21
View File
@@ -224,4 +224,25 @@ static inline mode_t vfs_getposixtype(int type) {
}
}
static inline mode_t vfs_getsystemtype(int type) {
switch (type) {
case TYPE_REGULAR:
return V_TYPE_REGULAR;
case TYPE_DIR:
return V_TYPE_DIR;
case TYPE_CHARDEV:
return V_TYPE_CHDEV;
case TYPE_BLOCKDEV:
return V_TYPE_BLKDEV;
case TYPE_FIFO:
return V_TYPE_FIFO;
case TYPE_LINK:
return V_TYPE_LINK;
case TYPE_SOCKET:
return V_TYPE_SOCKET;
default:
return -1;
}
}
#endif
+58
View File
@@ -0,0 +1,58 @@
#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_mknodat(context_t *, int dirfd, char *upath, mode_t mode, dev_t dev) {
syscallret_t ret = {
.ret = -1
};
size_t pathlen;
ret.errno = usercopy_strlen(upath, &pathlen);
if (ret.errno)
return ret;
char *path = alloc(pathlen + 1);
if (path == NULL) {
ret.errno = ENOMEM;
return ret;
}
ret.errno = usercopy_fromuser(path, upath, pathlen);
if (ret.errno) {
free(path);
return ret;
}
vnode_t *dirnode = NULL;
file_t *file = NULL;
ret.errno = dirfd_enter(path, dirfd, &file, &dirnode);
if (ret.errno)
goto cleanup;
int type = vfs_getsystemtype(GETTYPE(mode));
mode = GETMODE(mode);
vattr_t attr = {
.mode = UMASK(mode),
.gid = _cpu()->thread->proc->cred.gid,
.uid = _cpu()->thread->proc->cred.uid,
.rdevmajor = (type == V_TYPE_CHDEV || type == V_TYPE_BLKDEV) ? MAJORDEV(dev) : 0,
.rdevminor = (type == V_TYPE_CHDEV || type == V_TYPE_BLKDEV) ? MINORDEV(dev) : 0,
};
ret.errno = vfs_create(dirnode, path, &attr, type, NULL);
ret.ret = ret.errno ? -1 : 0;
cleanup:
if (dirnode)
dirfd_leave(dirnode, file);
free(path);
return ret;
}