diff options
author | dzwdz | 2022-08-08 14:33:37 +0200 |
---|---|---|
committer | dzwdz | 2022-08-08 14:33:37 +0200 |
commit | 3131d8c2f66bcecb62dfa4c69325951cd9b00706 (patch) | |
tree | 595cb0baf29c15d75ffc94d04af71d7ae94517ed /src/user/lib/fs/misc.c | |
parent | c7af8418c9a2222cde5ab3a6953b31803d0a8ef1 (diff) |
fs: getsize() on directories
Diffstat (limited to 'src/user/lib/fs/misc.c')
-rw-r--r-- | src/user/lib/fs/misc.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/user/lib/fs/misc.c b/src/user/lib/fs/misc.c index 54f54fd..16e95e7 100644 --- a/src/user/lib/fs/misc.c +++ b/src/user/lib/fs/misc.c @@ -74,9 +74,11 @@ void fs_whitelist(const char **list) { char *buf = malloc(buf_len); char *ipath; bool passthru, inject; + struct dirbuild db; if (!buf) exit(1); while (!_syscall_fs_wait(buf, buf_len, &res)) { + size_t blen; ipath = res.id; switch (res.op) { case VFSOP_OPEN: @@ -110,16 +112,17 @@ void fs_whitelist(const char **list) { break; case VFSOP_READ: - struct dirbuild db; - dir_start(&db, res.offset, buf, buf_len); - size_t blen = strlen(ipath); + case VFSOP_GETSIZE: + blen = strlen(ipath); + char *target = res.op == VFSOP_READ ? buf : NULL; + dir_start(&db, res.offset, target, buf_len); 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(buf, dir_finish(&db), 0); + _syscall_fs_respond(target, dir_finish(&db), 0); break; case VFSOP_CLOSE: @@ -175,10 +178,12 @@ void fs_union(const char **list) { break; case VFSOP_READ: + case VFSOP_GETSIZE: if (res.capacity > buflen) res.capacity = buflen; bool end = false; - dir_start(&db, res.offset, pre, res.capacity); + char *target = res.op == VFSOP_READ ? pre : NULL; + dir_start(&db, res.offset, target, res.capacity); for (size_t i = 0; !end && list[i]; i++) { const char *prefix = list[i]; size_t prefixlen = strlen(prefix); @@ -189,7 +194,7 @@ void fs_union(const char **list) { end = end || dir_append_from(&db, h); _syscall_close(h); } - _syscall_fs_respond(pre, dir_finish(&db), 0); + _syscall_fs_respond(target, dir_finish(&db), 0); break; default: @@ -242,13 +247,15 @@ void fs_dir_inject(const char *path) { break; case VFSOP_READ: + case VFSOP_GETSIZE: if (res.capacity > buf_len) res.capacity = buf_len; - dir_start(&db, res.offset, buf, res.capacity); + 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); - _syscall_fs_respond(buf, dir_finish(&db), 0); + _syscall_fs_respond(target, dir_finish(&db), 0); break; default: |