summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/ChangeLog.txt2
-rw-r--r--apps/nshlib/README.txt9
-rw-r--r--apps/nshlib/nsh_fscmds.c85
-rw-r--r--apps/nshlib/nsh_parse.c2
4 files changed, 88 insertions, 10 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt
index e22bab97b..a43c469d2 100644
--- a/apps/ChangeLog.txt
+++ b/apps/ChangeLog.txt
@@ -740,4 +740,6 @@
* examples/hidkbd/hidkbd_main.c: Now calls a function named
arch_usbhost_initialize() that must be provided by the platform-
specific code (2013-11-29).
+ * apps/nshlib/nsh_fscmds.c: Add an option to the mkfatfs command to
+ specify FAT12, FAT16, or FAT32 (2013-12-5).
diff --git a/apps/nshlib/README.txt b/apps/nshlib/README.txt
index 7a12ad4b4..8b2d4bcdd 100644
--- a/apps/nshlib/README.txt
+++ b/apps/nshlib/README.txt
@@ -554,9 +554,14 @@ o mkdir <path>
drw-rw-rw- 0 TMP/
nsh>
-o mkfatfs <path>
+o mkfatfs [-F <fatsize>] <block-driver>
+
+ Format a fat file system on the block device specified by <block-driver>
+ path. The FAT size may be provided as an option. Without the <fatsize>
+ option, mkfatfs will select either the FAT12 or FAT16 format. For
+ historical reasons, if you want the FAT32 format, it must be explicitly
+ specified on the command line.
- Format a fat file system on the block device specified by path.
NSH provides this command to access the mkfatfs() NuttX API.
This block device must reside in the NuttX pseudo filesystem and
must have been created by some call to register_blockdriver() (see
diff --git a/apps/nshlib/nsh_fscmds.c b/apps/nshlib/nsh_fscmds.c
index 3337dd592..ea30bd3b5 100644
--- a/apps/nshlib/nsh_fscmds.c
+++ b/apps/nshlib/nsh_fscmds.c
@@ -872,6 +872,7 @@ errout_with_paths:
{
free(filepath);
}
+
return ret;
}
#endif
@@ -1008,6 +1009,7 @@ int cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mkdir", NSH_ERRNO);
}
+
nsh_freefullpath(fullpath);
}
return ret;
@@ -1024,18 +1026,80 @@ int cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
struct fat_format_s fmt = FAT_FORMAT_INITIALIZER;
- char *fullpath = nsh_getfullpath(vtbl, argv[1]);
+ FAR char *fullpath;
+ bool badarg;
+ int option;
int ret = ERROR;
- if (fullpath)
+ /* mkfatfs [-F <fatsize>] <block-driver> */
+
+ badarg = false;
+ while ((option = getopt(argc, argv, ":F:")) != ERROR)
{
- ret = mkfatfs(fullpath, &fmt);
- if (ret < 0)
+ switch (option)
{
- nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mkfatfs", NSH_ERRNO);
+ case 'F':
+ fmt.ff_fattype = atoi(optarg);
+ if (fmt.ff_fattype != 0 && fmt.ff_fattype != 12 &&
+ fmt.ff_fattype != 16 && fmt.ff_fattype != 32)
+ {
+ nsh_output(vtbl, g_fmtargrange, argv[0]);
+ badarg = true;
+ }
+ break;
+
+ case ':':
+ nsh_output(vtbl, g_fmtargrequired, argv[0]);
+ badarg = true;
+ break;
+
+ case '?':
+ default:
+ nsh_output(vtbl, g_fmtarginvalid, argv[0]);
+ badarg = true;
+ break;
}
- nsh_freefullpath(fullpath);
}
+
+ /* If a bad argument was encountered, then return without processing the command */
+
+ if (badarg)
+ {
+ return ERROR;
+ }
+
+ /* There should be exactly one parameter left on the command-line */
+
+ if (optind == argc-1)
+ {
+ fullpath = nsh_getfullpath(vtbl, argv[optind]);
+ if (!fullpath)
+ {
+ nsh_output(vtbl, g_fmtcmdfailed, argv[0], "nsh_getfullpath",
+ NSH_ERRNO);
+ return ERROR;
+ }
+ }
+ else if (optind >= argc)
+ {
+ nsh_output(vtbl, g_fmttoomanyargs, argv[0]);
+ return ERROR;
+ }
+ else
+ {
+ nsh_output(vtbl, g_fmtargrequired, argv[0]);
+ return ERROR;
+ }
+
+ /* Now format the FAT file system */
+
+ ret = mkfatfs(fullpath, &fmt);
+ if (ret < 0)
+ {
+ nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mkfatfs", NSH_ERRNO);
+ }
+
+ nsh_freefullpath(fullpath);
return ret;
}
#endif
@@ -1059,8 +1123,10 @@ int cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mkfifo", NSH_ERRNO);
}
+
nsh_freefullpath(fullpath);
}
+
return ret;
}
#endif
@@ -1127,7 +1193,7 @@ int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
return ERROR;
}
- /* There should be exactly on parameter left on the command-line */
+ /* There should be exactly one parameter left on the command-line */
if (optind == argc-1)
{
@@ -1167,6 +1233,7 @@ int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
free(buffer);
return ERROR;
}
+
return ret;
errout_with_fmt:
@@ -1289,8 +1356,10 @@ int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "unlink", NSH_ERRNO);
}
+
nsh_freefullpath(fullpath);
}
+
return ret;
}
#endif
@@ -1314,8 +1383,10 @@ int cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "rmdir", NSH_ERRNO);
}
+
nsh_freefullpath(fullpath);
}
+
return ret;
}
#endif
diff --git a/apps/nshlib/nsh_parse.c b/apps/nshlib/nsh_parse.c
index a58d0b03a..0b977b836 100644
--- a/apps/nshlib/nsh_parse.c
+++ b/apps/nshlib/nsh_parse.c
@@ -299,7 +299,7 @@ static const struct cmdmap_s g_cmdmap[] =
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_FAT)
# ifndef CONFIG_NSH_DISABLE_MKFATFS
- { "mkfatfs", cmd_mkfatfs, 2, 2, "<path>" },
+ { "mkfatfs", cmd_mkfatfs, 2, 4, "[-F <fatsize>] <block-driver>" },
# endif
#endif