filesystem: add mkdir shell command
Change-Id: I84d8acd46ba3406eb3f4a73beaa98b7c132bea7f Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
70a2e138b7
commit
7e18ab70f9
1 changed files with 30 additions and 0 deletions
|
@ -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 }
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue