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 b53b0e3934
commit 6a0e4e78a6
3 changed files with 138 additions and 60 deletions

View file

@ -8,7 +8,7 @@
<tr align="center" bgcolor="#e4e4e4">
<td>
<h1><big><font color="#3c34ec"><i>NuttShell (NSH)</i></font></big></h1>
<p>Last Updated: May 25, 2012</p>
<p>Last Updated: June 11, 2012</p>
</td>
</tr>
</table>
@ -221,79 +221,85 @@
<tr>
<td><br></td>
<td>
<a href="#cmdping">2.24 Check Network Peer (ping)</a>
<a href="#cmdmv">2.24 Rename a File (mv)</a>
</td>
</tr>
<tr>
<td><br></td>
<td>
<a href="#cmdput">2.25 Send File Via TFTP (put)</a>
<a href="#cmdping">2.25 Check Network Peer (ping)</a>
</td>
</tr>
<tr>
<td><br></td>
<td>
<a href="#cmdpwd">2.26 Show Current Working Directory (pwd)</a>
<a href="#cmdput">2.26 Send File Via TFTP (put)</a>
</td>
</tr>
<tr>
<td><br></td>
<td>
<a href="#cmdrm">2.27 Remove a File (rm)</a>
<a href="#cmdpwd">2.27 Show Current Working Directory (pwd)</a>
</td>
</tr>
<tr>
<td><br></td>
<td>
<a href="#cmdrmdir">2.28 Remove a Directory (rmdir)</a>
<a href="#cmdrm">2.28 Remove a File (rm)</a>
</td>
</tr>
<tr>
<td><br></td>
<td>
<a href="#cmdset">2.29 Set an Environment Variable (set)</a>
<a href="#cmdrmdir">2.29 Remove a Directory (rmdir)</a>
</td>
</tr>
<tr>
<td><br></td>
<td>
<a href="#cmdsh">2.30 Execute an NSH Script (sh)</a>
<a href="#cmdset">2.30 Set an Environment Variable (set)</a>
</td>
</tr>
<tr>
<td><br></td>
<td>
<a href="#cmdsleep">2.31 Wait for Seconds (sleep)</a>
<a href="#cmdsh">2.31 Execute an NSH Script (sh)</a>
</td>
</tr>
<tr>
<td><br></td>
<td>
<a href="#cmdunmount">2.32 Unmount a File System (umount)</a>
<a href="#cmdsleep">2.32 Wait for Seconds (sleep)</a>
</td>
</tr>
<tr>
<td><br></td>
<td>
<a href="#cmdunset">2.33 Unset an Environment Variable (unset)</a>
<a href="#cmdunmount">2.33 Unmount a File System (umount)</a>
</td>
</tr>
<tr>
<td><br></td>
<td>
<a href="#cmdusleep">2.34 Wait for Microseconds (usleep)</a>
<a href="#cmdunset">2.34 Unset an Environment Variable (unset)</a>
</td>
</tr>
<tr>
<td><br></td>
<td>
<a href="#cmdwget">2.35 Get File Via HTTP (wget)</a>
<a href="#cmdusleep">2.35 Wait for Microseconds (usleep)</a>
</td>
</tr>
<tr>
<td><br></td>
<td>
<a href="#cmdxd">2.36 Hexadecimal Dump (xd)</a>
<a href="#cmdwget">2.36 Get File Via HTTP (wget)</a>
</td>
</tr>
<tr>
<td><br></td>
<td>
<a href="#cmdxd">2.37 Hexadecimal Dump (xd)</a>
</td>
</tr>
<tr>
@ -1483,7 +1489,25 @@ nsh>
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
<a name="cmdping"><h2>2.24 Check Network Peer (ping)</h2></a>
<a name="cmdmv"><h2>2.24 Rename a File (mv)</h2></a>
</td>
</tr>
</table>
<p><b>Command Syntax:</b></p>
<ul><pre>
mv &lt;old-path&gt; &lt;new-path&gt;
</pre></ul>
<p>
<b>Synopsis</b>.
Rename the file object at <code>&lt;old-path&gt;</code> to <code>&lt;new-path&gt;</code>.
Both paths must reside in the same mounted filesystem.
</p>
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
<a name="cmdping"><h2>2.25 Check Network Peer (ping)</h2></a>
</td>
</tr>
</table>
@ -1516,7 +1540,7 @@ nsh&gt;
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
<a name="cmdput"><h2>2.25 Send File Via TFTP (put)</h2></a>
<a name="cmdput"><h2>2.26 Send File Via TFTP (put)</h2></a>
</td>
</tr>
</table>
@ -1551,7 +1575,7 @@ put [-b|-n] [-f &lt;remote-path&gt;] -h &lt;ip-address&gt; &lt;local-path&gt;
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
<a name="cmdpwd"><h2>2.26 Show Current Working Directory (pwd)</h2></a>
<a name="cmdpwd"><h2>2.27 Show Current Working Directory (pwd)</h2></a>
</td>
</tr>
</table>
@ -1581,7 +1605,7 @@ nsh&gt;
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
<a name="cmdrm"><h2>2.27 Remove a File (rm)</h2></a>
<a name="cmdrm"><h2>2.28 Remove a File (rm)</h2></a>
</td>
</tr>
</table>
@ -1615,7 +1639,7 @@ nsh>
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
<a name="cmdrmdir"><h2>2.28 Remove a Directory (rmdir)</h2></a>
<a name="cmdrmdir"><h2>2.29 Remove a Directory (rmdir)</h2></a>
</td>
</tr>
</table>
@ -1650,7 +1674,7 @@ nsh>
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
<a name="cmdset"><h2>2.29 Set an Environment Variable (set)</h2></a>
<a name="cmdset"><h2>2.30 Set an Environment Variable (set)</h2></a>
</td>
</tr>
</table>
@ -1676,7 +1700,7 @@ nsh&gt;
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
<a name="cmdsh"><h2>2.30 Execute an NSH Script (sh)</h2></a>
<a name="cmdsh"><h2>2.31 Execute an NSH Script (sh)</h2></a>
</td>
</tr>
</table>
@ -1694,7 +1718,7 @@ sh &lt;script-path&gt;
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
<a name="cmdsleep"><h2>2.31 Wait for Seconds (sleep)</h2></a>
<a name="cmdsleep"><h2>2.32 Wait for Seconds (sleep)</h2></a>
</td>
</tr>
</table>
@ -1711,7 +1735,7 @@ sleep &lt;sec&gt;
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
<a name="cmdunmount"><h2>2.32 Unmount a File System (umount)</h2></a>
<a name="cmdunmount"><h2>2.33 Unmount a File System (umount)</h2></a>
</td>
</tr>
</table>
@ -1741,7 +1765,7 @@ nsh>
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
<a name="cmdunset"><h2>2.33 Unset an Environment Variable (unset)</h2></a>
<a name="cmdunset"><h2>2.34 Unset an Environment Variable (unset)</h2></a>
</td>
</tr>
</table>
@ -1767,7 +1791,7 @@ nsh&gt;
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
<a name="cmdusleep"><h2>2.34 Wait for Microseconds (usleep)</h2></a>
<a name="cmdusleep"><h2>2.35 Wait for Microseconds (usleep)</h2></a>
</td>
</tr>
</table>
@ -1784,7 +1808,7 @@ usleep &lt;usec&gt;
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
<a name="cmdwget">2.35 Get File Via HTTP (wget)</a>
<a name="cmdwget">2.36 Get File Via HTTP (wget)</a>
</td>
</tr>
</table>
@ -1811,7 +1835,7 @@ wget [-o &lt;local-path&gt;] &lt;url&gt;
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
<a name="cmdxd"><h2>2.36 Hexadecimal dump (xd)</h2></a>
<a name="cmdxd"><h2>2.37 Hexadecimal dump (xd)</h2></a>
</td>
</tr>
</table>
@ -1989,6 +2013,11 @@ nsh>
<td>!<code>CONFIG_DISABLE_MOUNTPOINT</code> &amp;&amp; <code>CONFIG_NFILE_DESCRIPTORS</code> &gt; 0 &amp;&amp; <code>CONFIG_FS_READABLE</code><sup>3</sup></td>
<td><code>CONFIG_NSH_DISABLE_MOUNT</code></td>
</tr>
<tr>
<td><b><code>mv</code></b></td>
<td>!<code>CONFIG_DISABLE_MOUNTPOINT</code> &amp;&amp; <code>CONFIG_NFILE_DESCRIPTORS</code> &gt; 0 &amp;&amp; <code>CONFIG_FS_WRITABLE</code><sup>3</sup></td>
<td><code>CONFIG_NSH_DISABLE_MV</code></td>
</tr>
<tr>
<td><b><code>ping</code></b></td>
<td><code>CONFIG_NET</code> &amp;&amp; <code>CONFIG_NET_ICMP</code> &amp;&amp;
@ -2590,6 +2619,7 @@ nsh>
<li><a href="#cmdmkfifo"><code>mkfifo</code></a></li>
<li><a href="#cmdmkrd"><code>mkrd</code></a></li>
<li><a href="#cmdmount"><code>mount</code></a></li>
<li><a href="#cmdmv"><code>mv</code></a></li>
<li><a href="#cmdoverview"><code>nice</code></a></li>
<li><a href="#environvars"><code>OLDPWD</code></a></li>
<li><a href="#overview">Overview</a></li>

View file

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

View file

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