
FAT12
Read, write, delete, mkdir, move, format — all 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. 12 chapters, ~1500 lines of C, one evolving codebase that compiles zero-warning on your machine and boots as a 32-bit kernel in QEMU.
Complete, 304 pages · from $19.99, pay what you want · DRM-free PDF & EPUB on Leanpub, Kindle on Amazon
★ Listed as recommended reading on fysnet.net, home of the FYSOS project and the Operating System Design book series.
Free sample: chapters 1–4, from the first sector read to your own cat. No email required, read it right in your browser.
🔒 Backed by Leanpub's 60-day 100% refund guarantee · free updates included
Meet the author
Leanpub co-founder Len Epp interviewed me for the book's launch video. Five minutes, published on Leanpub's own YouTube channel:
The video loads from YouTube (youtube-nocookie.com) only after you click play · Subscribe to Leanpub on YouTube · Privacy
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 5 — decoding clusters 4 to 7 from a real FAT, nibble by nibble, to follow a file's chain 6 → 7 → End.
What's Inside
12 chapters across three parts, ~1500 lines of C, one evolving codebase from first sector read to a booting kernel:
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
Appendixes
Extra ground for after you finish reading — real code and reference material
How it's built
One FAT12 implementation, two platform frontends. The exact same src/fat12.ccompiles unmodified into a CLI tool on your machine and into a 32-bit kernel booting in QEMU — only the BlockDevice underneath changes: a disk image file for the CLI, a RAM disk for the kernel, or raw ATA port I/O if you want the kernel's volume to survive a reboot on real hardware. The full source for every chapter is onGitHub — browse it before you buy.
Clean C, no magic — copied straight from Chapter 2. Here's the first on-disk struct your FAT12 code decodes:
#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 create /DATA/CONFIG/SETTINGS.TXT < settings.txt $ ./fat12-cli ls /DATA/CONFIG NAME TYPE/SIZE CREATED MODIFIED . <DIR> 2026-10-09 14:21:06 2026-10-09 14:21:06 .. <DIR> 2026-10-09 14:21:06 2026-10-09 14:21:06 SETTINGS.TXT 13 B 2026-10-09 14:21:06 2026-10-09 14:21:06 $ sudo mount -o loop disk.img /mnt/fat12 $ cat /mnt/fat12/DATA/CONFIG/SETTINGS.TXT verbose=true
Who is this for?
You — if you're building a hobby OS and want a filesystem you actually understand. You know C (pointers, structs, bit manipulation) and want to build a complete FAT12 implementation yourself, line by line, then run it in your own kernel. Small 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 FAT12 code is pure C, and the only assembly in the main chapters is a 27-line Multiboot stub in Chapter 12 that gets the kernel into C. You do need to know C: pointers, structs, and bitwise operations.
Is the book finished?
Yes. All 12 chapters and four appendixes (304 pages) are written and available now on Leanpub and Amazon. The book is being refined based on reader feedback, and every purchase includes all future updates for free.
What's included in the free sample?
Chapters 1 through 4: from the first raw sector read to mounting the volume, listing the root directory, and printing a file with your own cat command. It stops right where Chapter 5 takes over with the File Allocation Table and its 12-bit packing. No email address is required: the sample opens right in your browser.
Does the code run on real hardware, or just a CLI tool?
Both. The same FAT12 code compiles unmodified into a CLI tool for your development machine and into a 32-bit i386 kernel that boots in QEMU — with a RAM disk by default, or a real ATA PIO driver from the appendix if you want the kernel's volume to survive a reboot on real hardware. Only the BlockDevice implementation underneath changes.
How much does it cost?
The book is pay-what-you-want on Leanpub: $19.99 minimum, $29.99 suggested. You get DRM-free PDF and EPUB plus every future update. A Kindle edition is also available on Amazon.
What if I don't like the book?
Leanpub gives you a 100% refund on any purchase within 60 days, in two clicks. Kindle purchases follow Amazon's return policy.
Ready to build FAT12 yourself?
Get the complete book on Leanpub from $19.99 (pay what you want, suggested $29.99) or as a Kindle e-book on Amazon, or read the free four-chapter sample first — no email required.