📄 c-filesys4.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><link rel="STYLESHEET" type="text/css" href="wrs.css"><title> Local File Systems </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="GuideIX.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-filesys.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-filesys3.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-filesys5.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="85833">4.4 Raw File System: rawFs</a></i></h3></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85835"> </a>VxWorks provides a minimal "file system," rawFs, for use in systems that require only the most basic disk I/O functions. The rawFs file system, implemented in <b class="library">rawFsLib</b>, treats the entire disk volume much like a single large file. Although the dosFs and rt11Fs file systems do provide this ability to varying degrees, the rawFs file system offers advantages in size and performance if more complex functions are not required.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85837">4.4.1 Disk Organization</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85839"> </a>As mentioned previously, rawFs imposes no organization of the data on the disk.</p><dd><p class="Body"><a name="85840"> </a>The rawFs file system maintains no directory information; thus there is no division of the disk area into specific files, and no file names are used. All <b class="routine"><i class="routine">open</i></b><b>( )</b> operations on rawFs devices specify only the device name; no additional file names are allowed.</p><dd><p class="Body"><a name="85841"> </a>The entire disk area is available to any file descriptor that is open for the device. All read and write operations to the disk use a byte-offset relative to the start of the first block on the disk.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85842">4.4.2 Initializing the rawFs File System</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85844"> </a>Before any other operations can be performed, the rawFs library, <b class="library">rawFsLib</b>, must be initialized by calling <b class="routine"><i class="routine">rawFsInit</i></b><b>( )</b>. This routine takes a single parameter, the maximum number of rawFs file descriptors that can be open at one time. This count is used to allocate a set of descriptors; a descriptor is used each time a rawFs device is opened.</p><dd><p class="Body"><a name="85846"> </a>The <b class="routine"><i class="routine">rawFsInit</i></b><b>( )</b> routine also makes an entry for the rawFs file system in the I/O system driver table (with <b class="routine"><i class="routine">iosDrvInstall</i></b><b>( )</b>). This entry specifies the entry points for rawFs file operations and is for all devices that use the rawFs file system. The driver number assigned to the rawFs file systems is placed in a global variable <b class="symbol_lc">rawFsDrvNum</b>.</p><dd><p class="Body"><a name="85848"> </a>The <b class="routine"><i class="routine">rawFsInit</i></b><b>( )</b> routine is normally called by the <b class="routine"><i class="routine">usrRoot</i></b><b>( )</b> task after starting the VxWorks system. To use this initialization, define <b class="symbol_UC">INCLUDE_RAWFS</b> in the project facility VxWorks view, and set <b class="symbol_UC">NUM_RAWFS_FILES</b> to the desired maximum open file descriptor count on the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Params</font></b> tab of the properties window.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85851">4.4.3 Initializing a Device for Use with the rawFs File System</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85853"> </a>After the rawFs file system is initialized, the next step is to create one or more devices. Devices are created by the device driver's device creation routine (<i class="textVariable">xx</i><b class="routine"><i class="routine">DevCreate</i></b><b>( )</b>). The driver routine returns a pointer to a block device descriptor structure (<b class="symbol_UC">BLK_DEV</b>). The <b class="symbol_UC">BLK_DEV</b> structure describes the physical aspects of the device and specifies the routines in the device driver that a file system can call. For more information on block devices, see <a href="c-iosys9.html#85946"><i class="title">3.9.4 Block Devices</i></a>.</p><dd><p class="Body"><a name="85858"> </a>Immediately after its creation, the block device has neither a name nor a file system associated with it. To initialize a block device for use with rawFs, the already-created block device must be associated with rawFs and a name must be assigned to it. This is done with the <b class="routine"><i class="routine">rawFsDevInit</i></b><b>( )</b> routine. Its parameters are the name to be used to identify the device and a pointer to the block device descriptor structure (<b class="symbol_UC">BLK_DEV</b>):</p><dl class="margin"><dd><pre class="Code2"><b><a name="85860">RAW_VOL_DESC *pVolDesc; BLK_DEV *pBlkDev; pVolDesc = rawFsDevInit ("DEV1:", pBlkDev); </a></b></pre></dl><dd><p class="Body"><a name="85864"> </a>The <b class="routine"><i class="routine">rawFsDevInit</i></b><b>( )</b> call assigns the specified name to the device and enters the device in the I/O system device table (with <b class="routine"><i class="routine">iosDevAdd</i></b><b>( )</b>). It also allocates and initializes the file system's volume descriptor for the device. It returns a pointer to the volume descriptor to the caller; this pointer is used to identify the volume during certain file system calls.</p><dd><p class="Body"><a name="85865"> </a>Note that initializing the device for use with rawFs does not format the disk. That is done using an <b class="routine"><i class="routine">ioctl</i></b><b>( )</b> call with the <b class="symbol_UC">FIODISKFORMAT</b> function.</p><dd><p class="Body"><a name="85867"> </a>No disk initialization (<b class="symbol_UC">FIODISKINIT</b>) is required, because there are no file system structures on the disk. Note, however, that rawFs accepts that <b class="routine"><i class="routine">ioctl</i></b><b>( )</b> function code for compatibility with other file systems; in such cases, it performs no action and always returns <b class="symbol_UC">OK</b>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85869">4.4.4 Mounting Volumes</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85871"> </a>A disk volume is <i class="term">mounted</i> automatically, generally during the first <b class="routine"><i class="routine">open</i></b><b>( )</b> or <b class="routine"><i class="routine">creat</i></b><b>( )</b> operation. (Certain <b class="routine"><i class="routine">ioctl</i></b><b>( )</b> functions also cause the disk to be mounted.) The volume is again mounted automatically on the first disk access following a ready-change operation (see <a href="c-filesys4.html#85885"><i class="title">4.4.6 Changing Disks</i></a>).</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="87183"><b class="symbol_UC"><font face="Helvetica, sans-serif" size="-1" class="sans">CAUTION: </font></b></a>Because device names are recognized by the I/O system using simple substring matching, file systems should not use a slash (<b>/</b>) alone as a name; unexpected results may occur.</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="H3"><i><a name="85875">4.4.5 File I/O</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85877"> </a>To begin I/O to a rawFs device, first open the device using the standard <b class="routine"><i class="routine">open</i></b><b>( )</b> function. (The <b class="routine"><i class="routine">creat</i></b><b>( )</b> function can be used instead, although nothing is actually "created.") Data on the rawFs device is written and read using the standard I/O routines <b class="routine"><i class="routine">write</i></b><b>( )</b> and <b class="routine"><i class="routine">read</i></b><b>( )</b>. For more information, see <a href="c-iosys3.html#83659"><i class="title">3.3 Basic I/O</i></a>.</p><dd><p class="Body"><a name="85881"> </a>The character pointer associated with a file descriptor (that is, the byte offset where reads and writes take place) can be set by using <b class="routine"><i class="routine">ioctl</i></b><b>( )</b> with the <b class="symbol_UC">FIOSEEK</b> function.</p><dd><p class="Body"><a name="85882"> </a>Multiple file descriptors can be open simultaneously for a single device. These must be carefully managed to avoid modifying data that is also being used by another file descriptor. In most cases, such multiple open descriptors use <b class="symbol_UC">FIOSEEK</b> to set their character pointers to separate disk areas.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85885">4.4.6 Changing Disks</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85887"> </a>The rawFs file system must be notified when removable disks are changed (for example, when floppies are swapped). Two different notification methods are provided: (1) <b class="routine"><i class="routine">rawFsVolUnmount</i></b><b>( )</b> and (2) the ready-change mechanism.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="85890">Unmounting Volumes</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85891"> </a>The first method of announcing a disk change is to call <b class="routine"><i class="routine">rawFsVolUnmount</i></b><b>( )</b> prior to removing the disk. This call flushes all modified file descriptor buffers if possible (see <a href="c-filesys4.html#85933"><i class="title">Synchronizing Volumes</i></a>) and also marks any open file descriptors as obsolete. The next I/O operation remounts the disk. Calling <b class="routine"><i class="routine">ioctl</i></b><b>( )</b> with <b class="symbol_UC">FIOUNMOUNT</b> is equivalent to using <b class="routine"><i class="routine">rawFsVolUnmount</i></b><b>( )</b>. Any open file descriptor to the device can be used in the <b class="routine"><i class="routine">ioctl</i></b><b>( )</b> call.</p><dd><p class="Body"><a name="85896"> </a>Attempts to use obsolete file descriptors for further I/O operations produce an <b class="symbol_UC">S_rawFsLib_FD_OBSOLETE</b> error. To free an obsolete descriptor, use <b class="routine"><i class="routine">close</i></b><b>( )</b>, as usual. This frees the descriptor even though it produces the same error.</p><dd><p class="Body"><a name="85901"> </a>ISRs must not call <b class="routine"><i class="routine">rawFsVolUnmount</i></b><b>( )</b> directly, because the call can pend while the device becomes available. The ISR can instead give a semaphore that prompts a task to unmount the volume. (Note that <b class="routine"><i class="routine">rawFsReadyChange</i></b><b>( )</b> can be called directly from ISRs; see <a href="c-filesys4.html#85914"><i class="title">Announcing Disk Changes with Ready-Change</i></a>.)</p><dd><p class="Body"><a name="85905"> </a>When <b class="routine"><i class="routine">rawFsVolUnmount</i></b><b>( )</b> is called, it attempts to write buffered data out to the disk. Its use is therefore inappropriate for situations where the disk-change notification does not occur until a new disk is inserted, because the old buffered data would be written to the new disk. In this case, use <b class="routine"><i class="routine">rawFsReadyChange</i></b><b>( )</b>, which is described in <a href="c-filesys4.html#85914"><i class="title">Announcing Disk Changes with Ready-Change</i></a>.</p><dd><p class="Body"><a name="85909"> </a>If <b class="routine"><i class="routine">rawFsVolUnmount</i></b><b>( )</b> is called after the disk is physically removed, the data flushing portion of its operation fails. However, the file descriptors are still marked as obsolete, and the disk is marked as requiring remounting. An error is <i class="emphasis">not</i> returned by <b class="routine"><i class="routine">rawFsVolUnmount</i></b><b>( )</b>; to avoid lost data in this situation, explicitly synchronize the disk before removing it (see <a href="c-filesys4.html#85933"><i class="title">Synchronizing Volumes</i></a>).</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="85914">Announcing Disk Changes with Ready-Change</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85916"> </a><b><i></i></b>The second method of announcing that a disk change is taking place is with the <i class="term">ready-change</i> mechanism. A change in the disk's ready-status is interpreted by <b class="library">rawFsLib</b> to indicate that the disk must be remounted during the next I/O call.</p><dd><p class="Body"><a name="85917"> </a>There are three ways to announce a ready-change:</p></dl><dl class="margin"><p class="listspace"><ul class="Bullet" type="disc"><li><a name="85919"> </a>By calling <b class="routine"><i class="routine">rawFsReadyChange</i></b><b>( )</b> directly.</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="85921"> </a>By calling <b class="routine"><i class="routine">ioctl</i></b><b>( )</b> with <b class="symbol_UC">FIODISKCHANGE</b>.</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="85922"> </a>By having the device driver set the <b class="symbol_lc">bd_readyChanged</b> field in the <b class="symbol_UC">BLK_DEV</b> structure to TRUE; this has the same effect as notifying <b class="library">rawFsLib</b> directly.</li></ul></p></dl><dl class="margin"><dd><p class="Body"><a name="85923"> </a>The ready-change announcement does not cause buffered data to be flushed to the disk. It merely marks the volume as needing remounting. As a result, data written to files can be lost. This can be avoided by synchronizing the disk before asserting ready-change. The combination of synchronizing and asserting ready-change provides all the functionality of <b class="routine"><i class="routine">rawFsVolUnmount</i></b><b>( )</b> except for marking file descriptors as obsolete.</p><dd><p class="Body"><a name="85925"> </a>Ready-change can be used in ISRs, because it does not attempt to flush data or perform other operations that could cause delay.</p><dd><p class="Body"><a name="85926"> </a>The block device driver status-check routine (identified by the <b class="symbol_lc">bd_statusChk</b> field in the <b class="symbol_UC">BLK_DEV</b> structure) is useful for asserting ready-change for devices that only detect a disk change after the new disk is inserted. This routine is called at the beginning of each <b class="routine"><i class="routine">open</i></b><b>( )</b> or <b class="routine"><i class="routine">creat</i></b><b>( )</b>, before the file system checks for ready-change.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="85929">Disks with No Change Notification</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85930"> </a>If it is not possible for a ready-change to be announced each time the disk is changed, close all file descriptors for the volume before changing the disk.</p></dl>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -