⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nfsdrv.c

📁 vxworks的完整的源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
    if ((pNfsDev = (NFS_DEV *) KHEAP_ALLOC(sizeof (NFS_DEV) + nfsMaxPath - 1)) 	   == NULL)	return (ERROR);    /* perform an nfs mount of the directory */    if (nfsDirMount (host, fileSystem, &fileHandle) != OK)	{	KHEAP_FREE((char *) pNfsDev);	return (ERROR);	}    /* fill in the nfs device descripter */    (void) strcpy (pNfsDev->host, host);    (void) strcpy (pNfsDev->fileSystem, fileSystem);    bcopy ((char *) &fileHandle, (char *) &pNfsDev->fileHandle, sizeof(nfs_fh));    /*     * If no device name was specified, use the name of the file system     * being mounted.  For instance, if the file system is called "/d0",     * the corresponding nfs device will be named "/d0".     */    if (localName == NULL)	localName = fileSystem;		/* name the same as remote fs */    /* add device to I/O system */    if (iosDevAdd ((DEV_HDR *) pNfsDev, localName, nfsDrvNum) != OK)	{	KHEAP_FREE((char *) pNfsDev);	return (ERROR);	}    return (OK);    }/********************************************************************************* nfsMountAll - mount all file systems exported by a specified host** This routine mounts the file systems exported by the host <pHostName>* which are accessible by <pClientName>. A <pClientName> entry of NULL* will only mount file systems that are accessible by any client. * The nfsMount() routine is called to mount each file system. It creates* a local device for each mount that has the same name as the remote file* system.** If the <quietFlag> setting is FALSE, each file system is printed on* standard output after it is mounted successfully.** RETURNS: OK, or ERROR if any mount fails.** SEE ALSO: nfsMount()*/STATUS nfsMountAll    (    char *pHostName, 	/* name of remote host */    char *pClientName, 	/* name of a client specified in access list, if any */    BOOL quietFlag      /* FALSE = print name of each mounted file system */    )    {    exports	nfsExportBody;    exports 	pExport;    groups 	pGroup;    BOOL	accessFlag;    STATUS	status = OK;    if (nfsExportRead (pHostName, &nfsExportBody) != OK)        return (ERROR);    if (nfsExportBody)        {        /* Attempt to mount each file system in export list */        pExport = nfsExportBody;        while (pExport != NULL)            {            accessFlag = TRUE;      /* Allow mounting if not restricted. */            pGroup = pExport->ex_groups;            if (pGroup != NULL)                {                accessFlag = FALSE;    /* Limit mount to matching clients. */                if (pClientName != NULL)                    {                    /* Check for match with client name. */                    while (!accessFlag && pGroup != NULL)                        {                        if (strcmp (pGroup->gr_name, pClientName))                            pGroup = pGroup->gr_next;                        else                            accessFlag = TRUE;                        }                    }                }            if (accessFlag)                {                if (nfsMount (pHostName, pExport->ex_dir, (char *) NULL) != OK)                    status = ERROR;                else                    {                    if (!quietFlag)                        printf ("%s\n", pExport->ex_dir);                    }                }            pExport = pExport->ex_next;            }	}    nfsExportFree (&nfsExportBody);    return (status);    }/********************************************************************************* nfsDevShow - display the mounted NFS devices** This routine displays the device names and their associated NFS file systems.** EXAMPLE:* .CS*     -> nfsDevShow*     device name          file system*     -----------          -----------*     /yuba1/              yuba:/yuba1*     /wrs1/               wrs:/wrs1* .CE** RETURNS: N/A*/void nfsDevShow (void)    {    char    *fileSysName;    DEV_HDR *pDev0 = NULL;    DEV_HDR *pDev1;    if ((fileSysName = (char *) alloca (nfsMaxPath)) == NULL)	{	printf ("Memory allocation error\n");	return;	}    printf ("%-20.20s %-50.50s\n", "device name", "file system");    printf ("%-20.20s %-50.50s\n", "-----------", "-----------");    /* get entries from the I/O system's device list */    while ((pDev1 = iosNextDevGet (pDev0)) != NULL)	{	if (pDev1->drvNum == nfsDrvNum)	    {	    /* found an nfs device, print information */	    (void) strcpy (fileSysName, ((NFS_DEV *) pDev1)->host);	    (void) strcat (fileSysName, ":");	    (void) strcat (fileSysName, ((NFS_DEV *) pDev1)->fileSystem);	    printf ("%-20.20s %-50.50s\n", pDev1->name, fileSysName);	    }	pDev0 = pDev1;	}    }/********************************************************************************* nfsUnmount - unmount an NFS device** This routine unmounts file systems that were previously mounted via NFS.** RETURNS: OK, or ERROR if <localName> is not an NFS device or cannot* be mounted.* * SEE ALSO: nfsMount()*/STATUS nfsUnmount    (    char *localName     /* local of nfs device */    )    {    FAST NFS_DEV *pNfsDev;    char *dummy;    /* find the device in the I/O system */#ifdef _WRS_VXWORKS_5_X    if ((pNfsDev = (NFS_DEV *) iosDevFind (localName,                                            (char **)&dummy)) == NULL)#else    if ((pNfsDev = (NFS_DEV *) iosDevFind (localName,                                            (const char **)&dummy)) == NULL)#endif /* _WRS_VXWORKS_5_X */        	{	return (ERROR);	}    /* make sure device is an nfs driver and the names match exactly */    if ((pNfsDev->devHdr.drvNum != nfsDrvNum) ||	(strcmp (pNfsDev->devHdr.name, localName) != 0))	{	errnoSet (S_nfsDrv_NOT_AN_NFS_DEVICE);	return (ERROR);	}    /* perform an nfs unmount of the directory */    if (nfsDirUnmount (pNfsDev->host, pNfsDev->fileSystem) == ERROR)	return (ERROR);    /* delete the device from the I/O system */    iosDevDelete ((DEV_HDR *) pNfsDev);    KHEAP_FREE((char *) pNfsDev);    return (OK);    }/********************************************************************************* nfsDevListGet - create list of all the NFS devices in the system** This routine fills the array <nfsDevlist> up to <listSize>, with handles to* NFS devices currently in the system.** RETURNS: The number of entries filled in the <nfsDevList> array.* * SEE ALSO: nfsDevInfoGet()*/int nfsDevListGet    (    unsigned long nfsDevList[],	/* NFS dev list of handles */    int           listSize	/* number of elements available in the list */    )    {    int       numMounted;    DEV_HDR * pDev0 = NULL;    DEV_HDR * pDev1;    /*  Collect information of all the NFS currently mounted.  */    numMounted = 0;    while ((numMounted < listSize) && ((pDev1 = iosNextDevGet (pDev0)) != NULL))        {        if (pDev1->drvNum == nfsDrvNum)            {            /* found an nfs device, save pointer to the device */            nfsDevList [numMounted] = (unsigned long) pDev1;            numMounted++;            }        pDev0 = pDev1;        }    return (numMounted);    }/********************************************************************************* nfsDevInfoGet - read configuration information from the requested NFS device** This routine accesses the NFS device specified in the parameter <nfsDevHandle>* and fills in the structure pointed to by <pnfsInfo>. The calling function * should allocate memory for <pnfsInfo> and for the two character buffers,* 'remFileSys' and 'locFileSys', that are part of <pnfsInfo>. These buffers * should have a size of 'nfsMaxPath'.** RETURNS: OK if <pnfsInfo> information is valid, otherwise ERROR.* * SEE ALSO: nfsDevListGet()*/STATUS nfsDevInfoGet    (    unsigned long   nfsDevHandle,	/* NFS device handle */    NFS_DEV_INFO  * pnfsInfo		/* ptr to struct to hold config info */    )    {    NFS_DEV *pnfsDev;    DEV_HDR *pDev0;    DEV_HDR *pDev1;    if (pnfsInfo == NULL)	return (ERROR);    /* Intialize pointer variables */    pnfsDev = NULL;    pDev0   = NULL;    /* Verify that the device is still in the list of devices */    while ((pDev1 = iosNextDevGet (pDev0)) != NULL)        {        if (pDev1 == (DEV_HDR *) nfsDevHandle)	    {	    pnfsDev = (NFS_DEV *) pDev1;	    break;				/* Found Device */	    }        pDev0 = pDev1;        }     if (pnfsDev != NULL)	{	strcpy (pnfsInfo->hostName,   pnfsDev->host);	strcpy (pnfsInfo->remFileSys, pnfsDev->fileSystem);	strcpy (pnfsInfo->locFileSys, pnfsDev->devHdr.name);	return (OK);	}    return (ERROR);    }/* routines supplied to the I/O system *//********************************************************************************* nfsCreate - create a remote NFS file** Returns an open nfs file descriptor.** Used for creating files only, not directories.* Called only by the I/O system.** To give the file a particular mode (UNIX chmod() style), use nfsOpen().** RETURNS: Pointer to NFS file descriptor, or ERROR.*/LOCAL int nfsCreate    (    NFS_DEV *pNfsDev,   /* pointer to nfs device */    char *fileName,     /* nfs file name (relative to mount point) */    int mode            /* mode (O_RDONLY, O_WRONLY, or O_RDWR) */    )    {    /* file descriptor mode legality is checked for in nfsOpen */    /* don't allow null filenames */    if (fileName [0] == EOS)	{	errnoSet (S_ioLib_NO_FILENAME);	return (ERROR);	}    /* open the file being created,       give the file default UNIX file permissions */    return (nfsOpen (pNfsDev, fileName , O_CREAT | O_TRUNC | mode,                     DEFAULT_FILE_PERM));    }/********************************************************************************* nfsDelete - delete a remote file** Deletes a file on a remote system.* Called only by the I/O system.** RETURNS: OK or ERROR.*/LOCAL int nfsDelete    (    NFS_DEV *pNfsDev,   /* pointer to nfs device */    char *fileName      /* remote file name */    )    {    /* don't allow null filenames */    if (fileName [0] == EOS)	{	errnoSet (S_ioLib_NO_FILENAME);	return (ERROR);	}    return (nfsFileRemove (pNfsDev->host, &pNfsDev->fileHandle, fileName));    }/********************************************************************************* nfsChkFilePerms - check the NFS file permissions with a given permission.** This routine compares the NFS file permissions with a given permission.** This routine is basically designed for nfsOpen() to verify* the target file's permission prior to deleting it due to O_TRUNC.** The parameter "perm" will take 4(read), 2(write), 1(execute), or* combinations of them.** OK means the file has valid permission whichever group is.* FOLLOW_LINK means this path name contains link.  ERROR means* the file doesn't have matched permissions.* * Called only by the I/O system.** RETURNS: OK, FOLLOW_LINK, ERROR*/LOCAL int nfsChkFilePerms    (    NFS_DEV *	pNfsDev,		/* pointer to nfs device */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -