From fe5a5e928ec596b126dfbf829b3e7d57978dda26 Mon Sep 17 00:00:00 2001 From: Aurel Feer Date: Thu, 2 Jun 2022 17:01:13 +0200 Subject: [PATCH] implement fs_init on demand for shelly --- usr/shelly/shelly.c | 17 ++++++++++++----- usr/shelly/shelly.h | 2 ++ usr/shelly/shelly_cmd.c | 4 ++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/usr/shelly/shelly.c b/usr/shelly/shelly.c index b8c6dde..f65d8b7 100644 --- a/usr/shelly/shelly.c +++ b/usr/shelly/shelly.c @@ -25,6 +25,17 @@ static struct shelly_st_global * global_state; #include "shelly_cmd.c" +static void init_fs_on_demand(void) { + errval_t err; + if (global_state->did_init_filesystem == false) { + err = filesystem_init(); + if (err_is_fail(err)) DEBUG_ERR(err, "Failed to init filesystem"); + global_state->did_init_filesystem = true; + SHELLY_DEBUG("initialized filesystem\n"); + } +} + + bool is_newline(char c) { return c == ASCII_NL || c == ASCII_EOF || c == ASCII_CR; } @@ -222,6 +233,7 @@ int main(int argc, char *argv[]) global_state->buffer_i = 0; global_state->ws = get_default_waitset(); global_state->current_getchar_request = NULL; + global_state->did_init_filesystem = false; //afeer: map lpuart registers struct capref cap_arg0 = { @@ -288,11 +300,6 @@ int main(int argc, char *argv[]) SHELLY_DEBUG("registered as shelly server\n"); - // err = filesystem_init(); - // if (err_is_fail(err)) DEBUG_ERR(err, "Failed to init filesystem"); - - // SHELLY_DEBUG("initialized filesystem\n"); - err = shelly_write_str("Welcome to Shelly(TM)(TM)!\n\r"); if (err_is_fail(err)) USER_PANIC_ERR(err, "while trying to write welcome message"); diff --git a/usr/shelly/shelly.h b/usr/shelly/shelly.h index 2728d90..de25453 100644 --- a/usr/shelly/shelly.h +++ b/usr/shelly/shelly.h @@ -40,6 +40,7 @@ struct shelly_st_local { //state that is shared for all clients struct shelly_st_global { struct waitset * ws; + bool did_init_filesystem; void * lpuart_base; // < virtual address of the lpuart device registers void * gic_base; // < virtual address of the gic device registers @@ -60,5 +61,6 @@ void shelly_reset_buffer(void); errval_t shelly_buffer_append(char c); static void handle_client_request(void *arg, size_t header_size, void *header_buf, size_t payload_size); static void send_response(struct shelly_st_local * local_state, errval_t err, char c, size_t payload_size, void *payload); +static void init_fs_on_demand(void); #endif // ndef SHELLY_H_ diff --git a/usr/shelly/shelly_cmd.c b/usr/shelly/shelly_cmd.c index f25054d..4abddbb 100644 --- a/usr/shelly/shelly_cmd.c +++ b/usr/shelly/shelly_cmd.c @@ -228,12 +228,16 @@ static errval_t handle_shelly_cmd(char* line, size_t len) { } else if (strcmp(cmd, "help") == 0) { return shelly_cmd_help(remaining_line); } else if (strcmp(cmd, "ls") == 0) { + init_fs_on_demand(); return shelly_cmd_ls(remaining_line); } else if (strcmp(cmd, "cat") == 0) { + init_fs_on_demand(); return shelly_cmd_cat(remaining_line); } else if (strcmp(cmd, "mkdir") == 0) { + init_fs_on_demand(); return shelly_cmd_mkdir(remaining_line); } else if (strcmp(cmd, "rmdir") == 0) { + init_fs_on_demand(); return shelly_cmd_rmdir(remaining_line); } else { char buf[256];