summaryrefslogtreecommitdiff
path: root/src/user/lib/fs/misc.c
diff options
context:
space:
mode:
authordzwdz2022-10-02 15:49:24 +0200
committerdzwdz2022-10-02 15:49:24 +0200
commita835fa4792fa2afd84d7e27bd242add06763db72 (patch)
tree55ed3928afaca30461880c4b200460fdbca37c0d /src/user/lib/fs/misc.c
parent8b3d3950ca115f1c614e85db9f25fc683864db14 (diff)
user/libc: rework fs_whitelist; fix minor bugs
Diffstat (limited to 'src/user/lib/fs/misc.c')
-rw-r--r--src/user/lib/fs/misc.c81
1 files changed, 1 insertions, 80 deletions
diff --git a/src/user/lib/fs/misc.c b/src/user/lib/fs/misc.c
index 7a66b80..f660f6f 100644
--- a/src/user/lib/fs/misc.c
+++ b/src/user/lib/fs/misc.c
@@ -22,8 +22,7 @@ bool fork2_n_mount(const char *path) {
}
static int dir_seglen(const char *path) {
- /* in human terms:
- * if path contains /, return its position + 1
+ /* if path contains /, return its position + 1
* otherwise, return strlen */
int len = 0;
while (path[len]) {
@@ -85,84 +84,6 @@ void fs_passthru(const char *prefix) {
exit(0);
}
-void fs_whitelist(const char **list) {
- const size_t buflen = 1024;
- char *buf = malloc(buflen);
- if (!buf) exit(1);
- for (;;) {
- struct ufs_request res;
- handle_t reqh = _syscall_fs_wait(buf, buflen, &res);
- if (reqh < 0) break;
-
- char *ipath = res.id;
- size_t blen;
- bool passthru, inject;
- struct dirbuild db;
-
- switch (res.op) {
- case VFSOP_OPEN:
- passthru = false;
- inject = false;
-
- for (const char **iter = list; *iter; iter++) {
- size_t len = strlen(*iter);
- bool ro = false;
- if (len >= 3 && !memcmp(*iter + len - 3, ":ro", 3)) {
- ro = true;
- len -= 3;
- }
- if (len <= res.len && !memcmp(buf, *iter, len)) {
- if (ro) res.flags |= OPEN_RO;
- passthru = true;
- break;
- }
- if (res.len < len &&
- buf[res.len - 1] == '/' &&
- !memcmp(buf, *iter, res.len))
- {
- inject = true;
- }
- }
- if (passthru) {
- forward_open(reqh, buf, res.len, res.flags);
- } else if (inject) {
- // TODO all the inject points could be precomputed
- ipath = malloc(res.len + 1);
- memcpy(ipath, buf, res.len);
- ipath[res.len] = '\0';
- _syscall_fs_respond(reqh, ipath, 0, 0);
- } else {
- _syscall_fs_respond(reqh, NULL, -1, 0);
- }
- break;
-
- case VFSOP_READ:
- case VFSOP_GETSIZE:
- blen = strlen(ipath);
- char *target = res.op == VFSOP_READ ? buf : NULL;
- dir_start(&db, res.offset, target, buflen);
- for (const char **iter = list; *iter; iter++) {
- // TODO could be precomputed too
- size_t len = strlen(*iter); // inefficient, whatever
- if (blen < len && !memcmp(ipath, *iter, blen))
- dir_appendl(&db, *iter + blen, dir_seglen(*iter + blen));
- }
- _syscall_fs_respond(reqh, target, dir_finish(&db), 0);
- break;
-
- case VFSOP_CLOSE:
- free(ipath);
- _syscall_fs_respond(reqh, NULL, 0, 0);
- break;
-
- default:
- _syscall_fs_respond(reqh, NULL, -1, 0);
- break;
- }
- }
- exit(0);
-}
-
void fs_union(const char **list) {
struct ufs_request res;