MS-DOS and Windows 9x share almost the same FAT and directory structure. In this ariticle, let me talk about them.
MS-DOS stores your files on the disk. Then, how are they arranged? Let me explain it to you.
Let's firstly see how books are stored. Usually, people store information in books. Books are a kind of mass media. They can hold both text and graphic information. Each book has a name, which are usually different from one to another, so that we can distinguish one book from others. A book usually consists of paper only. The number of pieces of paper composing a book can be counted. Every book takes up a certain amount of space in the bookshelf when they are put in a book shelf. They can be moved when there is need to rearrange them.
The MS-DOS FAT file system is somewhat alike. See a list of its features below.
MS-DOS FAT file system has these features:
1. Each file takes up a certain number of clusters (also called allocation units), just like each book consists of a certain number
pieces of paper. Each cluster is unique on the disk. They can be numbered. By MS-DOS, a certain disk has a fixed cluster size, and clusters are continuously defined on the disk.
2. Books cannot be divided, but a file can be divided and then stored on a disk. Why should this be done? Because moving books on a bookshelf is easy, but moving files on a disk from one place to another usually takes much time; and what's more important, files may be modified, so a file may increase or decrease from time to time. If files are stored sequentially, there may be much work in moving the rest files on the disk while there is only one file being modified. So files should not be always stored sequentially on the disk like books on the bookshelf. To enable divided storage of files on the disk, FAT is used. FAT is used to hold chains of files on the disk. Because each cluster can be numbered, it is possible to locate a file on a disk. If you have learned programming, you may have the knowledge of linked lists. Information in the FAT is like linked lists. The pointer to the head node of the linked list is stored in a directory, the following pointers are stored in the FAT. Each FAT entry represents a cluster. To distinguish between occupied clusters and free clusters, clusters are numbered from three. Zero-value FAT entries represent free clusters. On the other hand, there should be an end mark for chains in the FAT. MS-DOS uses 0xFFF, 0xFFFF, 0xFFFFFFFF respectively as end marks of FAT12, FAT16 and FAT32. These marks are quite like NULL in programming. MS-DOS also reserved other marks, which are 0xFF7, 0xFFF7, 0xFFFFFFF7 respectively as "bad cluster" marks (marking bad disk areas) for FAT12, FAT16 and FAT32. Bad clusters are marked in the FAT in order to avoid writing to bad sections of the disk.
3. Directories are used for storing the names of files. Just like books have their names, files also have their names. They are listed in the directory. Also, the number of the first cluster of the file is also listed in the directory. By MS-DOS, there is a root directory on a disk. The root directory has a fixed number of entries available for files, and its position on the disk is fixed. (Since Windows 95 OSR 2, its file system FAT32 has a sizable root directory which also has a corresponding chain list in the FAT like subdirectories.) A "directory entry" contains basic information of a file or a subdirectory in the directory. Since MS-DOS 2.0, MS-DOS supports tree-structured directories. To do so, MS-DOS uses subdirectories. A subdirectory is stored on the disk like a file, but it contains directory entries that are similar to those in the root directory. Of course this is a good idea. Number of entries in a subdirectory is unlimited (compared with the root directory; of course it is limited by disk space), because a subdirectory can extend or shrink like a file. To distinguish used entries from free entries, MS-DOS states that if an entry starts with the character 0xE5 (in ASCII, a Greek character Sigma) or 0x00, the entry is free(may be an entry of a deleted file).
4. The specification of a drive (logical drive; a volume) (FAT type [8/12/16/32; 1 FAT or 2 FATs], compatible MS-DOS version, disk size, cluster size, root directory size, volume label, volume serial number, etc.) is stored in the boot sector. Usually, a sector is a continuous 512 byte block on the disk (its actual size depends on the type of the disk). The boot sector also contains the boot program for MS-DOS. 2 FATs, 1 root directory and the boot sector are created during the MS-DOS FORMAT.COM process of a usual logical drive.
That's a story about FAT and MS-DOS directory structure. For practical use, here are some paragraphs talking about real disk allocation by MS-DOS.
Floppy disks are widely used today. Although they are not used so often now as they were, they are still common. I think the specification of current MS-DOS formatted 3.5 inch High Density floppies can be shown as an example. This example is a Windows Me boot disk.
1. The very beginning sector of the disk is the boot sector. This is always true when you are using MS-DOS (it is also true for most operating systems). There is a program in the boot sector that loads the operating system. The program in the boot sector is loaded by a program in the master boot sector (MBR) or by the computer BIOS program.The file system layout of 3.5 inch floppy disks has been described above.
Now let's talk about some common operations of MS-DOS.