Kick off your book project in 3 hours! Live workshop on Zoom. You’ll leave with a real book project, progress on your first chapter, and a clear plan to keep going. Saturday, June 6, 2026. Learn more…

Leanpub Header

Skip to main content

FAT12

Understanding and Implementing the Classic File System in C

This book is 35% completeLast updated on 2026-05-26

A hands-on guide to building a complete FAT12 filesystem driver in C — from reading your first sector to running code in QEMU. Write everything yourself, boot sector to cat command.

Minimum price

$19.99

$19.99

You pay

Author earns

$
PDF
EPUB
WEB
73
Pages
13,600Words
About

About

About the Book

A filesystem is just bytes on a disk waiting for a decoder ring. This book builds that ring.

FAT12 is the oldest and simplest member of the FAT family — small volumes, simple allocation, flat root directory, and still everywhere: the default for QEMU and VirtualBox floppy images, EFI boot partitions, and embedded firmware. Learn FAT12 once and you already understand FAT16 and FAT32.

You will write every line of code yourself, from the boot sector decoder up to a working cat command in QEMU:

- Build a portable block device abstraction so your filesystem code runs on files and bare metal

- Decode every field of the boot sector and compute disk geometry

- Navigate the famously awkward 12-bit File Allocation Table

- Walk the root directory, read files, and follow cluster chains

- Write files, create directories, delete and rename entries

- Format a disk from scratch

- Port the same library to a 32-bit i386 kernel via ATA PIO and VGA text mode

The code is written for understanding, not production — every I/O check is suppressed to keep the FAT12 logic front and center. Each chapter includes debugging tips and a Production callout explaining what a real-world driver would do differently.

Who this is for: You are building or tinkering with a hobby OS. You know C — pointers, structs, bitwise operations. You have skimmed filesystem tutorials but now you want to actually write one.

Author

About the Author

Björn Götz

I am Björn Götz, a German software engineer who loves understanding low-level systems and explaining them to others.

Contents

Table of Contents

Preface

  1. Why FAT12?
  2. Who This Book Is For
  3. What You Will Build
  4. What You Will Learn
  5. A Note on Style
  6. How to Read This Book
  7. About the Author
  8. Feedback

Prerequisites

  1. Operating System
  2. C Compiler and Dependencies
  3. Editor and Hex Editor
  4. Getting the Code (Optional)

Hello, Disk!

  1. What Is FAT12?
  2. Creating a Virtual Disk
  3. Sectors and LBA
  4. A Tale of Four Regions
  5. Project Layout
  6. A Portable Foundation: The BlockDevice
  7. Reading Sector 0
  8. What Is Next

The Blueprint (BPB)

  1. Boot Sector Structure
  2. Mapping Bytes to Structs
  3. The FAT12 Library
  4. The Info Command
  5. Debugging
  6. Production Notes
  7. What Is Next

The Root Directory

  1. What Is the Root Directory?
  2. The DirectoryEntry Struct
  3. Decoding Timestamps
  4. Where Is the Root Directory?
  5. Geometry Functions
  6. Loading the Root Directory
  7. The ls Command
  8. Updating the Header
  9. Building
  10. Verification: Create Real Files
  11. Debugging with a Hexdump
  12. Production Notes
  13. What Is Next

Reading Files

  1. What the FAT Actually Is
  2. Where the FAT Lives
  3. Data Region Geometry
  4. Reading an Entry
  5. Loading the FAT
  6. File API
  7. The cat Command
  8. Updating the Header
  9. Building
  10. Verification: Create a Real File
  11. Hexdump Verification
  12. Multi-Cluster File
  13. Production Notes
  14. FAT Family: FAT16 and FAT32
  15. What Is Next

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub