diff options
Diffstat (limited to 'src/user')
-rw-r--r-- | src/user/app/init/driver/tmpfs.c | 9 | ||||
-rw-r--r-- | src/user/app/shell/builtins.c | 18 | ||||
-rw-r--r-- | src/user/bootstrap/tar.c | 5 | ||||
-rw-r--r-- | src/user/lib/syscall.c | 4 |
4 files changed, 35 insertions, 1 deletions
diff --git a/src/user/app/init/driver/tmpfs.c b/src/user/app/init/driver/tmpfs.c index 96fdf39..7414320 100644 --- a/src/user/app/init/driver/tmpfs.c +++ b/src/user/app/init/driver/tmpfs.c @@ -15,7 +15,9 @@ struct node { }; struct node *root = NULL; -static struct node special_root; +static struct node special_root = { + .size = 0, +}; static struct node *lookup(const char *path, size_t len) { for (struct node *iter = root; iter; iter = iter->next) { @@ -109,6 +111,11 @@ void tmpfs_drv(void) { _syscall_fs_respond(NULL, res.len, 0); break; + case VFSOP_GETSIZE: + ptr = (void*)res.id; + _syscall_fs_respond(NULL, ptr->size, 0); + break; + default: _syscall_fs_respond(NULL, -1, 0); break; diff --git a/src/user/app/shell/builtins.c b/src/user/app/shell/builtins.c index d409bfd..53534ed 100644 --- a/src/user/app/shell/builtins.c +++ b/src/user/app/shell/builtins.c @@ -48,6 +48,23 @@ static void cmd_echo(int argc, char **argv) { printf("\n"); } +void cmd_getsize(int argc, char **argv) { + if (argc < 2) { + eprintf("missing arguments"); + return; + } + + for (int i = 1; i < argc; i++) { + handle_t h = _syscall_open(argv[i], strlen(argv[i]), 0); + if (h < 0) { + eprintf("error opening %s", argv[i]); + continue; + } + printf("%s: %d\n", argv[i], (int)_syscall_getsize(h)); + _syscall_close(h); + } +} + void cmd_hexdump(int argc, char **argv) { const size_t buflen = 512; uint8_t *buf = malloc(buflen); @@ -141,6 +158,7 @@ static void cmd_touch(int argc, char **argv) { struct builtin builtins[] = { {"cat", cmd_cat}, {"echo", cmd_echo}, + {"getsize", cmd_getsize}, {"hexdump", cmd_hexdump}, {"ls", cmd_ls}, {"sleep", cmd_sleep}, diff --git a/src/user/bootstrap/tar.c b/src/user/bootstrap/tar.c index 150a993..0356987 100644 --- a/src/user/bootstrap/tar.c +++ b/src/user/bootstrap/tar.c @@ -33,6 +33,11 @@ void tar_driver(void *base) { tar_read(&res, base, ~0); break; + case VFSOP_GETSIZE: + // TODO works weirdly on directories / the root dir + _syscall_fs_respond(NULL, tar_size(res.id), 0); + break; + default: _syscall_fs_respond(NULL, -1, 0); // unsupported break; diff --git a/src/user/lib/syscall.c b/src/user/lib/syscall.c index ffda454..e22f718 100644 --- a/src/user/lib/syscall.c +++ b/src/user/lib/syscall.c @@ -38,6 +38,10 @@ long _syscall_write(handle_t h, const void __user *buf, size_t len, long offset, return _syscall(_SYSCALL_WRITE, (long)h, (long)buf, (long)len, offset, (long)flags); } +long _syscall_getsize(handle_t h) { + return _syscall(_SYSCALL_GETSIZE, (long)h, 0, 0, 0, 0); +} + long _syscall_close(handle_t h) { return _syscall(_SYSCALL_CLOSE, (long)h, 0, 0, 0, 0); } |