From a82c594ec12e6950e7bec190871361fcf95604e8 Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 20 Apr 2012 23:15:41 +0000 Subject: More NFS updates git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4638 42af7a65-404d-4744-a932-0658087f49c3 --- apps/nshlib/nsh_fscmds.c | 131 +++++++++++++++++++++++++++++++++++++++++++++- apps/nshlib/nsh_parse.c | 9 +++- nuttx/fs/fs_mount.c | 8 ++- nuttx/fs/nfs/nfs_args.h | 2 +- nuttx/fs/nfs/nfs_mount.h | 2 +- nuttx/fs/nfs/nfs_proto.h | 2 +- nuttx/fs/nfs/nfs_socket.c | 26 ++++++--- nuttx/fs/nfs/nfs_socket.h | 23 +++----- nuttx/fs/nfs/nfs_util.c | 16 ++---- nuttx/fs/nfs/nfs_vfsops.c | 49 +++++++++-------- 10 files changed, 201 insertions(+), 67 deletions(-) diff --git a/apps/nshlib/nsh_fscmds.c b/apps/nshlib/nsh_fscmds.c index 56a52737a..b3c394834 100644 --- a/apps/nshlib/nsh_fscmds.c +++ b/apps/nshlib/nsh_fscmds.c @@ -1174,7 +1174,7 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) return ERROR; } - /* The source and target pathes might be relative to the current + /* The source and target paths might be relative to the current * working directory. */ @@ -1185,7 +1185,7 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) } target = nsh_getfullpath(vtbl, argv[optind+1]); - if (!source) + if (!target) { nsh_freefullpath(source); return ERROR; @@ -1206,6 +1206,133 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) #endif #endif +/**************************************************************************** + * Name: cmd_nfsmount + ****************************************************************************/ + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && \ + defined(CONFIG_FS_READABLE) && defined(CONFIG_NET) && defined(CONFIG_NFS) +#ifndef CONFIG_NSH_DISABLE_NFSMOUNT +int cmd_nfsmount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + struct nfs_args data; + FAR char *address; + FAR char *target; + FAR char *protocol = NULL; + bool badarg = false; +#ifdef CONFIG_NET_IPv6 + struct in6_addr inaddr; +#else + struct in_addr inaddr: +#endif + int ret; + + /* Get the NFS mount options */ + + int option; + while ((option = getopt(argc, argv, ":p:")) != ERROR) + { + switch (option) + { + /* Protocol may be UDP or TCP/IP */ + + case 'p': + protocol = optarg; + break; + + /* Handle missing required arguments */ + + case ':': + nsh_output(vtbl, g_fmtargrequired, argv[0]); + badarg = true; + break; + + /* Handle unrecognized arguments */ + + case '?': + default: + nsh_output(vtbl, g_fmtarginvalid, argv[0]); + badarg = true; + break; + } + } + + /* If a bad argument was encountered, then return without processing the + * command. + */ + + if (badarg) + { + return ERROR; + } + + /* There are two required arguments after the options: (1) The NFS server IP + * address and then (1) the path to the mount point. + */ + + if (optind + 2 < argc) + { + nsh_output(vtbl, g_fmttoomanyargs, argv[0]); + return ERROR; + } + else if (optind + 2 > argc) + { + nsh_output(vtbl, g_fmtargrequired, argv[0]); + return ERROR; + } + + /* The next argument on the command line should be the NFS server IP address + * in standard IPv4 (or IPv6) dot format. + */ + + address = argv[optind]; + if (!address) + { + return ERROR; + } + + /* The target mount point path might be relative to the current working + * directory. + */ + + target = nsh_getfullpath(vtbl, argv[optind+1]); + if (!target) + { + return ERROR; + } + + /* Convert the IP address string into its binary form */ + +#ifdef CONFIG_NET_IPv6 + ret = inet_pton(AF_INET, address, &inaddr); +#else + ret = inet_pton(AF_INET6, address, &inaddr); +#endif + if (ret != 1) + { + nsh_freefullpath(target); + return ERROR; + } + + /* Place all of the NFS arguements into the nfs_args structure */ +#warning "Missing logic" + + /* Perform the mount */ + + ret = mount(NULL, target, "nfs", 0, (FAR void *)&data); + if (ret < 0) + { + nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mount", NSH_ERRNO); + } + + /* We no longer need the allocated mount point path */ + + nsh_freefullpath(target); + return ret; +} +#endif +#endif + /**************************************************************************** * Name: cmd_rm ****************************************************************************/ diff --git a/apps/nshlib/nsh_parse.c b/apps/nshlib/nsh_parse.c index 67d529013..218f6aad9 100644 --- a/apps/nshlib/nsh_parse.c +++ b/apps/nshlib/nsh_parse.c @@ -259,7 +259,7 @@ static const struct cmdmap_s g_cmdmap[] = #if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_READABLE) # ifndef CONFIG_NSH_DISABLE_MOUNT - { "mount", cmd_mount, 4, 5, "-t " }, + { "mount", cmd_mount, 4, 5, "-t " }, # endif #endif @@ -267,6 +267,13 @@ static const struct cmdmap_s g_cmdmap[] = { "mw", cmd_mw, 2, 3, "[=][ ]" }, #endif +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && \ + defined(CONFIG_FS_READABLE) && defined(CONFIG_NET) && defined(CONFIG_NFS) +# ifndef CONFIG_NSH_DISABLE_NFSMOUNT + { "nfsmount", cmd_nfsmount, 3, 5, "[-p ] " }, +# endif +#endif + #if defined(CONFIG_NET) && defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING) && \ !defined(CONFIG_DISABLE_CLOCK) && !defined(CONFIG_DISABLE_SIGNALS) # ifndef CONFIG_NSH_DISABLE_PING diff --git a/nuttx/fs/fs_mount.c b/nuttx/fs/fs_mount.c index cdb60592a..a7b871aaf 100644 --- a/nuttx/fs/fs_mount.c +++ b/nuttx/fs/fs_mount.c @@ -78,7 +78,7 @@ /* These file systems do not require block drivers */ -#if defined(CONFIG_FS_NXFFS) || defined(CONFIG_APPS_BINDIR) +#if defined(CONFIG_FS_NXFFS) || defined(CONFIG_APPS_BINDIR) || defined(CONFIG_NFS) # define NONBDFS_SUPPORT #endif @@ -120,12 +120,18 @@ static const struct fsmap_t g_bdfsmap[] = #ifdef CONFIG_FS_NXFFS extern const struct mountpt_operations nxffs_operations; #endif +#ifdef CONFIG_NFS +extern const struct mountpt_operations nfs_operations; +#endif static const struct fsmap_t g_nonbdfsmap[] = { #ifdef CONFIG_FS_NXFFS { "nxffs", &nxffs_operations }, #endif +#ifdef CONFIG_NFS + { "nfs", &nfs_operations }, +#endif #ifdef CONFIG_APPS_BINDIR { "binfs", &binfs_operations }, #endif diff --git a/nuttx/fs/nfs/nfs_args.h b/nuttx/fs/nfs/nfs_args.h index fd81968f4..9a8dfd980 100644 --- a/nuttx/fs/nfs/nfs_args.h +++ b/nuttx/fs/nfs/nfs_args.h @@ -116,7 +116,7 @@ struct nfs_args int readahead; /* # of blocks to readahead */ int leaseterm; /* Term (sec) of lease */ int deadthresh; /* Retrans threshold */ - char *hostname; /* server's name */ +//char *hostname; /* server's name */ int acregmin; /* cache attrs for reg files min time */ int acregmax; /* cache attrs for reg files max time */ int acdirmin; /* cache attrs for dirs min time */ diff --git a/nuttx/fs/nfs/nfs_mount.h b/nuttx/fs/nfs/nfs_mount.h index a07963a43..29aed1d13 100644 --- a/nuttx/fs/nfs/nfs_mount.h +++ b/nuttx/fs/nfs/nfs_mount.h @@ -68,7 +68,7 @@ struct nfsmount { int nm_flag; /* Flags for soft/hard... */ int nm_state; /* Internal state flags */ - struct inode *nm_blkdriver; /* Vfs structure for this filesystem */ +//struct inode *nm_blkdriver; /* Vfs structure for this filesystem */ struct nfsnode *nm_head; /* A list to all files opened on this mountpoint */ bool nm_mounted; /* true: The file system is ready */ sem_t nm_sem; /* Used to assume thread-safe access */ diff --git a/nuttx/fs/nfs/nfs_proto.h b/nuttx/fs/nfs/nfs_proto.h index 0f874e28a..bafc230c7 100644 --- a/nuttx/fs/nfs/nfs_proto.h +++ b/nuttx/fs/nfs/nfs_proto.h @@ -302,7 +302,7 @@ typedef struct fhandle fhandle_t; union nfsfh { - fhandle_t fh_generic; +//fhandle_t fh_generic; unsigned char fh_bytes[NFS_MAXFHSIZE]; }; typedef union nfsfh nfsfh_t; diff --git a/nuttx/fs/nfs/nfs_socket.c b/nuttx/fs/nfs/nfs_socket.c index 8b0f28660..b13d0cfb2 100644 --- a/nuttx/fs/nfs/nfs_socket.c +++ b/nuttx/fs/nfs/nfs_socket.c @@ -82,7 +82,11 @@ static struct rpc_program nfs3_program = * Public Variables ****************************************************************************/ +uint32_t nfs_true; +uint32_t nfs_false; +uint32_t nfs_xdrneg1; int nfs_ticks; +struct nfsstats nfsstats; /**************************************************************************** * Private Functions @@ -94,10 +98,20 @@ int nfs_ticks; void nfs_init(void) { - rpcclnt_init(); + nfs_true = txdr_unsigned(TRUE); + nfs_false = txdr_unsigned(FALSE); + nfs_xdrneg1 = txdr_unsigned(-1); + + nfs_ticks = (CLOCKS_PER_SEC * NFS_TICKINTVL + 500) / 1000; + if (nfs_ticks < 1) + { + nfs_ticks = 1; + } + + rpcclnt_init(); } -int nfsx_connect(struct nfsmount *nmp) +int nfs_connect(struct nfsmount *nmp) { struct rpcclnt *rpc; int error = 0; @@ -151,19 +165,19 @@ int nfsx_connect(struct nfsmount *nmp) /* NFS disconnect. Clean up and unlink. */ -void nfsx_disconnect(struct nfsmount *nmp) +void nfs_disconnect(struct nfsmount *nmp) { rpcclnt_disconnect(nmp->nm_rpcclnt); } #ifdef CONFIG_NFS_TCPIP -void nfsx_safedisconnect(struct nfsmount *nmp) +void nfs_safedisconnect(struct nfsmount *nmp) { rpcclnt_safedisconnect(nmp->nm_rpcclnt); } #endif -int nfsx_request_xx(struct nfsmount *nmp, int procnum, void *datain, void *dataout) +int nfs_request(struct nfsmount *nmp, int procnum, void *datain, void *dataout) { int error; struct rpcclnt *clnt; @@ -223,7 +237,7 @@ out: /* terminate any outstanding RPCs. */ -int nfsx_nmcancelreqs(struct nfsmount *nmp) +int nfs_nmcancelreqs(struct nfsmount *nmp) { return rpcclnt_cancelreqs(nmp->nm_rpcclnt); } diff --git a/nuttx/fs/nfs/nfs_socket.h b/nuttx/fs/nfs/nfs_socket.h index 31987dff3..7b31bf9f4 100644 --- a/nuttx/fs/nfs/nfs_socket.h +++ b/nuttx/fs/nfs/nfs_socket.h @@ -42,17 +42,6 @@ * Pre-processor definitions ****************************************************************************/ -#define nfs_connect(nmp) nfs_connect_nfsx (nmp) -#define nfs_disconnect(nmp) nfs_disconnect_nfsx(nmp) -#define nfs_nmcancelreqs (nmp) nfsx_nmcancelreqs(nmp) -#define nfsx_request(nmp, m, i, o) \ - nfsx_request_xx(nmp, m, i, o) - -#ifdef CONFIG_NFS_TCPIP -# define nfs_sigintr nfs_sigintr_nfsx -#define nfs_safedisconnect nfsx_safedisconnect -#endif - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -66,14 +55,14 @@ extern "C" { #endif EXTERN void nfs_init(void); -EXTERN int nfsx_connect(struct nfsmount *); -EXTERN void nfsx_disconnect(struct nfsmount *); +EXTERN int nfs_connect(struct nfsmount *); +EXTERN void nfs_disconnect(struct nfsmount *); #ifdef CONFIG_NFS_TCPIP -EXTERN int nfsx_sigintr(struct nfsmount *, struct nfsreq *, cthread_t *); -EXTERN void nfsx_safedisconnect(struct nfsmount *); +EXTERN int nfs_sigintr(struct nfsmount *, struct nfsreq *, cthread_t *); +EXTERN void nfs_safedisconnect(struct nfsmount *); #endif -EXTERN int nfsx_request_xx(struct nfsmount *, int, void*, void*); -EXTERN int nfsx_nmcancelreqs(struct nfsmount *); +EXTERN int nfs_request(struct nfsmount *, int, void*, void*); +EXTERN int nfs_nmcancelreqs(struct nfsmount *); #undef EXTERN #if defined(__cplusplus) diff --git a/nuttx/fs/nfs/nfs_util.c b/nuttx/fs/nfs/nfs_util.c index 1e8805a92..6f5dd6991 100755 --- a/nuttx/fs/nfs/nfs_util.c +++ b/nuttx/fs/nfs/nfs_util.c @@ -120,31 +120,23 @@ void nfs_semgive(struct nfsmount *nmp) int nfs_checkmount(struct nfsmount *nmp) { struct nfsnode *file; - struct inode *inode; - struct geometry geo; - int ret; - /* If the fs_mounted flag is false, then we have already handled the loss + /* If the nm_mounted flag is false, then we have already handled the loss * of the mount. */ - DEBUGASSERT(nmp && nmp->nm_blkdriver); + DEBUGASSERT(nmp); if (nmp->nm_mounted) { /* We still think the mount is healthy. Check an see if this is * still the case */ - inode = nmp->nm_blkdriver; - if (inode->u.i_bops && inode->u.i_bops->geometry) +#warning "This makes no sense... If you get here, then you know that nmp->nm_mounted and the code will always return OK. Something is wrong." + if (nmp->nm_mounted == true) { - ret = inode->u.i_bops->geometry(inode, &geo); - if (ret == OK && geo.geo_available && !geo.geo_mediachanged) - { return OK; - } } - /* If we get here, the mount is NOT healthy */ nmp->nm_mounted = false; diff --git a/nuttx/fs/nfs/nfs_vfsops.c b/nuttx/fs/nfs/nfs_vfsops.c index 856ed6819..d7c19469d 100644 --- a/nuttx/fs/nfs/nfs_vfsops.c +++ b/nuttx/fs/nfs/nfs_vfsops.c @@ -105,9 +105,9 @@ static ssize_t nfs_read(FAR struct file *filep, char *buffer, size_t buflen); static ssize_t nfs_write(FAR struct file *filep, const char *buffer, size_t buflen); static int nfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir); -static int nfs_mount(FAR struct inode *blkdriver, const void *data, +static int nfs_bind(FAR struct inode *blkdriver, const void *data, void **handle); -static int nfs_unmount(void *handle, FAR struct inode **blkdriver); +static int nfs_unbind(void *handle, FAR struct inode **blkdriver); static int nfs_statfs(struct inode *mountpt, struct statfs *buf); static int nfs_remove(struct inode *mountpt, const char *relpath); static int nfs_mkdir(struct inode *mountpt, const char *relpath, @@ -122,19 +122,18 @@ static int nfs_fsinfo(struct inode *mountpt, const char *relpath, * External Public Data (this belong in a header file) ****************************************************************************/ -extern uint32_t nfs_true, nfs_false; +extern uint32_t nfs_true; +extern uint32_t nfs_false; extern uint32_t nfs_xdrneg1; -extern nfstype nfsv3_type[8]; extern struct nfsstats nfsstats; extern int nfs_ticks; -extern uint32_t nfs_procids[NFS_NPROCS]; /**************************************************************************** * Public Data ****************************************************************************/ /* nfs vfs operations. */ -const struct mountpt_operations nfs_ops = +const struct mountpt_operations nfs_operations = { nfs_open, /* open */ NULL, /* close */ @@ -149,8 +148,8 @@ const struct mountpt_operations nfs_ops = nfs_readdir, /* readdir */ NULL, /* rewinddir */ - nfs_mount, /* bind */ - nfs_unmount, /* unbind */ + nfs_bind, /* bind */ + nfs_unbind, /* unbind */ nfs_statfs, /* statfs */ nfs_remove, /* unlink */ @@ -220,7 +219,7 @@ nfs_open(FAR struct file *filep, FAR const char *relpath, again: nfsstats.rpccnt[NFSPROC_CREATE]++; vap = nmp->nm_head->n_fattr; - sp.sa_modetrue = nfs_true; + sp.sa_modetrue = true; sp.sa_mode = txdr_unsigned(vap.fa_mode); sp.sa_uidfalse = nfs_xdrneg1; sp.sa_gidfalse = nfs_xdrneg1; @@ -980,14 +979,14 @@ void nfs_decode_args(struct nfsmount *nmp, struct nfs_args *argp) * ****************************************************************************/ -int mountnfs(struct nfs_args *argp, struct inode *blkdriver, +int mountnfs(struct nfs_args *argp,/* struct inode *blkdriver,*/ struct sockaddr *nam, void **handle) { struct nfsmount *nmp; int error; /* Open the block driver */ - +/* if (!blkdriver || !blkdriver->u.i_bops) { fdbg("No block driver/ops\n"); @@ -1000,16 +999,16 @@ int mountnfs(struct nfs_args *argp, struct inode *blkdriver, fdbg("No open method\n"); return -ENODEV; } - +*/ /* Create an instance of the mountpt state structure */ - +/* nmp = (struct nfsmount *)kzalloc(sizeof(struct nfsmount)); if (!nmp) { fdbg("Failed to allocate mountpoint structure\n"); return -ENOMEM; } - +*/ /* Initialize the allocated mountpt state structure. The filesystem is * responsible for one reference ont the blkdriver inode and does not * have to addref() here (but does have to release in ubind(). @@ -1017,8 +1016,7 @@ int mountnfs(struct nfs_args *argp, struct inode *blkdriver, sem_init(&nmp->nm_sem, 0, 0); /* Initialize the semaphore that controls access */ -//vfs_getnewfsid(mp); - nmp->nm_blkdriver = blkdriver; /* Save the block driver reference */ +//nmp->nm_blkdriver = blkdriver; /* Save the block driver reference */ nmp->nm_timeo = NFS_TIMEO; nmp->nm_retry = NFS_RETRANS; nmp->nm_wsize = NFS_WSIZE; @@ -1057,7 +1055,7 @@ int mountnfs(struct nfs_args *argp, struct inode *blkdriver, nmp->nm_mounted = true; nfs_init(); - *handle = blkdriver->i_private = &nmp; + *handle /*= blkdriver->i_private*/ = &nmp; nfs_semgive(nmp); return 0; @@ -1070,7 +1068,7 @@ bad: } /**************************************************************************** - * Name: nfs_mount + * Name: nfs_bind * * Description: This implements a portion of the mount operation. This * function allocates and initializes the mountpoint private data and @@ -1080,7 +1078,7 @@ bad: * ****************************************************************************/ -static int nfs_mount(struct inode *blkdriver, const void *data, void **handle) +static int nfs_bind(struct inode *blkdriver, const void *data, void **handle) { int error; struct nfs_args args; @@ -1107,7 +1105,7 @@ static int nfs_mount(struct inode *blkdriver, const void *data, void **handle) } nam = args.addr; - error = mountnfs(&args, blkdriver, nam, handle); + error = mountnfs(&args/*, blkdriver*/, nam, handle); return error; } @@ -1119,7 +1117,7 @@ static int nfs_mount(struct inode *blkdriver, const void *data, void **handle) * ****************************************************************************/ -int nfs_unmount(void *handle, struct inode **blkdriver) +int nfs_unbind(void *handle, struct inode **blkdriver) { struct nfsmount *nmp = (struct nfsmount *) handle ; int error; @@ -1141,7 +1139,7 @@ int nfs_unmount(void *handle, struct inode **blkdriver) else { /* Unmount ... close the block driver */ - + /* if (nmp->nm_blkdriver) { struct inode *inode = nmp->nm_blkdriver; @@ -1151,20 +1149,21 @@ int nfs_unmount(void *handle, struct inode **blkdriver) { (void)inode->u.i_bops->close(inode); } - + */ /* We hold a reference to the block driver but should * not but mucking with inodes in this context. So, we will just return * our contained reference to the block driver inode and let the umount * logic dispose of it. */ - + /* if (blkdriver) { *blkdriver = inode; } + } } - + */ /* Release the mountpoint private data */ nfs_disconnect(nmp); -- cgit v1.2.3