syscalls: chroot getpeername getsockname socketpair

This commit is contained in:
Matheus
2024-06-04 22:45:04 -03:00
parent b230d58a3f
commit b607ca7f4b
7 changed files with 316 additions and 12 deletions
+44
View File
@@ -0,0 +1,44 @@
#include <kernel/syscalls.h>
#include <kernel/scheduler.h>
#include <kernel/vfs.h>
#include <kernel/alloc.h>
#include <errno.h>
syscallret_t syscall_chroot(context_t *, const char *upath) {
syscallret_t ret = {
.ret = -1
};
if (upath > (char *)USERSPACE_END) {
ret.errno = EFAULT;
return ret;
}
// TODO safe string ops
char *path = alloc(strlen(upath) + 1);
strcpy(path, upath);
vnode_t *ref = path[0] == '/' ? sched_getroot() : sched_getcwd();
vnode_t *new = NULL;
ret.errno = vfs_lookup(&new, ref, path, NULL, 0);
if (ret.errno)
goto cleanup;
if (new->type != V_TYPE_DIR) {
ret.errno = ENOTDIR;
goto cleanup;
}
sched_setroot(new);
ret.ret = 0;
cleanup:
if (new)
VOP_RELEASE(new);
free(path);
VOP_RELEASE(ref);
return ret;
}