summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2013-04-30 18:03:04 -0600
committerGregory Nutt <gnutt@nuttx.org>2013-04-30 18:03:04 -0600
commitdb3072bd6f1ace9bd459ca802d8cd226e901de72 (patch)
treea3fd1a146a3a18dfc7e6ea84393fd50994fc463d /apps
parent82b5ec73c0007df5cf0a5a04d54ea159e76b2951 (diff)
downloadpx4-nuttx-db3072bd6f1ace9bd459ca802d8cd226e901de72.tar.gz
px4-nuttx-db3072bd6f1ace9bd459ca802d8cd226e901de72.tar.bz2
px4-nuttx-db3072bd6f1ace9bd459ca802d8cd226e901de72.zip
Add -h option to NSH git command; And NSH mksmartfs command. From Ken Petit
Diffstat (limited to 'apps')
-rw-r--r--apps/ChangeLog.txt4
-rw-r--r--apps/nshlib/Kconfig8
-rw-r--r--apps/nshlib/nsh.h5
-rw-r--r--apps/nshlib/nsh_fscmds.c56
-rw-r--r--apps/nshlib/nsh_mntcmds.c163
-rw-r--r--apps/nshlib/nsh_parse.c14
6 files changed, 217 insertions, 33 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt
index 4676d8b8e..8871019f4 100644
--- a/apps/ChangeLog.txt
+++ b/apps/ChangeLog.txt
@@ -536,3 +536,7 @@
6.28 2013-xx-xx Gregory Nutt <gnutt@nuttx.org>
* apps/examples/mtdpart: Provides a simple test of MTD partitions.
+ * apps/nshlib/nsh_mntcmds.c: Add a -h option to the df command to show
+ the volume information in human readable form (Ken Petit, 2013-4-30).
+ * apps/nshlib/nsh_fscmds.c: Add support for the mksmartfs command.
+ (Ken Petit, 2013-4-30).
diff --git a/apps/nshlib/Kconfig b/apps/nshlib/Kconfig
index 92bc83cfd..72041ec76 100644
--- a/apps/nshlib/Kconfig
+++ b/apps/nshlib/Kconfig
@@ -216,10 +216,18 @@ config NSH_DISABLE_XD
endmenu
+menu "Configure Command Options"
+
+config NSH_CMDOPT_DF_H
+ bool "df: Enable [-h] man-readable format"
+ default n
+
config NSH_CODECS_BUFSIZE
int "File buffer size used by CODEC commands"
default 128
+endmenu
+
config NSH_FILEIOSIZE
int "NSH I/O buffer size"
default 1024
diff --git a/apps/nshlib/nsh.h b/apps/nshlib/nsh.h
index 3afbce8f9..2dee86b87 100644
--- a/apps/nshlib/nsh.h
+++ b/apps/nshlib/nsh.h
@@ -669,6 +669,11 @@ void nsh_usbtrace(void);
int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
# endif
# endif /* CONFIG_FS_FAT */
+# ifdef CONFIG_FS_SMARTFS
+# ifndef CONFIG_NSH_DISABLE_MKSMARTFS
+ int cmd_mksmartfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+# endif
+# endif /* CONFIG_FS_SMARTFS */
# endif /* !CONFIG_DISABLE_MOUNTPOINT */
# if !defined(CONFIG_DISABLE_ENVIRON)
# ifndef CONFIG_NSH_DISABLE_CD
diff --git a/apps/nshlib/nsh_fscmds.c b/apps/nshlib/nsh_fscmds.c
index 35d5c81bd..99d6268a5 100644
--- a/apps/nshlib/nsh_fscmds.c
+++ b/apps/nshlib/nsh_fscmds.c
@@ -54,6 +54,9 @@
# ifdef CONFIG_FS_FAT
# include <nuttx/fs/mkfatfs.h>
# endif
+# ifdef CONFIG_FS_SMARTFS
+# include <nuttx/fs/mksmartfs.h>
+# endif
# ifdef CONFIG_NFS
# include <sys/socket.h>
# include <netinet/in.h>
@@ -980,7 +983,7 @@ int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
int ret = ERROR;
if (fullpath)
- {
+ {
ret = mkfatfs(fullpath, &fmt);
if (ret < 0)
{
@@ -1129,6 +1132,57 @@ errout_with_fmt:
#endif
/****************************************************************************
+ * Name: cmd_mksmartfs
+ ****************************************************************************/
+
+#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && \
+ defined(CONFIG_FS_SMARTFS)
+#ifndef CONFIG_NSH_DISABLE_MKSMARTFS
+int cmd_mksmartfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
+{
+ char *fullpath = nsh_getfullpath(vtbl, argv[1]);
+ int ret = ERROR;
+#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
+ int nrootdirs = 1;
+#endif
+
+ if (fullpath)
+ {
+ /* Test if number of root directories was supplied */
+
+#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
+ if (argc == 3)
+ {
+ nrootdirs = atoi(argv[2]);
+ }
+
+ if (nrootdirs > 8 || nrootdirs < 1)
+ {
+ nsh_output(vtbl, "Invalid number of root directories specified\n");
+ }
+ else
+#endif
+ {
+#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
+ ret = mksmartfs(fullpath, nrootdirs);
+#else
+ ret = mksmartfs(fullpath);
+#endif
+ if (ret < 0)
+ {
+ nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mksmartfs", NSH_ERRNO);
+ }
+ }
+
+ nsh_freefullpath(fullpath);
+ }
+
+ return ret;
+}
+#endif
+#endif
+
+/****************************************************************************
* Name: cmd_mv
****************************************************************************/
diff --git a/apps/nshlib/nsh_mntcmds.c b/apps/nshlib/nsh_mntcmds.c
index 5557dba7e..3933ed909 100644
--- a/apps/nshlib/nsh_mntcmds.c
+++ b/apps/nshlib/nsh_mntcmds.c
@@ -80,42 +80,16 @@
****************************************************************************/
/****************************************************************************
- * Name: df_handler
- ****************************************************************************/
-
-#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \
- defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_DF)
-static int df_handler(FAR const char *mountpoint,
- FAR struct statfs *statbuf, FAR void *arg)
-{
- FAR struct nsh_vtbl_s *vtbl = (FAR struct nsh_vtbl_s *)arg;
-
- DEBUGASSERT(mountpoint && statbuf && vtbl);
-
- nsh_output(vtbl, "%6ld %8ld %8ld %8ld %s\n",
- statbuf->f_bsize, statbuf->f_blocks,
- statbuf->f_blocks - statbuf->f_bavail, statbuf->f_bavail,
- mountpoint);
-
- return OK;
-}
-#endif
-
-/****************************************************************************
- * Name: mount_handler
+ * Name: get_fstype
****************************************************************************/
#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \
defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_MOUNT)
#ifndef CONFIG_NUTTX_KERNEL
-static int mount_handler(FAR const char *mountpoint,
- FAR struct statfs *statbuf, FAR void *arg)
+static const char* get_fstype(FAR struct statfs *statbuf)
{
- FAR struct nsh_vtbl_s *vtbl = (FAR struct nsh_vtbl_s *)arg;
FAR const char *fstype;
- DEBUGASSERT(mountpoint && statbuf && vtbl);
-
/* Get the file system type */
switch (statbuf->f_type)
@@ -150,11 +124,127 @@ static int mount_handler(FAR const char *mountpoint,
break;
#endif
+#ifdef CONFIG_FS_SMARTFS
+ case SMARTFS_MAGIC:
+ fstype = "smartfs";
+ break;
+#endif
+
default:
fstype = "Unrecognized";
break;
}
+ return fstype;
+}
+#endif
+#endif
+
+/****************************************************************************
+ * Name: df_handler
+ ****************************************************************************/
+
+#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \
+ defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_DF)
+static int df_handler(FAR const char *mountpoint,
+ FAR struct statfs *statbuf, FAR void *arg)
+{
+ FAR struct nsh_vtbl_s *vtbl = (FAR struct nsh_vtbl_s *)arg;
+
+ DEBUGASSERT(mountpoint && statbuf && vtbl);
+
+ nsh_output(vtbl, "%6ld %8ld %8ld %8ld %s\n",
+ statbuf->f_bsize, statbuf->f_blocks,
+ statbuf->f_blocks - statbuf->f_bavail, statbuf->f_bavail,
+ mountpoint);
+
+ return OK;
+}
+
+/****************************************************************************
+ * Name: df_man_readable_handler
+ ****************************************************************************/
+
+#ifdef CONFIG_NSH_CMDOPT_DF_H
+static int df_man_readable_handler(FAR const char *mountpoint,
+ FAR struct statfs *statbuf, FAR void *arg)
+{
+ FAR struct nsh_vtbl_s *vtbl = (FAR struct nsh_vtbl_s *)arg;
+ uint32_t size;
+ uint32_t used;
+ uint32_t free;
+ int which;
+ char sizelabel;
+ char freelabel;
+ char usedlabel;
+ const char labels[5] = { 'B', 'K', 'M', 'G', 'T' };
+
+ DEBUGASSERT(mountpoint && statbuf && vtbl);
+
+ size = statbuf->f_bsize * statbuf->f_blocks;
+ free = statbuf->f_bsize * statbuf->f_bavail;
+ used = size - free;
+
+ /* Find the label for size */
+
+ which = 0;
+ while (size >= 1024)
+ {
+ which++;
+ size >>= 10;
+ }
+ sizelabel = labels[which];
+
+ /* Find the label for free */
+
+ which = 0;
+ while (free >= 1024)
+ {
+ which++;
+ free >>= 10;
+ }
+ freelabel = labels[which];
+
+ /* Find the label for used */
+
+ which = 0;
+ while (used >= 1024)
+ {
+ which++;
+ used >>= 10;
+ }
+ usedlabel = labels[which];
+
+ nsh_output(vtbl, "%-10s %6ld%c %8ld%c %8ld%c %s\n", get_fstype(statbuf),
+ size, sizelabel, used, usedlabel, free, freelabel,
+ mountpoint);
+
+ return OK;
+}
+#endif /* CONFIG_NSH_CMDOPT_DF_H */
+
+#endif /* CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) &&
+ defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_DF) */
+
+/****************************************************************************
+ * Name: mount_handler
+ ****************************************************************************/
+
+#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \
+ defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_MOUNT)
+#ifndef CONFIG_NUTTX_KERNEL
+static int mount_handler(FAR const char *mountpoint,
+ FAR struct statfs *statbuf, FAR void *arg)
+{
+ FAR struct nsh_vtbl_s *vtbl = (FAR struct nsh_vtbl_s *)arg;
+ FAR const char *fstype;
+
+ DEBUGASSERT(mountpoint && statbuf && vtbl);
+
+ /* Get the file system type */
+
+ fstype = get_fstype(statbuf);
+
nsh_output(vtbl, " %s type %s\n", mountpoint, fstype);
return OK;
}
@@ -187,10 +277,19 @@ static inline int mount_show(FAR struct nsh_vtbl_s *vtbl, FAR const char *progna
defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_DF)
int cmd_df(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
- nsh_output(vtbl, " Block Number\n");
- nsh_output(vtbl, " Size Blocks Used Available Mounted on\n");
-
- return foreach_mountpoint(df_handler, (FAR void *)vtbl);
+#ifdef CONFIG_NSH_CMDOPT_DF_H
+ if (argc > 1 && strcmp(argv[1], "-h") == 0)
+ {
+ nsh_output(vtbl, "Filesystem Size Used Available Mounted on\n");
+ return foreach_mountpoint(df_man_readable_handler, (FAR void *)vtbl);
+ }
+ else
+#endif
+ {
+ nsh_output(vtbl, " Block Number\n");
+ nsh_output(vtbl, " Size Blocks Used Available Mounted on\n");
+ return foreach_mountpoint(df_handler, (FAR void *)vtbl);
+ }
}
#endif
diff --git a/apps/nshlib/nsh_parse.c b/apps/nshlib/nsh_parse.c
index d5ffd81ee..5722023d3 100644
--- a/apps/nshlib/nsh_parse.c
+++ b/apps/nshlib/nsh_parse.c
@@ -187,8 +187,12 @@ static const struct cmdmap_s g_cmdmap[] =
#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \
defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_DF)
+#ifdef CONFIG_NSH_CMDOPT_DF_H
+ { "df", cmd_df, 1, 2, "[-h]" },
+#else
{ "df", cmd_df, 1, 1, NULL },
#endif
+#endif
#if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SYSLOG) && \
defined(CONFIG_RAMLOG_SYSLOG) && !defined(CONFIG_NSH_DISABLE_DMESG)
@@ -296,6 +300,16 @@ static const struct cmdmap_s g_cmdmap[] =
# endif
#endif
+#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_SMARTFS)
+# ifndef CONFIG_NSH_DISABLE_MKSMARTFS
+#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
+ { "mksmartfs", cmd_mksmartfs, 2, 3, "<path> [<num-root-directories>]" },
+#else
+ { "mksmartfs", cmd_mksmartfs, 2, 2, "<path>" },
+#endif
+# endif
+#endif
+
#ifndef CONFIG_NSH_DISABLE_MH
{ "mh", cmd_mh, 2, 3, "<hex-address>[=<hex-value>][ <hex-byte-count>]" },
#endif