FAT12
Read, write, delete, mkdir, move, format — all in C, no assembly.
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.
FAT table walking, directory parsing — all of it
Read, write, delete, mkdir, move, format
Diagrams + step-by-step C for straddling entries
Same code runs in CLI tool and QEMU
Hexdumps and
fsck.fat checks, not assertionsGCC — 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
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:
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
Part II · Writing
The filesystem starts doing work
Part III · Advanced
Format from scratch, then boot bare metal
Appendices
Reference material for after you finish reading
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.
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)
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
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.
Ready to build your own FAT12 driver?
Get the full book on Leanpub, or read the free four-chapter sample first — no email required.