shell: mufs: add proper mounting and unmounting
This commit is contained in:
parent
92fc0e0ff1
commit
7b5187973a
3 changed files with 50 additions and 19 deletions
|
@ -15,6 +15,7 @@
|
|||
#include <fs/mufs.h>
|
||||
|
||||
static void do_mufs_mount(const char *s);
|
||||
static void do_mufs_unmount(const char *s);
|
||||
static void do_mufs_format(const char *s);
|
||||
static void do_mufs_mkdir(const char *s);
|
||||
static void do_mufs_rmdir(const char *s);
|
||||
|
@ -40,7 +41,7 @@ static struct cmd mufs_cmds[] = {
|
|||
};
|
||||
|
||||
extern struct flash_dev *flash;
|
||||
struct mufs mufs;
|
||||
struct mufs *mufs;
|
||||
|
||||
static void do_mufs_mount(const char *s)
|
||||
{
|
||||
|
@ -51,13 +52,30 @@ static void do_mufs_mount(const char *s)
|
|||
return;
|
||||
}
|
||||
|
||||
if (mufs_mount(&mufs, flash) < 0) {
|
||||
do_mufs_unmount(NULL);
|
||||
|
||||
if (!(mufs = mufs_mount(flash))) {
|
||||
fprintf(stderr, "error: unable to mount the filesystem.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("log2_nentries=%u\n", mufs.log2_nentries);
|
||||
printf("nentries=%u\n", UINT32_C(1) << mufs.log2_nentries);
|
||||
flash = NULL;
|
||||
}
|
||||
|
||||
static void do_mufs_unmount(const char *s)
|
||||
{
|
||||
(void)s;
|
||||
|
||||
if (!mufs)
|
||||
return;
|
||||
|
||||
if (flash) {
|
||||
flash_release(flash);
|
||||
flash = mufs->dev;
|
||||
}
|
||||
|
||||
mufs_unmount(mufs);
|
||||
mufs = NULL;
|
||||
}
|
||||
|
||||
static void do_mufs_format(const char *s)
|
||||
|
@ -77,7 +95,7 @@ static void do_mufs_format(const char *s)
|
|||
|
||||
static void do_mufs_mkdir(const char *s)
|
||||
{
|
||||
if (mufs_mkdir(&mufs, s) < 0) {
|
||||
if (mufs_mkdir(mufs, s) < 0) {
|
||||
fprintf(stderr, "error: unable to create the directory\n");
|
||||
return;
|
||||
}
|
||||
|
@ -85,7 +103,7 @@ static void do_mufs_mkdir(const char *s)
|
|||
|
||||
static void do_mufs_rmdir(const char *s)
|
||||
{
|
||||
if (mufs_rmdir(&mufs, s) < 0) {
|
||||
if (mufs_rmdir(mufs, s) < 0) {
|
||||
fprintf(stderr, "error: unable to remove the directory\n");
|
||||
return;
|
||||
}
|
||||
|
@ -95,7 +113,7 @@ static void do_mufs_stat(const char *s)
|
|||
{
|
||||
struct mufs_stat stat;
|
||||
|
||||
if (mufs_stat(&mufs, s, &stat) < 0) {
|
||||
if (mufs_stat(mufs, s, &stat) < 0) {
|
||||
fprintf(stderr, "error: unable to stat the file\n");
|
||||
return;
|
||||
}
|
||||
|
@ -114,7 +132,7 @@ static void do_mufs_cat(const char *s)
|
|||
char data[256];
|
||||
struct mufs_file *file;
|
||||
|
||||
if (!(file = mufs_open(&mufs, s, MUFS_READ))) {
|
||||
if (!(file = mufs_open(mufs, s, MUFS_READ))) {
|
||||
fprintf(stderr, "error: unable to open the file\n");
|
||||
return;
|
||||
}
|
||||
|
@ -143,7 +161,7 @@ static void do_mufs_append(const char *s)
|
|||
|
||||
*line++ = '\0';
|
||||
|
||||
if (!(file = mufs_open(&mufs, path, MUFS_WRITE | MUFS_APPEND))) {
|
||||
if (!(file = mufs_open(mufs, path, MUFS_WRITE | MUFS_APPEND))) {
|
||||
fprintf(stderr, "error: unable to open the file\n");
|
||||
goto err_free_path;
|
||||
}
|
||||
|
@ -170,7 +188,7 @@ static void do_mufs_mv(const char *s)
|
|||
|
||||
*new++ = '\0';
|
||||
|
||||
if (mufs_rename(&mufs, old, new) < 0) {
|
||||
if (mufs_rename(mufs, old, new) < 0) {
|
||||
fprintf(stderr, "error: unable to move the file\n");
|
||||
goto err_free_old;
|
||||
}
|
||||
|
@ -181,7 +199,7 @@ err_free_old:
|
|||
|
||||
static void do_mufs_rm(const char *s)
|
||||
{
|
||||
if (mufs_unlink(&mufs, s) < 0) {
|
||||
if (mufs_unlink(mufs, s) < 0) {
|
||||
fprintf(stderr, "error: unable to remove the file\n");
|
||||
return;
|
||||
}
|
||||
|
@ -192,7 +210,7 @@ static void do_mufs_ls(const char *s)
|
|||
struct mufs_dirent ent;
|
||||
struct mufs_dir *dir;
|
||||
|
||||
if (!(dir = mufs_opendir(&mufs, s))) {
|
||||
if (!(dir = mufs_opendir(mufs, s))) {
|
||||
fprintf(stderr, "error: unable to open the directory\n");
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue