aboutsummaryrefslogtreecommitdiff
path: root/nuttx/fs
diff options
context:
space:
mode:
authorpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2012-06-11 23:47:31 +0000
committerpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2012-06-11 23:47:31 +0000
commit23817b959fb904906e58500abc2d47804b1dd925 (patch)
tree19e791f957e0cd01c5bf7608a23e07bc07a58ed7 /nuttx/fs
parent8eeb48d78cce99d332984552f43059a97e98870a (diff)
downloadpx4-firmware-23817b959fb904906e58500abc2d47804b1dd925.tar.gz
px4-firmware-23817b959fb904906e58500abc2d47804b1dd925.tar.bz2
px4-firmware-23817b959fb904906e58500abc2d47804b1dd925.zip
Add NSH mv command
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4830 7fd9a85b-ad96-42d3-883c-3090e2eb8679
Diffstat (limited to 'nuttx/fs')
-rw-r--r--nuttx/fs/nfs/nfs_vfsops.c103
-rw-r--r--nuttx/fs/nfs/rpc_clnt.c11
2 files changed, 81 insertions, 33 deletions
diff --git a/nuttx/fs/nfs/nfs_vfsops.c b/nuttx/fs/nfs/nfs_vfsops.c
index ea40e02ee..6d78a2cec 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;
}
- 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);
+ /* 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]++;
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 ff7fcfdfc..34d5ccc13 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 */