📄 mountlib.c
字号:
/* mountLib.c - Mount protocol library *//* Copyright 1994 - 2001 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01s,10may02,kbw making man page edits01r,07may02,kbw making man page edits01q,05nov01,vvv made max. path length configurable (SPR #63551)01p,05nov01,wap Fix memory leak in mountproc_umnt_1 and mountproc_umntall_1 (SPR #63489)01o,15oct01,rae merge from truestack ver 01v, base 01m (SPRs 62705, 29301/29362, 32821/31223)01n,04dec00,ijm fixed file descriptor leak in nfsUnexport (SPR# 7531)01n,21jun00,rsh upgrade to dosFs 2.001l,05nov98,rjc modifications for dosfs2.01m,14mar99,jdi doc: removed refs to config.h and/or configAll.h (SPR 25663).01l,05feb99,dgp document errno values01k,26aug97,spm removed compiler warnings (SPR #7866)01j,12dec96,jag fix spr 7601 on procedure mountproc_umnt_1, deleted unused variable deleteThis.01i,30aug95,rch fix for spr 4333.01h,27feb95,jdi doc: changed dosFsMode to dosFsFileMode (doc only) (SPR 4085).01g,11feb95,jdi doc format repair.01f,24jan95,rhp update initialization info for exportable file systems, and misc doc tweaks01e,11may94,jmm integrated Roland's doc changes01d,25apr94,jmm doc cleanup; changed mode to readOnly in NFS_EXPORT_ENTRY01c,21apr94,jmm fixed problem with mountproc_dump_1 overwritting strings documentation cleanup, reordered routines01b,20apr94,jmm formatting cleanup, mountproc_dump_1 and mountproc_exports_1 fixed01a,07mar94,jmm written*//*DESCRIPTIONThis library implements a mount server to support mounting VxWorksfile systems remotely. The mount server is an implementation ofversion 1 of the mount protocol as defined in RFC 1094. It is closelyconnected with version 2 of the Network File System ProtocolSpecification, which in turn is implemented by the library nfsdLib.\&NOTE: The only routines in this library that are normally called byapplications are nfsExport() and nfsUnexport(). The mount daemon isnormally initialized indirectly by nfsdInit().The mount server is initialized by calling mountdInit(). Normally,this is done by nfsdInit(), although it is possible to callmountdInit() directly if the NFS server is not being initialized.Defining INCLUDE_NFS_SERVER enables the call to nfsdInit() duringthe boot process, which in turn calls mountdInit(), so there isnormally no need to call either routine manually. mountdInit() spawnsone task, `tMountd', which registers as an RPC service with theportmapper.Currently, only the dosFsLib file system is supported.File systems are exported with the nfsExport() call.To export VxWorks file systems via NFS, you need facilities from boththis library and from nfsdLib. To include both, add INCLUDE_NFS_SERVERand rebuild VxWorks..SS ExampleThe following example illustrates how to export anexisting dosFs file system.First, initialize the block device containing your file system.Then assuming the dosFs system is called "/export" execute the following code on the target:.CSnfsExport ("/export", 0, FALSE, 0); /@ make available remotely @/.CEThis makes it available to allclients to be mounted using the client's NFS mounting command. (OnUNIX systems, mounting file systems normally requires root privileges.)VxWorks does not normally provide authentication services for NFSrequests, and the DOS file system does not provide file permissions.If you need to authenticate incoming requests, see the documentationfor nfsdInit() and mountdInit() for information about authorizationhooks.The following requests are accepted from clients. For details oftheir use, see Appendix A of RFC 1094, "NFS: Network File SystemProtocol Specification.".TStab(|);lf3 lf3l n. Procedure Name | Procedure Number_ MOUNTPROC_NULL | 0 MOUNTPROC_MNT | 1 MOUNTPROC_DUMP | 2 MOUNTPROC_UMNT | 3 MOUNTPROC_UMNTALL | 4 MOUNTPROC_EXPORT | 5.TESEE ALSO: dosFsLib, nfsdLib, RFC 1094INTERNAL: mountd is not reentrant, and there cannot be more than onemountd task running at any one time.The routines called by mountd are named mountproc_ROUTINENAME_1. Thisis the standard RPC naming convention used by code generated fromrpcgen.*//* LINTLIBRARY */#include "vxWorks.h"#include "sys/stat.h"#include "ioLib.h"#include "taskLib.h"#include "lstLib.h"#include "mountLib.h"#include "nfsdLib.h"#include "pathLib.h"#include "rpcLib.h"#include "rpc/pmap_clnt.h"#include "rpc/rpc.h"#include "rpcLib.h"#include "inetLib.h"#include "semLib.h"#include "hostLib.h"#include "stdio.h"#include "stdlib.h"#include "string.h"#include "xdr_nfsserv.h"#include "private/nfsHashP.h"#include "memPartLib.h"/* defines */#ifndef KHEAP_REALLOC#define KHEAP_REALLOC(pBuf,newsize) memPartRealloc(memPartIdKernel,pBuf,newsize)#endif /* KHEAP_REALLOC */#ifdef __GNUC__# ifndef alloca# define alloca __builtin_alloca# endif#endif/* IMPORTS */IMPORT int nfsMaxPath; /* max. length of file path *//* DATA STRUCTURES */typedef struct { char * next; /* next and prev are used by lstLib */ char * prev; char clientName [MAXHOSTNAMELEN + 1]; /* name of the host mounting this * directory */ /* * Mounted directory. Though it appears a single character, it is a char * array. The array is allocated when a MOUNT_CLIENT struct is allocated. * This change was required for adding configurable path length support. */ char directory [1]; } MOUNT_CLIENT;/* GLOBALS */int mountdNExports = MAX_EXPORTED_FILESYSTEMS; /* max. num. exported FS's */int mountdTaskId = 0; /* Task ID of the mountd task */int mountdPriorityDefault = MOUNTD_PRIORITY_DEFAULT; /* default priority */int mountdStackSizeDefault = MOUNTD_STACKSIZE_DEFAULT; /* default stack *//* LOCALS */LOCAL FUNCPTR mountdAuthHook = NULL; /* Hook to run to authorize packets */LOCAL LIST * mountPoints = NULL; /* Linked list of exported mount points */LOCAL SEM_ID mountSem = NULL; /* Sem controlling access to mountPoints */LOCAL LIST * nfsClients = NULL; /* Linked list of clients mounting fs's */LOCAL SEM_ID clientsSem = NULL; /* Sem controlling access to nfsClients */LOCAL int fsIdNumber = 1; /* ID number for exported file systems *//* forward LOCAL functions */LOCAL void mountdRequestProcess (struct svc_req * rqstp, register SVCXPRT * transp);LOCAL char * svc_reqToHostName (struct svc_req * rqstp, char * hostName);LOCAL MOUNT_CLIENT * mountListFind (struct svc_req * rqstp, dirpath * path);/******************************************************************************** mountdInit - initialize the mount daemon* * This routine spawns a mount daemon if one does not already* exist. Defaults for the <priority> and <stackSize> arguments are* in the global variables `mountdPriorityDefault' and* `mountdStackSizeDefault', and are initially set to* MOUNTD_PRIORITY_DEFAULT and MOUNTD_STACKSIZE_DEFAULT respectively.** Normally, no authorization checking is performed by either mountd or* nfsd. To add authorization checking, set <authHook> to point to a* routine declared as follows:** .CS* nfsstat routine* (* int progNum, /@ RPC program number @/* int versNum, /@ RPC program version number @/* int procNum, /@ RPC procedure number @/* struct sockaddr_in clientAddr, /@ address of the client @/* MOUNTD_ARGUMENT * mountdArg /@ argument of the call @/* )* .CE* * The <authHook> callback must return OK if the request is authorized,* and any defined NFS error code (usually NFSERR_ACCES) if not.** VXWORKS AE PROTECTION DOMAINS* Under VxWorks AE, you can call mountdInit() from within the kernel * protection domain only, and the function referenced in the <authHook> * parameter must reside in the kernel protection domain. * This restriction does not apply under non-AE versions of VxWorks. ** RETURNS: OK, or ERROR if the mount daemon could not be correctly* initialized.*/STATUS mountdInit ( int priority, /* priority of the mount daemon */ int stackSize, /* stack size of the mount daemon */ FUNCPTR authHook, /* hook to run to authorize each request */ int nExports, /* maximum number of exported file systems */ int options /* currently unused - set to 0 */ ) { if (0 != mountdTaskId) { printf ("Mount daemon already initialized\n"); return (ERROR); } mountdAuthHook = authHook; if (nExports > 0) mountdNExports = nExports; if ((nfsClients = KHEAP_ALLOC (sizeof (*nfsClients))) == NULL) return (ERROR); if ((clientsSem = semMCreate (SEM_Q_PRIORITY)) == NULL) { KHEAP_FREE ((char *)nfsClients); return (ERROR); } lstInit (nfsClients); if ((mountPoints = KHEAP_ALLOC (sizeof (*mountPoints))) == NULL) return (ERROR); if ((mountSem = semMCreate (SEM_Q_PRIORITY)) == NULL) { KHEAP_FREE ((char *)mountPoints); return (ERROR); } lstInit (mountPoints); if (priority == 0) priority = mountdPriorityDefault; if (stackSize == 0) stackSize = mountdStackSizeDefault; if ((mountdTaskId = taskSpawn ("tMountd", priority, 0, stackSize, (FUNCPTR) mountd, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) == ERROR) { perror ("Could not spawn mountd task"); return (ERROR); } return (OK); }/******************************************************************************** mountd - mount daemon process** This routine processes incoming mount daemon requests. It is* normally used as the entry point of a task by mountdInit() and* should not be called directly. It will only return if svc_run()* returns, which should only happen if select() returns an error.* * This routine is global only so that its name will appear in the* task display list.* * Most of this routine was generated by rpcgen.** RETURNS: N/A* * NOMANUAL*/void mountd ( void ) { register SVCXPRT *transp; rpcTaskInit (); (void) pmap_unset(MOUNTPROG, MOUNTVERS); transp = svcudp_create(RPC_ANYSOCK); if (transp == NULL) { fprintf(stderr, "cannot create udp service."); exit(1); } if (!svc_register(transp, MOUNTPROG, MOUNTVERS, mountdRequestProcess, IPPROTO_UDP)) { fprintf(stderr, "unable to register (MOUNTPROG, MOUNTVERS, udp)."); exit(1); } svc_run(); /* Should never reach this point */ fprintf(stderr, "svc_run returned"); exit(1); }/******************************************************************************** mountdRequestProcess - process mount requests* * This routine is registered from the mountd process via* svc_register(). It parses the incoming request, decides which* mountproc_*_1 routine to call, calls it, and sends the reply back* to the client.* * NOTE: Most of this routine was generated by rpcgen.* * RETURNS: N/A.* * NOMANUAL*/LOCAL void mountdRequestProcess ( struct svc_req * rqstp, register SVCXPRT * transp ) { MOUNTD_ARGUMENT argument; char * result = NULL; bool_t (*xdr_argument)(), (*xdr_result)(); char * (*local)(); nfsstat authorized; /* return val of user auth routine */ switch (rqstp->rq_proc) { case MOUNTPROC_NULL: xdr_argument = xdr_void; xdr_result = xdr_void; local = (char *(*)()) mountproc_null_1; break; case MOUNTPROC_MNT: xdr_argument = xdr_dirpath; xdr_result = xdr_fhstatus; local = (char *(*)()) mountproc_mnt_1; break; case MOUNTPROC_DUMP: xdr_argument = xdr_void; xdr_result = xdr_mountlist; local = (char *(*)()) mountproc_dump_1; break; case MOUNTPROC_UMNT: xdr_argument = xdr_dirpath; xdr_result = xdr_void; local = (char *(*)()) mountproc_umnt_1; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -