From 2545e9bc4bbca11a60f93237c1da513c41a07f1a Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 4 Aug 2012 00:37:25 +0000 Subject: Add the NSH df command git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@5007 7fd9a85b-ad96-42d3-883c-3090e2eb8679 --- apps/ChangeLog.txt | 2 + apps/nshlib/README.txt | 42 +++++++--- apps/nshlib/nsh.h | 3 + apps/nshlib/nsh_mntcmds.c | 64 ++++++++++---- apps/nshlib/nsh_parse.c | 13 ++- nuttx/Documentation/NuttShell.html | 168 +++++++++++++++++++++++-------------- 6 files changed, 196 insertions(+), 96 deletions(-) diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt index ecba28589..8cd30ae83 100755 --- a/apps/ChangeLog.txt +++ b/apps/ChangeLog.txt @@ -268,3 +268,5 @@ * apps/nshlib/nsh_mntcmds.c: Separated mount-related commands out of nsh_fscmds.c. Extended to the mount command so that if no arguments are provided, then the current mountpoints are enumerated. + * apps/nshlib/nsh_mntcmds.c: Add an NSH df command to list the + properties of mounted file systems. diff --git a/apps/nshlib/README.txt b/apps/nshlib/README.txt index 45d14f30d..543b9a448 100644 --- a/apps/nshlib/README.txt +++ b/apps/nshlib/README.txt @@ -308,6 +308,22 @@ o dd if= of= [bs=] [count=] [skip=] brw-rw-rw- 0 ram0 nsh> dd if=/dev/ram0 of=/dev/null +o df + + Show the state of each mounted volume + + Example: + + nsh> mount + /etc type romfs + /tmp type vfat + nsh> df + Block Number + Size Blocks Used Available Mounted on + 64 6 6 0 /etc + 512 985 2 983 /tmp + nsh> + o echo [ [...]] Copy the sequence of strings and expanded environment variables to @@ -808,6 +824,7 @@ Command Dependencies on Configuration Settings cd !CONFIG_DISABLE_ENVIRON && CONFIG_NFILE_DESCRIPTORS > 0 cp CONFIG_NFILE_DESCRIPTORS > 0 dd CONFIG_NFILE_DESCRIPTORS > 0 + df !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_READABLE (see note 3) echo -- exec -- exit -- @@ -858,18 +875,19 @@ settings. All of these settings make the configuration of NSH potentially compl also allow it to squeeze into very small memory footprints. CONFIG_NSH_DISABLE_CAT, CONFIG_NSH_DISABLE_CD, CONFIG_NSH_DISABLE_CP, - CONFIG_NSH_DISABLE_DD, CONFIG_NSH_DISABLE_ECHO, CONFIG_NSH_DISABLE_EXEC, - CONFIG_NSH_DISABLE_EXIT, CONFIG_NSH_DISABLE_FREE, CONFIG_NSH_DISABLE_GET, - CONFIG_NSH_DISABLE_HELP, CONFIG_NSH_DISABLE_IFCONFIG, CONFIG_NSH_DISABLE_KILL, - CONFIG_NSH_DISABLE_LOSETUP, CONFIG_NSH_DISABLE_LS, CONFIG_NSH_DISABLE_MB, - CONFIG_NSH_DISABLE_MKDIR, CONFIG_NSH_DISABLE_MKFATFS, CONFIG_NSH_DISABLE_MKFIFO, - CONFIG_NSH_DISABLE_MKRD, CONFIG_NSH_DISABLE_MH, CONFIG_NSH_DISABLE_MOUNT, - CONFIG_NSH_DISABLE_MW, CONFIG_NSH_DISABLE_MV, CONFIG_NSH_DISABLE_NFSMOUNT, - CONFIG_NSH_DISABLE_PS, CONFIG_NSH_DISABLE_PING, CONFIG_NSH_DISABLE_PUT, - CONFIG_NSH_DISABLE_PWD, CONFIG_NSH_DISABLE_RM, CONFIG_NSH_DISABLE_RMDIR, - CONFIG_NSH_DISABLE_SET, CONFIG_NSH_DISABLE_SH, CONFIG_NSH_DISABLE_SLEEP, - CONFIG_NSH_DISABLE_TEST, CONFIG_NSH_DISABLE_UMOUNT, CONFIG_NSH_DISABLE_UNSET, - CONFIG_NSH_DISABLE_USLEEP, CONFIG_NSH_DISABLE_WGET, CONFIG_NSH_DISABLE_XD + CONFIG_NSH_DISABLE_DD, CONFIG_NSH_DISABLE_DF, CONFIG_NSH_DISABLE_ECHO, + CONFIG_NSH_DISABLE_EXEC, CONFIG_NSH_DISABLE_EXIT, CONFIG_NSH_DISABLE_FREE, + CONFIG_NSH_DISABLE_GET, CONFIG_NSH_DISABLE_HELP, CONFIG_NSH_DISABLE_IFCONFIG, + CONFIG_NSH_DISABLE_KILL, CONFIG_NSH_DISABLE_LOSETUP, CONFIG_NSH_DISABLE_LS, + CONFIG_NSH_DISABLE_MB, CONFIG_NSH_DISABLE_MKDIR, CONFIG_NSH_DISABLE_MKFATFS, + CONFIG_NSH_DISABLE_MKFIFO, CONFIG_NSH_DISABLE_MKRD, CONFIG_NSH_DISABLE_MH, + CONFIG_NSH_DISABLE_MOUNT, CONFIG_NSH_DISABLE_MW, CONFIG_NSH_DISABLE_MV, + CONFIG_NSH_DISABLE_NFSMOUNT, CONFIG_NSH_DISABLE_PS, CONFIG_NSH_DISABLE_PING, + CONFIG_NSH_DISABLE_PUT, CONFIG_NSH_DISABLE_PWD, CONFIG_NSH_DISABLE_RM, + CONFIG_NSH_DISABLE_RMDIR, CONFIG_NSH_DISABLE_SET, CONFIG_NSH_DISABLE_SH, + CONFIG_NSH_DISABLE_SLEEP, CONFIG_NSH_DISABLE_TEST, CONFIG_NSH_DISABLE_UMOUNT, + CONFIG_NSH_DISABLE_UNSET, CONFIG_NSH_DISABLE_USLEEP, CONFIG_NSH_DISABLE_WGET, + CONFIG_NSH_DISABLE_XD NSH-Specific Configuration Settings ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/apps/nshlib/nsh.h b/apps/nshlib/nsh.h index e4fb1e43e..439c2ffd1 100644 --- a/apps/nshlib/nsh.h +++ b/apps/nshlib/nsh.h @@ -508,6 +508,9 @@ void nsh_usbtrace(void); int cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); # endif # ifdef CONFIG_FS_READABLE +# ifndef CONFIG_NSH_DISABLE_DF + int cmd_df(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif # ifndef CONFIG_NSH_DISABLE_MOUNT int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); # endif diff --git a/apps/nshlib/nsh_mntcmds.c b/apps/nshlib/nsh_mntcmds.c index 054119e02..b5935bdea 100644 --- a/apps/nshlib/nsh_mntcmds.c +++ b/apps/nshlib/nsh_mntcmds.c @@ -76,12 +76,34 @@ * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: df_handler + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \ + defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_MOUNT) +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 !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_READABLE) -#ifndef CONFIG_NSH_DISABLE_MOUNT +#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \ + defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_MOUNT) static int mount_handler(FAR const char *mountpoint, FAR struct statfs *statbuf, FAR void *arg) { @@ -133,31 +155,44 @@ static int mount_handler(FAR const char *mountpoint, return OK; } #endif -#endif /**************************************************************************** * Name: mount_show ****************************************************************************/ -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_READABLE) -#ifndef CONFIG_NSH_DISABLE_MOUNT +#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \ + defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_MOUNT) static inline int mount_show(FAR struct nsh_vtbl_s *vtbl, FAR const char *progname) { return foreach_mountpoint(mount_handler, (FAR void *)vtbl); } #endif -#endif /**************************************************************************** * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: cmd_df + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \ + 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); +} +#endif + /**************************************************************************** * Name: cmd_mount ****************************************************************************/ -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_READABLE) -#ifndef CONFIG_NSH_DISABLE_MOUNT +#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \ + defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_MOUNT) int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { char *source; @@ -247,15 +282,13 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) return ret; } #endif -#endif /**************************************************************************** * Name: cmd_nfsmount ****************************************************************************/ -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && \ - defined(CONFIG_NET) && defined(CONFIG_NFS) -#ifndef CONFIG_NSH_DISABLE_NFSMOUNT +#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \ + defined(CONFIG_NET) && defined(CONFIG_NFS) && !defined(CONFIG_NSH_DISABLE_NFSMOUNT) int cmd_nfsmount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { struct nfs_args data; @@ -354,14 +387,13 @@ int cmd_nfsmount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) return ret; } #endif -#endif /**************************************************************************** * Name: cmd_umount ****************************************************************************/ -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_READABLE) -#ifndef CONFIG_NSH_DISABLE_UMOUNT +#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \ + defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_UMOUNT) int cmd_umount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { char *fullpath = nsh_getfullpath(vtbl, argv[1]); @@ -378,7 +410,7 @@ int cmd_umount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) } nsh_freefullpath(fullpath); } + return ret; } #endif -#endif diff --git a/apps/nshlib/nsh_parse.c b/apps/nshlib/nsh_parse.c index d62f6b5a9..00319a98b 100644 --- a/apps/nshlib/nsh_parse.c +++ b/apps/nshlib/nsh_parse.c @@ -163,13 +163,18 @@ static const struct cmdmap_s g_cmdmap[] = { "date", cmd_date, 1, 3, "[-s \"MMM DD HH:MM:SS YYYY\"]" }, #endif -#if CONFIG_NFILE_DESCRIPTORS > 0 -# ifndef CONFIG_NSH_DISABLE_DD +#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_NSH_DISABLE_DD) { "dd", cmd_dd, 3, 6, "if= of= [bs=] [count=] [skip=]" }, # endif -# if defined(CONFIG_SYSLOG) && defined(CONFIG_RAMLOG_SYSLOG) && !defined(CONFIG_NSH_DISABLE_DMESG) + +#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \ + defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_DF) + { "df", cmd_df, 1, 1, NULL }, +#endif + +#if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SYSLOG) && \ + defined(CONFIG_RAMLOG_SYSLOG) && !defined(CONFIG_NSH_DISABLE_DMESG) { "dmesg", cmd_dmesg, 1, 1, NULL }, -# endif #endif #ifndef CONFIG_NSH_DISABLE_ECHO diff --git a/nuttx/Documentation/NuttShell.html b/nuttx/Documentation/NuttShell.html index 86014074f..e561a9bb3 100644 --- a/nuttx/Documentation/NuttShell.html +++ b/nuttx/Documentation/NuttShell.html @@ -119,193 +119,199 @@
- 2.7 Echo Strings and Variables (echo) + 2.7 Show volume status (df)
- 2.8 Execute User Code (exec) + 2.8 Echo Strings and Variables (echo)
- 2.9 Exit NSH (exit) + 2.9 Execute User Code (exec)
- 2.10 Show Memory Manager Status (free) + 2.10 Exit NSH (exit)
- 2.11 Get File Via TFTP (get) + 2.11 Show Memory Manager Status (free)
- 2.12 Show Usage Command Usage (help) + 2.12 Get File Via TFTP (get)
- 2.13 Show Network Configuration (ifconfig) + 2.13 Show Usage Command Usage (help)
- 2.14 Send a signal to a task (kill) + 2.14 Show Network Configuration (ifconfig)
- 2.15 Setup/teardown the Loop Device (losetup) + 2.15 Send a signal to a task (kill)
- 2.16 List Directory Contents (ls) + 2.16 Setup/teardown the Loop Device (losetup)
- 2.17 Access Memory (mb, mh, and mw) + 2.17 List Directory Contents (ls)
- 2.18 Show Current Tasks and Threads (ps) + 2.18 Access Memory (mb, mh, and mw)
- 2.19 Create a Directory (mkdir) + 2.19 Show Current Tasks and Threads (ps)
- 2.20 Create a FAT Filesystem (mkfatfs) + 2.20 Create a Directory (mkdir)
- 2.21 Create a FIFO (mkfifo) + 2.21 Create a FAT Filesystem (mkfatfs)
- 2.22 Create a RAMDISK (mkrd) + 2.22 Create a FIFO (mkfifo)
- 2.23 Mount a File System (mount) + 2.23 Create a RAMDISK (mkrd)
- 2.24 Rename a File (mv) + 2.24 Mount a File System (mount)
- 2.25 Mount an NFS file system (nfsmount) + 2.25 Rename a File (mv)
- 2.26 Check Network Peer (ping) + 2.26 Mount an NFS file system (nfsmount)
- 2.27 Send File Via TFTP (put) + 2.27 Check Network Peer (ping)
- 2.28 Show Current Working Directory (pwd) + 2.28 Send File Via TFTP (put)
- 2.29 Remove a File (rm) + 2.29 Show Current Working Directory (pwd)
- 2.30 Remove a Directory (rmdir) + 2.30 Remove a File (rm)
- 2.31 Set an Environment Variable (set) + 2.31 Remove a Directory (rmdir)
- 2.32 Execute an NSH Script (sh) + 2.32 Set an Environment Variable (set)
- 2.33 Wait for Seconds (sleep) + 2.33 Execute an NSH Script (sh)
- 2.34 Unmount a File System (umount) + 2.34 Wait for Seconds (sleep)
- 2.35 Unset an Environment Variable (unset) + 2.35 Unmount a File System (umount)
- 2.36 Wait for Microseconds (usleep) + 2.36 Unset an Environment Variable (unset)
- 2.37 Get File Via HTTP (wget) + 2.37 Wait for Microseconds (usleep)
- 2.38 Hexadecimal Dump (xd) + 2.38 Get File Via HTTP (wget) + + + +
+ + 2.39 Hexadecimal Dump (xd) @@ -872,7 +878,35 @@ nsh> dd if=/dev/ram0 of=/dev/null + +
-

2.7 Echo Strings and Variables (echo)

+

2.7 Show Volument Status (df)

+
+

Command Syntax:

+
    +df
    +
+

+ Synopsis. + Show the state of each mounted volume. + As an example: +

+
    +nsh> mount
    + /etc type romfs
    +  /tmp type vfat
    +nsh> df
    +  Block  Number
    +  Size   Blocks     Used Available Mounted on
    +    64        6        6         0 /etc
    +   512      985        2       983 /tmp
    +nsh> 
    +
+ + + +
+

2.8 Echo Strings and Variables (echo)

@@ -890,7 +924,7 @@ echo [<string|$name> [<string|$name>...]]
-

2.8 Execute User Code (exec)

+

2.9 Execute User Code (exec)

@@ -909,7 +943,7 @@ exec <hex-address>
-

2.9 Exit NSH (exit)

+

2.10 Exit NSH (exit)

@@ -928,7 +962,7 @@ exit
-

2.10 Show Memory Manager Status (free)

+

2.11 Show Memory Manager Status (free)

@@ -970,7 +1004,7 @@ nsh>
-

2.11 Get File Via TFTP (get)

+

2.12 Get File Via TFTP (get)

@@ -1005,7 +1039,7 @@ get [-b|-n] [-f <local-path>] -h <ip-address> <remote-path>
-

2.12 Show Usage Command Usage (help)

+

2.13 Show Usage Command Usage (help)

@@ -1022,7 +1056,7 @@ help
-

2.13 Show Network Configuration (ifconfig)

+

2.14 Show Network Configuration (ifconfig)

@@ -1073,7 +1107,7 @@ ifconfig nic_name ip_address
-

2.14 Send a signal to a task (kill)

+

2.15 Send a signal to a task (kill)

@@ -1114,7 +1148,7 @@ nsh>
-

2.15 Setup/teardown the Loop Device (losetup)

+

2.16 Setup/teardown the Loop Device (losetup)

@@ -1167,7 +1201,7 @@ losetup d <dev-path>
-

2.16 List Directory Contents (ls)

+

2.17 List Directory Contents (ls)

@@ -1204,7 +1238,7 @@ ls [-lRs] <dir-path>
-

2.17 Access Memory (mb, mh, and mw)

+

2.18 Access Memory (mb, mh, and mw)

@@ -1258,7 +1292,7 @@ nsh>
-

2.18 Show Current Tasks and Threads (ps)

+

2.19 Show Current Tasks and Threads (ps)

@@ -1284,7 +1318,7 @@ nsh>
-

2.19 Create a Directory (mkdir)

+

2.20 Create a Directory (mkdir)

@@ -1319,7 +1353,7 @@ nsh>
-

2.20 Create a FAT Filesystem (mkfatfs)

+

2.21 Create a FAT Filesystem (mkfatfs)

@@ -1339,7 +1373,7 @@ mkfatfs <path>
-

2.21 Create a FIFO (mkfifo)

+

2.22 Create a FIFO (mkfifo)

@@ -1377,7 +1411,7 @@ nsh>
-

2.22 Create a RAMDISK (mkrd)

+

2.23 Create a RAMDISK (mkrd)

@@ -1428,7 +1462,7 @@ nsh>
-

2.23 Mount a File System (mount)

+

2.24 Mount a File System (mount)

@@ -1507,7 +1541,7 @@ nsh> mount
-

2.24 Rename a File (mv)

+

2.25 Rename a File (mv)

@@ -1525,7 +1559,7 @@ mv <old-path> <new-path>
-

2.25 Mount an NFS file system (nfsmount)

+

2.26 Mount an NFS file system (nfsmount)

@@ -1544,7 +1578,7 @@ nfsmount <server-address> <mount-point> <remote-path>
-

2.26 Check Network Peer (ping)

+

2.27 Check Network Peer (ping)

@@ -1577,7 +1611,7 @@ nsh>
-

2.27 Send File Via TFTP (put)

+

2.28 Send File Via TFTP (put)

@@ -1612,7 +1646,7 @@ put [-b|-n] [-f <remote-path>] -h <ip-address> <local-path>
-

2.28 Show Current Working Directory (pwd)

+

2.29 Show Current Working Directory (pwd)

@@ -1642,7 +1676,7 @@ nsh>
-

2.29 Remove a File (rm)

+

2.30 Remove a File (rm)

@@ -1676,7 +1710,7 @@ nsh>
-

2.30 Remove a Directory (rmdir)

+

2.31 Remove a Directory (rmdir)

@@ -1711,7 +1745,7 @@ nsh>
-

2.31 Set an Environment Variable (set)

+

2.32 Set an Environment Variable (set)

@@ -1737,7 +1771,7 @@ nsh>
-

2.32 Execute an NSH Script (sh)

+

2.33 Execute an NSH Script (sh)

@@ -1755,7 +1789,7 @@ sh <script-path>
-

2.33 Wait for Seconds (sleep)

+

2.34 Wait for Seconds (sleep)

@@ -1772,7 +1806,7 @@ sleep <sec>
-

2.34 Unmount a File System (umount)

+

2.35 Unmount a File System (umount)

@@ -1802,7 +1836,7 @@ nsh>
-

2.35 Unset an Environment Variable (unset)

+

2.36 Unset an Environment Variable (unset)

@@ -1828,7 +1862,7 @@ nsh>
-

2.36 Wait for Microseconds (usleep)

+

2.37 Wait for Microseconds (usleep)

@@ -1872,7 +1906,7 @@ wget [-o <local-path>] <url>
-

2.37 Hexadecimal dump (xd)

+

2.38 Hexadecimal dump (xd)

@@ -1965,6 +1999,11 @@ nsh> CONFIG_NFILE_DESCRIPTORS > 0 CONFIG_NSH_DISABLE_DD + + df + !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_READABLE3 + CONFIG_NSH_DISABLE_DF + echo
@@ -2647,9 +2686,10 @@ nsh>
  • Current working directory
  • date
  • dd
  • -
  • echo
  • +
  • df
  • +
  • echo
  • Environment Variables
  • /etc/init.d/rcS
  • exec
  • -- cgit v1.2.3