diff --git a/nshlib/README.txt b/nshlib/README.txt index b106116c3..8bc10b4d5 100644 --- a/nshlib/README.txt +++ b/nshlib/README.txt @@ -745,7 +745,7 @@ o mkdir drw-rw-rw- 0 TMP/ nsh> -o mkfatfs [-F ] +o mkfatfs [-F ] [-r ] Format a fat file system on the block device specified by path. The FAT size may be provided as an option. Without the @@ -753,6 +753,14 @@ o mkfatfs [-F ] historical reasons, if you want the FAT32 format, it must be explicitly 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. This block device must reside in the NuttX pseudo file system and must have been created by some call to register_blockdriver() (see diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c index e3facaf58..cc4ab89de 100644 --- a/nshlib/nsh_command.c +++ b/nshlib/nsh_command.c @@ -305,7 +305,7 @@ static const struct cmdmap_s g_cmdmap[] = #if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && \ defined(CONFIG_FSUTILS_MKFATFS) # ifndef CONFIG_NSH_DISABLE_MKFATFS - { "mkfatfs", cmd_mkfatfs, 2, 4, "[-F ] " }, + { "mkfatfs", cmd_mkfatfs, 2, 6, "[-F ] [-r ] " }, # endif #endif diff --git a/nshlib/nsh_fscmds.c b/nshlib/nsh_fscmds.c index 1542fead6..0af480ea8 100644 --- a/nshlib/nsh_fscmds.c +++ b/nshlib/nsh_fscmds.c @@ -1220,7 +1220,7 @@ int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) /* mkfatfs [-F ] */ badarg = false; - while ((option = getopt(argc, argv, ":F:")) != ERROR) + while ((option = getopt(argc, argv, ":F:r:")) != ERROR) { switch (option) { @@ -1234,6 +1234,15 @@ int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) } break; + case 'r': + fmt.ff_rootdirentries = atoi(optarg); + if (fmt.ff_rootdirentries < 0) + { + nsh_output(vtbl, g_fmtargrange, argv[0]); + badarg = true; + } + break; + case ':': nsh_output(vtbl, g_fmtargrequired, argv[0]); badarg = true;