diff --git a/ChangeLog.txt b/ChangeLog.txt index 9f5d7f71e..aa2bd8236 100755 --- a/ChangeLog.txt +++ b/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/nshlib/README.txt b/nshlib/README.txt index 4f2a27239..2ac9dfb19 100644 --- a/nshlib/README.txt +++ b/nshlib/README.txt @@ -602,6 +602,11 @@ o mount -t This is a test nsh> +o mv + + Rename the file object at to . 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/nshlib/nsh.h b/nshlib/nsh.h index e31fa20f1..988106f22 100644 --- a/nshlib/nsh.h +++ b/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/nshlib/nsh_fscmds.c b/nshlib/nsh_fscmds.c index c67ccf3b2..b3b4ae770 100644 --- a/nshlib/nsh_fscmds.c +++ b/nshlib/nsh_fscmds.c @@ -1212,6 +1212,50 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) #endif #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/nshlib/nsh_parse.c b/nshlib/nsh_parse.c index e497dc67f..f95444f0b 100644 --- a/nshlib/nsh_parse.c +++ b/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, " " }, +# endif +#endif + #ifndef CONFIG_NSH_DISABLE_MW { "mw", cmd_mw, 2, 3, "[=][ ]" }, #endif