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
- Resolving a Path
- The Data Region
- Locating Data on Disk
- The Cluster Chain
- Decoding the 12-Bit Packing
- Loading the FAT
- Reading a Cluster Chain
- Putting It All Together
- The cat Command
- What’s Next
Chapter 5: Full Path Walking
- Subdirectories: Files in Disguise
- The Path Walking Algorithm
- Retrofitting Reads
- What’s Next
Part II: Writing
Chapter 6: Writing Files
- Finding a Free Slot
- Encoding the Name
- Encoding the Timestamp
- Linking the File
- Opening a File for Writing
- Buffering the Write
- Cluster Allocation
- Writing the Data
- Closing the File
- The Create CLI Command
- What’s Next
Chapter 7: Creating Directories
- Assembling the Directory
- The
mkdirCLI Command - What’s Next
Chapter 8: Deleting
- When Is a Directory Empty?
- Freeing a Cluster Chain
- Putting It All Together
- The
rmCLI Command - What’s Next
Chapter 9: Moving (and Renaming)
- Rename vs. Move
- Moving the Entry
- The
mvCLI Command - What’s Next
Part III: Advanced
Chapter 10: Formatting
- The Blueprint
- The FAT Size Problem
- The Boot Sector
- The File Allocation Tables
- The Root Directory
- The Data Region
- Putting It All Together
- The
formatCLI Command - What’s Next
Chapter 11: Into the Kernel
- The RAM Disk Block Device
- Printing to Screen
- The Kernel
- Building the Kernel
- The Freestanding Environment
- Booting the Kernel
- What’s Next
Conclusion
- What’s Next
- Thank You
Appendixes
Appendix A: Talking to a Real Disk
- The ATA Protocol
- Talking to the Ports
- Opening and Closing
- Reading
- Writing
- Replacing the RAM Disk
- Building and Running
Appendix B: 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
- Worked Example
- Summary
Appendix C: The Boot Sector’s Leftovers
- Hidden Sectors (Partitioning)
- CHS (Cylinder-Head-Sector) Addressing
- Media Descriptor
- Extended BPB — Additional Fields
- OEM Name (Original Equipment Manufacturer)
- Summary
Appendix D: FAT Family Reference
- FAT Entry Widths and Values
- Root directory
- BPB
- Volume Size Limits
Appendix E: 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