summaryrefslogtreecommitdiff
path: root/src/user
diff options
context:
space:
mode:
authordzwdz2022-09-21 18:07:21 +0200
committerdzwdz2022-09-21 18:07:21 +0200
commit8b3d3950ca115f1c614e85db9f25fc683864db14 (patch)
tree155705b792ec7e27075252744a9d01f7d7932c38 /src/user
parent95be8a2f9eda62b8061e02ee129a89c6dc54870b (diff)
user/lib: ufs_wait
Diffstat (limited to 'src/user')
-rw-r--r--src/user/app/login/login.c10
-rw-r--r--src/user/lib/fs/misc.c19
-rw-r--r--src/user/lib/fs/misc.h5
-rw-r--r--src/user/lib/include/__errno.h1
4 files changed, 26 insertions, 9 deletions
diff --git a/src/user/app/login/login.c b/src/user/app/login/login.c
index 59befb1..5d9eb36 100644
--- a/src/user/app/login/login.c
+++ b/src/user/app/login/login.c
@@ -36,18 +36,10 @@ static void drv(const char *user) {
char *buf = malloc(PATH_MAX);
for (;;) {
struct ufs_request req;
- handle_t reqh = _syscall_fs_wait(buf, PATH_MAX, &req);
+ handle_t reqh = ufs_wait(buf, PATH_MAX, &req);
if (reqh < 0) break;
-
switch (req.op) {
case VFSOP_OPEN:
- /* null terminate for segcmp */
- if (req.len == PATH_MAX) {
- _syscall_fs_respond(reqh, NULL, -1, 0);
- break;
- }
- buf[req.len] = '\0';
-
if (segcmp(buf, 1, "Users") && segcmp(buf, 2, user)) { // /Users/$user/**
forward_open(reqh, buf, req.len, req.flags);
} else if (segcmp(buf, 1, "Users") && segcmp(buf, 3, "private")) { // /Users/*/private/**
diff --git a/src/user/lib/fs/misc.c b/src/user/lib/fs/misc.c
index 3a04649..7a66b80 100644
--- a/src/user/lib/fs/misc.c
+++ b/src/user/lib/fs/misc.c
@@ -1,5 +1,6 @@
#include <camellia/flags.h>
#include <camellia/syscalls.h>
+#include <errno.h>
#include <shared/mem.h>
#include <stdbool.h>
#include <stdio.h>
@@ -289,6 +290,24 @@ void fs_dir_inject(const char *path) {
exit(0);
}
+handle_t ufs_wait(char *buf, size_t len, struct ufs_request *req) {
+ handle_t reqh;
+ for (;;) {
+ reqh = _syscall_fs_wait(buf, len, req);
+ if (reqh < 0) break;
+ if (req->op == VFSOP_OPEN) {
+ if (req->len == len) {
+ _syscall_fs_respond(reqh, NULL, -ENAMETOOLONG, 0);
+ continue;
+ }
+ buf[req->len] = '\0';
+ // TODO ensure passed paths don't have null bytes in them in the kernel
+ }
+ break;
+ }
+ return reqh;
+}
+
bool mount_at_pred(const char *path) {
// TODO preprocess path - simplify & ensure trailing slash
if (!fork2_n_mount(path)) {
diff --git a/src/user/lib/fs/misc.h b/src/user/lib/fs/misc.h
index d90100d..35184e1 100644
--- a/src/user/lib/fs/misc.h
+++ b/src/user/lib/fs/misc.h
@@ -14,5 +14,10 @@ void fs_dir_inject(const char *path);
bool mount_at_pred(const char *path);
+// TODO separate fs drivers and wrappers around syscalls
+
+/** like _syscall_fs_wait, but ensures *buf is a null terminated string on VFSOP_OPEN */
+handle_t ufs_wait(char *buf, size_t len, struct ufs_request *req);
+
/** Mounts something and injects its path into the fs */
#define MOUNT_AT(path) for (; mount_at_pred(path); exit(1))
diff --git a/src/user/lib/include/__errno.h b/src/user/lib/include/__errno.h
index d6d5e6a..69113cb 100644
--- a/src/user/lib/include/__errno.h
+++ b/src/user/lib/include/__errno.h
@@ -13,4 +13,5 @@ E( 10, "EACCES")
E( 11, "EMFILE all file descriptors taken")
E( 12, "ECONNRESET")
E(200, "EISDIR")
+E(201, "ENAMETOOLONG")
#endif