The Files Area

The remainder of the volume after the root directory is known as the files area. MS-DOS views the sectors in this area as a pool of clusters, each containing one or more logical sectors, depending on the disk format. Each cluster has a corresponding entry in the FAT that describes its current use: available, reserved, assigned to a file, or unusable (because of defects in the medium). Because the first two fields of the FAT are reserved, the first cluster in the files area is assigned the number 2.

When a file is extended under versions 1 and 2, MS-DOS searches the FAT from the beginning until it finds a free cluster (designated by a zero FAT field); it then changes that FAT field to a last-cluster mark and updates the previous last cluster of the file's chain to point to the new last cluster. Under versions 3.0 and later, however, MS-DOS searches the FAT from the most recently allocated cluster; this reduces file fragmentation and improves overall access times.

Directories other than the root directory are simply a special type of file. Their storage is allocated from the files area, and their contents are 32-byte entries——in the same format as those used in the root directory——that describe files or other directories. Directory entries that describe other directories contain an attribute byte with bit 4 set, zero in the file-length field, and the date and time that the directory was created (Figure 10-7). The first cluster field points, of course, to the first cluster in the files area that belongs to the directory. (The directory's other clusters can be found only by tracing through the FAT.)

All directories except the root directory contain two special directory entries with the names . and ... MS-DOS puts these entries in place when it creates a directory, and they cannot be deleted. The . entry is an alias for the current directory; its cluster field points to the cluster in which it is found. The .. entry is an alias for the directory's parent (the directory immediately above it in the tree structure); its cluster field points to the first cluster of the parent directory. If the parent is the root directory, the cluster field of the .. entry contains zero (Figure 10-8).

.

.

.

0080 4D 59 44 49 52 20 20 20 20 20 20 10 00 00 00 00 MYDIR .....

0090 00 00 00 00 00 00 87 9A 9B 0A 2A 00 00 00 00 00 ..........*.....

.

.

.

Figure 10-7. Extract from the root directory of an MS-DOS disk, showing the entry for a subdirectory named MYDIR. Bit 4 in the attribute byte is set, the cluster field points to the first cluster of the subdirectory file, the date and time stamps are valid, but the file length is zero.

0 1 2 3 4 5 6 7 8 9 A B C D E F

0000 2E 20 20 20 20 20 20 20 20 20 20 10 00 00 00 00 . .....

0010 00 00 00 00 00 00 87 9A 9B 0A 2A 00 00 00 00 00 ..........*.....

0020 2E 2E 20 20 20 20 20 20 20 20 20 10 00 00 00 00 .. .....

0030 00 00 00 00 00 00 87 9A 9B 0A 00 00 00 00 00 00 ................

0040 4D 59 46 49 4C 45 20 20 44 41 54 20 00 00 00 00 MYFILE DAT ....

0050 00 00 00 00 00 00 98 9A 9B 0A 2B 00 15 00 00 00 ..........+.....

0060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

0070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

.

.

.

Figure 10-8. Hex dump of the first block of the directory MYDIR. Note the . and .. entries. This directory contains exactly one file, MYFILE.DAT.