📄 c-filesys2.html
字号:
<h4 class="H4"><i><a name="84530">Files</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84532"> </a>The disk space allocated to a file in the MS-DOS/dosFs file system is a set of clusters that are chained together through entries in the FAT. A file is not necessarily made up of contiguous clusters; the various clusters can be located anywhere on the disk and in any order.</p><dd><p class="Body"><a name="84533"> </a>Each file has a descriptive entry in the directory where it resides. This entry contains the file's name, size, last modification date and time, and a field giving several important attributes (read-only, system, hidden, modified since last archived). It also contains the starting cluster number for the file; subsequent clusters are located using the FAT.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84535">Volume Label </a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84536"> </a>An MS-DOS/dosFs disk can have a <i class="term">volume label</i> associated with it. The volume label is a special entry in the root directory. Rather than containing the name of a file or subdirectory, the volume label entry contains a string used to identify the volume. This string can contain up to 11 characters. The volume label entry is identified by a special value of the file-attribute byte in the directory entry.</p><dd><p class="Body"><a name="84537"> </a>Note that a volume label entry is not reported using <b class="routine"><i class="routine">ls</i></b><b>( )</b>. However, it does occupy one of the fixed number of entries in the root directory.</p><dd><p class="Body"><a name="84539"> </a>The volume label can be added to a dosFs volume by using the <b class="routine"><i class="routine">ioctl</i></b><b>( )</b> call with the <b class="symbol_UC">FIOLABELSET</b> function. This adds a label entry to the volume's root directory if none exists or changes the label string in an existing volume label entry. The volume label entry takes up one of the fixed number of root directory entries; attempting to add an entry when the root directory is full results in an error.</p><dd><p class="Body"><a name="84541"> </a>The current volume label string for a volume can be obtained by calling the <b class="routine"><i class="routine">ioctl</i></b><b>( )</b> call with the <b class="symbol_UC">FIOLABELGET</b> function. If the volume has no label, this call returns <b class="symbol_UC">ERROR</b> and sets <b class="symbol_lc">errno</b> to <b class="symbol_UC">S_dosFsLib_NO_LABEL</b>.</p><dd><p class="Body"><a name="84543"> </a>Disks initialized under VxWorks or under MS-DOS 5.0 (or later) also contain the volume label string within a boot sector field.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84547">4.2.2 Initializing the dosFs File System</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84548"> </a>Note that before any other operations can be performed, the dosFs file system library, <b class="library">dosFsLib</b>, must be initialized by calling <b class="routine"><i class="routine">dosFsInit</i></b><b>( )</b>. This routine takes a single parameter, the maximum number of dosFs file descriptors that can be open at one time. That number of file descriptors is allocated during initialization; a descriptor is used each time your application opens a file, directory, or the file system device.</p><dd><p class="Body"><a name="84550"> </a>The <b class="routine"><i class="routine">dosFsInit</i></b><b>( )</b> routine also makes an entry for the file system in the I/O system driver table (with <b class="routine"><i class="routine">iosDrvInstall</i></b><b>( )</b>). This entry specifies entry points for dosFs file operations and is used for all devices that use the dosFs file system. The driver number assigned to the dosFs file system is recorded in a global variable <b class="symbol_lc">dosFsDrvNum</b>.</p><dd><p class="Body"><a name="86798"> </a>The <b class="routine"><i class="routine">dosFsInit</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, select <b class="symbol_UC">INCLUDE_DOSFS</b> for inclusion in the project facility VxWorks view, and set <b class="symbol_UC">NUM_DOSFS_FILES</b> to the desired maximum open file count on the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Params</font></b> properties tab. </p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="86803">4.2.3 Initializing a Device for Use with dosFs</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84559"> </a>After the dosFs 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 that the device driver provides to a file system. 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="84564"> </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 the dosFs file system, the already-created block device must be associated with dosFs and a name must be assigned to it. This is done with the <b class="routine"><i class="routine">dosFsDevInit</i></b><b>( )</b> routine. Its parameters are the name to be used to identify the device, a pointer to the block device descriptor structure (<b class="symbol_UC">BLK_DEV</b>), and a pointer to the volume configuration structure <b class="symbol_UC">DOS_VOL_CONFIG</b> (see <a href="c-filesys2.html#84591"><i class="title">4.2.4 Volume Configuration</i></a>). For example:</p><dl class="margin"><dd><pre class="Code2"><b><a name="84569">DOS_VOL_DESC *pVolDesc; DOS_VOL_CONFIG configStruct; pVolDesc = dosFsDevInit ("DEV1:", pBlkDev, &configStruct);</a></b></pre></dl><dd><p class="Body"><a name="84571"> </a>The <b class="routine"><i class="routine">dosFsDevInit</i></b><b>( )</b> call performs the following tasks:</p></dl><dl class="margin"><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84572"> </a>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>).</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84573"> </a>Allocates and initializes the file system's volume descriptor for the device.</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84574"> </a>Returns a pointer to the volume descriptor. This pointer is subsequently used to identify the volume during certain file system calls.</li></ul></p></dl><dl class="margin"><dd><p class="Body"><a name="84575"> </a>Initializing the device for use with dosFs does not format the disk, nor does it initialize the disk with MS-DOS structures (root directory, FAT, and so on). This permits using <b class="routine"><i class="routine">dosFsDevInit</i></b><b>( )</b>with disks that already have data in an existing MS-DOS file system; see <a href="c-filesys2.html#85002"><i class="title">4.2.6 Using an Already Initialized Disk</i></a>. Formatting and DOS disk initialization can be done using the <b class="routine"><i class="routine">ioctl</i></b><b>( )</b> functions <b class="symbol_UC">FIODISKFORMAT</b> and <b class="symbol_UC">FIODISKINIT</b>, respectively.</p><dd><p class="Body"><a name="84582"> </a>The <b class="routine"><i class="routine">dosFsMkfs</i></b><b>( )</b> call provides an easier method of initializing a dosFs device; it does the following:</p></dl><dl class="margin"><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84583"> </a>Provides a set of default configuration values.</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84584"> </a>Calls <b class="routine"><i class="routine">dosFsDevInit</i></b><b>( )</b><b>.</b></li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84585"> </a>Initializes the disk structures using <b class="routine"><i class="routine">ioctl</i></b><b>( )</b> with the <b></b><b class="symbol_UC">FIODISKINIT</b> function.</li></ul></p></dl><dl class="margin"><dd><p class="Body"><a name="84586"> </a>The routine <b class="routine"><i class="routine">dosFsMkfs</i></b><b>( )</b> by default does not enable any dosFs-specific volume options (<b class="symbol_UC">DOS_OPT_CHANGENOWARN</b>, <b class="symbol_UC">DOS_OPT_AUTOSYNC</b>, <b class="symbol_UC">DOS_OPT_LONGNAMES</b>, <b class="symbol_UC">DOS_OPT_LOWERCASE</b>, or <b class="symbol_UC">DOS_OPT_EXPORT</b>). To enable any combination of these options, use <b class="routine"><i class="routine">dosFsMkfsOptionsSet</i></b><b>( )</b><b> </b>before calling <b class="routine"><i class="routine">dosFsMkfs</i></b><b>( )</b> to initialize the disk. For more information on the default configuration values, see the manual entry for <b class="routine"><i class="routine">dosFsMkfs</i></b><b>( )</b>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84591">4.2.4 Volume Configuration</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84594"> </a>The volume configuration structure, <b class="symbol_UC">DOS_VOL_CONFIG</b>, is used during the <b class="routine"><i class="routine">dosFsDevInit</i></b><b>( )</b> call. This structure contains various dosFs file system variables describing the layout of data on the disk. Most of the fields in the structure correspond to those in the boot sector. <a href="c-filesys2.html#84602">Table 4-1</a> lists the fields in the <b class="symbol_UC">DOS_VOL_CONFIG</b> structure.<p class="table"><h4 class="EntityTitle"><a name="84602"><font face="Helvetica, sans-serif" size="-1" class="sans">Table 4-1: <b class="symbol_UC">DOS_VOL_CONFIG</b> Fields</font></a></h4><table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="84606"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Field</font></b></div></th><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="84608"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Description</font></b></div></th></tr><tr><td colspan="20"><hr class="tablerule2"></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84610"> </a><b class="symbol_lc">dosvc_mediaByte</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84612"> </a>Media-descriptor byte </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84614"> </a><b class="symbol_lc">dosvc_secPerClust</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84616"> </a>Number of sectors per cluster </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84618"> </a><b class="symbol_lc">dosvc_nResrvd</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84620"> </a>Number of reserved sectors that precede the first FAT copy; the minimum is 1 (the boot sector) </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84622"> </a><b class="symbol_lc">dosvc_nFats</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84624"> </a>Number of FAT copies </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84626"> </a><b class="symbol_lc">dosvc_secPerFat</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84628"> </a>Number of sectors per FAT copy </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84630"> </a><b class="symbol_lc">dosvc_maxRootEnts</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84632"> </a>Maximum number of entries in root directory </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84634"> </a><b class="symbol_lc">dosvc_nHidden</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84636"> </a>Number of hidden sectors, normally 0 </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84638"> </a><b class="symbol_lc">dosvc_options</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84640"> </a>VxWorks-specific file system options </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84642"> </a><b class="symbol_lc">dosvc_reserved</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84644"> </a>Reserved for future use by Wind River Systems </div></td></tr><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p></p><dd><p class="Body"><a name="84646"> </a>Calling <b class="routine"><i class="routine">dosFsConfigInit</i></b><b>( )</b>is a convenient way to initialize <b class="symbol_UC">DOS_VOL_CONFIG</b>. It takes the configuration variables as parameters and fills in the structure. This is useful for initializing devices interactively from the Tornado shell (see the <i class="title">Tornado User's Guide: Shell</i>). The <b class="symbol_UC">DOS_VOL_CONFIG</b> structure must be allocated <i class="emphasis">before</i> <b class="routine"><i class="routine">dosFsConfigInit</i></b><b>( )</b> is called. </p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84647"><b class="symbol_UC">DOS_VOL_CONFIG</b> Fields</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84651"> </a>All but the last two<b class="symbol_UC"> DOS_VOL_CONFIG</b> fields in <a href="c-filesys2.html#84602">Table 4-1</a> describe standard MS-DOS characteristics. The field <b class="symbol_lc">dosvc_options</b> is specific to the dosFs file system. Possible options for this field are shown in <a href="c-filesys2.html#84659">Table 4-2</a>.<p class="table"><h4 class="EntityTitle"><a name="84659"><font face="Helvetica, sans-serif" size="-1" class="sans">Table 4-2: dosFs Volume Options</font></a></h4><table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><th rowspan="1" colspan="1">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -