mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-10-21 23:02:13 +08:00
NSH: Add an option to the mkfatfs command to specify FAT12, FAT16, or FAT32
This commit is contained in:
@@ -740,4 +740,6 @@
|
|||||||
* examples/hidkbd/hidkbd_main.c: Now calls a function named
|
* examples/hidkbd/hidkbd_main.c: Now calls a function named
|
||||||
arch_usbhost_initialize() that must be provided by the platform-
|
arch_usbhost_initialize() that must be provided by the platform-
|
||||||
specific code (2013-11-29).
|
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).
|
||||||
|
|
||||||
|
@@ -554,9 +554,14 @@ o mkdir <path>
|
|||||||
drw-rw-rw- 0 TMP/
|
drw-rw-rw- 0 TMP/
|
||||||
nsh>
|
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.
|
NSH provides this command to access the mkfatfs() NuttX API.
|
||||||
This block device must reside in the NuttX pseudo filesystem and
|
This block device must reside in the NuttX pseudo filesystem and
|
||||||
must have been created by some call to register_blockdriver() (see
|
must have been created by some call to register_blockdriver() (see
|
||||||
|
@@ -872,6 +872,7 @@ errout_with_paths:
|
|||||||
{
|
{
|
||||||
free(filepath);
|
free(filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#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_output(vtbl, g_fmtcmdfailed, argv[0], "mkdir", NSH_ERRNO);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsh_freefullpath(fullpath);
|
nsh_freefullpath(fullpath);
|
||||||
}
|
}
|
||||||
return ret;
|
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)
|
int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct fat_format_s fmt = FAT_FORMAT_INITIALIZER;
|
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;
|
int ret = ERROR;
|
||||||
|
|
||||||
if (fullpath)
|
/* mkfatfs [-F <fatsize>] <block-driver> */
|
||||||
|
|
||||||
|
badarg = false;
|
||||||
|
while ((option = getopt(argc, argv, ":F:")) != ERROR)
|
||||||
{
|
{
|
||||||
ret = mkfatfs(fullpath, &fmt);
|
switch (option)
|
||||||
if (ret < 0)
|
|
||||||
{
|
{
|
||||||
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;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#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_output(vtbl, g_fmtcmdfailed, argv[0], "mkfifo", NSH_ERRNO);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsh_freefullpath(fullpath);
|
nsh_freefullpath(fullpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -1127,7 +1193,7 @@ int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|||||||
return ERROR;
|
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)
|
if (optind == argc-1)
|
||||||
{
|
{
|
||||||
@@ -1167,6 +1233,7 @@ int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|||||||
free(buffer);
|
free(buffer);
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
errout_with_fmt:
|
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_output(vtbl, g_fmtcmdfailed, argv[0], "unlink", NSH_ERRNO);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsh_freefullpath(fullpath);
|
nsh_freefullpath(fullpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#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_output(vtbl, g_fmtcmdfailed, argv[0], "rmdir", NSH_ERRNO);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsh_freefullpath(fullpath);
|
nsh_freefullpath(fullpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -299,7 +299,7 @@ static const struct cmdmap_s g_cmdmap[] =
|
|||||||
|
|
||||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_FAT)
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_FAT)
|
||||||
# ifndef CONFIG_NSH_DISABLE_MKFATFS
|
# ifndef CONFIG_NSH_DISABLE_MKFATFS
|
||||||
{ "mkfatfs", cmd_mkfatfs, 2, 2, "<path>" },
|
{ "mkfatfs", cmd_mkfatfs, 2, 4, "[-F <fatsize>] <block-driver>" },
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user