diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt index 9f5d7f71e3..aa2bd8236e 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 4f2a272396..2ac9dfb199 100644 --- a/apps/nshlib/README.txt +++ b/apps/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/apps/nshlib/nsh.h b/apps/nshlib/nsh.h index e31fa20f1c..988106f224 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 c67ccf3b23..b3b4ae770d 100644 --- a/apps/nshlib/nsh_fscmds.c +++ b/apps/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/apps/nshlib/nsh_parse.c b/apps/nshlib/nsh_parse.c index e497dc67fa..f95444f0b6 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, " " }, +# endif +#endif + #ifndef CONFIG_NSH_DISABLE_MW { "mw", cmd_mw, 2, 3, "[=][ ]" }, #endif diff --git a/nuttx/Documentation/NuttShell.html b/nuttx/Documentation/NuttShell.html index 1a2a1da062..72629580f8 100644 --- a/nuttx/Documentation/NuttShell.html +++ b/nuttx/Documentation/NuttShell.html @@ -8,7 +8,7 @@

NuttShell (NSH)

-

Last Updated: May 25, 2012

+

Last Updated: June 11, 2012

@@ -221,79 +221,85 @@
- 2.24 Check Network Peer (ping) + 2.24 Rename a File (mv)
- 2.25 Send File Via TFTP (put) + 2.25 Check Network Peer (ping)
- 2.26 Show Current Working Directory (pwd) + 2.26 Send File Via TFTP (put)
- 2.27 Remove a File (rm) + 2.27 Show Current Working Directory (pwd)
- 2.28 Remove a Directory (rmdir) + 2.28 Remove a File (rm)
- 2.29 Set an Environment Variable (set) + 2.29 Remove a Directory (rmdir)
- 2.30 Execute an NSH Script (sh) + 2.30 Set an Environment Variable (set)
- 2.31 Wait for Seconds (sleep) + 2.31 Execute an NSH Script (sh)
- 2.32 Unmount a File System (umount) + 2.32 Wait for Seconds (sleep)
- 2.33 Unset an Environment Variable (unset) + 2.33 Unmount a File System (umount)
- 2.34 Wait for Microseconds (usleep) + 2.34 Unset an Environment Variable (unset)
- 2.35 Get File Via HTTP (wget) + 2.35 Wait for Microseconds (usleep)
- 2.36 Hexadecimal Dump (xd) + 2.36 Get File Via HTTP (wget) + + + +
+ + 2.37 Hexadecimal Dump (xd) @@ -1483,7 +1489,25 @@ nsh> + +
-

2.24 Check Network Peer (ping)

+

2.24 Rename a File (mv)

+
+ +

Command Syntax:

+
    +mv <old-path> <new-path>
    +
+

+ Synopsis. + Rename the file object at <old-path> to <new-path>. + Both paths must reside in the same mounted filesystem. +

+ + + +
+

2.25 Check Network Peer (ping)

@@ -1516,7 +1540,7 @@ nsh>
-

2.25 Send File Via TFTP (put)

+

2.26 Send File Via TFTP (put)

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

2.26 Show Current Working Directory (pwd)

+

2.27 Show Current Working Directory (pwd)

@@ -1581,7 +1605,7 @@ nsh>
-

2.27 Remove a File (rm)

+

2.28 Remove a File (rm)

@@ -1615,7 +1639,7 @@ nsh>
-

2.28 Remove a Directory (rmdir)

+

2.29 Remove a Directory (rmdir)

@@ -1650,7 +1674,7 @@ nsh>
-

2.29 Set an Environment Variable (set)

+

2.30 Set an Environment Variable (set)

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

2.30 Execute an NSH Script (sh)

+

2.31 Execute an NSH Script (sh)

@@ -1694,7 +1718,7 @@ sh <script-path>
-

2.31 Wait for Seconds (sleep)

+

2.32 Wait for Seconds (sleep)

@@ -1711,7 +1735,7 @@ sleep <sec>
-

2.32 Unmount a File System (umount)

+

2.33 Unmount a File System (umount)

@@ -1741,7 +1765,7 @@ nsh>
-

2.33 Unset an Environment Variable (unset)

+

2.34 Unset an Environment Variable (unset)

@@ -1767,7 +1791,7 @@ nsh>
-

2.34 Wait for Microseconds (usleep)

+

2.35 Wait for Microseconds (usleep)

@@ -1784,7 +1808,7 @@ usleep <usec>
- 2.35 Get File Via HTTP (wget) + 2.36 Get File Via HTTP (wget)
@@ -1811,7 +1835,7 @@ wget [-o <local-path>] <url>
-

2.36 Hexadecimal dump (xd)

+

2.37 Hexadecimal dump (xd)

@@ -1989,6 +2013,11 @@ nsh> !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_READABLE3 CONFIG_NSH_DISABLE_MOUNT + + mv + !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE3 + CONFIG_NSH_DISABLE_MV + ping CONFIG_NET && CONFIG_NET_ICMP && @@ -2590,6 +2619,7 @@ nsh>
  • mkfifo
  • mkrd
  • mount
  • +
  • mv
  • nice
  • OLDPWD
  • Overview
  • diff --git a/nuttx/fs/nfs/nfs_vfsops.c b/nuttx/fs/nfs/nfs_vfsops.c index ea40e02eea..6d78a2cec0 100644 --- a/nuttx/fs/nfs/nfs_vfsops.c +++ b/nuttx/fs/nfs/nfs_vfsops.c @@ -2239,11 +2239,18 @@ errout_with_semaphore: static int nfs_rename(struct inode *mountpt, const char *oldrelpath, const char *newrelpath) { - struct nfsmount *nmp; - struct nfsnode *np; - struct RENAME3args rename; + struct nfsmount *nmp; + struct file_handle from_handle; + struct file_handle to_handle; + char from_name[NAME_MAX+1]; + char to_name[NAME_MAX+1]; + struct nfs_fattr fattr; + struct RENAME3args request; struct rpc_reply_rename resok; - int error = 0; + FAR uint32_t *ptr; + int namelen; + int reqlen; + int error; /* Sanity checks */ @@ -2252,7 +2259,6 @@ static int nfs_rename(struct inode *mountpt, const char *oldrelpath, /* Get the mountpoint private data from the inode structure */ nmp = (struct nfsmount *)mountpt->i_private; - np = nmp->nm_head; /* Check if the mount is still healthy */ @@ -2260,30 +2266,77 @@ static int nfs_rename(struct inode *mountpt, const char *oldrelpath, error = nfs_checkmount(nmp); if (error != OK) { + fdbg("ERROR: nfs_checkmount returned: %d\n", error); goto errout_with_semaphore; } - if (np->n_type != NFREG && np->n_type != NFDIR) + /* Find the NFS node of the directory containing the 'from' object */ + + error = nfs_finddir(nmp, oldrelpath, &from_handle, &fattr, from_name); + if (error != OK) { - fdbg("open eacces typ=%d\n", np->n_type); - error = EACCES; - goto errout_with_semaphore; + fdbg("ERROR: nfs_finddir returned: %d\n", error); + return error; } + /* Find the NFS node of the directory containing the 'from' object */ + + error = nfs_finddir(nmp, newrelpath, &to_handle, &fattr, to_name); + if (error != OK) + { + fdbg("ERROR: nfs_finddir returned: %d\n", error); + return error; + } + + /* Format the RENAME RPC arguements */ + + ptr = (FAR uint32_t *)&request; + reqlen = 0; + + /* Copy the variable length, 'from' directory file handle */ + + *ptr++ = txdr_unsigned(from_handle.length); + reqlen += sizeof(uint32_t); + + memcpy(ptr, &from_handle.handle, from_handle.length); + reqlen += (int)from_handle.length; + ptr += uint32_increment(from_handle.length); + + /* Copy the variable-length 'from' object name */ + + namelen = strlen(from_name); + + *ptr++ = txdr_unsigned(namelen); + reqlen += sizeof(uint32_t); + + memcpy(ptr, from_name, namelen); + reqlen += uint32_alignup(namelen); + ptr += uint32_increment(namelen); + + /* Copy the variable length, 'to' directory file handle */ + + *ptr++ = txdr_unsigned(to_handle.length); + reqlen += sizeof(uint32_t); + + memcpy(ptr, &to_handle.handle, to_handle.length); + ptr += uint32_increment(to_handle.length); + reqlen += (int)to_handle.length; + + /* Copy the variable-length 'to' object name */ + + namelen = strlen(to_name); + + *ptr++ = txdr_unsigned(namelen); + reqlen += sizeof(uint32_t); + + memcpy(ptr, to_name, namelen); + reqlen += uint32_alignup(namelen); + + /* Perform the RENAME RPC */ + nfsstats.rpccnt[NFSPROC_RENAME]++; - memset(&rename, 0, sizeof(struct RENAME3args)); - memset(&resok, 0, sizeof(struct rpc_reply_rename)); - rename.from.fhandle.length = txdr_unsigned(np->n_fhsize); - memcpy(&rename.from.fhandle.handle, &np->n_fhandle, sizeof(nfsfh_t)); - rename.from.length = txdr_unsigned(64); - strncpy((FAR char *)rename.from.name, oldrelpath, 64); - rename.to.fhandle.length = txdr_unsigned(np->n_fhsize); - memcpy(&rename.to.fhandle.handle, &np->n_fhandle, sizeof(nfsfh_t)); - rename.to.length = txdr_unsigned(64); - strncpy((FAR char *)rename.to.name, newrelpath, 64); - error = nfs_request(nmp, NFSPROC_RENAME, - (FAR const void *)&rename, sizeof(struct RENAME3args), + (FAR const void *)&request, reqlen, (FAR void *)&resok, sizeof(struct rpc_reply_rename)); /* Check if the rename was successful */ @@ -2300,14 +2353,6 @@ static int nfs_rename(struct inode *mountpt, const char *oldrelpath, } #endif - if (error) - { - goto errout_with_semaphore; - } - - memcpy(&np->n_fattr, &resok.rename.todir_wcc.after, sizeof(struct nfs_fattr)); - np->n_flags |= NFSNODE_MODIFIED; - errout_with_semaphore: nfs_semgive(nmp); return -error; diff --git a/nuttx/fs/nfs/rpc_clnt.c b/nuttx/fs/nfs/rpc_clnt.c index ff7fcfdfc3..34d5ccc133 100644 --- a/nuttx/fs/nfs/rpc_clnt.c +++ b/nuttx/fs/nfs/rpc_clnt.c @@ -1291,15 +1291,18 @@ static int rpcclnt_buildheader(struct rpcclnt *rpc, int procid, int prog, int ve case NFSPROC_RENAME: { - /* Copy the variable, caller-provided data into the call message structure */ + /* Copy the variable length, caller-provided data into the call + * message structure. + */ struct rpc_call_rename *callmsg = (struct rpc_call_rename *)msgbuf; memcpy(&callmsg->rename, request, *reqlen); - /* Return the full size of the message (including messages headers) */ + /* Return the full size of the message (the size of variable data + * plus the size of the messages header). + */ - DEBUGASSERT(*reqlen == sizeof(struct RENAME3args)); - *reqlen = sizeof(struct rpc_call_rename); + *reqlen += sizeof(struct rpc_call_header); /* Format the message header */