|
|
|
@ -7,6 +7,7 @@ |
|
|
|
|
|
|
|
|
|
#include <errno.h> |
|
|
|
|
|
|
|
|
|
#include <console.h> |
|
|
|
|
#include <flash.h> |
|
|
|
|
#include <ftl.h> |
|
|
|
|
#include <macros.h> |
|
|
|
@ -17,15 +18,13 @@ |
|
|
|
|
extern struct flash_dev *flash; |
|
|
|
|
struct mufs *mufs = NULL; |
|
|
|
|
|
|
|
|
|
extern struct usart_console *admin_con; |
|
|
|
|
|
|
|
|
|
static void do_mufs_mount(FILE *out, const char **argv, size_t argc) |
|
|
|
|
static void do_mufs_mount(struct console *con, const char **argv, size_t argc) |
|
|
|
|
{ |
|
|
|
|
(void)argc; |
|
|
|
|
(void)argv; |
|
|
|
|
|
|
|
|
|
if (!flash) { |
|
|
|
|
fprintf(out, "error: no flash device probed.\n"); |
|
|
|
|
fprintf(con->fp, "error: no flash device probed.\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -35,20 +34,20 @@ static void do_mufs_mount(FILE *out, const char **argv, size_t argc) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!(mufs = mufs_mount(flash))) { |
|
|
|
|
fprintf(out, "error: unable to mount the filesystem.\n"); |
|
|
|
|
fprintf(con->fp, "error: unable to mount the filesystem.\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
flash = NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void do_mufs_unmount(FILE *out, const char **argv, size_t argc) |
|
|
|
|
static void do_mufs_unmount(struct console *con, const char **argv, size_t argc) |
|
|
|
|
{ |
|
|
|
|
(void)argc; |
|
|
|
|
(void)argv; |
|
|
|
|
|
|
|
|
|
if (!mufs) { |
|
|
|
|
fprintf(out, "no mufs filesystem currently active\n"); |
|
|
|
|
fprintf(con->fp, "no mufs filesystem currently active\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -62,74 +61,74 @@ static void do_mufs_unmount(FILE *out, const char **argv, size_t argc) |
|
|
|
|
mufs = NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void do_mufs_format(FILE *out, const char **argv, size_t argc) |
|
|
|
|
static void do_mufs_format(struct console *con, const char **argv, size_t argc) |
|
|
|
|
{ |
|
|
|
|
(void)argc; |
|
|
|
|
(void)argv; |
|
|
|
|
|
|
|
|
|
if (!flash) { |
|
|
|
|
fprintf(out, "error: no flash device probed.\n"); |
|
|
|
|
fprintf(con->fp, "error: no flash device probed.\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mufs_format(flash) < 0) { |
|
|
|
|
fprintf(out, "error: unable to format the flash device.\n"); |
|
|
|
|
fprintf(con->fp, "error: unable to format the flash device.\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void do_mufs_mkdir(FILE *out, const char **argv, size_t argc) |
|
|
|
|
static void do_mufs_mkdir(struct console *con, const char **argv, size_t argc) |
|
|
|
|
{ |
|
|
|
|
if (argc < 1) { |
|
|
|
|
fprintf(out, "usage: mufs mkdir <path>\n"); |
|
|
|
|
fprintf(con->fp, "usage: mufs mkdir <path>\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!mufs) { |
|
|
|
|
fprintf(out, "error: no file system mounted.\n"); |
|
|
|
|
fprintf(con->fp, "error: no file system mounted.\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mufs_mkdir(mufs, argv[0]) < 0) { |
|
|
|
|
fprintf(out, "error: unable to create the directory\n"); |
|
|
|
|
fprintf(con->fp, "error: unable to create the directory\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void do_mufs_rmdir(FILE *out, const char **argv, size_t argc) |
|
|
|
|
static void do_mufs_rmdir(struct console *con, const char **argv, size_t argc) |
|
|
|
|
{ |
|
|
|
|
if (argc < 1) { |
|
|
|
|
fprintf(out, "usage: mufs rmdir <path>\n"); |
|
|
|
|
fprintf(con->fp, "usage: mufs rmdir <path>\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!mufs) { |
|
|
|
|
fprintf(out, "error: no file system mounted.\n"); |
|
|
|
|
fprintf(con->fp, "error: no file system mounted.\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mufs_rmdir(mufs, argv[0]) < 0) { |
|
|
|
|
fprintf(out, "error: unable to remove the directory\n"); |
|
|
|
|
fprintf(con->fp, "error: unable to remove the directory\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void do_mufs_stat(FILE *out, const char **argv, size_t argc) |
|
|
|
|
static void do_mufs_stat(struct console *con, const char **argv, size_t argc) |
|
|
|
|
{ |
|
|
|
|
struct mufs_stat stat; |
|
|
|
|
|
|
|
|
|
if (argc < 1) { |
|
|
|
|
fprintf(out, "usage: mufs stat <path>\n"); |
|
|
|
|
fprintf(con->fp, "usage: mufs stat <path>\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!mufs) { |
|
|
|
|
fprintf(out, "error: no file system mounted.\n"); |
|
|
|
|
fprintf(con->fp, "error: no file system mounted.\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mufs_stat(mufs, argv[0], &stat) < 0) { |
|
|
|
|
fprintf(out, "error: unable to stat the file\n"); |
|
|
|
|
fprintf(con->fp, "error: unable to stat the file\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -142,82 +141,82 @@ static void do_mufs_stat(FILE *out, const char **argv, size_t argc) |
|
|
|
|
printf(" file size: %" PRIu32 " bytes\n", stat.file_size); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void do_mufs_cat(FILE *out, const char **argv, size_t argc) |
|
|
|
|
static void do_mufs_cat(struct console *con, const char **argv, size_t argc) |
|
|
|
|
{ |
|
|
|
|
char data[256]; |
|
|
|
|
struct mufs_file *file; |
|
|
|
|
|
|
|
|
|
if (argc < 1) { |
|
|
|
|
fprintf(out, "usage: mufs cat <path>\n"); |
|
|
|
|
fprintf(con->fp, "usage: mufs cat <path>\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!mufs) { |
|
|
|
|
fprintf(out, "error: no file system mounted.\n"); |
|
|
|
|
fprintf(con->fp, "error: no file system mounted.\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!(file = mufs_open(mufs, argv[0], MUFS_READ))) { |
|
|
|
|
fprintf(out, "error: unable to open the file\n"); |
|
|
|
|
fprintf(con->fp, "error: unable to open the file\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
while (mufs_read(file, data, sizeof data) != 0) { |
|
|
|
|
fwrite(data, sizeof *data, sizeof data, out); |
|
|
|
|
fwrite(data, sizeof *data, sizeof data, con->fp); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
mufs_close(file); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void do_mufs_write(FILE *out, const char **argv, size_t argc) |
|
|
|
|
static void do_mufs_write(struct console *con, const char **argv, size_t argc) |
|
|
|
|
{ |
|
|
|
|
char data[256]; |
|
|
|
|
struct mufs_file *file; |
|
|
|
|
ssize_t ret; |
|
|
|
|
|
|
|
|
|
if (argc < 1) { |
|
|
|
|
fprintf(out, "usage: mufs write <path>\n"); |
|
|
|
|
fprintf(con->fp, "usage: mufs write <path>\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!mufs) { |
|
|
|
|
fprintf(out, "error: no file system mounted.\n"); |
|
|
|
|
fprintf(con->fp, "error: no file system mounted.\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!(file = mufs_open(mufs, argv[0], MUFS_WRITE))) { |
|
|
|
|
fprintf(out, "error: unable to open the file\n"); |
|
|
|
|
fprintf(con->fp, "error: unable to open the file\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fprintf(out, "> "); |
|
|
|
|
fprintf(con->fp, "> "); |
|
|
|
|
|
|
|
|
|
while ((ret = console_read(admin_con, data, sizeof data)) > 0) { |
|
|
|
|
while ((ret = console_read(con, data, sizeof data)) > 0) { |
|
|
|
|
mufs_write(file, data, ret); |
|
|
|
|
fprintf(out, "> "); |
|
|
|
|
fprintf(con->fp, "> "); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
mufs_close(file); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void do_mufs_append(FILE *out, const char **argv, size_t argc) |
|
|
|
|
static void do_mufs_append(struct console *con, const char **argv, size_t argc) |
|
|
|
|
{ |
|
|
|
|
struct mufs_file *file; |
|
|
|
|
char data[256]; |
|
|
|
|
size_t n; |
|
|
|
|
|
|
|
|
|
if (argc < 2) { |
|
|
|
|
fprintf(out, "usage: mufs append <path> <line>\n"); |
|
|
|
|
fprintf(con->fp, "usage: mufs append <path> <line>\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!mufs) { |
|
|
|
|
fprintf(out, "error: no file system mounted.\n"); |
|
|
|
|
fprintf(con->fp, "error: no file system mounted.\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!(file = mufs_open(mufs, argv[0], MUFS_WRITE | MUFS_APPEND))) { |
|
|
|
|
fprintf(out, "error: unable to open the file\n"); |
|
|
|
|
fprintf(con->fp, "error: unable to open the file\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -231,43 +230,43 @@ static void do_mufs_append(FILE *out, const char **argv, size_t argc) |
|
|
|
|
mufs_close(file); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void do_mufs_mv(FILE *out, const char **argv, size_t argc) |
|
|
|
|
static void do_mufs_mv(struct console *con, const char **argv, size_t argc) |
|
|
|
|
{ |
|
|
|
|
if (argc < 2) { |
|
|
|
|
fprintf(out, "usage: mufs mv <old> <new>\n"); |
|
|
|
|
fprintf(con->fp, "usage: mufs mv <old> <new>\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!mufs) { |
|
|
|
|
fprintf(out, "error: no file system mounted.\n"); |
|
|
|
|
fprintf(con->fp, "error: no file system mounted.\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mufs_rename(mufs, argv[0], argv[1]) < 0) { |
|
|
|
|
fprintf(out, "error: unable to move the file\n"); |
|
|
|
|
fprintf(con->fp, "error: unable to move the file\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void do_mufs_rm(FILE *out, const char **argv, size_t argc) |
|
|
|
|
static void do_mufs_rm(struct console *con, const char **argv, size_t argc) |
|
|
|
|
{ |
|
|
|
|
if (argc < 1) { |
|
|
|
|
fprintf(out, "usage: mufs rm <path>\n"); |
|
|
|
|
fprintf(con->fp, "usage: mufs rm <path>\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!mufs) { |
|
|
|
|
fprintf(out, "error: no file system mounted.\n"); |
|
|
|
|
fprintf(con->fp, "error: no file system mounted.\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mufs_unlink(mufs, argv[0]) < 0) { |
|
|
|
|
fprintf(out, "error: unable to remove the file\n"); |
|
|
|
|
fprintf(con->fp, "error: unable to remove the file\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void do_mufs_ls(FILE *out, const char **argv, size_t argc) |
|
|
|
|
static void do_mufs_ls(struct console *con, const char **argv, size_t argc) |
|
|
|
|
{ |
|
|
|
|
struct mufs_dirent ent; |
|
|
|
|
struct mufs_dir *dir; |
|
|
|
@ -278,17 +277,17 @@ static void do_mufs_ls(FILE *out, const char **argv, size_t argc) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!mufs) { |
|
|
|
|
fprintf(out, "error: no file system mounted.\n"); |
|
|
|
|
fprintf(con->fp, "error: no file system mounted.\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!(dir = mufs_opendir(mufs, path))) { |
|
|
|
|
fprintf(out, "error: unable to open the directory\n"); |
|
|
|
|
fprintf(con->fp, "error: unable to open the directory\n"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
while (mufs_readdir(dir, &ent) == 0) { |
|
|
|
|
fprintf(out, "%s\n", ent.path); |
|
|
|
|
fprintf(con->fp, "%s\n", ent.path); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
mufs_closedir(dir); |
|
|
|
@ -310,7 +309,7 @@ static struct cmd mufs_cmds[] = { |
|
|
|
|
{ NULL, NULL, NULL }, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
void do_mufs_cmd(FILE *out, const char **argv, size_t argc) |
|
|
|
|
void do_mufs_cmd(struct console *con, const char **argv, size_t argc) |
|
|
|
|
{ |
|
|
|
|
cmd_exec(mufs_cmds, out, argv, argc); |
|
|
|
|
cmd_exec(mufs_cmds, con, argv, argc); |
|
|
|
|
} |
|
|
|
|