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

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

✅ All C, no assembly detoursFAT table walking, directory parsing — all of it
✅ Complete operationsRead, write, delete, mkdir, move, format
✅ 12-bit packing finally explainedDiagrams + step-by-step C for straddling entries
✅ Portable to your kernelSame code runs in CLI tool and QEMU
✅ Verified at every stepHexdumps and Linux's own FAT driver, not assertions
✅ Compiles zero-warningGCC — no 2009-era bit-rot to patch through

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

One narrative
No triangulating between the OSDev Wiki, a dead 2009 assembly tutorial, and scattered blog posts — one 12-chapter arc from first sector to bare-metal kernel
Production notes
Callouts flag exactly what a real driver would do differently, so you know what you're trading for clarity
Four appendixes
Not just reference material — a real ATA PIO disk driver, real long-filename (LFN) decoding, the boot sector fields the chapters skip, and a FAT12 vs. FAT16/FAT32 comparison
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 4 to 7 from FAT bytes 6 to 11 (ff ff ff 07 f0 ff), showing which nibbles each even and odd entry owns in little-endian order

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

1 Hello, Disk!
2 Mounting the Filesystem
3 Listing the Root Directory
4 Reading Files
5 Reading Multi-Cluster Files
6 Full Path Walking

Part II · Writing

The filesystem starts doing work

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

Part III · Advanced

Format from scratch, then boot bare metal

11 Formatting
12 Running FAT12 Inside a Kernel

Appendixes

Extra ground for after you finish reading — real code and reference material

Talking to a Real Disk (ATA PIO)
A First Look at Long Filename Support (LFN / VFAT)
The Boot Sector Fields We Skipped
FAT12 vs. FAT16 vs. FAT32

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.

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

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)
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 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
build.sh prints nothing because there are no warnings to print — and Linux's own FAT driver reads back exactly what our code wrote

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.

"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 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.