summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-06-27 22:03:32 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-06-27 22:03:32 +0000
commit56224ea316165af86d3db983464e40e1b5b2ac63 (patch)
tree9bf3f1ac1df2f9519effd9e9fc42c4a60c278d4b
parentc7b072472b974b59b144ee4e2a3fe4cab92baf82 (diff)
downloadpx4-nuttx-56224ea316165af86d3db983464e40e1b5b2ac63.tar.gz
px4-nuttx-56224ea316165af86d3db983464e40e1b5b2ac63.tar.bz2
px4-nuttx-56224ea316165af86d3db983464e40e1b5b2ac63.zip
Refactor nfs_socket.c/.h logic; Those files are not gone
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4878 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--nuttx/fs/nfs/Make.defs2
-rw-r--r--nuttx/fs/nfs/nfs.h3
-rw-r--r--nuttx/fs/nfs/nfs_socket.c203
-rw-r--r--nuttx/fs/nfs/nfs_socket.h69
-rw-r--r--nuttx/fs/nfs/nfs_util.c73
-rw-r--r--nuttx/fs/nfs/nfs_vfsops.c47
-rw-r--r--nuttx/fs/nfs/rpc_clnt.c2
7 files changed, 119 insertions, 280 deletions
diff --git a/nuttx/fs/nfs/Make.defs b/nuttx/fs/nfs/Make.defs
index c3c323bc3..fc4682f85 100644
--- a/nuttx/fs/nfs/Make.defs
+++ b/nuttx/fs/nfs/Make.defs
@@ -42,7 +42,7 @@ CSRCS +=
# Files required for NFS RPC
ASRCS +=
-CSRCS += rpc_clnt.c nfs_socket.c nfs_util.c nfs_vfsops.c
+CSRCS += rpc_clnt.c nfs_util.c nfs_vfsops.c
# Argument for dependency checking
diff --git a/nuttx/fs/nfs/nfs.h b/nuttx/fs/nfs/nfs.h
index dfff4a96d..af24357a4 100644
--- a/nuttx/fs/nfs/nfs.h
+++ b/nuttx/fs/nfs/nfs.h
@@ -124,6 +124,9 @@ EXTERN void nfs_semtake(FAR struct nfsmount *nmp);
EXTERN void nfs_semgive(FAR struct nfsmount *nmp);
EXTERN int nfs_checkmount(FAR struct nfsmount *nmp);
EXTERN int nfs_fsinfo(FAR struct nfsmount *nmp);
+EXTERN int nfs_request(struct nfsmount *nmp, int procnum,
+ FAR void *request, size_t reqlen,
+ FAR void *response, size_t resplen);
EXTERN int nfs_lookup(FAR struct nfsmount *nmp, FAR const char *filename,
FAR struct file_handle *fhandle,
FAR struct nfs_fattr *obj_attributes,
diff --git a/nuttx/fs/nfs/nfs_socket.c b/nuttx/fs/nfs/nfs_socket.c
deleted file mode 100644
index b0159372e..000000000
--- a/nuttx/fs/nfs/nfs_socket.c
+++ /dev/null
@@ -1,203 +0,0 @@
-/****************************************************************************
- * fs/nfs/nfs_socket.c
- *
- * Copyright (C) 2012 Gregory Nutt. All rights reserved.
- * Copyright (C) 2012 Jose Pablo Rojas Vargas. All rights reserved.
- * Author: Jose Pablo Rojas Vargas <jrojas@nx-engineering.com>
- * Gregory Nutt <gnutt@nuttx.org>
- *
- * Leveraged from OpenBSD:
- *
- * copyright (c) 2004
- * the regents of the university of michigan
- * all rights reserved
- *
- * permission is granted to use, copy, create derivative works and redistribute
- * this software and such derivative works for any purpose, so long as the name
- * of the university of michigan is not used in any advertising or publicity
- * pertaining to the use or distribution of this software without specific,
- * written prior authorization. if the above copyright notice or any other
- * identification of the university of michigan is included in any copy of any
- * portion of this software, then the disclaimer below must also be included.
- *
- * this software is provided as is, without representation from the university
- * of michigan as to its fitness for any purpose, and without warranty by the
- * university of michigan of any kind, either express or implied, including
- * without limitation the implied warranties of merchantability and fitness for
- * a particular purpose. the regents of the university of michigan shall not be
- * liable for any damages, including special, indirect, incidental, or
- * consequential damages, with respect to any claim arising out of or in
- * connection with the use of the software, even if it has been or is hereafter
- * advised of the possibility of such damages.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <sys/socket.h>
-#include <queue.h>
-#include <time.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <debug.h>
-#include <nuttx/kmalloc.h>
-
-#include "nfs_proto.h"
-#include "nfs_mount.h"
-#include "nfs.h"
-#include "rpc.h"
-#include "xdr_subs.h"
-#include "nfs_socket.h"
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Variables
- ****************************************************************************/
-
-/****************************************************************************
- * Public Variables
- ****************************************************************************/
-
-uint32_t nfs_true;
-uint32_t nfs_false;
-uint32_t nfs_xdrneg1;
-struct nfsstats nfsstats;
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: nfs_init
- ****************************************************************************/
-
-void nfs_init(void)
-{
- nfs_true = txdr_unsigned(TRUE);
- nfs_false = txdr_unsigned(FALSE);
- nfs_xdrneg1 = txdr_unsigned(-1);
-
- rpcclnt_init();
-}
-
-/****************************************************************************
- * Name: nfs_connect
- ****************************************************************************/
-
-int nfs_connect(struct nfsmount *nmp)
-{
- struct rpcclnt *rpc;
-
- if (nmp == NULL)
- {
- return EFAULT;
- }
-
- /* Create an instance of the rpc state structure */
-
- rpc = (struct rpcclnt *)kzalloc(sizeof(struct rpcclnt));
- if (!rpc)
- {
- fdbg("ERROR: Failed to allocate rpc structure\n");
- return ENOMEM;
- }
-
- fvdbg("Connecting\n");
-
- /* Translate nfsmnt flags -> rpcclnt flags */
-
- rpc->rc_path = nmp->nm_path;
- rpc->rc_name = &nmp->nm_nam;
- rpc->rc_sotype = nmp->nm_sotype;
- rpc->rc_retry = nmp->nm_retry;
-
- nmp->nm_rpcclnt = rpc;
-
- return rpcclnt_connect(rpc);
-}
-
-/****************************************************************************
- * Name: nfs_disconnect
- *
- * Description:
- * NFS disconnect. Clean up and unlink.
- *
- ****************************************************************************/
-
-void nfs_disconnect(struct nfsmount *nmp)
-{
- rpcclnt_disconnect(nmp->nm_rpcclnt);
-}
-
-int nfs_request(struct nfsmount *nmp, int procnum,
- FAR void *request, size_t reqlen,
- FAR void *response, size_t resplen)
-{
- struct rpcclnt *clnt = nmp->nm_rpcclnt;
- struct nfs_reply_header replyh;
- int trylater_delay;
- int error;
-
-tryagain:
- error = rpcclnt_request(clnt, procnum, NFS_PROG, NFS_VER3,
- request, reqlen, response, resplen);
- if (error != 0)
- {
- fdbg("ERROR: rpcclnt_request failed: %d\n", error);
- return error;
- }
-
- memcpy(&replyh, response, sizeof(struct nfs_reply_header));
-
- if (replyh.nfs_status != 0)
- {
- if (fxdr_unsigned(uint32_t, replyh.nfs_status) > 32)
- {
- error = EOPNOTSUPP;
- }
- else
- {
- /* NFS_ERRORS are the same as NuttX errno values */
-
- error = fxdr_unsigned(uint32_t, replyh.nfs_status);
- }
-
- return error;
- }
-
- if (replyh.rpc_verfi.authtype != 0)
- {
- error = fxdr_unsigned(int, replyh.rpc_verfi.authtype);
-
- if (error == EAGAIN)
- {
- error = 0;
- trylater_delay *= NFS_TIMEOUTMUL;
- if (trylater_delay > NFS_MAXTIMEO)
- {
- trylater_delay = NFS_MAXTIMEO;
- }
-
- goto tryagain;
- }
-
- fdbg("ERROR: NFS error %d from server\n", error);
- return error;
- }
-
- fvdbg("NFS_SUCCESS\n");
- return OK;
-}
diff --git a/nuttx/fs/nfs/nfs_socket.h b/nuttx/fs/nfs/nfs_socket.h
deleted file mode 100644
index 32485b310..000000000
--- a/nuttx/fs/nfs/nfs_socket.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/****************************************************************************
- * fs/nfs/nfs_socket.h
- *
- * Copyright (C) 2012 Gregory Nutt. All rights reserved.
- * Copyright (C) 2012 Jose Pablo Rojas Vargas. All rights reserved.
- * Author: Jose Pablo Rojas Vargas <jrojas@nx-engineering.com>
- *
- * Leveraged from OpenBSD:
- *
- * copyright (c) 2004
- * the regents of the university of michigan
- * all rights reserved
- *
- * permission is granted to use, copy, create derivative works and redistribute
- * this software and such derivative works for any purpose, so long as the name
- * of the university of michigan is not used in any advertising or publicity
- * pertaining to the use or distribution of this software without specific,
- * written prior authorization. if the above copyright notice or any other
- * identification of the university of michigan is included in any copy of any
- * portion of this software, then the disclaimer below must also be included.
- *
- * this software is provided as is, without representation from the university
- * of michigan as to its fitness for any purpose, and without warranty by the
- * university of michigan of any kind, either express or implied, including
- * without limitation the implied warranties of merchantability and fitness for
- * a particular purpose. the regents of the university of michigan shall not be
- * liable for any damages, including special, indirect, incidental, or
- * consequential damages, with respect to any claim arising out of or in
- * connection with the use of the software, even if it has been or is hereafter
- * advised of the possibility of such damages.
- *
- ****************************************************************************/
-
-#ifndef __FS_NFS_NFS_SOCKET_H
-#define __FS_NFS_NFS_SOCKET_H
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-/****************************************************************************
- * Pre-processor definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Function Prototypes
- ****************************************************************************/
-
-#undef EXTERN
-#if defined(__cplusplus)
-#define EXTERN extern "C"
-extern "C" {
-#else
-#define EXTERN extern
-#endif
-
-EXTERN void nfs_init(void);
-EXTERN int nfs_connect(struct nfsmount *nmp);
-EXTERN void nfs_disconnect(struct nfsmount *nmp);
-EXTERN int nfs_request(struct nfsmount *nmp, int procnum,
- FAR void *request, size_t reqlen,
- FAR void *response, size_t resplen);
-
-#undef EXTERN
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /* __FS_NFS_NFS_SOCKET_H */
diff --git a/nuttx/fs/nfs/nfs_util.c b/nuttx/fs/nfs/nfs_util.c
index 8ab3e974e..33c5f0a89 100644
--- a/nuttx/fs/nfs/nfs_util.c
+++ b/nuttx/fs/nfs/nfs_util.c
@@ -58,7 +58,6 @@
#include "nfs_proto.h"
#include "nfs_mount.h"
#include "nfs_node.h"
-#include "nfs_socket.h"
#include "xdr_subs.h"
/****************************************************************************
@@ -197,6 +196,78 @@ int nfs_checkmount(struct nfsmount *nmp)
}
/****************************************************************************
+ * Name: nfs_request
+ *
+ * Desciption:
+ * Perform the NFS request. On successful receipt, it verifies the NFS level of the
+ * returned values.
+ *
+ * Return Value:
+ * Zero on success; a positive errno value on failure.
+ *
+ ****************************************************************************/
+
+int nfs_request(struct nfsmount *nmp, int procnum,
+ FAR void *request, size_t reqlen,
+ FAR void *response, size_t resplen)
+{
+ struct rpcclnt *clnt = nmp->nm_rpcclnt;
+ struct nfs_reply_header replyh;
+ int trylater_delay;
+ int error;
+
+tryagain:
+ error = rpcclnt_request(clnt, procnum, NFS_PROG, NFS_VER3,
+ request, reqlen, response, resplen);
+ if (error != 0)
+ {
+ fdbg("ERROR: rpcclnt_request failed: %d\n", error);
+ return error;
+ }
+
+ memcpy(&replyh, response, sizeof(struct nfs_reply_header));
+
+ if (replyh.nfs_status != 0)
+ {
+ if (fxdr_unsigned(uint32_t, replyh.nfs_status) > 32)
+ {
+ error = EOPNOTSUPP;
+ }
+ else
+ {
+ /* NFS_ERRORS are the same as NuttX errno values */
+
+ error = fxdr_unsigned(uint32_t, replyh.nfs_status);
+ }
+
+ return error;
+ }
+
+ if (replyh.rpc_verfi.authtype != 0)
+ {
+ error = fxdr_unsigned(int, replyh.rpc_verfi.authtype);
+
+ if (error == EAGAIN)
+ {
+ error = 0;
+ trylater_delay *= NFS_TIMEOUTMUL;
+ if (trylater_delay > NFS_MAXTIMEO)
+ {
+ trylater_delay = NFS_MAXTIMEO;
+ }
+
+ goto tryagain;
+ }
+
+ fdbg("ERROR: NFS error %d from server\n", error);
+ return error;
+ }
+
+ fvdbg("NFS_SUCCESS\n");
+ return OK;
+}
+
+/****************************************************************************
* Name: nfs_lookup
*
* Desciption:
diff --git a/nuttx/fs/nfs/nfs_vfsops.c b/nuttx/fs/nfs/nfs_vfsops.c
index 12c4705dd..3cd5a47dc 100644
--- a/nuttx/fs/nfs/nfs_vfsops.c
+++ b/nuttx/fs/nfs/nfs_vfsops.c
@@ -81,7 +81,6 @@
#include "nfs_node.h"
#include "nfs_mount.h"
#include "xdr_subs.h"
-#include "nfs_socket.h"
/****************************************************************************
* Pre-processor Definitions
@@ -104,6 +103,18 @@
#endif
/****************************************************************************
+ * Public Variables
+ ****************************************************************************/
+
+uint32_t nfs_true;
+uint32_t nfs_false;
+uint32_t nfs_xdrneg1;
+
+#ifdef CONFIG_NFS_STATISTICS
+struct nfsstats nfsstats;
+#endif
+
+/****************************************************************************
* Private Type Definitions
****************************************************************************/
@@ -947,6 +958,7 @@ static ssize_t nfs_write(FAR struct file *filep, const char *buffer,
/* Now loop until we send the entire user buffer */
+ writesize = 0;
for (byteswritten = 0; byteswritten < buflen; )
{
/* Make sure that the attempted write size does not exceed the RPC maximum */
@@ -1578,6 +1590,7 @@ static int nfs_bind(FAR struct inode *blkdriver, FAR const void *data,
{
FAR struct nfs_args *argp = (FAR struct nfs_args *)data;
FAR struct nfsmount *nmp;
+ struct rpcclnt *rpc;
struct rpc_call_fs getattr;
struct rpc_reply_getattr resok;
struct nfs_mount_parameters nprmt;
@@ -1643,7 +1656,11 @@ static int nfs_bind(FAR struct inode *blkdriver, FAR const void *data,
/* Initialize NFS */
- nfs_init();
+ nfs_true = txdr_unsigned(TRUE);
+ nfs_false = txdr_unsigned(FALSE);
+ nfs_xdrneg1 = txdr_unsigned(-1);
+
+ rpcclnt_init();
/* Set initial values of other fields */
@@ -1665,7 +1682,27 @@ static int nfs_bind(FAR struct inode *blkdriver, FAR const void *data,
{
/* Connection-less... connect now */
- error = nfs_connect(nmp);
+ /* Create an instance of the rpc state structure */
+
+ rpc = (struct rpcclnt *)kzalloc(sizeof(struct rpcclnt));
+ if (!rpc)
+ {
+ fdbg("ERROR: Failed to allocate rpc structure\n");
+ return ENOMEM;
+ }
+
+ fvdbg("Connecting\n");
+
+ /* Translate nfsmnt flags -> rpcclnt flags */
+
+ rpc->rc_path = nmp->nm_path;
+ rpc->rc_name = &nmp->nm_nam;
+ rpc->rc_sotype = nmp->nm_sotype;
+ rpc->rc_retry = nmp->nm_retry;
+
+ nmp->nm_rpcclnt = rpc;
+
+ error = rpcclnt_connect(nmp->nm_rpcclnt);
if (error != OK)
{
fdbg("ERROR: nfs_connect failed: %d\n", error);
@@ -1708,7 +1745,7 @@ bad:
{
/* Disconnect from the server */
- nfs_disconnect(nmp);
+ rpcclnt_disconnect(nmp->nm_rpcclnt);
/* Free connection-related resources */
@@ -1772,7 +1809,7 @@ int nfs_unbind(FAR void *handle, FAR struct inode **blkdriver)
/* Disconnect from the server */
- nfs_disconnect(nmp);
+ rpcclnt_disconnect(nmp->nm_rpcclnt);
/* And free any allocated resources */
diff --git a/nuttx/fs/nfs/rpc_clnt.c b/nuttx/fs/nfs/rpc_clnt.c
index 08855647c..0e2a394ba 100644
--- a/nuttx/fs/nfs/rpc_clnt.c
+++ b/nuttx/fs/nfs/rpc_clnt.c
@@ -682,7 +682,7 @@ bad:
* Name: rpcclnt_request
*
* Description:
- * Perform the RPC reqquest. Logic formats the RPC CALL message and calls
+ * Perform the RPC request. Logic formats the RPC CALL message and calls
* rpcclnt_send to send the RPC CALL message. It then calls rpcclnt_reply()
* to get the response. It may attempt to re-send the CALL message on
* certain errors.