nshlib/nsh_fscmds.c: Add the -r option which can be used to specify the number of entries in the FAT12/FAT16 root directory.

This commit is contained in:
Boris Astardzhiev 2018-05-11 09:50:54 -06:00 committed by Gregory Nutt
parent b6410136b7
commit 2c2fc512d6
3 changed files with 20 additions and 3 deletions

View File

@ -745,7 +745,7 @@ o mkdir <path>
drw-rw-rw- 0 TMP/ drw-rw-rw- 0 TMP/
nsh> nsh>
o mkfatfs [-F <fatsize>] <block-driver> o mkfatfs [-F <fatsize>] [-r <rootdirentries>] <block-driver>
Format a fat file system on the block device specified by <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> path. The FAT size may be provided as an option. Without the <fatsize>
@ -753,6 +753,14 @@ o mkfatfs [-F <fatsize>] <block-driver>
historical reasons, if you want the FAT32 format, it must be explicitly historical reasons, if you want the FAT32 format, it must be explicitly
specified on the command line. specified on the command line.
The -r option may be specified to select the the number of entries in
the root directory. Typical values for small volumes would be 112 or 224;
512 should be used for large volumes, such as hard disks or very large
SD cards. The default is 512 entries in all cases.
The reported number of root directory entries used with FAT32 is zero
because the FAT32 root directory is a cluster chain.
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 file system and This block device must reside in the NuttX pseudo file system and
must have been created by some call to register_blockdriver() (see must have been created by some call to register_blockdriver() (see

View File

@ -305,7 +305,7 @@ static const struct cmdmap_s g_cmdmap[] =
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && \ #if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && \
defined(CONFIG_FSUTILS_MKFATFS) defined(CONFIG_FSUTILS_MKFATFS)
# ifndef CONFIG_NSH_DISABLE_MKFATFS # ifndef CONFIG_NSH_DISABLE_MKFATFS
{ "mkfatfs", cmd_mkfatfs, 2, 4, "[-F <fatsize>] <block-driver>" }, { "mkfatfs", cmd_mkfatfs, 2, 6, "[-F <fatsize>] [-r <rootdirentries>] <block-driver>" },
# endif # endif
#endif #endif

View File

@ -1220,7 +1220,7 @@ int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
/* mkfatfs [-F <fatsize>] <block-driver> */ /* mkfatfs [-F <fatsize>] <block-driver> */
badarg = false; badarg = false;
while ((option = getopt(argc, argv, ":F:")) != ERROR) while ((option = getopt(argc, argv, ":F:r:")) != ERROR)
{ {
switch (option) switch (option)
{ {
@ -1234,6 +1234,15 @@ int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
} }
break; break;
case 'r':
fmt.ff_rootdirentries = atoi(optarg);
if (fmt.ff_rootdirentries < 0)
{
nsh_output(vtbl, g_fmtargrange, argv[0]);
badarg = true;
}
break;
case ':': case ':':
nsh_output(vtbl, g_fmtargrequired, argv[0]); nsh_output(vtbl, g_fmtargrequired, argv[0]);
badarg = true; badarg = true;