Skip to content

Commit

Permalink
sys/shell/vfs: add umount, rmount and mkdir commands
Browse files Browse the repository at this point in the history
  • Loading branch information
fjmolinas committed May 23, 2022
1 parent 99bb1f6 commit 81f1720
Showing 1 changed file with 70 additions and 3 deletions.
73 changes: 70 additions & 3 deletions sys/shell/commands/sc_vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,26 @@ static void _vfs_usage(char **argv)
printf("%s ls <path>\n", argv[0]);
printf("%s cp <src> <dest>\n", argv[0]);
printf("%s mv <src> <dest>\n", argv[0]);
printf("%s mkdir <path> \n", argv[0]);
printf("%s rm <file>\n", argv[0]);
printf("%s df [path]\n", argv[0]);
if (MOUNTPOINTS_NUMOF > 0) {
printf("%s mount [path]\n", argv[0]);
}
if (MOUNTPOINTS_NUMOF > 0) {
printf("%s umount [path]\n", argv[0]);
}
if (MOUNTPOINTS_NUMOF > 0) {
printf("%s remount [path]\n", argv[0]);
}
puts("r: Read [bytes] bytes at [offset] in file <path>");
puts("w: Write (<a>: append, <o> overwrite) <ascii> or <hex> string <data> in file <path>");
puts("ls: list files in <path>");
puts("ls: List files in <path>");
puts("mv: Move <src> file to <dest>");
puts("mkdir: Create directory <path> ");
puts("cp: Copy <src> file to <dest>");
puts("rm: Unlink (delete) <file>");
puts("df: show file system space utilization stats");
puts("df: Show file system space utilization stats");
}

/* Macro used by _errno_string to expand errno labels to string and print it */
Expand Down Expand Up @@ -167,8 +175,39 @@ static int _mount_handler(int argc, char **argv)
return -1;
}

uint8_t buf[16];
int res = vfs_mount_by_path(argv[1]);
_errno_string(res, (char *)buf, sizeof(buf));
return res;
}

static int _umount_handler(int argc, char **argv)
{
if (argc < 2) {
printf("usage: %s [path]\n", argv[0]);
puts("umount pre-configured mount point");
return -1;
}

uint8_t buf[16];
int res = vfs_unmount_by_path(argv[1]);

_errno_string(res, (char *)buf, sizeof(buf));
return res;
}

static int _remount_handler(int argc, char **argv)
{
if (argc < 2) {
printf("usage: %s [path]\n", argv[0]);
puts("remount pre-configured mount point");
return -1;
}

uint8_t buf[16];
vfs_unmount_by_path(argv[1]);
int res = vfs_mount_by_path(argv[1]);
puts(strerror(res));
_errno_string(res, (char *)buf, sizeof(buf));
return res;
}

Expand Down Expand Up @@ -528,6 +567,25 @@ static int _rm_handler(int argc, char **argv)
return 0;
}

static int _mkdir_handler(int argc, char **argv)
{
if (argc < 2) {
_vfs_usage(argv);
return 1;
}
char *dir_name = argv[1];
printf("%s: mkdir: %s\n", argv[0], dir_name);

int res = vfs_mkdir(dir_name, 0);
if (res < 0) {
char errbuf[16];
_errno_string(res, (char *)errbuf, sizeof(errbuf));
printf("mkdir ERR: %s\n", errbuf);
return 2;
}
return 0;
}

int _ls_handler(int argc, char **argv)
{
if (argc < 2) {
Expand Down Expand Up @@ -620,6 +678,9 @@ int _vfs_handler(int argc, char **argv)
else if (strcmp(argv[1], "mv") == 0) {
return _mv_handler(argc - 1, &argv[1]);
}
else if (strcmp(argv[1], "mkdir") == 0) {
return _mkdir_handler(argc - 1, &argv[1]);
}
else if (strcmp(argv[1], "rm") == 0) {
return _rm_handler(argc - 1, &argv[1]);
}
Expand All @@ -629,6 +690,12 @@ int _vfs_handler(int argc, char **argv)
else if (MOUNTPOINTS_NUMOF > 0 && strcmp(argv[1], "mount") == 0) {
return _mount_handler(argc - 1, &argv[1]);
}
else if (MOUNTPOINTS_NUMOF > 0 && strcmp(argv[1], "umount") == 0) {
return _umount_handler(argc - 1, &argv[1]);
}
else if (MOUNTPOINTS_NUMOF > 0 && strcmp(argv[1], "remount") == 0) {
return _remount_handler(argc - 1, &argv[1]);
}
else {
printf("vfs: unsupported sub-command \"%s\"\n", argv[1]);
return 1;
Expand Down

0 comments on commit 81f1720

Please sign in to comment.