Preface
- Why FAT12?
- Who This Book Is For
- What We Will Build
- How This Book Is Structured
- A Note on Style
- How to Read This Book
- About the Author
- Feedback
Prerequisites
- Operating System
- C Compiler
- mkfs.fat
- QEMU (Chapter 11 Only)
- Hex Dump Utility
- Getting the Code (Optional)
Part I: Reading
Chapter 1: Hello, Disk!
- Creating a Virtual Disk
- Sectors and LBA
- The Block Device
- Reading the Volume Label
- Tracing the Translation
- What’s Next
Chapter 2: The Boot Sector
- What Is the Boot Sector?
- Mirroring the Layout in C
- Mounting and Unmounting
- Bytes Per Sector
- Total Sectors
- Reserved Sector(s)
- Extended BPB
- Booting from FAT12
- What’s Next
Chapter 3: The Root Directory
- The Directory Entry
- Position and Size
- Hexdumping the Root Directory
- The 8.3 Name Format
- The Attribute Byte
- Decoding Timestamps
- Directory Iteration
- The ls Command
- What’s Next
Chapter 4: Reading Files
- Clusters: The Allocation Units
- Locating Data on Disk
- The Cluster Chain
- Decoding the 12-Bit Packing
- Loading the FAT
- Locating a File
- Reading a Cluster Chain
- Putting It All Together
- The cat Command
- What’s Next
Chapter 5: Full Path Walking
- Directories: Files in Disguise
- The Path Walking Algorithm
- Retrofitting Path Walking
- What’s Next
Part II: Writing
Chapter 6: Writing Files
- Manipulating FAT Entries
- Cluster Allocation
- Writing the Data
- Directory Entry Creation
- Putting It All Together
- The Write CLI Command
- What’s Next
Chapter 7: Creating Directories
- What Are
.and..? - Extending a Directory Chain
- Finding or Extending a Slot
- Directory Manipulation Helpers
- Updating
create_dir_entry - Updating
fat12_close - The
fat12_mkdirFunction - Helper: Creating Directory Contents
- The
mkdirCLI Command - Verification
- Bonus: Copy
- What’s Next
Chapter 8: Deleting
- Freeing the cluster chain
- Marking a directory entry deleted
- When is a directory empty?
- Putting it all together
- The
rmCLI Command - Verifying Deletion
- What’s Next
Chapter 9: Moving (and Renaming)
- The Two Cases
- Updating
.and.. - The
fat12_moveFunction - The
mvCLI Command - Computing the Geometry
- The Boot Sector
- The File Allocation Tables
- The Root Directory
- The Data Region
- The
formatCLI Command - Verification
- What’s Next
Chapter 11: Into the Kernel
- The Freestanding Environment
- The ATA Block Device Driver
- VGA Text Mode
- The Kernel
- Booting the Kernel
- What’s Next
Appendixes
Appendix: Boot Sector Reference Fields
- Hidden Sectors (Partitioning)
- CHS (Cylinder-Head-Sector) Addressing
- Media Descriptor
- Extended BPB — Additional Fields
- OEM Name (Original Equipment Manufacturer)
- Summary
Appendix: FAT Family Reference
- FAT Entry Widths and Values
- Root directory
- BPB
- Volume Size Limits
Appendix: FAT12 Cheat Sheet
- Disk Layout
- Position Formulas
- Boot Sector (512 bytes)
- Directory Entry (32 bytes)
- FAT12 Entry (12 bits)
- Timestamp Format
- 8.3 Filename Format
- Quick Reference: Cluster Math
Appendix: Long Filename Support (LFN / VFAT)
- Overview
- How It Works
- LFN Entry Structure (32 bytes)
- Sequence Number
- Character Encoding
- Checksum Algorithm
- 8.3 Alias Generation
- Reading LFN Entries
- Writing LFN Entries
- Deleting LFN Entries
- Moving and Renaming
- Worked Example
- Summary
Conclusion
- The Architecture
- What’s Next
- Thank You