FAT12

Read, write, delete, mkdir, rmdir, rename, format — all in C, no assembly.

Available now on Leanpub — actively polishing
FAT12 book cover — Read, write, delete, mkdir, rmdir, rename, and format in C

This book takes you from first sector to a complete, dual-platform FAT12 implementation. 11 chapters, ~1500 lines of C, one evolving codebase that compiles zero-warning on both your development machine and in QEMU as a 32-bit kernel.

All C, no assembly
FAT table walking, directory parsing — all of it
Complete operations
Read, write, delete, mkdir, rmdir, rename, format
12-bit packing finally explained
Diagrams + step-by-step C for straddling entries
Portable to your kernel
Same code runs in CLI tool and QEMU
Compiles zero-warning
GCC/Clang, no patching, no bit-rot
11 chapters, 1500 lines
One evolving codebase from chapter 1 to 11

Leanpub sample includes chapters 1–3. No email required for the PDF.

Björn Götz

Beta readers welcome

The manuscript is content-complete and I'm polishing it based on reviewer feedback. If you'd like a free copy in exchange for your thoughts, send me an email:

fat12@softwarefreak.net

What makes this book different

Complete in C
Every operation — read, write, delete, mkdir, rename, format — in one C codebase
Dual-platform
Same library runs as a CLI tool and as a 32-bit kernel in QEMU
12-bit packing
Full chapter with diagrams and step-by-step C for the byte-boundary straddle
One codebase
11 chapters, ~1500 lines, evolving from first sector read to full format

Visual, byte-accurate diagrams

Every on-disk structure comes with a color-coded field map — no guesswork, no "offset 27 stores the first cluster, trust me." Here is the BPB layout, byte 11 through 35:

BPB field map — BIOS Parameter Block byte layout showing bytes_per_sector, sectors_per_cluster, and all 25 bytes of the FAT12 BPB

What's Inside

11 chapters, ~1500 lines of C, one evolving codebase:

1 Hello, Disk!
2 The Blueprint (BPB)
3 The Root Directory
4 Reading Files
5 Full Path Walking
6 Writing Files
7 Creating Directories
8 Deleting
9 Renaming & Moving
10 Formatting
11 Into the Kernel

See the code

Clean C, no magic. Here's the core typesystem your FAT12 driver starts with:

typedef struct
      {
          uint8_t  jmp[3];
          uint8_t  oem[8];
          uint16_t bytes_per_sector;
          uint8_t  sectors_per_cluster;
          uint16_t reserved_sectors;
          uint8_t  fat_count;
          uint16_t root_entry_count;
          uint16_t total_sectors_16;
          uint8_t  media_descriptor;
          uint16_t fat_size_16;
          uint16_t sectors_per_track;
          uint16_t head_count;
          uint32_t hidden_sectors;
          uint32_t total_sectors_32;
      } __attribute__((packed)) BPB;
BPB struct — packed, matches on-disk layout exactly

Who is this for?

You — if you're building a hobby OS and need a filesystem driver. You know C (pointers, structs, bit manipulation) and want a complete FAT12 implementation you can drop into your kernel.

Recommended

OS Design Book Series by Ben Lunt — a comprehensive deep dive into operating system internals.