implement fs_init on demand for shelly

This commit is contained in:
Aurel Feer 2022-06-02 17:01:13 +02:00
parent 99a46acb05
commit fe5a5e928e
3 changed files with 18 additions and 5 deletions

View File

@ -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");

View File

@ -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_

View File

@ -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];