mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #18112 from fjmolinas/pr_vfs_rmount_mkdir
sys/shell/vfs: add umount, rmount and mkdir commands
This commit is contained in:
commit
c72d4ccc0e
@ -60,18 +60,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 */
|
||||
@ -170,8 +178,39 @@ static int _mount_handler(int argc, char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint8_t buf[16];
|
||||
int res = vfs_mount_by_path(argv[1]);
|
||||
puts(strerror(res));
|
||||
_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]);
|
||||
_errno_string(res, (char *)buf, sizeof(buf));
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -531,6 +570,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) {
|
||||
@ -623,6 +681,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]);
|
||||
}
|
||||
@ -632,6 +693,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;
|
||||
|
Loading…
Reference in New Issue
Block a user