CPSC 304 - Operating Systems
Sector 0 and BPB - Example of FAT

Earl M. Rodd - Malone College - www.malone.edu/erodd

Overview

All Intel based PCs use sector 0 as a "boot sector". Also in this sector is control information used to "anchor" the filesystem. Below I document the details of sector 0 when the file system is FAT, the original DOS file system. The concept is identical for other file systems, even though some of the fields will be different.

FAT operation

Basic Disk Layout

A FAT disk always has the layout shown in the table below. The size of the FAT itself and of the root directory is contained in the Bios Parameter Block (BPB) in sector 0. Next we will look carefully at what is in the BPB. Notice that the root directory is a fixed size! This means that on a FAT disk, if you attempt to put more files that this number in the root directory, the attempt will fail!
Sector
Description
0
Boot Record with BPB (if not bootable partition, no boot information)
fatsize
Copy of FAT table (size is from BPB in sector 0)
fatsize
Second copy of FAT table (same size of first copy)
32*entries
Root directory. Number of entries is in the BPB in sector 0.
Remainder of disk
Data area (files and subdirectories)

First, we will look at the BPB, then the layout of a directory entry. Note that while we will examine the root directory, subdirectories have the exact same layout. The difference is that the root directory is at a fixed location on the disk and has a fixed size whereas subdirectories are normal files and can be scattered anywhere on the disk and can be of any size (until the disk is full).

The BPB

The first sector of a disk contains the Bios Parameter Block(BPB). With more sophisticated file systems, sector 0 still contains a BPB (or something like it) with basic information about the filesystem so that the File Manager can find the root diretory or master file table or whatever that filesystem calls its main control area. With FAT, the BPB contains more information than newer file systems, mostly because there are more fixed values with FAT.

Notice that fields which are WORDs are in an unusual format of reversed bytes. This is because an Intel machine is "little endian" meaning that 2 byte words are reversed when they are placed into CPU registers for processing. Thus, on disk, they are stored in reverse order. Thus the two byte value: X'0102' on disk is actually the number X'0201' which is:

0 times 16**3 +2 times 16**2 (256*2=512) +0 times 16 +1 (1) -------------- 513

The very first thing in sector 0 is a "JUMP" instruction. This is an INTEL hardware instruction which is a "GOTO". When a machine is booted, the ROM reads sector 0 and executes it as code. In order to put data in sector 0 (BPB), it is necessary to do a "GOTO" to branch around this data. After the BPB is more code which is used to boot the system (assuming this is a bootable diskette or partition).
Displacement(dec(hex))
Size
Description
0
3
JUMP (X'EBxx) plus NOP (X'90')
3
8
ASCII Vendor/Version
11 (0B)
2(WORD)
Bytes per sector (e.g. X0002 = X0200 = 512 decimal)
13 (0D)
1
Sectors per cluster (1 for diskettes)
14 (0E)
2
Reserved Sectors
16 (10)
1
Number of FATs (usually 2)
17 (11)
2(WORD)
Number of entries in the ROOT directory
19 (13)
2(WORD)
Sectors in the partition
21 (15)
1
Media Descriptor (code for disk size/type)
22 (16)
2(WORD)
Number of sectors in one FAT
24 (18)
2(WORD)
Sectors per track
26 (1A)
2(WORD)
Number of heads
28 (2C)
2(WORD)
Number of hidden sectors