I recover disks as a hobby, so I end up looking at hex a lot. A 3.5" 1.44 MB floppy formatted with FAT12 has a simple layout of 2880 sectors of 512 bytes:
| Region | Sectors | What |
|---|---|---|
| Boot sector | 1 | Geometry, label, boot code |
| FAT #1 | 9 | The allocation chain |
| FAT #2 | 9 | A copy, for luck |
| Root directory | 14 | 224 entries of 32 bytes |
| Data area | 2847 | One sector per cluster |
A directory entry holds the name (8.3), attributes, dates, the first cluster and the file size. To read a file you take its first cluster, then ask the FAT "what comes next?". The answer is another cluster number, or an end-of-chain marker (0xFF8 to 0xFFF).
The "12" is for 12-bit entries, so two entries are packed into three bytes. Fetching entry n:
uint16_t fat12_get(const uint8_t *fat, unsigned n) {
unsigned off = n + n / 2; /* n * 1.5 */
uint16_t v = fat[off] | (fat[off + 1] << 8);
return (n & 1) ? (v >> 4) : (v & 0x0FFF);
}
Clusters are numbered from 2, because entries 0 and 1 are reserved for the media descriptor. An entry of 0x000 means free, 0xFF7 marks a bad cluster.
When a floppy "lost its files", the directory is usually fine and it is a damaged FAT sector that cut a chain in half. The second FAT copy has saved a few of mine.