diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-05-18 01:11:57 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-05-18 01:11:57 +0000 |
commit | f2307dd23f254c58cbc85bcf553ec583509a7082 (patch) | |
tree | 4ba8fa96f460c5e5230ff1dd326f62b88ed0832a | |
parent | d53035bc78b3fbbd640a6a7535b9cdf7ca0d9667 (diff) | |
download | px4-nuttx-f2307dd23f254c58cbc85bcf553ec583509a7082.tar.gz px4-nuttx-f2307dd23f254c58cbc85bcf553ec583509a7082.tar.bz2 px4-nuttx-f2307dd23f254c58cbc85bcf553ec583509a7082.zip |
NFS update
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4746 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r-- | apps/nshlib/nsh_fscmds.c | 4 | ||||
-rw-r--r-- | nuttx/fs/nfs/nfs_mount.h | 2 | ||||
-rw-r--r-- | nuttx/fs/nfs/nfs_node.h | 4 | ||||
-rw-r--r-- | nuttx/fs/nfs/nfs_proto.h | 8 | ||||
-rw-r--r-- | nuttx/fs/nfs/nfs_socket.c | 28 | ||||
-rw-r--r-- | nuttx/fs/nfs/nfs_socket.h | 6 | ||||
-rw-r--r-- | nuttx/fs/nfs/nfs_vfsops.c | 17 | ||||
-rw-r--r-- | nuttx/fs/nfs/rpc.h | 276 | ||||
-rw-r--r-- | nuttx/fs/nfs/rpc_clnt.c | 912 | ||||
-rw-r--r-- | nuttx/include/nuttx/fs/nfs.h | 9 |
10 files changed, 1039 insertions, 227 deletions
diff --git a/apps/nshlib/nsh_fscmds.c b/apps/nshlib/nsh_fscmds.c index ebe5f8177..041809faa 100644 --- a/apps/nshlib/nsh_fscmds.c +++ b/apps/nshlib/nsh_fscmds.c @@ -1348,7 +1348,7 @@ int cmd_nfsmount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) sin = (FAR struct sockaddr_in *)&data.addr; sin->sin_family = AF_INET; - sin->sin_port = htons(NFS_PORT); + sin->sin_port = htons(NFS_PMAPPORT); sin->sin_addr = inaddr; data.addrlen = sizeof(struct sockaddr_in); @@ -1362,8 +1362,6 @@ int cmd_nfsmount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) data.acregmax = 60; data.acdirmin = 30; data.acdirmax = 60; - data.rsize = 0; - data.wsize = 0; data.timeo = (tcp) ? 70 : 7; /* Perform the mount */ diff --git a/nuttx/fs/nfs/nfs_mount.h b/nuttx/fs/nfs/nfs_mount.h index cd3980f79..82bb26fe5 100644 --- a/nuttx/fs/nfs/nfs_mount.h +++ b/nuttx/fs/nfs/nfs_mount.h @@ -75,7 +75,7 @@ struct nfsmount sem_t nm_sem; /* Used to assume thread-safe access */ int nm_numgrps; /* Max. size of groupslist */ nfsfh_t nm_fh; /* File handle of root dir */ - char *nm_path; /* server's path of the directory being mount */ + char nm_path[90]; /* server's path of the directory being mount */ int nm_fhsize; /* Size of root file handle */ struct rpcclnt *nm_rpcclnt; /* rpc state */ struct socket *nm_so; /* Rpc socket */ diff --git a/nuttx/fs/nfs/nfs_node.h b/nuttx/fs/nfs/nfs_node.h index 98867c900..e32c49d78 100644 --- a/nuttx/fs/nfs/nfs_node.h +++ b/nuttx/fs/nfs/nfs_node.h @@ -142,9 +142,9 @@ struct nfsnode struct timespec nf_mtim; off_t nd_direof; /* Directory EOF offset cache */ } n_un2; - short n_fhsize; /* size in bytes, of fh */ +//short n_fhsize; /* size in bytes, of fh */ short n_flag; /* Flag for locking.. */ - nfsfh_t n_fh; /* Small File Handle */ +//nfsfh_t n_fh; /* Small File Handle */ time_t n_accstamp; /* Access cache timestamp */ uid_t n_accuid; /* Last access requester */ int n_accmode; /* Last mode requested */ diff --git a/nuttx/fs/nfs/nfs_proto.h b/nuttx/fs/nfs/nfs_proto.h index 7fecb60b4..36407ba03 100644 --- a/nuttx/fs/nfs/nfs_proto.h +++ b/nuttx/fs/nfs/nfs_proto.h @@ -632,14 +632,8 @@ struct READDIR3resok struct dirlist3 reply; }; -struct FSINFOargs +struct FS3args { nfsfh_t fsroot; }; - -struct FSSTAT3args -{ - nfsfh_t fsroot; -}; - #endif diff --git a/nuttx/fs/nfs/nfs_socket.c b/nuttx/fs/nfs/nfs_socket.c index c1508171d..5234c86a2 100644 --- a/nuttx/fs/nfs/nfs_socket.c +++ b/nuttx/fs/nfs/nfs_socket.c @@ -141,9 +141,9 @@ int nfs_connect(struct nfsmount *nmp) nfsmnt_to_rpcclnt(nmp->nm_flag, rpc->rc_flag, NOCONN); nfsmnt_to_rpcclnt(nmp->nm_flag, rpc->rc_flag, DUMBTIMR); - //rpc->rc_flag |= RPCCLNT_REDIRECT; /* Make this a mount option. */ +//rpc->rc_flag |= RPCCLNT_REDIRECT; /* Make this a mount option. */ - rpc->rc_authtype = RPCAUTH_NULL; /* for now */ +//rpc->rc_authtype = RPCAUTH_NULL; /* for now */ rpc->rc_path = nmp->nm_path; rpc->rc_name = &nmp->nm_nam; @@ -152,7 +152,7 @@ int nfs_connect(struct nfsmount *nmp) rpc->rc_rsize = (nmp->nm_rsize > nmp->nm_readdirsize) ? nmp->nm_rsize : nmp->nm_readdirsize; rpc->rc_wsize = nmp->nm_wsize; - rpc->rc_deadthresh = nmp->nm_deadthresh; +//rpc->rc_deadthresh = nmp->nm_deadthresh; rpc->rc_timeo = nmp->nm_timeo; rpc->rc_retry = nmp->nm_retry; @@ -180,29 +180,31 @@ void nfs_safedisconnect(struct nfsmount *nmp) } #endif -int nfs_request(struct nfsmount *nmp, int procnum, void *datain, void **dataout) +int nfs_request(struct nfsmount *nmp, int procnum, FAR const void *datain, + void *dataout) { int error; struct rpcclnt *clnt= nmp->nm_rpcclnt; - struct rpc_reply reply; + struct rpc_reply_header replyh; int trylater_delay; tryagain: - memset(&reply, 0, sizeof(reply)); + memset(&replyh, 0, sizeof(struct rpc_reply_header)); error = rpcclnt_request(clnt, procnum, nmp->nm_rpcclnt->rc_prog->prog_id, - nmp->nm_rpcclnt->rc_prog->prog_version, &reply, datain); + nmp->nm_rpcclnt->rc_prog->prog_version, dataout, + datain); if (error != 0) { goto out; } - *dataout = (void *)reply.stat.where; + bcopy(dataout, &replyh, sizeof(replyh)); - if (reply.rpc_verfi.authtype != 0) + if (replyh.rpc_verfi.authtype != 0) { - error = fxdr_unsigned(int, reply.rpc_verfi.authtype); + error = fxdr_unsigned(int, replyh.rpc_verfi.authtype); if ((nmp->nm_flag & NFSMNT_NFSV3) && error == NFSERR_TRYLATER) { @@ -240,9 +242,13 @@ out: return error; } +#undef COMP +#ifdef COMP + /* terminate any outstanding RPCs. */ int nfs_nmcancelreqs(struct nfsmount *nmp) { - return rpcclnt_cancelreqs(nmp->nm_rpcclnt); + return 0; //rpcclnt_cancelreqs(nmp->nm_rpcclnt); } +#endif
\ No newline at end of file diff --git a/nuttx/fs/nfs/nfs_socket.h b/nuttx/fs/nfs/nfs_socket.h index 4fa4c05ad..01313cad8 100644 --- a/nuttx/fs/nfs/nfs_socket.h +++ b/nuttx/fs/nfs/nfs_socket.h @@ -61,9 +61,11 @@ EXTERN void nfs_disconnect(struct nfsmount *); EXTERN int nfs_sigintr(struct nfsmount *, struct nfsreq *, cthread_t *); EXTERN void nfs_safedisconnect(struct nfsmount *); #endif -EXTERN int nfs_request(struct nfsmount *, int, void *, void **); +EXTERN int nfs_request(struct nfsmount *, int, FAR const void *, void *); +#undef COMP +#ifdef COMP EXTERN int nfs_nmcancelreqs(struct nfsmount *); - +#endif #undef EXTERN #if defined(__cplusplus) } diff --git a/nuttx/fs/nfs/nfs_vfsops.c b/nuttx/fs/nfs/nfs_vfsops.c index 879c21ed2..c089ef981 100644 --- a/nuttx/fs/nfs/nfs_vfsops.c +++ b/nuttx/fs/nfs/nfs_vfsops.c @@ -593,7 +593,7 @@ int nfs_readdirrpc(struct nfsmount *nmp, struct nfsnode *np, int error = 0; void *datareply; struct READDIR3args readir; - struct READDIR3resok *resok; + struct READDIR3resok *resok = NULL; /* Loop around doing readdir rpc's of size nm_readdirsize * truncated to a multiple of NFS_READDIRBLKSIZ. @@ -903,6 +903,7 @@ void nfs_decode_args(struct nfsmount *nmp, struct nfs_args *argp) nmp->nm_readdirsize = maxio; } +/* if ((argp->flags & NFSMNT_MAXGRPS) && argp->maxgrouplist >= 0 && argp->maxgrouplist <= NFS_MAXGRPS) { @@ -914,6 +915,7 @@ void nfs_decode_args(struct nfsmount *nmp, struct nfs_args *argp) { nmp->nm_readahead = argp->readahead; } +*/ if (argp->flags & NFSMNT_ACREGMIN && argp->acregmin >= 0) { @@ -1028,11 +1030,7 @@ int mountnfs(struct nfs_args *argp, void **handle) nmp->nm_acdirmin = NFS_MINATTRTIMO; nmp->nm_acdirmax = NFS_MAXATTRTIMO; nmp->nm_fh = argp->fh; -//strncpy(&mp->mnt_stat.f_fstypename[0], mp->mnt_vfc->vfc_name, MFSNAMELEN); -//memmove(hst, mp->mnt_stat.f_mntfromname, MNAMELEN); -//bcopy(pth, nmp->nm_mntonname, 90); - nmp->nm_path = argp->path; -//memmove(argp, &mp->mnt_stat.mount_info.nfs_args, sizeof(*argp)); + strncpy(nmp->nm_path, argp->path,90); nmp->nm_nam = argp->addr; nfs_decode_args(nmp, argp); @@ -1048,6 +1046,7 @@ int mountnfs(struct nfs_args *argp, void **handle) } nmp->nm_head = np; + /* Set up the sockets and per-host congestion */ nmp->nm_sotype = argp->sotype; @@ -1179,7 +1178,7 @@ static int nfs_statfs(struct inode *mountpt, struct statfs *sbp) int error = 0; uint64_t tquad; void *datareply; - struct FSSTAT3args fsstat; + struct FS3args fsstat; /* Sanity checks */ @@ -1210,7 +1209,7 @@ static int nfs_statfs(struct inode *mountpt, struct statfs *sbp) } nfsstats.rpccnt[NFSPROC_FSSTAT]++; - memset(&fsstat, 0, sizeof(struct FSSTAT3args)); + memset(&fsstat, 0, sizeof(struct FS3args)); fsstat.fsroot = nmp->nm_fh; error = nfs_request(nmp, NFSPROC_FSSTAT, &fsstat, &datareply); if (error) @@ -1542,7 +1541,7 @@ errout_with_semaphore: static int nfs_fsinfo(struct inode *mountpt, const char *relpath, struct stat *buf) { struct nfsv3_fsinfo *fsp; - struct FSINFOargs fsinfo; + struct FS3args fsinfo; struct nfsmount *nmp; uint32_t pref, max; int error = 0; diff --git a/nuttx/fs/nfs/rpc.h b/nuttx/fs/nfs/rpc.h index f6b8d6674..16bafa440 100644 --- a/nuttx/fs/nfs/rpc.h +++ b/nuttx/fs/nfs/rpc.h @@ -74,6 +74,7 @@ ****************************************************************************/ #include <sys/types.h> +#include "nfs_proto.h" /**************************************************************************** * Pre-processor Definitions @@ -99,7 +100,7 @@ #define PMAPPROG 100000 #define PMAPVERS 2 #define PMAPPROC_NULL 0 -#define MAPPROC_SET 1 +#define PMAPPROC_SET 1 #define PMAPPROC_UNSET 2 #define PMAPPROC_GETPORT 3 #define PMAPPROC_DUMP 4 @@ -109,6 +110,12 @@ * Public Types ****************************************************************************/ +struct xidr +{ + uint32_t xid; +}; + +/* PMAP headers */ struct call_args_pmap { uint32_t prog; @@ -117,56 +124,51 @@ struct call_args_pmap uint32_t port; }; - struct call_result_pmap +struct call_result_pmap { uint16_t port; - unsigned char *extradata; }; - struct call_result_mount +/* MOUNTD headers */ + +struct call_args_mount { - uint16_t problem; - nfsfh_t fhandle; + char *rpath; + uint8_t len; }; -struct rpc_program +struct call_result_mount { - uint32_t prog_id; - uint32_t prog_version; - char *prog_name; + uint16_t problem; + nfsfh_t fhandle; }; -struct rpctask +/* Generic RPC call headers */ + +enum auth_flavor { - dq_entry_t r_chain; - struct rpcclnt *r_rpcclnt; - uint32_t r_xid; - int r_flags; /* flags on request, see below */ - int r_retry; /* max retransmission count */ - int r_rexmit; /* current retrans count */ - int r_timer; /* tick counter on reply */ - int r_procnum; /* NFS procedure number */ - int r_rtt; /* RTT for rpc */ + AUTH_NONE = 0, + AUTH_SYS = 1, + AUTH_SHORT = 2 + /* and more to be defined */ }; -/* Generic RPC headers */ - struct rpc_auth_info { - uint32_t authtype; /* auth type */ + enum auth_flavor authtype; /* auth type */ uint32_t authlen; /* auth length */ }; struct auth_unix { - int32_t ua_time; - int32_t ua_hostname; /* null */ - int32_t ua_uid; - int32_t ua_gid; - int32_t ua_gidlist; /* null */ + int32_t stamp; + unsigned char hostname; /* null */ + int32_t uid; + int32_t gid; + int32_t gidlist; /* null */ }; -struct rpc_call +struct rpc_call_header { uint32_t rp_xid; /* request transaction id */ int32_t rp_direction; /* call direction (0) */ @@ -174,7 +176,6 @@ struct rpc_call uint32_t rp_prog; /* program */ uint32_t rp_vers; /* version */ uint32_t rp_proc; /* procedure */ - unsigned char *data; struct rpc_auth_info rpc_auth; #ifdef CONFIG_NFS_UNIX_AUTH struct auth_unix rpc_unix; @@ -182,7 +183,75 @@ struct rpc_call struct rpc_auth_info rpc_verf; }; -struct rpc_reply +struct rpc_call_pmap +{ + struct rpc_call_header ch; + struct call_args_pmap pmap; +}; + +struct rpc_call_mount +{ + struct rpc_call_header ch; + struct call_args_mount mount; +}; + +struct rpc_call_create +{ + struct rpc_call_header ch; + struct CREATE3args create; +}; + +struct rpc_call_read +{ + struct rpc_call_header ch; + struct READ3args read; +}; + +struct rpc_call_write +{ + struct rpc_call_header ch; + struct WRITE3args write; +}; + +struct rpc_call_remove +{ + struct rpc_call_header ch; + struct REMOVE3args remove; +}; + +struct rpc_call_rename +{ + struct rpc_call_header ch; + struct RENAME3args rename; +}; + +struct rpc_call_mkdir +{ + struct rpc_call_header ch; + struct MKDIR3args mkdir; +}; + +struct rpc_call_rmdir +{ + struct rpc_call_header ch; + struct RMDIR3args rmdir; +}; + +struct rpc_call_readdir +{ + struct rpc_call_header ch; + struct READDIR3args readdir; +}; + +struct rpc_call_fs +{ + struct rpc_call_header ch; + struct FS3args fs; +}; + +/* Generic RPC reply headers */ + +struct rpc_reply_header { uint32_t rp_xid; /* request transaction id */ int32_t rp_direction; /* call direction (1) */ @@ -192,8 +261,6 @@ struct rpc_reply uint32_t type; uint32_t status; - unsigned char *where; /* Data */ - /* used only when reply == RPC_MSGDENIED and status == RPC_AUTHERR */ uint32_t autherr; @@ -207,60 +274,149 @@ struct rpc_reply } mismatch_info; } stat; + unsigned char *where; struct rpc_auth_info rpc_verfi; }; -/* RPC Client connection context. - * One allocated on every NFS mount. +struct rpc_reply_pmap +{ + struct rpc_reply_header rh; + struct call_result_pmap pmap; +}; + +struct rpc_reply_mount +{ + struct rpc_reply_header rh; + struct call_result_mount mount; +}; + +struct rpc_reply_create +{ + struct rpc_reply_header rh; + struct CREATE3resok create; +}; + +struct rpc_reply_write +{ + struct rpc_reply_header rh; + struct WRITE3resok write; +}; + +struct rpc_reply_read +{ + struct rpc_reply_header rh; + struct READ3resok read; +}; + +struct rpc_reply_remove +{ + struct rpc_reply_header rh; + struct REMOVE3resok remove; +}; + +struct rpc_reply_rename +{ + struct rpc_reply_header rh; + struct RENAME3resok rename; +}; + +struct rpc_reply_mkdir +{ + struct rpc_reply_header rh; + struct MKDIR3resok mkdir; +}; + +struct rpc_reply_rmdir +{ + struct rpc_reply_header rh; + struct RMDIR3resok rmdir; +}; + +struct rpc_reply_readdir +{ + struct rpc_reply_header rh; + struct READDIR3resok readdir; +}; + +struct rpc_reply_fsinfo +{ + struct rpc_reply_header rh; + struct nfsv3_fsinfo fsinfo; +}; + +struct rpc_reply_fsstat +{ + struct rpc_reply_header rh; + struct nfs_statfs fsstat; +}; + +/* RPC Client connection context. One allocated on every NFS mount. * Holds RPC specific information for mount. */ -/* XXX: please note that all pointer type variables are just set (not copied), - * so it is up to the user to free these values */ +struct rpc_program +{ + uint32_t prog_id; + uint32_t prog_version; + char *prog_name; +}; + +struct rpctask +{ + dq_entry_t r_chain; + struct rpcclnt *r_rpcclnt; + uint32_t r_xid; + int r_flags; /* flags on request, see below */ + int r_retry; /* max retransmission count */ + int r_rexmit; /* current retrans count */ + int r_timer; /* tick counter on reply */ + int r_procnum; /* NFS procedure number */ + int r_rtt; /* RTT for rpc */ +}; struct rpcclnt { - int rc_flag; /* For RPCCLNT_* flags */ + int rc_flag; /* For RPCCLNT_* flags */ - int rc_wsize; /* Max size of the request data */ - int rc_rsize; /* Max size of the response data */ - nfsfh_t rc_fh; /* File handle of root dir */ - char *rc_path; /* server's path of the directory being mount */ + int rc_wsize; /* Max size of the request data */ + int rc_rsize; /* Max size of the response data */ + nfsfh_t rc_fh; /* File handle of root dir */ + char *rc_path; /* server's path of the directory being mount */ struct sockaddr *rc_name; - struct socket *rc_so; /* Rpc socket */ + struct socket *rc_so; /* Rpc socket */ - uint8_t rc_sotype; /* Type of socket */ - int rc_soproto; /* and protocol */ - uint8_t rc_soflags; /* pr_flags for socket protocol */ + uint8_t rc_sotype; /* Type of socket */ + int rc_soproto; /* and protocol */ + uint8_t rc_soflags; /* pr_flags for socket protocol */ - int rc_timeo; /* Init timer for NFSMNT_DUMBTIMR */ - int rc_retry; /* Max retries */ - int rc_srtt[4]; /* Timers for rpcs */ + int rc_timeo; /* Init timer for NFSMNT_DUMBTIMR */ + int rc_retry; /* Max retries */ + int rc_srtt[4]; /* Timers for rpcs */ int rc_sdrtt[4]; - int rc_sent; /* Request send count */ - int rc_cwnd; /* Request send window */ - int rc_timeouts; /* Request timeouts */ + int rc_sent; /* Request send count */ + int rc_cwnd; /* Request send window */ + int rc_timeouts; /* Request timeouts */ - int rc_deadthresh; /* Threshold of timeouts-->dead server*/ +//int rc_deadthresh; /* Threshold of timeouts-->dead server*/ /* authentication: */ /* currently can be RPCAUTH_NULL, RPCAUTH_KERBV4, RPCAUTH_UNIX */ /* should be kept in XDR form */ - int rc_authtype; /* Authenticator type */ + // int rc_authtype; /* Authenticator type */ #ifdef CONFIG_NFS_UNIX_AUTH /* RPCAUTH_UNIX*/ - struct rpc_auth_info rc_oldauth; /* authentication */ + struct rpc_auth_info rc_oldauth; /* authentication */ #endif - void *rc_auth; +//void *rc_auth; struct rpc_program *rc_prog; //char *rc_servername; - int rc_proctlen; /* if == 0 then rc_proct == NULL */ + int rc_proctlen; /* if == 0 then rc_proct == NULL */ int *rc_proct; }; @@ -274,8 +430,10 @@ int rpcclnt_reconnect(struct rpctask *); void rpcclnt_disconnect(struct rpcclnt *); int rpcclnt_umount(struct rpcclnt *); void rpcclnt_safedisconnect(struct rpcclnt *); -int rpcclnt_request(struct rpcclnt *, int, int, int, struct rpc_reply *, void *); +int rpcclnt_request(struct rpcclnt *, int, int, int, void *, FAR const void *); +#undef COMP +#ifdef COMP int rpcclnt_cancelreqs(struct rpcclnt *); - +#endif #endif /* _RPCCLNT_H_ */ diff --git a/nuttx/fs/nfs/rpc_clnt.c b/nuttx/fs/nfs/rpc_clnt.c index ab0a381b9..0cf30d24b 100644 --- a/nuttx/fs/nfs/rpc_clnt.c +++ b/nuttx/fs/nfs/rpc_clnt.c @@ -176,7 +176,7 @@ char *rpc_errstr_auth[RPC_ERRSTR_AUTH_SIZE] = * Private Data ****************************************************************************/ -static int rpcclnt_backoff[8] = { 2, 4, 8, 16, 32, 64, 128, 256, }; +//static int rpcclnt_backoff[8] = { 2, 4, 8, 16, 32, 64, 128, 256, }; /* Static data, mostly RPC constants in XDR form */ @@ -206,13 +206,11 @@ static dq_queue_t rpctask_q; * Private Function Prototypes ****************************************************************************/ -static int rpcclnt_send(struct socket *, struct sockaddr *, struct rpc_call *, +static int rpcclnt_send(struct socket *, struct sockaddr *, int, int, void *, struct rpctask *); static int rpcclnt_receive(struct rpctask *, struct sockaddr *, - struct rpc_reply *, struct rpc_call *); -static int rpcclnt_reply(struct rpctask *, struct rpc_call *, - struct rpc_reply *); -static void rpcclnt_timer(void *, struct rpc_call *); + void *);//, struct rpc_call *); +static int rpcclnt_reply(struct rpctask *, struct rpc_reply_header *, void *); #ifdef CONFIG_NFS_TCPIP static int rpcclnt_sndlock(int *, struct rpctask *); static void rpcclnt_sndunlock(int *); @@ -220,11 +218,13 @@ static int rpcclnt_rcvlock(struct rpctask *); static void rpcclnt_rcvunlock(int *); static int rpcclnt_sigintr(struct rpcclnt *, struct rpctask *, cthread_t *); #endif +#ifdef COMP static void rpcclnt_softterm(struct rpctask *task); - +static void rpcclnt_timer(void *, struct rpc_call *); +#endif static uint32_t rpcclnt_proct(struct rpcclnt *, uint32_t); -static int rpcclnt_buildheader(struct rpcclnt *, int, int, int, void *, - struct rpc_call *); +static int rpcclnt_buildheader(struct rpcclnt *, int, int, int, struct xidr *, FAR const void *, + void *); /**************************************************************************** * Private Functions @@ -241,11 +241,11 @@ static int rpcclnt_buildheader(struct rpcclnt *, int, int, int, void *, */ static int -rpcclnt_send(struct socket *so, struct sockaddr *nam, struct rpc_call *call, - struct rpctask *rep) +rpcclnt_send(struct socket *so, struct sockaddr *nam, int procid, int prog, + void *call, struct rpctask *rep) { struct sockaddr *sendnam; - int error = 0; + int error = ESRCH; #ifdef CONFIG_NFS_TCPIP int soflags; #endif @@ -294,7 +294,127 @@ rpcclnt_send(struct socket *so, struct sockaddr *nam, struct rpc_call *call, flags = 0; } - error = psock_sendto(so, call, sizeof(*call), flags, sendnam, sizeof(*sendnam)); + if (prog == PMAPPROG) + { + if (procid == PMAPPROC_GETPORT) + { + struct rpc_call_pmap *callmsg = (struct rpc_call_pmap *)call; + error = psock_sendto(so, callmsg, sizeof(*callmsg), flags, + sendnam, sizeof(*sendnam)); + } + else if (procid == PMAPPROC_UNSET) + { + struct rpc_call_pmap *callmsg = (struct rpc_call_pmap *)call; + error = psock_sendto(so, callmsg, sizeof(*callmsg), flags, + sendnam, sizeof(*sendnam)); + } + } + + else if (prog == RPCPROG_MNT) + { + if (procid == RPCMNT_UMOUNT) + { + struct rpc_call_mount *callmsg = (struct rpc_call_mount *)call; + error = psock_sendto(so, callmsg, sizeof(*callmsg), flags, + sendnam, sizeof(*sendnam)); + } + else if (procid == RPCMNT_MOUNT) + { + struct rpc_call_mount *callmsg = (struct rpc_call_mount *)call; + error = psock_sendto(so, callmsg, sizeof(*callmsg), flags, + sendnam, sizeof(*sendnam)); + } + } + + else if (prog == NFS_PROG) + { + switch (procid) + { + case NFSPROC_CREATE: + { + struct rpc_call_create *callmsg = (struct rpc_call_create *)call; + error = psock_sendto(so, callmsg, sizeof(*callmsg), flags, + sendnam, sizeof(*sendnam)); + } + break; + + case NFSPROC_READ: + { + struct rpc_call_read *callmsg = (struct rpc_call_read *)call; + error = psock_sendto(so, callmsg, sizeof(*callmsg), flags, + sendnam, sizeof(*sendnam)); + } + break; + + case NFSPROC_WRITE: + { + struct rpc_call_write *callmsg = (struct rpc_call_write *)call; + error = psock_sendto(so, callmsg, sizeof(*callmsg), flags, + sendnam, sizeof(*sendnam)); + } + break; + + case NFSPROC_READDIR: + { + struct rpc_call_readdir *callmsg = (struct rpc_call_readdir *)call; + error = psock_sendto(so, callmsg, sizeof(*callmsg), flags, + sendnam, sizeof(*sendnam)); + } + break; + + case NFSPROC_FSSTAT: + { + struct rpc_call_fs *callmsg = (struct rpc_call_fs *)call; + error = psock_sendto(so, callmsg, sizeof(*callmsg), flags, + sendnam, sizeof(*sendnam)); + } + break; + + case NFSPROC_REMOVE: + { + struct rpc_call_remove *callmsg = (struct rpc_call_remove *)call; + error = psock_sendto(so, callmsg, sizeof(*callmsg), flags, + sendnam, sizeof(*sendnam)); + } + break; + + case NFSPROC_MKDIR: + { + struct rpc_call_mkdir *callmsg = (struct rpc_call_mkdir *)call; + error = psock_sendto(so, callmsg, sizeof(*callmsg), flags, + sendnam, sizeof(*sendnam)); + } + break; + + case NFSPROC_RMDIR: + { + struct rpc_call_rmdir *callmsg = (struct rpc_call_rmdir *)call; + error = psock_sendto(so, callmsg, sizeof(*callmsg), flags, + sendnam, sizeof(*sendnam)); + } + break; + + case NFSPROC_RENAME: + { + struct rpc_call_rename *callmsg = (struct rpc_call_rename *)call; + error = psock_sendto(so, callmsg, sizeof(*callmsg), flags, + sendnam, sizeof(*sendnam)); + } + break; + + case NFSPROC_FSINFO: + { + struct rpc_call_fs *callmsg = (struct rpc_call_fs *)call; + error = psock_sendto(so, callmsg, sizeof(*callmsg), flags, + sendnam, sizeof(*sendnam)); + } + break; + + default: + break; + } + } + if (error < 0) { if (rep != NULL) @@ -335,7 +455,7 @@ rpcclnt_send(struct socket *so, struct sockaddr *nam, struct rpc_call *call, */ static int rpcclnt_receive(struct rpctask *rep, struct sockaddr *aname, - struct rpc_reply *reply, struct rpc_call *call) + void *reply)//, struct rpc_call *call) { struct socket *so; #ifdef CONFIG_NFS_TCPIP @@ -558,8 +678,8 @@ static int rpcclnt_receive(struct rpctask *rep, struct sockaddr *aname, */ static int -rpcclnt_reply(struct rpctask *myrep, struct rpc_call *call, //Here we need to make changes for debugging - struct rpc_reply *reply) +rpcclnt_reply(struct rpctask *myrep, struct rpc_reply_header *replyheader, //Here we need to make changes for debugging + void *reply) { struct rpctask *rep; struct rpcclnt *rpc = myrep->r_rpcclnt; @@ -587,7 +707,7 @@ rpcclnt_reply(struct rpctask *myrep, struct rpc_call *call, //Here we need to m #endif /* Get the next Rpc reply off the socket */ - error = rpcclnt_receive(myrep, rpc->rc_name, reply, call); + error = rpcclnt_receive(myrep, rpc->rc_name, reply);//, call); #ifdef CONFIG_NFS_TCPIP rpcclnt_rcvunlock(&rpc->rc_flag); #endif @@ -611,11 +731,13 @@ rpcclnt_reply(struct rpctask *myrep, struct rpc_call *call, //Here we need to m RPC_RETURN(error); } - /* Get the xid and check that it is an rpc reply */ + bcopy(reply, replyheader, sizeof(struct rpc_reply_header)); - rxid = reply->rp_xid; + /* Get the xid and check that it is an rpc replysvr */ - if (reply->rp_direction != rpc_reply) + rxid = replyheader->rp_xid; + + if (replyheader->rp_direction != rpc_reply) { rpcstats.rpcinvalid++; if (myrep->r_flags & TASK_GETONEREP) @@ -713,8 +835,8 @@ rpcclnt_reply(struct rpctask *myrep, struct rpc_call *call, //Here we need to m static int rpcclnt_sigintr( struct rpcclnt *rpc, struct rpctask *task, cthread_t *td) { - struct proc *p; - sigset_t tmpset; + struct proc *p; + sigset_t tmpset; if (rpc == NULL) { @@ -873,6 +995,7 @@ static uint32_t rpcclnt_proct(struct rpcclnt *rpc, uint32_t procid) return 0; } +#ifdef COMP static void rpcclnt_softterm(struct rpctask *task) { task->r_flags |= TASK_SOFTTERM; @@ -882,6 +1005,7 @@ static void rpcclnt_softterm(struct rpctask *task) task->r_flags &= ~TASK_SENT; } } +#endif /**************************************************************************** * Public Functions @@ -944,9 +1068,10 @@ int rpcclnt_connect(struct rpcclnt *rpc) struct sockaddr_in sin; struct sockaddr_in *sa; struct call_args_pmap sdata; - struct call_result_pmap *rdata; - struct call_result_mount *mdata; - struct rpc_reply reply; + struct call_args_mount mountd; + struct rpc_reply_pmap *rdata; + struct rpc_reply_mount *mdata; + void *reply = NULL; struct timeval tv; uint16_t tport; @@ -977,6 +1102,20 @@ int rpcclnt_connect(struct rpcclnt *rpc) rpc->rc_so = so; rpc->rc_soflags = so->s_flags; + /* Always set receive timeout to detect server crash and reconnect. + * Otherwise, we can get stuck in psock_receive forever. + */ + + tv.tv_sec = 1; + tv.tv_usec = 0; + + error = psock_setsockopt(rpc->rc_so, SOL_SOCKET, SO_RCVTIMEO, + (const void *)&tv, sizeof(tv)); + if (error != 0) + { + goto bad; + } + /* Some servers require that the client port be a reserved port * number. We always allocate a reserved port, as this prevents * filehandle disclosure through UDP port capture. @@ -1000,20 +1139,6 @@ int rpcclnt_connect(struct rpcclnt *rpc) goto bad; } - /* Always set receive timeout to detect server crash and reconnect. - * Otherwise, we can get stuck in psock_receive forever. - */ - - tv.tv_sec = 1; - tv.tv_usec = 0; - - error = psock_setsockopt(rpc->rc_so, SOL_SOCKET, SO_RCVTIMEO, - (const void *)&tv, sizeof(tv)); - if (error != 0) - { - goto bad; - } - /* Protocols that do not require connections may be optionally left * unconnected for servers that reply from a port other than * NFS_PORT. @@ -1036,27 +1161,28 @@ int rpcclnt_connect(struct rpcclnt *rpc) goto bad; } - /* Do the RPC to get a dynamic bounding with the server using ppmap */ - /* Get port number for MOUNTD. */ + /* Do the RPC to get a dynamic bounding with the server using ppmap. + * Get port number for MOUNTD. + */ + memset(&sdata, 0, sizeof(sdata)); sdata.prog = txdr_unsigned(RPCPROG_MNT); sdata.vers = txdr_unsigned(RPCMNT_VER1); sdata.proc = txdr_unsigned(IPPROTO_UDP); sdata.port = 0; - memset(&reply, 0, sizeof(reply)); - error = rpcclnt_request(rpc, PMAPPROC_GETPORT, PMAPPROG, PMAPVERS, - &reply, &sdata); + reply, (FAR const void *)&sdata); if (error != 0) { goto bad; } - rdata = (struct call_result_pmap *)reply.stat.where; - + rdata = (struct rpc_reply_pmap *)reply; + nvdbg("Port from the server %d\n", rdata->pmap.port); sa = (FAR struct sockaddr_in *)saddr; - sa->sin_port = rdata->port; + sa->sin_port = rdata->pmap.port; + nvdbg("Port in socket %d\n", sa->sin_port); error = psock_connect(rpc->rc_so, saddr, sizeof(*saddr)); if (error) @@ -1067,19 +1193,25 @@ int rpcclnt_connect(struct rpcclnt *rpc) /* Do RPC to mountd. */ - memset(&reply, 0, sizeof(reply)); + //memset(&reply, 0, sizeof(reply)); + nvdbg("remote path %s\n", rpc->rc_path); + memset(&mountd, 0, sizeof(mountd)); + mountd.rpath = rpc->rc_path; + mountd.len = sizeof(mountd.rpath); + nvdbg("path %s\n", mountd.rpath ); + nvdbg("len %d\n", mountd.len); error = rpcclnt_request(rpc, RPCMNT_MOUNT, RPCPROG_MNT, RPCMNT_VER1, - &reply, &rpc->rc_path); + reply, (FAR const void *)&mountd); if (error != 0) { goto bad; } - mdata = (struct call_result_mount *)reply.stat.where; - rpc->rc_fh = mdata->fhandle; + mdata = (struct rpc_reply_mount *)reply; + rpc->rc_fh = mdata->mount.fhandle; - if (mdata->problem) + if (mdata->mount.problem) { ndbg("error mounting with the server %d\n", error); goto bad; @@ -1166,9 +1298,9 @@ int rpcclnt_umount(struct rpcclnt *rpc) { struct sockaddr *saddr; struct sockaddr_in *sa; - struct rpc_reply reply; + void *reply; struct call_args_pmap sdata; - struct call_result_pmap *rdata; + struct rpc_reply_pmap *rdata; int error; saddr = rpc->rc_name; @@ -1190,10 +1322,10 @@ int rpcclnt_umount(struct rpcclnt *rpc) goto bad; } - rdata = (struct call_result_pmap *)reply.stat.where; + rdata = (struct rpc_reply_pmap *)reply; sa = (FAR struct sockaddr_in *)saddr; - sa->sin_port = rdata->port; + sa->sin_port = rdata->pmap.port; error = psock_connect(rpc->rc_so, saddr, sizeof(*saddr)); @@ -1205,10 +1337,10 @@ int rpcclnt_umount(struct rpcclnt *rpc) /* Do RPC to umountd. */ - memset(&reply, 0, sizeof(reply)); + //memset(&reply, 0, sizeof(reply)); error = rpcclnt_request(rpc, RPCMNT_UMOUNT, RPCPROG_MNT, RPCMNT_VER1, - &reply, &rpc->rc_path); + reply, &rpc->rc_path); if (error != 0) { goto bad; @@ -1245,29 +1377,134 @@ void rpcclnt_safedisconnect(struct rpcclnt *rpc) */ int rpcclnt_request(struct rpcclnt *rpc, int procnum, int prog, int version, - struct rpc_reply *reply, void *datain) + void *dataout, FAR const void *datain) { - struct rpc_call *callhost; - struct rpc_reply *replysvr; - struct rpctask *task; + struct rpc_reply_header *replymgs; + struct rpc_reply_header replyheader; + struct rpctask *task = NULL; + struct xidr value; + struct rpc_call_pmap pmap; + struct rpc_call_mount mountd; + struct rpc_call_create create; + struct rpc_call_write write; + struct rpc_call_read read; + struct rpc_call_remove removef; + struct rpc_call_rename renamef; + struct rpc_call_mkdir mkdir; + struct rpc_call_rmdir rmdir; + struct rpc_call_readdir readdir; + struct rpc_call_fs fs; + void *msgcall = NULL; int error = 0; - /* Create an instance of the call state structure */ + memset(&replyheader, 0, sizeof(replyheader)); - callhost = (struct rpc_call *)kzalloc(sizeof(struct rpc_call)); - if (!callhost) + if (prog == PMAPPROG) { - fdbg("Failed to allocate call msg structure\n"); - return -ENOMEM; + if (procnum == PMAPPROC_GETPORT) + { + memset(&pmap, 0, sizeof(struct rpc_call_pmap)); + msgcall = &pmap; + } + else if (procnum == PMAPPROC_UNSET) + { + memset(&pmap, 0, sizeof(struct rpc_call_pmap)); + msgcall = &pmap; + } } + else if (prog == RPCPROG_MNT) + { + if (procnum == RPCMNT_UMOUNT) + { + memset(&mountd, 0, sizeof(struct rpc_call_mount)); + msgcall = &mountd; + } + else if (procnum == RPCMNT_MOUNT) + { + memset(&mountd, 0, sizeof(struct rpc_call_mount)); + msgcall = &mountd; + } + } + else if (prog == NFS_PROG) + { + switch (procnum) + { + case NFSPROC_CREATE: + { + memset(&create, 0, sizeof(struct rpc_call_create)); + msgcall = &create; + } + break; - /* Create an instance of the reply state structure */ + case NFSPROC_READ: + { + memset(&read, 0, sizeof(struct rpc_call_read)); + msgcall = &read; + } + break; - replysvr = (struct rpc_reply *)kzalloc(sizeof(struct rpc_reply)); - if (!replysvr) - { - fdbg("Failed to allocate reply msg structure\n"); - return -ENOMEM; + case NFSPROC_WRITE: + { + memset(&write, 0, sizeof(struct rpc_call_write)); + msgcall = &write; + } + break; + + case NFSPROC_RENAME: + { + memset(&renamef, 0, sizeof(struct rpc_call_rename)); + msgcall = &renamef; + } + break; + + case NFSPROC_REMOVE: + { + memset(&removef, 0, sizeof(struct rpc_call_remove)); + msgcall = &removef; + } + break; + + case NFSPROC_MKDIR: + { + memset(&mkdir, 0, sizeof(struct rpc_call_mkdir)); + msgcall = &mkdir; + } + break; + + case NFSPROC_RMDIR: + { + memset(&rmdir, 0, sizeof(struct rpc_call_rmdir)); + msgcall = &rmdir; + } + break; + + case NFSPROC_READDIR: + { + memset(&readdir, 0, sizeof(struct rpc_call_readdir)); + msgcall = &readdir; + } + break; + + case NFSPROC_FSSTAT: + { + memset(&fs, 0, sizeof(struct rpc_call_fs)); + msgcall = &fs; + } + break; + + case NFSPROC_FSINFO: + { + memset(&fs, 0, sizeof(struct rpc_call_fs)); + msgcall = &fs; + } + break; + + default: + { + error = ESRCH; + goto rpcmout; + } + } } /* Create an instance of the task state structure */ @@ -1279,7 +1516,7 @@ int rpcclnt_request(struct rpcclnt *rpc, int procnum, int prog, int version, return -ENOMEM; } - error = rpcclnt_buildheader(rpc, procnum, prog, version, datain, callhost); + error = rpcclnt_buildheader(rpc, procnum, prog, version, &value, datain, msgcall); if (error) { ndbg("building call header error"); @@ -1287,7 +1524,7 @@ int rpcclnt_request(struct rpcclnt *rpc, int procnum, int prog, int version, } task->r_rpcclnt = rpc; - task->r_xid = callhost->rp_xid; + task->r_xid = value.xid; task->r_procnum = procnum; if (rpc->rc_flag & RPCCLNT_SOFT) @@ -1337,7 +1574,8 @@ int rpcclnt_request(struct rpcclnt *rpc, int procnum, int prog, int version, #endif if (error == 0) { - error = rpcclnt_send(rpc->rc_so, rpc->rc_name, callhost, task); + error = rpcclnt_send(rpc->rc_so, rpc->rc_name, procnum, prog, + msgcall, task); #ifdef CONFIG_NFS_TCPIP if (rpc->rc_soflags & PR_CONNREQUIRED) @@ -1362,7 +1600,7 @@ int rpcclnt_request(struct rpcclnt *rpc, int procnum, int prog, int version, if (error == 0 || error == EPIPE) { - error = rpcclnt_reply(task, callhost, replysvr); + error = rpcclnt_reply(task, &replyheader, dataout); } nvdbg("out for reply %d\n", error); @@ -1385,23 +1623,25 @@ int rpcclnt_request(struct rpcclnt *rpc, int procnum, int prog, int version, /* Break down the rpc header and check if ok */ - reply->stat.type = fxdr_unsigned(uint32_t, replysvr->stat.type); - if (reply->stat.type == RPC_MSGDENIED) + nvdbg("Breakdown msg \n"); + memset(&replymgs, 0, sizeof(replymgs)); + replymgs->stat.type = fxdr_unsigned(uint32_t, replyheader.stat.type); + if (replymgs->stat.type == RPC_MSGDENIED) { - reply->stat.status = fxdr_unsigned(uint32_t, replysvr->stat.status); - switch (reply->stat.status) + replymgs->stat.status = fxdr_unsigned(uint32_t, replyheader.stat.status); + switch (replymgs->stat.status) { case RPC_MISMATCH: - reply->stat.mismatch_info.low = - fxdr_unsigned(uint32_t, replysvr->stat.mismatch_info.low); - reply->stat.mismatch_info.high = - fxdr_unsigned(uint32_t, replysvr->stat.mismatch_info.high); + replymgs->stat.mismatch_info.low = + fxdr_unsigned(uint32_t, replyheader.stat.mismatch_info.low); + replymgs->stat.mismatch_info.high = + fxdr_unsigned(uint32_t, replyheader.stat.mismatch_info.high); ndbg("RPC_MSGDENIED: RPC_MISMATCH error"); error = EOPNOTSUPP; break; case RPC_AUTHERR: - reply->stat.autherr = fxdr_unsigned(uint32_t, replysvr->stat.autherr); + replymgs->stat.autherr = fxdr_unsigned(uint32_t, replyheader.stat.autherr); ndbg("RPC_MSGDENIED: RPC_AUTHERR error"); error = EACCES; break; @@ -1412,7 +1652,7 @@ int rpcclnt_request(struct rpcclnt *rpc, int procnum, int prog, int version, } goto rpcmout; } - else if (reply->stat.type != RPC_MSGACCEPTED) + else if (replymgs->stat.type != RPC_MSGACCEPTED) { error = EOPNOTSUPP; goto rpcmout; @@ -1420,39 +1660,38 @@ int rpcclnt_request(struct rpcclnt *rpc, int procnum, int prog, int version, /* Verifier */ - reply->rpc_verfi.authtype = - fxdr_unsigned(uint32_t, replysvr->rpc_verfi.authtype); - reply->rpc_verfi.authlen = - fxdr_unsigned(uint32_t, replysvr->rpc_verfi.authlen); + replymgs->rpc_verfi.authtype = + fxdr_unsigned(enum auth_flavor, replyheader.rpc_verfi.authtype); + replymgs->rpc_verfi.authlen = + fxdr_unsigned(uint32_t, replyheader.rpc_verfi.authlen); - if (reply->stat.status == RPC_SUCCESS) + if (replymgs->stat.status == RPC_SUCCESS) { nvdbg("RPC_SUCCESS"); - reply->stat.where = replysvr->stat.where; } - else if (reply->stat.status == RPC_PROGMISMATCH) + else if (replymgs->stat.status == RPC_PROGMISMATCH) { - reply->stat.mismatch_info.low = - fxdr_unsigned(uint32_t, replysvr->stat.mismatch_info.low); - reply->stat.mismatch_info.high = - fxdr_unsigned(uint32_t, replysvr->stat.mismatch_info.high); + replymgs->stat.mismatch_info.low = + fxdr_unsigned(uint32_t, replyheader.stat.mismatch_info.low); + replymgs->stat.mismatch_info.high = + fxdr_unsigned(uint32_t, replyheader.stat.mismatch_info.high); ndbg("RPC_MSGACCEPTED: RPC_PROGMISMATCH error"); error = EOPNOTSUPP; } - else if (reply->stat.status > 5) + else if (replymgs->stat.status > 5) { error = EOPNOTSUPP; goto rpcmout; } rpcmout: - kfree(callhost); - kfree(replysvr); kfree(task); RPC_RETURN(error); } +#undef COMP +#ifdef COMP /* Nfs timer routine Scan the nfsreq list and retranmit any requests that * have timed out To avoid retransmission attempts on STREAM sockets (in the * future) make sure to set the r_retry field to 0 (implies nm_retry == 0). @@ -1547,9 +1786,8 @@ void rpcclnt_timer(void *arg, struct rpc_call *call) } else { - error = - psock_sendto(so, call, sizeof(*call), 0, rpc->rc_name, - sizeof(*rpc->rc_name)); + error = psock_sendto(so, call, sizeof(*call), 0, rpc->rc_name, + sizeof(*rpc->rc_name)); } if (!error) @@ -1588,15 +1826,14 @@ void rpcclnt_timer(void *arg, struct rpc_call *call) // rpcclnt_timer_handle = timeout(rpcclnt_timer, NULL, rpcclnt_ticks); } +#endif /* Build the RPC header and fill in the authorization info. */ int rpcclnt_buildheader(struct rpcclnt *rpc, int procid, int prog, int vers, - void *datain, struct rpc_call *call) + struct xidr *value, FAR const void *datain, + void *dataout) { -#ifdef CONFIG_NFS_UNIX_AUTH - struct timeval tv; -#endif srand(time(NULL)); int xidp = 0; @@ -1620,37 +1857,453 @@ int rpcclnt_buildheader(struct rpcclnt *rpc, int procid, int prog, int vers, rpcclnt_xid += xidp; } - call->rp_xid = txdr_unsigned(rpcclnt_xid); - call->rp_direction = rpc_call; - call->rp_rpcvers = rpc_vers; - call->rp_prog = txdr_unsigned(prog); - call->rp_vers = txdr_unsigned(vers); - call->rp_proc = txdr_unsigned(procid); - call->data = datain; + /* Perform the binding depending on the protocol type */ + + if (prog == PMAPPROG) + { + if (procid == PMAPPROC_GETPORT) + { + struct rpc_call_pmap *callmsg = (struct rpc_call_pmap *)dataout; + bcopy(datain, &callmsg->pmap, sizeof(struct call_args_pmap)); - /* rpc_auth part (auth_unix as root) */ + callmsg->ch.rp_xid = txdr_unsigned(rpcclnt_xid); + value->xid = callmsg->ch.rp_xid; + callmsg->ch.rp_direction = rpc_call; + callmsg->ch.rp_rpcvers = rpc_vers; + callmsg->ch.rp_prog = txdr_unsigned(prog); + callmsg->ch.rp_vers = txdr_unsigned(vers); + callmsg->ch.rp_proc = txdr_unsigned(procid); - call->rpc_auth.authtype = rpc_auth_null; - call->rpc_auth.authlen = txdr_unsigned(sizeof(NULL)); + /* rpc_auth part (auth_unix as root) */ + callmsg->ch.rpc_auth.authtype = rpc_auth_null; + //call->rpc_auth.authlen = 0; #ifdef CONFIG_NFS_UNIX_AUTH - tv.tv_sec = 1; - tv.tv_usec = 0; - call->rpc_unix.ua_time = txdr_unsigned(&tv->tv_sec); - call->rpc_unix.ua_hostname = 0; - call->rpc_unix.ua_uid = geteuid(); - call->rpc_unix.ua_gid = getegid(); - call->rpc_unix.ua_gidlist = 0; + callmsg->ch.rpc_unix.stamp = txdr_unsigned(1); + callmsg->ch.rpc_unix.hostname = 0; + callmsg->ch.rpc_unix.uid = setuid; + callmsg->ch.rpc_unix.gid = setgid; + callmsg->ch.rpc_unix.gidlist = 0; #endif + /* rpc_verf part (auth_null) */ - /* rpc_verf part (auth_null) */ + callmsg->ch.rpc_verf.authtype = rpc_auth_null; + //call->rpc_verf.authlen = 0; + return 0; + } + else if (procid == PMAPPROC_UNSET) + { + struct rpc_call_pmap *callmsg = (struct rpc_call_pmap *)dataout;; + bcopy(datain, &callmsg->pmap, sizeof(struct call_args_pmap)); + callmsg->ch.rp_xid = txdr_unsigned(rpcclnt_xid); + value->xid = callmsg->ch.rp_xid; + callmsg->ch.rp_direction = rpc_call; + callmsg->ch.rp_rpcvers = rpc_vers; + callmsg->ch.rp_prog = txdr_unsigned(prog); + callmsg->ch.rp_vers = txdr_unsigned(vers); + callmsg->ch.rp_proc = txdr_unsigned(procid); + + /* rpc_auth part (auth_unix as root) */ + + callmsg->ch.rpc_auth.authtype = rpc_auth_null; + //call->rpc_auth.authlen = 0; +#ifdef CONFIG_NFS_UNIX_AUTH + callmsg->ch.rpc_unix.stamp = txdr_unsigned(1); + callmsg->ch.rpc_unix.hostname = 0; + callmsg->ch.rpc_unix.uid = setuid; + callmsg->ch.rpc_unix.gid = setgid; + callmsg->ch.rpc_unix.gidlist = 0; +#endif + /* rpc_verf part (auth_null) */ - call->rpc_verf.authtype = 0; - call->rpc_verf.authlen = 0; + callmsg->ch.rpc_verf.authtype = rpc_auth_null; + //call->rpc_verf.authlen = 0; + return 0; + } + } + else if (prog == RPCPROG_MNT) + { + if (procid == RPCMNT_UMOUNT) + { + struct rpc_call_mount *callmsg = (struct rpc_call_mount *)dataout; + bcopy(datain, &callmsg->mount, sizeof(struct call_args_mount)); + callmsg->ch.rp_xid = txdr_unsigned(rpcclnt_xid); + value->xid = callmsg->ch.rp_xid; + callmsg->ch.rp_direction = rpc_call; + callmsg->ch.rp_rpcvers = rpc_vers; + callmsg->ch.rp_prog = txdr_unsigned(prog); + callmsg->ch.rp_vers = txdr_unsigned(vers); + callmsg->ch.rp_proc = txdr_unsigned(procid); + + /* rpc_auth part (auth_unix as root) */ + + callmsg->ch.rpc_auth.authtype = rpc_auth_null; + //call->rpc_auth.authlen = 0; +#ifdef CONFIG_NFS_UNIX_AUTH + callmsg->ch.rpc_unix.stamp = txdr_unsigned(1); + callmsg->ch.rpc_unix.hostname = 0; + callmsg->ch.rpc_unix.uid = setuid; + callmsg->ch.rpc_unix.gid = setgid; + callmsg->ch.rpc_unix.gidlist = 0; +#endif + /* rpc_verf part (auth_null) */ - return 0; + callmsg->ch.rpc_verf.authtype = rpc_auth_null; + //call->rpc_verf.authlen = 0; + return 0; + } + else if (procid == RPCMNT_MOUNT) + { + struct rpc_call_mount *callmsg = (struct rpc_call_mount *)dataout; + bcopy(datain, &callmsg->mount, sizeof(struct call_args_mount)); + callmsg->ch.rp_xid = txdr_unsigned(rpcclnt_xid); + value->xid = callmsg->ch.rp_xid; + callmsg->ch.rp_direction = rpc_call; + callmsg->ch.rp_rpcvers = rpc_vers; + callmsg->ch.rp_prog = txdr_unsigned(prog); + callmsg->ch.rp_vers = txdr_unsigned(vers); + callmsg->ch.rp_proc = txdr_unsigned(procid); + + /* rpc_auth part (auth_unix as root) */ + + callmsg->ch.rpc_auth.authtype = rpc_auth_null; + //call->rpc_auth.authlen = 0; +#ifdef CONFIG_NFS_UNIX_AUTH + callmsg->ch.rpc_unix.stamp = txdr_unsigned(1); + callmsg->ch.rpc_unix.hostname = 0; + callmsg->ch.rpc_unix.uid = setuid; + callmsg->ch.rpc_unix.gid = setgid; + callmsg->ch.rpc_unix.gidlist = 0; +#endif + /* rpc_verf part (auth_null) */ + + callmsg->ch.rpc_verf.authtype = rpc_auth_null; + //call->rpc_verf.authlen = 0; + return 0; + } + } + else if (prog == NFS_PROG) + { + switch (procid) + { + case NFSPROC_CREATE: + { + struct rpc_call_create *callmsg = (struct rpc_call_create *)dataout; + bcopy(datain, &callmsg->create, sizeof(struct CREATE3args)); + callmsg->ch.rp_xid = txdr_unsigned(rpcclnt_xid); + value->xid = callmsg->ch.rp_xid; + callmsg->ch.rp_direction = rpc_call; + callmsg->ch.rp_rpcvers = rpc_vers; + callmsg->ch.rp_prog = txdr_unsigned(prog); + callmsg->ch.rp_vers = txdr_unsigned(vers); + callmsg->ch.rp_proc = txdr_unsigned(procid); + + /* rpc_auth part (auth_unix as root) */ + + callmsg->ch.rpc_auth.authtype = rpc_auth_null; + //call->rpc_auth.authlen = 0; +#ifdef CONFIG_NFS_UNIX_AUTH + callmsg->ch.rpc_unix.stamp = txdr_unsigned(1); + callmsg->ch.rpc_unix.hostname = 0; + callmsg->ch.rpc_unix.uid = setuid; + callmsg->ch.rpc_unix.gid = setgid; + callmsg->ch.rpc_unix.gidlist = 0; +#endif + /* rpc_verf part (auth_null) */ + + callmsg->ch.rpc_verf.authtype = rpc_auth_null; + //call->rpc_verf.authlen = 0; + return 0; + } + + case NFSPROC_READ: + { + struct rpc_call_read *callmsg = (struct rpc_call_read *)dataout; + bcopy(datain, &callmsg->read, sizeof(struct READ3args)); + callmsg->ch.rp_xid = txdr_unsigned(rpcclnt_xid); + value->xid = callmsg->ch.rp_xid; + callmsg->ch.rp_direction = rpc_call; + callmsg->ch.rp_rpcvers = rpc_vers; + callmsg->ch.rp_prog = txdr_unsigned(prog); + callmsg->ch.rp_vers = txdr_unsigned(vers); + callmsg->ch.rp_proc = txdr_unsigned(procid); + + /* rpc_auth part (auth_unix as root) */ + + callmsg->ch.rpc_auth.authtype = rpc_auth_null; + //call->rpc_auth.authlen = 0; + +#ifdef CONFIG_NFS_UNIX_AUTH + callmsg->ch.rpc_unix.stamp = txdr_unsigned(1); + callmsg->ch.rpc_unix.hostname = 0; + callmsg->ch.rpc_unix.uid = setuid; + callmsg->ch.rpc_unix.gid = setgid; + callmsg->ch.rpc_unix.gidlist = 0; +#endif + /* rpc_verf part (auth_null) */ + + callmsg->ch.rpc_verf.authtype = rpc_auth_null; + //call->rpc_verf.authlen = 0; + return 0; + } + + case NFSPROC_WRITE: + { + struct rpc_call_write *callmsg = (struct rpc_call_write *)dataout; + bcopy(datain, &callmsg->write, sizeof(struct WRITE3args)); + callmsg->ch.rp_xid = txdr_unsigned(rpcclnt_xid); + value->xid = callmsg->ch.rp_xid; + callmsg->ch.rp_direction = rpc_call; + callmsg->ch.rp_rpcvers = rpc_vers; + callmsg->ch.rp_prog = txdr_unsigned(prog); + callmsg->ch.rp_vers = txdr_unsigned(vers); + callmsg->ch.rp_proc = txdr_unsigned(procid); + + /* rpc_auth part (auth_unix as root) */ + + callmsg->ch.rpc_auth.authtype = rpc_auth_null; + //call->rpc_auth.authlen = 0; + +#ifdef CONFIG_NFS_UNIX_AUTH + callmsg->ch.rpc_unix.stamp = txdr_unsigned(1); + callmsg->ch.rpc_unix.hostname = 0; + callmsg->ch.rpc_unix.uid = setuid; + callmsg->ch.rpc_unix.gid = setgid; + callmsg->ch.rpc_unix.gidlist = 0; +#endif + /* rpc_verf part (auth_null) */ + + callmsg->ch.rpc_verf.authtype = rpc_auth_null; + //call->rpc_verf.authlen = 0; + return 0; + } + + case NFSPROC_READDIR: + { + struct rpc_call_readdir *callmsg = (struct rpc_call_readdir *)dataout; + bcopy(datain, &callmsg->readdir, sizeof(struct READDIR3args)); + callmsg->ch.rp_xid = txdr_unsigned(rpcclnt_xid); + value->xid = callmsg->ch.rp_xid; + callmsg->ch.rp_direction = rpc_call; + callmsg->ch.rp_rpcvers = rpc_vers; + callmsg->ch.rp_prog = txdr_unsigned(prog); + callmsg->ch.rp_vers = txdr_unsigned(vers); + callmsg->ch.rp_proc = txdr_unsigned(procid); + + /* rpc_auth part (auth_unix as root) */ + + callmsg->ch.rpc_auth.authtype = rpc_auth_null; + //call->rpc_auth.authlen = 0; + +#ifdef CONFIG_NFS_UNIX_AUTH + callmsg->ch.rpc_unix.stamp = txdr_unsigned(1); + callmsg->ch.rpc_unix.hostname = 0; + callmsg->ch.rpc_unix.uid = setuid; + callmsg->ch.rpc_unix.gid = setgid; + callmsg->ch.rpc_unix.gidlist = 0; +#endif + /* rpc_verf part (auth_null) */ + + callmsg->ch.rpc_verf.authtype = rpc_auth_null; + //call->rpc_verf.authlen = 0; + return 0; + } + + case NFSPROC_FSSTAT: + { + struct rpc_call_fs *callmsg = (struct rpc_call_fs *)dataout; + bcopy(datain, &callmsg->fs, sizeof(struct FS3args)); + callmsg->ch.rp_xid = txdr_unsigned(rpcclnt_xid); + value->xid = callmsg->ch.rp_xid; + callmsg->ch.rp_direction = rpc_call; + callmsg->ch.rp_rpcvers = rpc_vers; + callmsg->ch.rp_prog = txdr_unsigned(prog); + callmsg->ch.rp_vers = txdr_unsigned(vers); + callmsg->ch.rp_proc = txdr_unsigned(procid); + + /* rpc_auth part (auth_unix as root) */ + + callmsg->ch.rpc_auth.authtype = rpc_auth_null; + //call->rpc_auth.authlen = 0; + +#ifdef CONFIG_NFS_UNIX_AUTH + callmsg->ch.rpc_unix.stamp = txdr_unsigned(1); + callmsg->ch.rpc_unix.hostname = 0; + callmsg->ch.rpc_unix.uid = setuid; + callmsg->ch.rpc_unix.gid = setgid; + callmsg->ch.rpc_unix.gidlist = 0; +#endif + /* rpc_verf part (auth_null) */ + + callmsg->ch.rpc_verf.authtype = rpc_auth_null; + //call->rpc_verf.authlen = 0; + return 0; + } + + case NFSPROC_REMOVE: + { + struct rpc_call_remove *callmsg = (struct rpc_call_remove *)dataout; + bcopy(datain, &callmsg->remove, sizeof(struct REMOVE3args)); + callmsg->ch.rp_xid = txdr_unsigned(rpcclnt_xid); + value->xid = callmsg->ch.rp_xid; + callmsg->ch.rp_direction = rpc_call; + callmsg->ch.rp_rpcvers = rpc_vers; + callmsg->ch.rp_prog = txdr_unsigned(prog); + callmsg->ch.rp_vers = txdr_unsigned(vers); + callmsg->ch.rp_proc = txdr_unsigned(procid); + + /* rpc_auth part (auth_unix as root) */ + + callmsg->ch.rpc_auth.authtype = rpc_auth_null; + //call->rpc_auth.authlen = 0; + +#ifdef CONFIG_NFS_UNIX_AUTH + callmsg->ch.rpc_unix.stamp = txdr_unsigned(1); + callmsg->ch.rpc_unix.hostname = 0; + callmsg->ch.rpc_unix.uid = setuid; + callmsg->ch.rpc_unix.gid = setgid; + callmsg->ch.rpc_unix.gidlist = 0; +#endif + /* rpc_verf part (auth_null) */ + + callmsg->ch.rpc_verf.authtype = rpc_auth_null; + //call->rpc_verf.authlen = 0; + return 0; + } + + case NFSPROC_MKDIR: + { + struct rpc_call_mkdir *callmsg = (struct rpc_call_mkdir *)dataout; + bcopy(datain, &callmsg->mkdir, sizeof(struct MKDIR3args)); + callmsg->ch.rp_xid = txdr_unsigned(rpcclnt_xid); + value->xid = callmsg->ch.rp_xid; + callmsg->ch.rp_direction = rpc_call; + callmsg->ch.rp_rpcvers = rpc_vers; + callmsg->ch.rp_prog = txdr_unsigned(prog); + callmsg->ch.rp_vers = txdr_unsigned(vers); + callmsg->ch.rp_proc = txdr_unsigned(procid); + + /* rpc_auth part (auth_unix as root) */ + + callmsg->ch.rpc_auth.authtype = rpc_auth_null; + //call->rpc_auth.authlen = 0; + +#ifdef CONFIG_NFS_UNIX_AUTH + callmsg->ch.rpc_unix.stamp = txdr_unsigned(1); + callmsg->ch.rpc_unix.hostname = 0; + callmsg->ch.rpc_unix.uid = setuid; + callmsg->ch.rpc_unix.gid = setgid; + callmsg->ch.rpc_unix.gidlist = 0; +#endif + /* rpc_verf part (auth_null) */ + + callmsg->ch.rpc_verf.authtype = rpc_auth_null; + //call->rpc_verf.authlen = 0; + return 0; + } + + case NFSPROC_RMDIR: + { + struct rpc_call_rmdir *callmsg = (struct rpc_call_rmdir *)dataout; + bcopy(datain, &callmsg->rmdir, sizeof(struct RMDIR3args)); + callmsg->ch.rp_xid = txdr_unsigned(rpcclnt_xid); + value->xid = callmsg->ch.rp_xid; + callmsg->ch.rp_direction = rpc_call; + callmsg->ch.rp_rpcvers = rpc_vers; + callmsg->ch.rp_prog = txdr_unsigned(prog); + callmsg->ch.rp_vers = txdr_unsigned(vers); + callmsg->ch.rp_proc = txdr_unsigned(procid); + + /* rpc_auth part (auth_unix as root) */ + + callmsg->ch.rpc_auth.authtype = rpc_auth_null; + //call->rpc_auth.authlen = 0; + +#ifdef CONFIG_NFS_UNIX_AUTH + callmsg->ch.rpc_unix.stamp = txdr_unsigned(1); + callmsg->ch.rpc_unix.hostname = 0; + callmsg->ch.rpc_unix.uid = setuid; + callmsg->ch.rpc_unix.gid = setgid; + callmsg->ch.rpc_unix.gidlist = 0; +#endif + /* rpc_verf part (auth_null) */ + + callmsg->ch.rpc_verf.authtype = rpc_auth_null; + //call->rpc_verf.authlen = 0; + return 0; + } + + case NFSPROC_RENAME: + { + struct rpc_call_rename *callmsg = (struct rpc_call_rename *)dataout; + bcopy(datain, &callmsg->rename, sizeof(struct RENAME3args)); + callmsg->ch.rp_xid = txdr_unsigned(rpcclnt_xid); + value->xid = callmsg->ch.rp_xid; + callmsg->ch.rp_direction = rpc_call; + callmsg->ch.rp_rpcvers = rpc_vers; + callmsg->ch.rp_prog = txdr_unsigned(prog); + callmsg->ch.rp_vers = txdr_unsigned(vers); + callmsg->ch.rp_proc = txdr_unsigned(procid); + + /* rpc_auth part (auth_unix as root) */ + + callmsg->ch.rpc_auth.authtype = rpc_auth_null; + //call->rpc_auth.authlen = 0; + +#ifdef CONFIG_NFS_UNIX_AUTH + callmsg->ch.rpc_unix.stamp = txdr_unsigned(1); + callmsg->ch.rpc_unix.hostname = 0; + callmsg->ch.rpc_unix.uid = setuid; + callmsg->ch.rpc_unix.gid = setgid; + callmsg->ch.rpc_unix.gidlist = 0; +#endif + /* rpc_verf part (auth_null) */ + + callmsg->ch.rpc_verf.authtype = rpc_auth_null; + //call->rpc_verf.authlen = 0; + return 0; + } + + case NFSPROC_FSINFO: + { + struct rpc_call_fs *callmsg = (struct rpc_call_fs *)dataout; + bcopy(datain, &callmsg->fs, sizeof(struct FS3args)); + callmsg->ch.rp_xid = txdr_unsigned(rpcclnt_xid); + value->xid = callmsg->ch.rp_xid; + callmsg->ch.rp_direction = rpc_call; + callmsg->ch.rp_rpcvers = rpc_vers; + callmsg->ch.rp_prog = txdr_unsigned(prog); + callmsg->ch.rp_vers = txdr_unsigned(vers); + callmsg->ch.rp_proc = txdr_unsigned(procid); + + /* rpc_auth part (auth_unix as root) */ + + callmsg->ch.rpc_auth.authtype = rpc_auth_null; + //call->rpc_auth.authlen = 0; + +#ifdef CONFIG_NFS_UNIX_AUTH + callmsg->ch.rpc_unix.stamp = txdr_unsigned(1); + callmsg->ch.rpc_unix.hostname = 0; + callmsg->ch.rpc_unix.uid = setuid; + callmsg->ch.rpc_unix.gid = setgid; + callmsg->ch.rpc_unix.gidlist = 0; +#endif + /* rpc_verf part (auth_null) */ + + callmsg->ch.rpc_verf.authtype = rpc_auth_null; + //call->rpc_verf.authlen = 0; + return 0; + } + + default: + break; + } + } + + return ESRCH; } +#ifdef COMP int rpcclnt_cancelreqs(struct rpcclnt *rpc) { struct rpctask *task; @@ -1687,3 +2340,4 @@ int rpcclnt_cancelreqs(struct rpcclnt *rpc) return EBUSY; } #endif +#endif diff --git a/nuttx/include/nuttx/fs/nfs.h b/nuttx/include/nuttx/fs/nfs.h index 431c1d130..4e009fb77 100644 --- a/nuttx/include/nuttx/fs/nfs.h +++ b/nuttx/include/nuttx/fs/nfs.h @@ -93,6 +93,7 @@ #define NFS_ARGSVERSION 3 /* change when nfs_args changes */ #define NFS_MAXFHSIZE 64 #define NFS_PORT 2049 +#define NFS_PMAPPORT 111 /**************************************************************************** * Public Types @@ -123,10 +124,10 @@ struct nfs_args int readdirsize; /* readdir size in bytes */ int timeo; /* initial timeout in .1 secs */ int retrans; /* times to retry send */ - int maxgrouplist; /* Max. size of group list */ - int readahead; /* # of blocks to readahead */ - int leaseterm; /* Term (sec) of lease */ - int deadthresh; /* Retrans threshold */ +//int maxgrouplist; /* Max. size of group list */ +//int readahead; /* # of blocks to readahead */ +//int leaseterm; /* Term (sec) of lease */ +//int deadthresh; /* Retrans threshold */ char *path; /* server's path of the directory being mount */ int acregmin; /* cache attrs for reg files min time */ int acregmax; /* cache attrs for reg files max time */ |