📄 c-filesys2.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-filesys1.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-filesys3.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="84387">4.2 MS-DOS-Compatible File System: dosFs</a></i></h3></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84388"> </a>Diskettes formatted using the dosFs file system are compatible with MS-DOS diskettes up to and including release 6.2. Hard disks initialized by the two file systems have slightly different formats. However, the data itself is compatible and dosFs can be configured to use a disk formatted by MS-DOS.</p><dd><p class="Body"><a name="84389"> </a>The dosFs file system offers considerable flexibility appropriate to the varying demands of real-time applications. Major features include:</p></dl><dl class="margin"><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84390"> </a>A hierarchical arrangement of files and directories, allowing efficient organization and permitting an arbitrary number of files to be created on a volume.</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84391"> </a>A choice of contiguous or non-contiguous files on a per-file basis. Non-contiguous files result in more efficient use of available disk space, while contiguous files offer enhanced performance.</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84392"> </a>Compatibility with widely available storage and retrieval media. Diskettes created with VxWorks (that do not use dosFs extended filenames) and MS-DOS PCs and other systems can be freely interchanged. Hard disks are compatible if the partition table is accounted for.</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84393"> </a>The ability to boot VxWorks from any local SCSI device that has a dosFs file system.</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84394"> </a>The ability to use longer file names than the 8-character filename plus 3-character extension (8.3) convention allowed by MS-DOS.</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84395"> </a>NFS (Network File System) support.</li></ul></p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84397">4.2.1 Disk Organization</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84398"> </a>The MS-DOS/dosFs file system provides the means for organizing disk data in a flexible manner. It maintains a hierarchical set of named directories, each containing files or other directories. Files can be appended; as they expand, new disk space is allocated automatically. The disk space allocated to a file is not necessarily contiguous, which results in a minimum of wasted space. However, to enhance its real-time performance, the dosFs file system allows contiguous space to be pre-allocated to files individually, thereby minimizing seek operations and providing more deterministic behavior.</p><dd><p class="Body"><a name="84402"> </a>The general organization of an MS-DOS/dosFs file system is shown in <a href="c-filesys2.html#84406">Figure 4-1</a> and the various elements are discussed in the following sections. <div class="frame"><h4 class="EntityTitle"><a name="84406"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure 4-1: MS-DOS Disk Organization</font></a></h4><dl class="margin"><div class="Anchor"><a name="84427"> </a><img class="figure" border="0" src="images/c-filesys0.gif"></div></dl></div></p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84429">Clusters</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84430"> </a>The disk space allocated to a file in an MS-DOS/dosFs file system consists of one or more disk <i class="term">clusters</i>. A cluster is a set of contiguous disk sectors.<sup><a href="#foot"><b class="FootnoteMarker">1</b></a></sup> For floppy disks, two sectors generally make up a cluster; for fixed disks, there can be more sectors per cluster. A cluster is the smallest amount of disk space the file system can allocate at a time. A large number of sectors per cluster allows a larger disk to be described in a fixed-size File Allocation Table (FAT; see <i class="emphasis"><a href="c-filesys2.html#84448"></i><i class="title">File Allocation Table</i><i class="emphasis"></a></i>), but can result in wasted disk space.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84440">Boot Sector</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84441"> </a>The first sector on an MS-DOS/dosFs hard disk or diskette is called the <i class="term">boot sector</i>. This sector contains a variety of configuration data. Some of the data fields describe the physical properties of the disk (such as the total number of sectors), and other fields describe file system variables (such as the size of the root directory).</p><dd><p class="Body"><a name="84442"> </a>The boot sector information is written to a disk when it is initialized. The dosFs file system can use diskettes that are initialized on another system (for example, using the <b class="symbol_UC">FORMAT</b> utility on an MS-DOS PC), or VxWorks can initialize the diskette, using the <b class="symbol_UC">FIODISKINIT</b> function of the <b class="routine"><i class="routine">ioctl</i></b><b>( )</b> call.</p><dd><p class="Body"><a name="84444"> </a>As the MS-DOS standard has evolved, various fields have been added to the boot sector definition. Disks initialized under VxWorks use the boot sector fields defined by MS-DOS version 5.0.</p><dd><p class="Body"><a name="84445"> </a>When MS-DOS initializes a hard disk, it writes a <i class="term">partition table</i> in addition to the boot sector. VxWorks does not create such a table. Therefore hard disks initialized by the two systems are not identical. VxWorks can read files from a disk formatted by MS-DOS if the block offset parameter in the device creation routine points beyond the partition table to the first byte of the data area.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84448">File Allocation Table</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84449"> </a>Each MS-DOS/dosFs volume contains a File Allocation Table (FAT). The FAT contains an entry for each cluster on the disk that can be allocated to a file or directory. When a cluster is unused (available for allocation), its entry is zero. If a cluster is allocated to a file, its entry is the cluster number of the next portion of the file. If a cluster is the last in a file, its entry is -1. Thus, the representation of a file (or directory) consists of a linked list of FAT entries. In the example shown in <a href="c-filesys2.html#84456">Figure 4-2</a>, one file consists of clusters 2, 300, and 500. Cluster 3 is unused.</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/note.gif"></td><td><hr><div class="CalloutCell"><a name="87807"><b class="symbol_UC"><font face="Helvetica, sans-serif" size="-1" class="sans">NOTE: </font></b></a>dosFs does not map bad disk sectors to the FAT.</div></td></tr><tr valign="top"><td></td><td><hr></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p callout><dl class="margin"><dd><p class="Body"><a name="87451"> </a><div class="frame"><h4 class="EntityTitle"><a name="84456"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure 4-2: FAT Entries</font></a></h4><dl class="margin"><div class="Anchor"><a name="84495"> </a><img class="figure" border="0" src="images/c-filesysa1.gif"></div></dl></div></p><dd><p class="Body"><a name="84496"> </a>The FAT uses either 12 or 16 bits per entry. Disk volumes that contain up to 4085 clusters use 12-bit entries; disks with more than 4085 clusters use 16-bit entries. The entries (particularly 12-bit entries) are encoded in a specific manner, done originally to take advantage of the Intel 8088 architecture. However, all FAT handling is done by the dosFs file system; thus the encoding and decoding is of no concern to VxWorks applications.</p><dd><p class="Body"><a name="84497"> </a>A volume typically contains multiple copies of the FAT. This redundancy allows data recovery in the event of a media error in the first FAT copy. </p></dl><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="86458"><b class="symbol_UC"><font face="Helvetica, sans-serif" size="-1" class="sans">CAUTION: </font></b></a>The dosFs file system maintains multiple FAT copies if that is the specified configuration; however, the copies are not automatically used in the event of an error.</div></td></tr><tr valign="top"><td></td><td><hr></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p callout><dl class="margin"><dd><p class="Body"><a name="84507"> </a>The size of the FAT and the number of FAT copies are determined by fields in the boot sector. For disks initialized using the dosFs file system, these parameters are specified during the <b class="routine"><i class="routine">dosFsDevInit</i></b><b>( )</b> call by setting fields in the volume configuration structure, <b class="symbol_UC">DOS_VOL_CONFIG</b>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84512">Root Directory</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84513"> </a>Each MS-DOS/dosFs volume contains a root directory. The root directory always occupies a set of contiguous disk sectors immediately following the FAT copies. The disk area occupied by the root directory is not described by entries in the FAT.</p><dd><p class="Body"><a name="84514"> </a>The root directory is of a fixed size; this size is specified by a field in the boot sector as the maximum allowed number of directory entries. For disks initialized using the dosFs file system, this size is specified during the <b class="routine"><i class="routine">dosFsDevInit</i></b><b>( )</b> call, by setting a field in the volume configuration structure, <b class="symbol_UC">DOS_VOL_CONFIG</b>.</p><dd><p class="Body"><a name="84517"> </a>Because the root directory has a fixed size, an error is returned if the directory is full and an attempt is made to add entries to it.</p><dd><p class="Body"><a name="84520"> </a>For more information on the contents of the directory entry, see <a href="c-filesys2.html#85091"><i class="title">4.2.13 Directory Entries</i></a>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84523">Subdirectories</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84524"> </a>In addition to the root directory, MS-DOS/dosFs volumes sometimes contain a hierarchy of subdirectories. Like the root directory, subdirectories contain entries for files and other subdirectories; however, in other ways they differ from the root directory and resemble files:</p></dl><dl class="margin"><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84525"> </a>First, each subdirectory is described by an entry in another directory, as is a file. Such a directory entry has a bit set in the file-attribute byte to indicate that it describes a subdirectory. Also, subdirectories, unlike the root directory, have user-assigned names.</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="87768"> </a>Second, the disk space allocated to a subdirectory is composed of a set of disk clusters, linked by FAT entries. This means that a subdirectory can grow as entries are added to it, and that the subdirectory is not necessarily made up of contiguous clusters. The root directory, unlike subdirectories, can be made up of any number of sectors, not necessarily equal to a whole number of clusters.</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84528"> </a>Third, subdirectories always contain two special entries. The "<b>.</b>" entry refers to the subdirectory itself, while the "<b>..</b>" entry refers to the subdirectory's parent directory. The root directory does not contain these special entries.</li></ul></p></dl></dl><font face="Helvetica, sans-serif" class="sans">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -