Karbosguide.com - Module 6a.4

About file systems (continued)

The contents:

  • Boot record
  • FAT areas
  • Root directory and other directories
  • The data area
  • Next page
  • Previous page

  • An example of the sectors in the four areas

    Let us look at a FAT formatted hard disk with 160 MB: How are the sectors utilized?

    Note: My calculations in this example are NOT 100% CORRECT, as a few bright readers have noticed. I am sorry. However, use them as an indication of how the disk is subdivided. One day I hope to give the correct picture...

    The partition contains exactly 157.9 MB, if we calculate correctly. We are talking about 165,656,576 bytes. The total data storage area is divided in 323,549 sectors, 512 bytes each. If you multiply, that results in 165,656,576 bytes:

    323,548 sectors x 512 bytes = 165,656,576 bytes.

    This equals to 157.9 MB as you can see from this:

    = 165,656,576 bytes
    divided with 1024 =
    161,774 Kilobytes
    161,774 Kilobytes
    divided with 1024 =
    157.9 Megabytes

    The file system now assumes control over these 323,548 sectors. The boot record occupies the first sector . In the following you find a brief description of the boot record and other administrative areas.

    Boot record

    The first disk sector is always reserved for the boot record. It contains information about the disk or its partitions. A physical hard disk can be divided into different partitions. DOS, Windows 95 and NT treat each partition as a separate drive.

    The boot record information enables the file system to handle the disk. At the same time, it includes a small program to use during system start-up. Here is a summary of that sector's contents (skip, if you do not understand):

    8086 instruction (JUMP).
    DOS name and version number.
    Bytes per sector.
    Sectors per cluster in the data area.
    Number of reserved sectors.
    Max. number of entries in the root directory.
    Total number of sectors.
    Media description (is this a hard disk?).
    Number of sectors per FAT
    Number of sectors per track.
    Number of disk read heads.
    Number of hidden sectors.
    BOOT-strap program routine, which reads the hidden file (like IO.SYS), which starts the operating system.

    The boot record is found on all disks, regardless of whether they are FAT or otherwise formatted. That sector contains the necessary description of the partition.

    The FAT areas

    After the boot record, we get to the FAT areas. There are usually two identical FATs. FAT number 2 is simply a spare copy of number 1, since FAT is essential for the function of the disk.

    The FAT file administration is actually a very simple system, but it is complicated to describe. Later, I will show some practical examples. Here is the first description. Even if you do not entirely understand the following, do not give up.

    FAT consists of a table of whole numbers, which has 65,536 16-bit entries . Each of these entries contain information about a cluster.

    The content of each FAT entry consists of a whole number . In the table below, they are written as four digit hexadecimal numbers, which show one of four options.

    Possible FAT cluster entry Value
    The cluster is part of a file, the last in the file. FFFF
    The cluster is part of a file. You can read the
    number of the next cluster in the same file.
    like A8F7
    The cluster is empty, thus free. 0000
    The cluster contains defective sectors. FFF7

    Example on reading a file

    When the file system has to read a file, it follows this routine. We imagine that the file occupies 4 clusters and it occupies cluster numbers 442, 443, 444, and 448. But how does the operating system read these addresses?

  • Find the file directory entrance (from its file address).

  • Read the first cluster, number 442 in the directory entrance.

  • Look up in FAT under number 442. We find the number of the next cluster (443).

  • Look up in FAT under number 443. We find the number of the next cluster (444).

  • Look up in FAT under number 444. We find the number of the next cluster (448).

  • Look up in FAT under number 448 to find FFFF (indicating the last cluster).

    FAT always works in this way. Whenever a file has to be read, its location is read in the table. Every time a file has to be written to a disk, vacant clusters must be found for it, and the information is stored in FAT, to facilitate retrieval.

    One of the great advantages of disk cache programs are, they always have a copy of FAT in RAM. In this way the disk cluster "map" can be read much faster than if the operating system had to read the FAT from the disk at each request.

    The size of FAT

    Since each cluster has a FAT entry, the size of the FAT areas depends on the disk size. Each entry occupies 16 bits.

    Let us return to the sector account in the example of a disk of 160 MB size:

    The maximum FAT size is 128 KB, since 2 16 files, 2 bytes each, equals 65,536 x 2 = 131,072 bytes or 128 KB. In our example, there turns out to be 40,400 clusters , since the disk partition is 160 MB.

    We have two FATís, at 40,400 X 2 bytes. That comes to a total of 161,600, and that will occupy 316 sectors.

    The root directory and other directories

    The last administrative area on the disk is the root directory. Since there are always 512 file or directory entrances in the root directory, it is the same size on all hard disks. The root directory is unique in its fixed size and its location in the root. Other than that, it is a directory like any other.

    Actually, a directory is a list of files and other directories. Thus, you can read the names of files and sub directories in the directory! The directory structure consists of a number of directory entries.

    Let us look at these directory entries, each of which occupies 32 bytes. The directory entries are identical, whether they are in the root directory or a sub directory.

    These entries, 32 bytes each, contain a lot of information like:

  • The file name (in 8.3 format)
  • File size in bytes
  • Date and time of last revision

    You can see the layout of the file entry on the illustration to the right. The 32 bytes are grouped in sections. This holds true for all entries, whether they point towards files or directories. This holds true for the root directory as well as all sub directories.

    Note that we also find the number of the first cluster. This is important, because this is where the operating system starts to localize the file.

    Remember the description of FAT above. You see that the start cluster number is read in the directory entry for the file.

    Next FAT reads the numbers of cluster number two and so on, if the file is spread over additional clusters.

    The location of any file is described in this manner: The first cluster is read in the directory entry (root or sub directory). The following cluster numbers are retrieved from FAT.

    On FAT16 formatted hard disks, the root directory occupies 512 entries, which are 32 bytes each. Thus, it occupies 16 KB.

  • All sub directories have at least two entries. They are rather special , in that they refer to the directory itself and to its "parent" directory (in which it is a sub directory). The entries can be seen with the DOS command DIR.

    The entry for the directory itself is seen as one dot. The entry for the parent directory is seen as two dots.

    The data area

    The rest of the disk contains the most important part, the data area, where all files and sub directories are stored. The data area is by far the largest part of the disk.

    The sectors in the data area are allocated in clusters. As mentioned before, the maximum number of clusters for data is 2 16 = 65,536. Our hard disk is 160 MB. That results in 40,400 clusters, 8 sectors each.

    All sub directory entries in the data area are organized in 32 byte files, which contain the same fields as the root directory entries.

    Completing the account

    The user has a 160 MB hard disk, but that is a somewhat theoretical view. Actually, the disk contains 323,548 sectors, 512 bytes each. They are distributed like this (or rather almost, there are minor errors in the calculations):

    Area Number of sectors Sector number
    Boot - record 1 0
    FAT 1 158 1 - 158
    FAT 2 158 159 - 316
    Root directory 32 317- 348
    Data area with 40,400 clusters of 4 KB 323,200 349 - 323,548

    Here is a graphic illustration of the same distribution:

  • Next page
  • Previous page

    To learn more

    Read Module 6b with a little about Windows 95/98.

    Read Module 6c about the relationship between BIOS, OS and hardware

    Read Module 7a about the videosystem

    Read about video cards in Module 7b .

    Read about digital sound in Module 7c .

    [Main page]
    [Karbo's Dictionary]
    [The Software Guides]

    Copyright (c) 1996-2016 by Michael B. Karbo. www.Karbosguide.com.