Note – this section of the manual is for information only. You do not need to read and understand this large and in depth section to use the driver! However you may want to if you wish to gain an understanding of disk access, the FAT filing system and how this driver works.
Terms used for hard disks and therefore MMC / SD memory cards
Remember when understanding these terms that hard disks uses multiple disks of magnetic material with a read/write head for each side of each disk. Bytes are read from and written to a disks surface in circular paths.
Track
The circular track on one surface of a disk (numbered 0 – #). This is not usually referred to.
Cylinder
All of the tracks in the same position on all of the surfaces (numbered 0 – #). This is not usually referred to other than when determining the parameters of a disk during initialisation.
Head
Each side of a disk has a read / write head (numbered 0 – #). This is not usually referred to other than when determining the parameters of a disk during initialisation.
Sector
This is the fundamental unit of disk mapping – all reading and writing to disks is carried out in sectors. A sector is usually 512 bytes in size, but can be 128 – 1024 bytes.
(Numbered as 1 – # (0 is reserved for identification purposes)).
Cluster
A cluster is a specified group of sectors. It is clusters that are the addressing unit when reading and writing files using the FAT system (i.e. a directory will point to a particular file using the cluster number that contains the start of the file). A cluster may only be used by one file, and large files will use multiple clusters to hold their data. A disk with a large cluster size (lots of sectors per cluster) will mean that disk space is wasted as any unused bytes after the end of a file in its final cluster will not be available for anything else. A disk with a small cluster size means less wastage. However, a small cluster size means a larger FAT table as a FAT table contains an entry for every cluster on a disk (or in the partition if the disk is partitioned), hence the need to FAT32 instead of FAT16 for larger volumes.
The valid range is 1 – 64 sectors per cluster. The first cluster that may be used is number 2 (clusters 0 & 1 are reserved).
The FAT filing system was developed for DOS and DOS thinks of a disk as a linear object, not as it is actually constructed. This means that DOS treats the sectors of a disk as a sequential list of sectors, from the first on the disk to the last. Whilst this made things more complex when writing drivers for hard disks, it makes things easier when dealing with modern flash memory cards as these are linear memory objects.
Byte Ordering
The FAT file system uses ‘little endian’. That is that the first byte read is the least significant byte of a large value, the next byte read is more significant than the last and so on. For example this is how a 32bit value would be stored (with the bit numbers shown):-
byte[3] 31 30 29 28 27 26 25 24 //This is the last byte read from the disk
byte[2] 23 22 21 20 19 18 17 16
byte[1] 15 14 13 12 11 10 09 08
byte[0] 07 06 05 04 03 02 01 00 //This is the first byte read from the disk
The following sections show how the different sections of a disk are organised for FAT16 and FAT32, looking at the disk as a linear memory object (which is how it is addressed). See the following sections for an in depth description of each block.
The Layout of a FAT16 Volume
| Start Address | Size | Contents |
| 0×00000000 | 512 bytes | Master Boot Record
(Amongst other things this specifies the address of each of the main partitions). |
| Partition Start Address + 0 | 512 bytes | Partition 1 -
The Boot Record. Located in the first sector of a partition. |
| Partition Start Address + 512 | As specified in the Boot Record | Partition 1 -
FAT table 1 |
| Partition Start Address + 512
+ (Size of FAT Table x (FAT table # – 1)) (*Note 1) |
As specified in the Boot Record | Partition 1 -
FAT table # (specified by ‘Number of Copies of FAT’ in master boot record. A value of 2 is normal) |
| Partition Start Address + 512 + (Size of FAT Table x Number of Copies of FAT) | As specified in the Boot Record | Partition 1 -
Root directory |
| Partition Start Address + 512 + (Size of FAT Table x Number of Copies of FAT)
+ Size of Root Directory |
Calculated from the Master Boot Record Total Partition Size | Partition 1 -
Data area for files and other directories. (This area occupies the remainder of the disk, or the space to the start of the next partition). |
Then follows further partitions if present:-
| Start Address | Size | Contents |
| Partition Start Address + 0 | 512 bytes | Partition 2 -
The Boot Record. Located in the first sector of a partition. |
| Partition Start Address + 512 | As specified in the Boot Record | Partition 2 -
FAT table 1 |
| Partition Start Address + 512
+ (Size of FAT Table x (FAT table # – 1)) (*Note 1) |
As specified in the Boot Record | Partition 2 -
FAT table # (specified by ‘Number of Copies of FAT’ in master boot record. A value of 2 is normal) |
| Partition Start Address + 512 + (Size of FAT Table x Number of Copies of FAT) | As specified in the Boot Record | Partition 2 -
Root directory |
| Partition Start Address + 512 + (Size of FAT Table x Number of Copies of FAT)
+ Size of Root Directory |
Calculated from the Master Boot Record Total Partition Size | Partition 2 -
Data area for files and other directories. (This area occupies the remainder of the disk, or the space to the start of the next partition). |
Repeated for each partition
Note1 – These cells may repeat or not be present at all.
The Layout of a FAT32 Volume
This is basically the same as for a FAT16 volume, but without the root directory included (and with each block using a different amount of space).
| Start Address | Size | Contents |
| 0×00000000 | 512 bytes | Master Boot Record
(Amongst other things this specifies the address of each of the main partitions). |
| Partition Start Address + 0 | 512 bytes | Partition 1 -
The Boot Record. Located in the first sector of a partition. |
| Partition Start Address + 512 | As specified in the Boot Record | Partition 1 -
FAT table 1 |
| Partition Start Address + 512
+ (Size of FAT Table x (FAT table # – 1)) (*Note 1) |
As specified in the Boot Record | Partition 1 -
FAT table # (specified by ‘Number of Copies of FAT’ in master boot record. A value of 2 is normal) |
| Partition Start Address + 512 + (Size of FAT Table x Number of Copies of FAT) | Calculated from the Master Boot Record Total Partition Size | Partition 1 -
Data area for files and other directories. (This area occupies the remainder of the disk, or the space to the start of the next partition). |
Then if there is more than 1 partition, the additional partitions follow:-
| Start Address | Size | Contents |
| Partition Start Address + 0 | 512 bytes | Partition 2 -
The Boot Record. Located in the first sector of a partition. |
| Partition Start Address + 512 | As specified in the Boot Record | Partition 2 -
FAT table 1 |
| Partition Start Address + 512
+ (Size of FAT Table x (FAT table # – 1)) |
As specified in the Boot Record | Partition 2 -
FAT table # (specified by ‘Number of Copies of FAT’ in master boot record. A value of 2 is normal) |
| Partition Start Address + 512 + (Size of FAT Table x Number of Copies of FAT) | Calculated from the Master Boot Record Total Partition Size | Partition 2 -
Data area for files and other directories. (This area occupies the remainder of the disk, or the space to the start of the next partition). |
Repeated for each partition
*Note 1 – Shaded cells may repeat or not be present at all.


