diff options
author | dzwdz | 2022-10-19 14:51:02 +0200 |
---|---|---|
committer | dzwdz | 2022-10-19 14:56:09 +0200 |
commit | d98c6dd0954bd753a9150d39364f3866579cf2f0 (patch) | |
tree | e174b25089ff4d0893e7cd583b04112212211c3e /src/user/app | |
parent | 3655115e5a3c50fc06afd801100a9d75d813fd2b (diff) |
user/logfs: a simple demo of the fs api
Diffstat (limited to 'src/user/app')
-rw-r--r-- | src/user/app/logfs/logfs.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/user/app/logfs/logfs.c b/src/user/app/logfs/logfs.c new file mode 100644 index 0000000..ba25564 --- /dev/null +++ b/src/user/app/logfs/logfs.c @@ -0,0 +1,34 @@ +#include <camellia.h> +#include <camellia/syscalls.h> +#include <err.h> +#include <stdio.h> +#include <stdlib.h> +#include <user/lib/fs/misc.h> + +_Noreturn void fs(void) { + const size_t buflen = 1024; + char *buf = malloc(buflen); + if (!buf) err(1, "malloc"); + for (;;) { + struct ufs_request req; + handle_t reqh = ufs_wait(buf, buflen, &req); + if (reqh < 0) errx(1, "ufs_wait error"); + + switch (req.op) { + case VFSOP_OPEN: + printf("[logfs] open(\"%s\", 0x%x)\n", buf, req.flags); + forward_open(reqh, buf, req.len, req.flags); + break; + default: + /* Unsupported vfs operation. + * Currently if you never create your own file descriptors you won't receive + * anything but VFSOP_OPEN, but it's idiomatic to handle this anyways. */ + _syscall_fs_respond(reqh, NULL, -1, 0); + break; + } + } +} + +int main(void) { + fs(); +} |