|
|
|
@ -20,14 +20,14 @@ |
|
|
|
|
extern struct flash_dev *flash; |
|
|
|
|
struct mufs *mufs = NULL; |
|
|
|
|
|
|
|
|
|
void shell_mount(struct console *con, size_t argc, const char **argv) |
|
|
|
|
int shell_mount(struct console *con, size_t argc, const char **argv) |
|
|
|
|
{ |
|
|
|
|
(void)argc; |
|
|
|
|
(void)argv; |
|
|
|
|
|
|
|
|
|
if (!flash) { |
|
|
|
|
fprintf(con->fp, "error: no flash device probed.\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mufs) { |
|
|
|
@ -37,20 +37,22 @@ void shell_mount(struct console *con, size_t argc, const char **argv) |
|
|
|
|
|
|
|
|
|
if (!(mufs = mufs_mount(flash))) { |
|
|
|
|
fprintf(con->fp, "error: unable to mount the filesystem.\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
flash = NULL; |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void shell_unmount(struct console *con, size_t argc, const char **argv) |
|
|
|
|
int shell_unmount(struct console *con, size_t argc, const char **argv) |
|
|
|
|
{ |
|
|
|
|
(void)argc; |
|
|
|
|
(void)argv; |
|
|
|
|
|
|
|
|
|
if (!mufs) { |
|
|
|
|
fprintf(con->fp, "no mufs filesystem currently active\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (flash) |
|
|
|
@ -61,106 +63,116 @@ void shell_unmount(struct console *con, size_t argc, const char **argv) |
|
|
|
|
|
|
|
|
|
mufs_unmount(mufs); |
|
|
|
|
mufs = NULL; |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void shell_format(struct console *con, size_t argc, const char **argv) |
|
|
|
|
int shell_format(struct console *con, size_t argc, const char **argv) |
|
|
|
|
{ |
|
|
|
|
(void)argc; |
|
|
|
|
(void)argv; |
|
|
|
|
|
|
|
|
|
if (!flash) { |
|
|
|
|
fprintf(con->fp, "error: no flash device probed.\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mufs_format(flash) < 0) { |
|
|
|
|
fprintf(con->fp, "error: unable to format the flash device.\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void shell_mkdir(struct console *con, size_t argc, const char **argv) |
|
|
|
|
int shell_mkdir(struct console *con, size_t argc, const char **argv) |
|
|
|
|
{ |
|
|
|
|
if (argc < 1) { |
|
|
|
|
fprintf(con->fp, "usage: mufs mkdir <path>\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!mufs) { |
|
|
|
|
fprintf(con->fp, "error: no file system mounted.\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mufs_mkdir(mufs, argv[0]) < 0) { |
|
|
|
|
fprintf(con->fp, "error: unable to create the directory\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void shell_rmdir(struct console *con, size_t argc, const char **argv) |
|
|
|
|
int shell_rmdir(struct console *con, size_t argc, const char **argv) |
|
|
|
|
{ |
|
|
|
|
if (argc < 1) { |
|
|
|
|
fprintf(con->fp, "usage: mufs rmdir <path>\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!mufs) { |
|
|
|
|
fprintf(con->fp, "error: no file system mounted.\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mufs_rmdir(mufs, argv[0]) < 0) { |
|
|
|
|
fprintf(con->fp, "error: unable to remove the directory\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void shell_stat(struct console *con, size_t argc, const char **argv) |
|
|
|
|
int shell_stat(struct console *con, size_t argc, const char **argv) |
|
|
|
|
{ |
|
|
|
|
struct mufs_stat stat; |
|
|
|
|
|
|
|
|
|
if (argc < 1) { |
|
|
|
|
fprintf(con->fp, "usage: mufs stat <path>\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!mufs) { |
|
|
|
|
fprintf(con->fp, "error: no file system mounted.\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mufs_stat(mufs, argv[0], &stat) < 0) { |
|
|
|
|
fprintf(con->fp, "error: unable to stat the file\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
switch (stat.type) { |
|
|
|
|
case MUFS_DIR: printf(" type: directory\n"); break; |
|
|
|
|
case MUFS_FILE: printf(" type: file\n"); break; |
|
|
|
|
default: return; |
|
|
|
|
default: return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printf(" file size: %" PRIu32 " bytes\n", stat.file_size); |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void shell_cat(struct console *con, size_t argc, const char **argv) |
|
|
|
|
int shell_cat(struct console *con, size_t argc, const char **argv) |
|
|
|
|
{ |
|
|
|
|
char data[256]; |
|
|
|
|
struct mufs_file *file; |
|
|
|
|
|
|
|
|
|
if (argc < 1) { |
|
|
|
|
fprintf(con->fp, "usage: mufs cat <path>\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!mufs) { |
|
|
|
|
fprintf(con->fp, "error: no file system mounted.\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!(file = mufs_open(mufs, argv[0], MUFS_READ))) { |
|
|
|
|
fprintf(con->fp, "error: unable to open the file\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
while (mufs_read(file, data, sizeof data) != 0) { |
|
|
|
@ -168,9 +180,11 @@ void shell_cat(struct console *con, size_t argc, const char **argv) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
mufs_close(file); |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void shell_write(struct console *con, size_t argc, const char **argv) |
|
|
|
|
int shell_write(struct console *con, size_t argc, const char **argv) |
|
|
|
|
{ |
|
|
|
|
char data[256]; |
|
|
|
|
struct mufs_file *file; |
|
|
|
@ -178,17 +192,17 @@ void shell_write(struct console *con, size_t argc, const char **argv) |
|
|
|
|
|
|
|
|
|
if (argc < 1) { |
|
|
|
|
fprintf(con->fp, "usage: mufs write <path>\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!mufs) { |
|
|
|
|
fprintf(con->fp, "error: no file system mounted.\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!(file = mufs_open(mufs, argv[0], MUFS_WRITE))) { |
|
|
|
|
fprintf(con->fp, "error: unable to open the file\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fprintf(con->fp, "> "); |
|
|
|
@ -199,9 +213,11 @@ void shell_write(struct console *con, size_t argc, const char **argv) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
mufs_close(file); |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void shell_append(struct console *con, size_t argc, const char **argv) |
|
|
|
|
int shell_append(struct console *con, size_t argc, const char **argv) |
|
|
|
|
{ |
|
|
|
|
struct mufs_file *file; |
|
|
|
|
char data[256]; |
|
|
|
@ -209,17 +225,17 @@ void shell_append(struct console *con, size_t argc, const char **argv) |
|
|
|
|
|
|
|
|
|
if (argc < 2) { |
|
|
|
|
fprintf(con->fp, "usage: mufs append <path> <line>\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!mufs) { |
|
|
|
|
fprintf(con->fp, "error: no file system mounted.\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!(file = mufs_open(mufs, argv[0], MUFS_WRITE | MUFS_APPEND))) { |
|
|
|
|
fprintf(con->fp, "error: unable to open the file\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
n = strlen(argv[1]); |
|
|
|
@ -230,45 +246,51 @@ void shell_append(struct console *con, size_t argc, const char **argv) |
|
|
|
|
|
|
|
|
|
mufs_write(file, data, n + 1); |
|
|
|
|
mufs_close(file); |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void shell_mv(struct console *con, size_t argc, const char **argv) |
|
|
|
|
int shell_mv(struct console *con, size_t argc, const char **argv) |
|
|
|
|
{ |
|
|
|
|
if (argc < 2) { |
|
|
|
|
fprintf(con->fp, "usage: mufs mv <old> <new>\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!mufs) { |
|
|
|
|
fprintf(con->fp, "error: no file system mounted.\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mufs_rename(mufs, argv[0], argv[1]) < 0) { |
|
|
|
|
fprintf(con->fp, "error: unable to move the file\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void shell_rm(struct console *con, size_t argc, const char **argv) |
|
|
|
|
int shell_rm(struct console *con, size_t argc, const char **argv) |
|
|
|
|
{ |
|
|
|
|
if (argc < 1) { |
|
|
|
|
fprintf(con->fp, "usage: mufs rm <path>\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!mufs) { |
|
|
|
|
fprintf(con->fp, "error: no file system mounted.\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mufs_unlink(mufs, argv[0]) < 0) { |
|
|
|
|
fprintf(con->fp, "error: unable to remove the file\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void shell_ls(struct console *con, size_t argc, const char **argv) |
|
|
|
|
int shell_ls(struct console *con, size_t argc, const char **argv) |
|
|
|
|
{ |
|
|
|
|
struct mufs_dirent ent; |
|
|
|
|
struct mufs_dir *dir; |
|
|
|
@ -280,12 +302,12 @@ void shell_ls(struct console *con, size_t argc, const char **argv) |
|
|
|
|
|
|
|
|
|
if (!mufs) { |
|
|
|
|
fprintf(con->fp, "error: no file system mounted.\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!(dir = mufs_opendir(mufs, path))) { |
|
|
|
|
fprintf(con->fp, "error: unable to open the directory\n"); |
|
|
|
|
return; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
while (mufs_readdir(dir, &ent) == 0) { |
|
|
|
@ -293,6 +315,7 @@ void shell_ls(struct console *con, size_t argc, const char **argv) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
mufs_closedir(dir); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static struct cmd mufs_cmds[] = { |
|
|
|
@ -311,7 +334,7 @@ static struct cmd mufs_cmds[] = { |
|
|
|
|
{ NULL, NULL, NULL }, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
void do_mufs_cmd(struct console *con, size_t argc, const char **argv) |
|
|
|
|
int do_mufs_cmd(struct console *con, size_t argc, const char **argv) |
|
|
|
|
{ |
|
|
|
|
cmd_exec(mufs_cmds, con, argc, argv); |
|
|
|
|
return cmd_exec(mufs_cmds, con, argc, argv); |
|
|
|
|
} |
|
|
|
|