diff options
author | dzwdz | 2022-08-11 21:16:15 +0200 |
---|---|---|
committer | dzwdz | 2022-08-11 21:16:15 +0200 |
commit | 12aee8d9c127a85105b3e8f24cbcebc61c2db3e4 (patch) | |
tree | 627cefddb41a26f5e7c4ea7fb2537db8e9faf5f4 /src/user/app/shell | |
parent | 9438c2fdaf4e75c9218a5fde84f121a7a0abb457 (diff) |
vfs: support for removing files
Diffstat (limited to 'src/user/app/shell')
-rw-r--r-- | src/user/app/shell/builtins.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/user/app/shell/builtins.c b/src/user/app/shell/builtins.c index efc427d..6611002 100644 --- a/src/user/app/shell/builtins.c +++ b/src/user/app/shell/builtins.c @@ -1,5 +1,6 @@ #include "builtins.h" #include "shell.h" +#include <camellia/path.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -135,6 +136,40 @@ static void cmd_ls(int argc, char **argv) { } } +static void cmd_rm(int argc, char **argv) { + if (argc < 2) { + eprintf("no arguments"); + return; + } + const size_t buflen = PATH_MAX; + char *buf = malloc(buflen); + for (int i = 1; i < argc; i++) { + handle_t h; + long ret; + size_t abslen; + char *path = argv[i]; + if (*path == '\0') { + eprintf("ignoring empty argument"); + continue; + } + abslen = absolutepath(buf, path, buflen); + if (!abslen) { + eprintf("invalid path %s", path); + continue; + } + h = _syscall_open(buf, abslen - 1, 0); + if (h < 0) { + eprintf("couldn't open %s (err %u)", path, -h); + continue; + } + ret = _syscall_remove(h); + if (ret < 0) { + eprintf("couldn't remove %s (err %u)", path, -ret); + continue; + } + } +} + static void cmd_sleep(int argc, char **argv) { if (argc < 2) { eprintf("no arguments"); @@ -177,6 +212,7 @@ struct builtin builtins[] = { {"getsize", cmd_getsize}, {"hexdump", cmd_hexdump}, {"ls", cmd_ls}, + {"rm", cmd_rm}, {"sleep", cmd_sleep}, {"touch", cmd_touch}, {"whitelist", cmd_whitelist}, |