From d026ce97b8faaa2f3f196281b96df0a04e30e4f9 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Thu, 21 Oct 2021 06:21:34 +0000 Subject: init/shell: fix crash when cat is ran without arguments --- src/init/shell.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/init') diff --git a/src/init/shell.c b/src/init/shell.c index 53ad995..33f6da3 100644 --- a/src/init/shell.c +++ b/src/init/shell.c @@ -44,10 +44,13 @@ static int readline(char *buf, size_t max) { } static void cmd_cat(const char *args) { - int fd = _syscall_open(args, strlen(args)); + int fd; static char buf[256]; int len = 256; + if (!args) return; // no argument + + fd = _syscall_open(args, strlen(args)); if (fd < 0) { printf("couldn't open.\n"); return; -- cgit v1.2.3 From d477902853ff07e8aa80fcc10307446680e28749 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Thu, 21 Oct 2021 06:41:24 +0000 Subject: init/shell: add a `catall` cmd - works like the old fs test --- src/init/shell.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/init') diff --git a/src/init/shell.c b/src/init/shell.c index 33f6da3..40283f8 100644 --- a/src/init/shell.c +++ b/src/init/shell.c @@ -74,6 +74,16 @@ void shell_loop(void) { printf("%s\n", args); } else if (!strcmp(cmd, "cat")) { cmd_cat(args); + } else if (!strcmp(cmd, "catall")) { + const char *files[] = { + "/init/fake.txt", + "/init/1.txt", "/init/2.txt", + "/init/dir/3.txt", NULL}; + for (int i = 0; files[i]; i++) { + printf("%s:\n", files[i]); + cmd_cat(files[i]); + printf("\n"); + } } else if (!strcmp(cmd, "exit")) { _syscall_exit(0); } else if (!strcmp(cmd, "fork")) { -- cgit v1.2.3 From 6d3960c8fdd361af32f88e4fb1e2deb892166932 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Thu, 21 Oct 2021 06:44:03 +0000 Subject: init/shell: add a `shadow` command for null mounts --- src/init/shell.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/init') diff --git a/src/init/shell.c b/src/init/shell.c index 40283f8..7cb8a8c 100644 --- a/src/init/shell.c +++ b/src/init/shell.c @@ -84,6 +84,8 @@ void shell_loop(void) { cmd_cat(files[i]); printf("\n"); } + } else if (!strcmp(cmd, "shadow")) { + _syscall_mount(-1, args, strlen(args)); } else if (!strcmp(cmd, "exit")) { _syscall_exit(0); } else if (!strcmp(cmd, "fork")) { -- cgit v1.2.3