summaryrefslogtreecommitdiff
path: root/src/user/lib/fs/misc.c
diff options
context:
space:
mode:
authordzwdz2023-08-04 01:20:38 +0200
committerdzwdz2023-08-06 00:36:07 +0200
commita71120adf590f699c4b8d6249a340976575ea530 (patch)
treefa099b8552c1536e29f1a1a9ec2bb04663b8370b /src/user/lib/fs/misc.c
parent2d7da42acbf2782636e481ebd79f30700fb7dc9e (diff)
libc: fs_dirinject2 for injecting multiple paths
Diffstat (limited to 'src/user/lib/fs/misc.c')
-rw-r--r--src/user/lib/fs/misc.c78
1 files changed, 2 insertions, 76 deletions
diff --git a/src/user/lib/fs/misc.c b/src/user/lib/fs/misc.c
index c68d2be..2a39e9a 100644
--- a/src/user/lib/fs/misc.c
+++ b/src/user/lib/fs/misc.c
@@ -20,20 +20,6 @@ bool fork2_n_mount(const char *path) {
return false;
}
-static int dir_seglen(const char *path) {
- /* if path contains /, return its position + 1
- * otherwise, return strlen */
- int len = 0;
- while (path[len]) {
- if (path[len] == '/') {
- len++;
- break;
- }
- len++;
- }
- return len;
-}
-
void forward_open(hid_t reqh, const char *path, long len, int flags) {
// TODO use threads
// TODO solve for more complex cases, e.g. fs_union
@@ -41,7 +27,7 @@ void forward_open(hid_t reqh, const char *path, long len, int flags) {
* but that should only hold the caller back, and not the fs driver.
*
* for example, running `httpd` in one term would prevent you from doing
- * basically anything on the second term, because fs_dir_inject would be
+ * basically anything on the second term, because fs_dirinject would be
* stuck on open()ing the socket */
if (!_sys_fork(FORK_NOREAP, NULL)) {
_sys_fs_respond(reqh, NULL, _sys_open(path, len, flags), FSR_DELEGATE);
@@ -150,66 +136,6 @@ void fs_union(const char **list) {
exit(0);
}
-
-void fs_dir_inject(const char *path) {
- struct fs_dir_handle {
- const char *inject;
- int delegate, inject_len;
- };
- const size_t path_len = strlen(path);
- const size_t buflen = 1024;
- char *buf = malloc(buflen);
- if (!buf) exit(1);
-
- for (;;) {
- struct ufs_request res;
- hid_t reqh = _sys_fs_wait(buf, buflen, &res);
- if (reqh < 0) break;
- struct fs_dir_handle *data = res.id;
- switch (res.op) {
- struct dirbuild db;
- case VFSOP_OPEN:
- if (buf[res.len - 1] == '/' &&
- res.len < path_len && !memcmp(path, buf, res.len))
- {
- /* opening a directory that we're injecting into */
- data = malloc(sizeof *data);
- data->delegate = _sys_open(buf, res.len, res.flags);
- data->inject = path + res.len;
- data->inject_len = dir_seglen(data->inject);
- _sys_fs_respond(reqh, data, 0, 0);
- } else {
- forward_open(reqh, buf, res.len, res.flags);
- }
- break;
-
- case VFSOP_CLOSE:
- if (data->delegate >= 0)
- close(data->delegate);
- free(data);
- _sys_fs_respond(reqh, NULL, 0, 0);
- break;
-
- case VFSOP_READ:
- case VFSOP_GETSIZE:
- if (res.capacity > buflen)
- res.capacity = buflen;
- char *target = res.op == VFSOP_READ ? buf : NULL;
- dir_start(&db, res.offset, target, res.capacity);
- dir_appendl(&db, data->inject, data->inject_len);
- if (data->delegate >= 0)
- dir_append_from(&db, data->delegate);
- _sys_fs_respond(reqh, target, dir_finish(&db), 0);
- break;
-
- default:
- _sys_fs_respond(reqh, NULL, -1, 0);
- break;
- }
- }
- exit(0);
-}
-
hid_t ufs_wait(char *buf, size_t len, struct ufs_request *req) {
hid_t reqh;
for (;;) {
@@ -240,7 +166,7 @@ bool mount_at_pred(const char *path) {
if (strcmp("/", path) && !fork2_n_mount("/")) {
_klogf("%s: dir", path);
setproctitle("d'%s'", path);
- fs_dir_inject(path);
+ fs_dirinject(path);
exit(1);
}
return false; /* continue after the for loop */