Add -h option to NSH git command; And NSH mksmartfs command. From Ken Petit
This commit is contained in:
parent
11d87d9e4f
commit
cadc8bf98f
@ -536,3 +536,7 @@
|
|||||||
6.28 2013-xx-xx Gregory Nutt <gnutt@nuttx.org>
|
6.28 2013-xx-xx Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
|
||||||
* apps/examples/mtdpart: Provides a simple test of MTD partitions.
|
* 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).
|
||||||
|
@ -216,10 +216,18 @@ config NSH_DISABLE_XD
|
|||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
|
menu "Configure Command Options"
|
||||||
|
|
||||||
|
config NSH_CMDOPT_DF_H
|
||||||
|
bool "df: Enable [-h] man-readable format"
|
||||||
|
default n
|
||||||
|
|
||||||
config NSH_CODECS_BUFSIZE
|
config NSH_CODECS_BUFSIZE
|
||||||
int "File buffer size used by CODEC commands"
|
int "File buffer size used by CODEC commands"
|
||||||
default 128
|
default 128
|
||||||
|
|
||||||
|
endmenu
|
||||||
|
|
||||||
config NSH_FILEIOSIZE
|
config NSH_FILEIOSIZE
|
||||||
int "NSH I/O buffer size"
|
int "NSH I/O buffer size"
|
||||||
default 1024
|
default 1024
|
||||||
|
@ -669,6 +669,11 @@ void nsh_usbtrace(void);
|
|||||||
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);
|
||||||
# endif
|
# endif
|
||||||
# endif /* CONFIG_FS_FAT */
|
# 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 */
|
# endif /* !CONFIG_DISABLE_MOUNTPOINT */
|
||||||
# if !defined(CONFIG_DISABLE_ENVIRON)
|
# if !defined(CONFIG_DISABLE_ENVIRON)
|
||||||
# ifndef CONFIG_NSH_DISABLE_CD
|
# ifndef CONFIG_NSH_DISABLE_CD
|
||||||
|
@ -54,6 +54,9 @@
|
|||||||
# ifdef CONFIG_FS_FAT
|
# ifdef CONFIG_FS_FAT
|
||||||
# include <nuttx/fs/mkfatfs.h>
|
# include <nuttx/fs/mkfatfs.h>
|
||||||
# endif
|
# endif
|
||||||
|
# ifdef CONFIG_FS_SMARTFS
|
||||||
|
# include <nuttx/fs/mksmartfs.h>
|
||||||
|
# endif
|
||||||
# ifdef CONFIG_NFS
|
# ifdef CONFIG_NFS
|
||||||
# include <sys/socket.h>
|
# include <sys/socket.h>
|
||||||
# include <netinet/in.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;
|
int ret = ERROR;
|
||||||
|
|
||||||
if (fullpath)
|
if (fullpath)
|
||||||
{
|
{
|
||||||
ret = mkfatfs(fullpath, &fmt);
|
ret = mkfatfs(fullpath, &fmt);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
@ -1128,6 +1131,57 @@ errout_with_fmt:
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#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
|
* Name: cmd_mv
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
@ -80,42 +80,16 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: df_handler
|
* Name: get_fstype
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#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
|
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \
|
#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \
|
||||||
defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_MOUNT)
|
defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_MOUNT)
|
||||||
#ifndef CONFIG_NUTTX_KERNEL
|
#ifndef CONFIG_NUTTX_KERNEL
|
||||||
static int mount_handler(FAR const char *mountpoint,
|
static const char* get_fstype(FAR struct statfs *statbuf)
|
||||||
FAR struct statfs *statbuf, FAR void *arg)
|
|
||||||
{
|
{
|
||||||
FAR struct nsh_vtbl_s *vtbl = (FAR struct nsh_vtbl_s *)arg;
|
|
||||||
FAR const char *fstype;
|
FAR const char *fstype;
|
||||||
|
|
||||||
DEBUGASSERT(mountpoint && statbuf && vtbl);
|
|
||||||
|
|
||||||
/* Get the file system type */
|
/* Get the file system type */
|
||||||
|
|
||||||
switch (statbuf->f_type)
|
switch (statbuf->f_type)
|
||||||
@ -150,11 +124,127 @@ static int mount_handler(FAR const char *mountpoint,
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_FS_SMARTFS
|
||||||
|
case SMARTFS_MAGIC:
|
||||||
|
fstype = "smartfs";
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fstype = "Unrecognized";
|
fstype = "Unrecognized";
|
||||||
break;
|
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);
|
nsh_output(vtbl, " %s type %s\n", mountpoint, fstype);
|
||||||
return OK;
|
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)
|
defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_DF)
|
||||||
int cmd_df(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
int cmd_df(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||||
{
|
{
|
||||||
nsh_output(vtbl, " Block Number\n");
|
#ifdef CONFIG_NSH_CMDOPT_DF_H
|
||||||
nsh_output(vtbl, " Size Blocks Used Available Mounted on\n");
|
if (argc > 1 && strcmp(argv[1], "-h") == 0)
|
||||||
|
{
|
||||||
return foreach_mountpoint(df_handler, (FAR void *)vtbl);
|
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
|
#endif
|
||||||
|
|
||||||
|
@ -187,8 +187,12 @@ static const struct cmdmap_s g_cmdmap[] =
|
|||||||
|
|
||||||
#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \
|
#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \
|
||||||
defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_DF)
|
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 },
|
{ "df", cmd_df, 1, 1, NULL },
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SYSLOG) && \
|
#if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SYSLOG) && \
|
||||||
defined(CONFIG_RAMLOG_SYSLOG) && !defined(CONFIG_NSH_DISABLE_DMESG)
|
defined(CONFIG_RAMLOG_SYSLOG) && !defined(CONFIG_NSH_DISABLE_DMESG)
|
||||||
@ -296,6 +300,16 @@ static const struct cmdmap_s g_cmdmap[] =
|
|||||||
# endif
|
# endif
|
||||||
#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
|
#ifndef CONFIG_NSH_DISABLE_MH
|
||||||
{ "mh", cmd_mh, 2, 3, "<hex-address>[=<hex-value>][ <hex-byte-count>]" },
|
{ "mh", cmd_mh, 2, 3, "<hex-address>[=<hex-value>][ <hex-byte-count>]" },
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user