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>
|
||||
|
||||
* 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
|
||||
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
@ -1128,6 +1131,57 @@ errout_with_fmt:
|
||||
#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
|
||||
****************************************************************************/
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user