Add NSH mv command

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4830 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2012-06-11 23:47:31 +00:00
parent d86ab22cd0
commit 6104a388de
5 changed files with 67 additions and 7 deletions

View File

@ -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

View File

@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -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

View File

@ -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
****************************************************************************/

View File

@ -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