summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-06-11 23:47:31 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-06-11 23:47:31 +0000
commit4041ad545516f94eb7de87c8709fbb0f226f291b (patch)
tree19e791f957e0cd01c5bf7608a23e07bc07a58ed7 /apps
parentbd8ecb86d024eee0bdef1687b582f64879354c36 (diff)
downloadpx4-nuttx-4041ad545516f94eb7de87c8709fbb0f226f291b.tar.gz
px4-nuttx-4041ad545516f94eb7de87c8709fbb0f226f291b.tar.bz2
px4-nuttx-4041ad545516f94eb7de87c8709fbb0f226f291b.zip
Add NSH mv command
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4830 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps')
-rwxr-xr-xapps/ChangeLog.txt3
-rw-r--r--apps/nshlib/README.txt18
-rw-r--r--apps/nshlib/nsh.h3
-rw-r--r--apps/nshlib/nsh_fscmds.c44
-rw-r--r--apps/nshlib/nsh_parse.c6
5 files changed, 67 insertions, 7 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt
index 9f5d7f71e..aa2bd8236 100755
--- a/apps/ChangeLog.txt
+++ b/apps/ChangeLog.txt
@@ -237,5 +237,6 @@
* apps/nshlib/nsh_usbdev.c: User now has to press ENTER 3 times before
USB console will start. Otherwise, the USB console starts before there
is anyone at the other end to listen.
- * apps/nshilib/nsh_usbdev.c and nsh_consolemain.c: Add support for the USB
+ * apps/nshlib/nsh_usbdev.c and nsh_consolemain.c: Add support for the USB
capability when a USB console is used.
+ * apps/nshlib/nsh_fscmds.c: Add the 'mv' command
diff --git a/apps/nshlib/README.txt b/apps/nshlib/README.txt
index 4f2a27239..2ac9dfb19 100644
--- a/apps/nshlib/README.txt
+++ b/apps/nshlib/README.txt
@@ -602,6 +602,11 @@ o mount -t <fstype> <block-device> <dir-path>
This is a test
nsh>
+o mv <old-path> <new-path>
+
+ Rename the file object at <old-path> to <new-path>. Both paths must
+ reside in the same mounted filesystem.
+
o ps
Show the currently active threads and tasks. For example,
@@ -802,6 +807,7 @@ Command Dependencies on Configuration Settings
mkfifo CONFIG_NFILE_DESCRIPTORS > 0
mkrd !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE (see note 4)
mount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_READABLE (see note 3)
+ mv !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE (see note 4)
ping CONFIG_NET && CONFIG_NET_ICMP && CONFIG_NET_ICMP_PING && !CONFIG_DISABLE_CLOCK && !CONFIG_DISABLE_SIGNALS
ps --
put CONFIG_NET && CONFIG_NET_UDP && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NET_BUFSIZE >= 558 (see note 1,2)
@@ -840,12 +846,12 @@ also allow it to squeeze into very small memory footprints.
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_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_MW, CONFIG_NSH_DISABLE_MV, 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 e31fa20f1..988106f22 100644
--- a/apps/nshlib/nsh.h
+++ b/apps/nshlib/nsh.h
@@ -521,6 +521,9 @@ void nsh_usbtrace(void);
# ifndef CONFIG_NSH_DISABLE_MKRD
int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
# endif
+# ifndef CONFIG_NSH_DISABLE_MV
+ int cmd_mv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+# endif
# ifndef CONFIG_NSH_DISABLE_RM
int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
# endif
diff --git a/apps/nshlib/nsh_fscmds.c b/apps/nshlib/nsh_fscmds.c
index c67ccf3b2..b3b4ae770 100644
--- a/apps/nshlib/nsh_fscmds.c
+++ b/apps/nshlib/nsh_fscmds.c
@@ -1213,6 +1213,50 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
#endif
/****************************************************************************
+ * Name: cmd_mv
+ ****************************************************************************/
+
+#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE)
+#ifndef CONFIG_NSH_DISABLE_MV
+int cmd_mv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
+{
+ char *oldpath;
+ char *newpath;
+ int ret;
+
+ /* Get the full path to the old and new file paths */
+
+ oldpath = nsh_getfullpath(vtbl, argv[1]);
+ if (!oldpath)
+ {
+ return ERROR;
+ }
+
+ newpath = nsh_getfullpath(vtbl, argv[2]);
+ if (!newpath)
+ {
+ nsh_freefullpath(newpath);
+ return ERROR;
+ }
+
+ /* Perform the mount */
+
+ ret = rename(oldpath, newpath);
+ if (ret < 0)
+ {
+ nsh_output(vtbl, g_fmtcmdfailed, argv[0], "rename", NSH_ERRNO);
+ }
+
+ /* Free the file paths */
+
+ nsh_freefullpath(oldpath);
+ nsh_freefullpath(newpath);
+ return ret;
+}
+#endif
+#endif
+
+/****************************************************************************
* Name: cmd_nfsmount
****************************************************************************/
diff --git a/apps/nshlib/nsh_parse.c b/apps/nshlib/nsh_parse.c
index e497dc67f..f95444f0b 100644
--- a/apps/nshlib/nsh_parse.c
+++ b/apps/nshlib/nsh_parse.c
@@ -263,6 +263,12 @@ static const struct cmdmap_s g_cmdmap[] =
# endif
#endif
+#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE)
+# ifndef CONFIG_NSH_DISABLE_MV
+ { "mv", cmd_mv, 3, 3, "<old-path> <new-path>" },
+# endif
+#endif
+
#ifndef CONFIG_NSH_DISABLE_MW
{ "mw", cmd_mw, 2, 3, "<hex-address>[=<hex-value>][ <hex-byte-count>]" },
#endif