From 7e18ab70f9f4ad44d3c303ea4ebbaf6b28cb048c Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Sun, 8 Jan 2017 13:53:39 -0500 Subject: [PATCH] filesystem: add mkdir shell command Change-Id: I84d8acd46ba3406eb3f4a73beaa98b7c132bea7f Signed-off-by: Anas Nashif --- subsys/fs/shell.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/subsys/fs/shell.c b/subsys/fs/shell.c index 8c80dd690dc..cac76c276bb 100644 --- a/subsys/fs/shell.c +++ b/subsys/fs/shell.c @@ -27,6 +27,35 @@ static char cwd[MAX_PATH_LEN] = "/"; +static int cmd_mkdir(int argc, char *argv[]) +{ + int res; + char path[MAX_PATH_LEN]; + + if (argc < 2) { + printk("Missing argument\n"); + return 0; + } + + if (argv[1][0] == '/') { + strncpy(path, argv[1], sizeof(path) - 1); + path[MAX_PATH_LEN - 1] = '\0'; + } else { + if (strcmp(cwd, "/") == 0) { + snprintf(path, sizeof(path), "/%s", argv[1]); + } else { + snprintf(path, sizeof(path), "%s/%s", cwd, argv[1]); + } + } + res = fs_mkdir(path); + if (res) { + printk("Error creating dir[%d]\n", res); + return res; + } + + return 0; +} + static int cmd_ls(int argc, char *argv[]) { char path[MAX_PATH_LEN]; @@ -139,6 +168,7 @@ struct shell_cmd fs_commands[] = { { "ls", cmd_ls, "List files in current directory" }, { "cd", cmd_cd, "Change working directory" }, { "pwd", cmd_pwd, "Print current working directory" }, + { "mkdir", cmd_mkdir, "Create directory" }, { NULL, NULL } };