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

📄 c-fileaxs3.html

📁 vxworks相关论文
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><link rel="STYLESHEET" type="text/css" href="wrs.css"><title>    File Access Applications     </title></head><body bgcolor="FFFFFF"><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="c-fileaxs.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-fileaxs.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-fileaxs2.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-fileaxs4.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p><font face="Helvetica, sans-serif" class="sans"><h3 class="H2"><i><a name="90111">11.3  &nbsp;&nbsp;NFS </a></i></h3></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="90113"> </a>The I/O driver <b class="library">nfsDrv</b>, which provides NFS client support, uses the client routines in the library <b class="library">nfsLib</b> to access files on an NFS file server.</p><dd><p class="Body"><a name="90114"> </a>VxWorks also allows you to run an NFS server to export files to other systems.  The server task <b class="task">mountd</b> allows other systems on the network to mount VxWorks file systems (dosFs only); then the server task <b class="task">nfsd</b> allows them to read and write to those files.  The VxWorks NFS server facilities are implemented in the following libraries:</p></dl><dl class="margin"><dd><div class="Item"><a name="90118"> </a><b class="library">mountLib</b> </div><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="90119"> </a>Mount Protocol library.  Provides functions to manage exporting file systems.</div><br></dl></dl><dd><div class="Item"><a name="90121"> </a><b class="library">nfsdLib</b> </div><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="90122"> </a>NFS Server library.  Provides functions to manage requests from remote NFS clients.</div><br></dl></dl></dl><dl class="margin"><dd><p class="Body"><a name="90124"> </a>The routines in the VxWorks NFS libraries are implemented using RPC.  For more information, see the reference entries for these libraries and <a href="c-rpc.html#94280"><i class="title">RPC: Remote Procedure Calls</i></a>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="90128">11.3.1  &nbsp;&nbsp;VxWorks Target as Client</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="90130"> </a>To access files on UNIX, NFS clients <i class="term">mount</i> file systems from NFS servers.  On a UNIX NFS server, the file <b class="file">/etc/exports</b> specifies which of the server's file systems can be mounted by NFS clients.  For example, if <b class="file">/etc/exports</b> contains the following line:</p><dl class="margin"><dd><pre class="Code2"><b><a name="90131">/usr</a></b></pre></dl><dd><p class="Body"><a name="92882"> </a>then the file system <b class="file">/usr</b> 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 <b class="file">/etc/exports</b> allow the exported file system to be restricted to certain machines or users.</p></dl></dl><dl class="margin"><dd><p class="table" callout><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td valign="top" width="40"><br><img border="0" alt="*" src="icons/caution.gif"></td><td><hr><div class="CalloutCell"><a name="93523"><b class="symbol_UC"><font face="Helvetica, sans-serif" size="-1" class="sans">CAUTION:  </font></b></a>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.</div></td></tr><tr valign="top"><td></td><td><hr></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p callout></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="92901">Creating VxWorks Network Devices that Use NFS</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="90144"> </a>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 <b class="routine"><i class="routine">nfsMount</i></b><b>(</b>&nbsp;<b>)</b>:</p><dl class="margin"><dd><pre class="Code2"><b><a name="90145">nfsMount ("<i class="textVariable">host</i>", "<i class="textVariable">hostFileSys</i>", "<i class="textVariable">localName</i>")</a></b></pre></dl><dd><p class="Body"><a name="90146"> </a>Its arguments are:</p></dl><dl class="margin"><dd><div class="Item"><a name="90147"> </a><i class="textVariable">host</i> </div><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="90148"> </a>The host name of the NFS server where the file system resides. </div><br></dl></dl><dd><div class="Item"><a name="90149"> </a><i class="textVariable">hostFileSys</i> </div><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="90150"> </a>The name of the desired host file system or subdirectory. </div><br></dl></dl><dd><div class="Item"><a name="90151"> </a><i class="textVariable">localName</i> </div><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="90152"> </a>The local name to assign to the file system. </div><br></dl></dl></dl><dl class="margin"><dd><p class="Body"><a name="90153"> </a>For example, the following call mounts <b class="symbol_lc">/usr</b> of the host <b class="symbol_lc">mars</b> as <b class="symbol_lc">/vwusr</b> locally:</p><dl class="margin"><dd><pre class="Code2"><b><a name="90154"></b><tt class="output">-&gt; </tt><b>nfsMount "mars", "/usr", "/vwusr"</a></b></pre></dl><dd><p class="Body"><a name="90155"> </a>The host name <b class="symbol_lc">mars</b> must already be in VxWorks's list of hosts (added with the routine <b class="routine"><i class="routine">hostAdd</i></b><b>(</b>&nbsp;<b>)</b>).  VxWorks then creates a local I/O device <b class="file">/vwusr</b> that refers to the mounted file system.  A reference on VxWorks to a file with the name <b class="file">/vwusr/darger/myfile</b> refers to the file <b class="file">/usr/darger/myfile</b> on the host <b class="symbol_lc">mars</b> as if it were local to the VxWorks system.</p><dd><p class="Body"><a name="90157"> </a>If VxWorks is configured with "NFS mount all" on, VxWorks mounts all host-exported NFS file systems.  The relevant configuration macro is  <b class="symbol_UC">INCLUDE_NFS_MOUNT_ALL</b>.  Otherwise, the network startup routine, <b class="routine"><i class="routine">usrNetInit</i></b><b>(</b>&nbsp;<b>)</b> in <b class="file">usrNetwork.c</b>, 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 (<b>/</b>). For example, if NFS is included and you boot <b class="file">/usr/wind/target/config</b><tt class="output">/</tt><i class="textVariable">bspname</i><b class="file">/vxWorks</b>, then VxWorks attempts to mount <b class="file">/usr</b> from the boot host with NFS.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="90159">Setting the User ID for Remote File Access with NFS</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="90161"> </a>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 <b class="symbol_UC">AUTH_UNIX</b>.  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 <b class="routine"><i class="routine">nfsAuthUnixSet</i></b><b>(</b>&nbsp;<b>)</b>.  For example, to set the user ID to 1000 and the group ID to 200 for the machine <b>mars</b>, use:</p><dl class="margin"><dd><pre class="Code2"><b><a name="90164"></b><tt class="output">-&gt; </tt><b>nfsAuthUnixSet "mars", 1000, 200, 0</a></b></pre></dl><dd><p class="Body"><a name="90166"> </a>The routine <b class="routine"><i class="routine">nfsAuthUnixPrompt</i></b><b>(</b>&nbsp;<b>)</b> 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 <b class="file">/etc/passwd</b>.  A list of groups that a user belongs to is specified in the file <b class="file">/etc/group</b>.</p><dd><p class="Body"><a name="90167"> </a>A default user ID and group ID is specified during configuration by setting the user identifier for NFS access (the configuration constant <b class="symbol_UC">NFS_USER_ID</b>, set by default to 2001) and the group identifier for NFS access (the configuration constant  <b class="symbol_UC">NFS_GROUP_ID</b>, 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.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="90171">11.3.2  &nbsp;&nbsp;VxWorks Target as Server</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="90173"> </a>To export a dosFs file system with NFS, carry out the following steps:</p></dl><dl class="margin"><ul class="BulletSingle" type="disc"><li><a name="90174"> </a>Initialize a dosFs file system, with the option that makes it NFS-exportable.</li></ul><ul class="BulletSingle" type="disc"><li><a name="90176"> </a>Register the file system for export, with a call to <b class="routine"><i class="routine">nfsExport</i></b><b>(&nbsp;)</b>.</li></ul></dl><dl class="margin"><dd><p class="Body"><a name="90177"> </a>To use the file system from another machine after you export it, you must also:</p></dl><dl class="margin"><ul class="BulletSingle" type="disc"><li><a name="90178"> </a>Mount the remote VxWorks file system using local host facilities.</li></ul></dl><dl class="margin"><dd><p class="Body"><a name="94422"> </a>To include NFS Server support, reconfigure VxWorks. The relevant configuration macro is  <b class="symbol_UC">INCLUDE_NFS_SERVER</b>.  If you wish, you can run a VxWorks system with only NFS Server support (no client support).</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="94426">Initializing an NFS-Exportable File System</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="90184"> </a>To export a dosFs file system with NFS, you must initialize that file system with the <b class="symbol_UC">DOS_OPT_EXPORT</b> option (see <i class="title">VxWorks Programmer' Guide: Volume Configuration</i>).  With this option, the dosFs initialization code creates some small additional in-memory data structures; these structures make the file system exportable.</p><dd><p class="Body"><a name="90186"> </a>The following steps initialize a DOS file system called <b class="file">/export</b> 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.</p></dl><dl class="margin"><p><ol class="List"><li value="1."><a name="90187"> </a>Initialize the block device containing your file system. </li></ol></p><dl class="margin"><dd><div class="Indent"><a name="90188"> </a>For example, you can use a SCSI drive as follows:</div><br><dl class="margin"><dd><pre class="Code3"><b><a name="90189">scsiAutoConfig (NULL); pPhysDev = scsiPhysDevIdGet (NULL, 1, 0); pBlkDev = scsiBlkDevCreate (pPhysDev, 0, 0);</a></b></pre></dl><dd><div class="Indent"><a name="90190"> </a>Calling <b class="routine"><i class="routine">scsiAutoConfig</i></b><b>(&nbsp;)</b> configures all SCSI devices connected to the default system controller.  (Real applications often use <b class="routine"><i class="routine">scsiPhysDevCreate</i></b><b>(&nbsp;)</b>instead, to specify an explicit configuration for particular devices.) The <b class="routine"><i class="routine">scsiPhysDevIdGet</i></b><b>(&nbsp;)</b> call identifies the SCSI drive by specifying the SCSI controller (<b class="symbol_UC">NULL </b>specifies the default controller), the bus ID (1), and the Logical Unit Number (0).  The call to <b class="routine"><i class="routine">scsiBlkDevCreate</i></b><b>(&nbsp;)</b> initializes the data structures to manage that particular drive.</div><br></dl><p><ol class="List"><li value="2."><a name="90191"> </a>Initialize the file system with the usual dosFs facilities, but also specify the option <b class="symbol_UC">DOS_OPT_EXPORT</b>. If your NFS client is PC-based, it may also require the <b class="symbol_UC">DOS_OPT_LOWERCASE</b> option.  For example, if the device already has a valid dosFs file system on it (see <i class="title">VxWorks Programmer's Guide: Using an Already Initialized Disk</i>), initialize it as follows:</li></ol></p><dl class="margin"><dl class="margin"><dd><pre class="Code3"><b><a name="90193">dosFsDevInitOptionsSet (DOS_OPT_EXPORT); dosFsDevInit ("/export", pBlkDev, NULL);</a></b></pre></dl>

⌨️ 快捷键说明

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