The I/O driver nfsDrv, which provides NFS client support, uses the client routines in the library nfsLib to access files on an NFS file server.
VxWorks also allows you to run an NFS server to export files to other systems. The server task mountd allows other systems on the network to mount VxWorks file systems (dosFs only); then the server task nfsd allows them to read and write to those files. The VxWorks NFS server facilities are implemented in the following libraries:
The routines in the VxWorks NFS libraries are implemented using RPC. For more information, see the reference entries for these libraries and RPC: Remote Procedure Calls.
To access files on UNIX, NFS clients mount file systems from NFS servers. On a UNIX NFS server, the file /etc/exports specifies which of the server's file systems can be mounted by NFS clients. For example, if /etc/exports contains the following line:
/usr
then the file system /usr can be mounted by NFS clients such as VxWorks. If a file system is not listed in this file, it cannot be mounted by other machines. Other optional fields in /etc/exports allow the exported file system to be restricted to certain machines or users.
![]() |
CAUTION: On Windows, most networking packages that support NFS also supply a mechanism for exporting files so that they are visible on the network. See your Windows and networking software documentation for information on this facility.
|
||||||||||||||||||
Access to a remote NFS file system is established by mounting that file system locally and creating an I/O device for it using the routine nfsMount( ):
nfsMount ("host", "hostFileSys", "localName")
For example, the following call mounts /usr of the host mars as /vwusr locally:
-> nfsMount "mars", "/usr", "/vwusr"
The host name mars must already be in VxWorks's list of hosts (added with the routine hostAdd( )). VxWorks then creates a local I/O device /vwusr that refers to the mounted file system. A reference on VxWorks to a file with the name /vwusr/darger/myfile refers to the file /usr/darger/myfile on the host mars as if it were local to the VxWorks system.
If VxWorks is configured with "NFS mount all" on, VxWorks mounts all host-exported NFS file systems. The relevant configuration macro is INCLUDE_NFS_MOUNT_ALL. Otherwise, the network startup routine, usrNetInit( ) in usrNetwork.c, tries to mount the file system from which VxWorks was booted--as long as NFS is included in the VxWorks configuration and the VxWorks boot file begins with a slash (/). For example, if NFS is included and you boot /usr/wind/target/config/bspname/vxWorks, then VxWorks attempts to mount /usr from the boot host with NFS.
When making an NFS request to a host system, the NFS server expects more information than the user's name. NFS is built on top of Remote Procedure Call (RPC) and uses a type of RPC authentication known as AUTH_UNIX. This mechanism requires the user ID and a list of group IDs to which the user belongs. These parameters can be set on VxWorks using nfsAuthUnixSet( ). For example, to set the user ID to 1000 and the group ID to 200 for the machine mars, use:
-> nfsAuthUnixSet "mars", 1000, 200, 0
The routine nfsAuthUnixPrompt( ) provides a more interactive way of setting the NFS authentication parameters from the Tornado shell. On UNIX systems, a user ID is specified in the file /etc/passwd. A list of groups that a user belongs to is specified in the file /etc/group.
A default user ID and group ID is specified during configuration by setting the user identifier for NFS access (the configuration constant NFS_USER_ID, set by default to 2001) and the group identifier for NFS access (the configuration constant NFS_GROUP_ID, set by default to 100) respectively. The NFS authentication parameters are set to these values at system startup. If NFS file access is unsuccessful, make sure that the configuration is correct.
To export a dosFs file system with NFS, you must initialize that file system with the DOS_OPT_EXPORT option (see VxWorks Programmer' Guide: Volume Configuration). With this option, the dosFs initialization code creates some small additional in-memory data structures; these structures make the file system exportable.
The following steps initialize a DOS file system called /export on a SCSI drive. You can use any block device instead of SCSI. Your BSP can also support other suitable device drivers; see your BSP's documentation.
scsiAutoConfig (NULL); pPhysDev = scsiPhysDevIdGet (NULL, 1, 0); pBlkDev = scsiBlkDevCreate (pPhysDev, 0, 0);
dosFsDevInitOptionsSet (DOS_OPT_EXPORT); dosFsDevInit ("/export", pBlkDev, NULL);
![]() |
CAUTION: For NFS-exportable file systems, the device name must not end in a slash.
|
||||||||||||||||||
After you have an exportable file system, call nfsExport( )to make it available to NFS clients on your network. Then mount the file system from the remote NFS client, using the facilities of that system. The following example shows how to export the new dosFs file system from a VxWorks platform called vxTarget, and how to mount it from a typical UNIX system.
nfsExport ("/export", 0, FALSE, 0);
![]() |
CAUTION: On UNIX systems, you normally need root access to mount file systems.
|
||||||||||||||||||
Several global variables allow you to specify dosFs facilities related to NFS support. Because these facilities use global variables, you can export previously existing dosFs file systems without altering the existing configuration stored with the file system data on disk.
However, because these are global variables, you must take care to avoid race conditions if more than one task initializes dosFs file systems. If your application initializes file systems for NFS on the fly, you may need mutual exclusion surrounding these global variable settings and the corresponding file system initialization.
You can specify a single user ID, group ID, and mode (permissions) for all files within a dosFs file system. To specify these values, define the following global variables before initializing a dosFs file system with either dosFsDevInit( ) or dosFsMkfs( ):
![]() |
WARNING: dosFsFileMode controls only how the file access mode is reported to NFS clients; it does not override local access restrictions on the DOS file system. In particular, if any file in an exported file system has DOS_ATTR_RDONLY set in its file-attribute byte, no modifications to that file are permitted regardless of what dosFsFileMode says.
|
||||||||||||||||||
The VxWorks NFS Server can export only dosFs file systems, which leads to the following DOS limitations: