FAT12

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

FAT12 book cover — Read, write, delete, mkdir, move, and format in C

Every FAT12 tutorial on the internet stops at "read a file" — assembly-only, dead links, code that hasn't compiled since 2009. This book goes all the way: from a raw sector to a complete, dual-platform FAT12 implementation. 11 chapters, ~1500 lines of C, one evolving codebase that compiles zero-warning on your machine and boots as a 32-bit kernel in QEMU.

All C, no assembly
FAT table walking, directory parsing — all of it
Complete operations
Read, write, delete, mkdir, move, 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
Verified at every step
Hexdumps and fsck.fat checks, not assertions
Compiles zero-warning
GCC — no 2009-era bit-rot to patch through

Leanpub sample includes chapters 1–4 — including the 12-bit FAT packing chapter. No email required for the PDF.

🔒 Backed by Leanpub's no-questions-asked refund policy · free updates for life

What makes this book different

One narrative
No triangulating between the OSDev Wiki, a dead 2009 assembly tutorial, and scattered blog posts — one 11-chapter arc from first sector to full format
Production notes
Callouts flag exactly what a real driver would do differently, so you know what you're trading for clarity
Reference appendices
FAT12 vs. FAT16/FAT32 comparison, an on-disk cheat sheet, and a long-filename (LFN) primer for after you finish
Not an AI shortcut
An LLM can generate a FAT12 driver for you. It won't explain why the 12-bit packing works — or catch the bug when it doesn't

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's the chapter every FAT12 forum thread is really asking about: 12-bit entries packed across byte boundaries, in little-endian byte order. Most tutorials wave their hands here. This book walks a real worked example by hand, cluster by cluster, until the bit math actually clicks:

Worked example diagram decoding FAT12 clusters 5, 6, and 7 from a file's raw FAT bytes, showing the little-endian byte swap and odd/even nibble extraction

From Chapter 4 — decoding clusters 5, 6, and 7 of a real file's cluster chain, byte by byte.

What's Inside

11 chapters across three parts, ~1500 lines of C, one evolving codebase from first sector read to full format:

Part I · Reading

From raw bytes to file contents

1 Hello, Disk!
2 The Boot Sector
3 The Root Directory
4 Reading Files
5 Full Path Walking

Part II · Writing

The filesystem starts doing work

6 Writing Files
7 Creating Directories
8 Deleting
9 Moving (and Renaming)

Part III · Advanced

Format from scratch, then boot bare metal

10 Formatting
11 Into the Kernel

Appendices

Reference material for after you finish reading

Boot Sector Reference Fields
FAT Family Reference
FAT12 Cheat Sheet
Long Filename Support (LFN / VFAT)

How it's built

One FAT12 library, two platform frontends. The exact same src/fat12.c compiles unmodified into a CLI tool on your machine and into a 32-bit kernel booting in QEMU — only the BlockDevice underneath changes, from a file descriptor to raw ATA port I/O.

Architecture overview: CLI and kernel platform frontends connect through the File System API to the shared FAT12 library, which connects through the Block Device API to either a disk image file or an ATA driver

Clean C, no magic — copied straight from Chapter 2. Here's the core typesystem your FAT12 driver starts with:

#pragma pack(push, 1)

typedef struct {
    uint16_t bytes_per_sector;
    uint8_t  sectors_per_cluster;
    uint16_t reserved_sector_count;
    uint8_t  num_fats;
    uint16_t root_entry_count;
    uint16_t total_sectors_16;
    uint8_t  media;
    uint16_t fat_size_16;
    uint16_t sectors_per_track;
    uint16_t number_of_heads;
    uint32_t hidden_sectors;
    uint32_t total_sectors_32;
} BPB;

#pragma pack(pop)
BPB struct from src/layout.h — packed, matches on-disk layout exactly

And here's the payoff — a real terminal session against a freshly formatted disk image:

$ ./build.sh
$ ./fat12-cli mkdir /DATA
$ ./fat12-cli mkdir /DATA/CONFIG
$ ./fat12-cli write /DATA/CONFIG/SETTINGS.TXT settings.txt
$ ./fat12-cli cat /DATA/CONFIG/SETTINGS.TXT
verbose=true
$ fsck.fat -n disk.img
fsck.fat 4.2 (2021-01-31)
disk.img: 4 files, 3/4067 clusters
build.sh prints nothing because there are no warnings to print — fsck.fat confirms the disk it produced is valid

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. Small, 1–4 MiB disk images mean every structure fits in a handful of sectors you can hexdump end to end — no dependencies beyond a C compiler.

Frequently Asked Questions

Do I need to know x86 assembly to read this book?

No. The book stays in C after the boot sector — no assembly beyond the few bytes of jump instruction every FAT12 volume already has. You do need to know C: pointers, structs, and bitwise operations.

Is the book finished?

All 11 chapters are written and available now on Leanpub. The book is being refined based on reader feedback, and every purchase includes free updates for life, so future revisions are already included.

What's included in the free sample?

Chapters 1 through 4, including the 12-bit FAT packing chapter. No email address is required to download the sample PDF.

Does the code run on real hardware, or just a CLI tool?

Both. The same FAT12 library compiles unmodified into a CLI tool for your development machine and into a 32-bit i386 kernel that boots in QEMU over real ATA PIO — only the BlockDevice implementation underneath changes.

What if I don't like the book?

Leanpub offers a no-questions-asked refund policy on every purchase.

"I wrote this because I couldn't find a hands-on FAT12 guide — just scattered forum posts and a 2009 assembly tutorial with dead links. This is the book I wish I'd had when I started."

— Björn Götz, author

Ready to build your own FAT12 driver?

Get the full book on Leanpub, or read the free four-chapter sample first — no email required.