An Implementation Guide for Systems Programmers
Introduction
- Who This Book Is For
- What You Will Learn
- How to Use This Book
- Conventions
Chapter 1: The Story of ext
- The Original ext Filesystem (1992)
- ext2: A Production Filesystem (1993-2001)
- ext3: Adding Journaling (2001)
- ext4: Scaling to Petabytes (2008-Present)
- Design Continuity and Breaking Changes
Chapter 2: On-Disk Layout Fundamentals
- The Superblock Structure
- Block Groups and Group Descriptors
- Block and Inode Bitmaps
- The Inode Table Layout
- Bootloader Blocks and Reserved Space
Chapter 3: The Inode – Anatomy of a File
- The ext4_inode Structure (256 Bytes)
- Direct, Indirect, Double, and Triple Indirect Blocks
- Extent Trees (ext4_extent_header and ext4_extent)
- Inline Data for Small Files
- Timestamps: Birth Time, Nanosecond Precision, and Y2038
Chapter 4: Directory Formats
- Linear Directories (ext4_dir_entry_2)
- The HTree Indexing Algorithm
- Hash Algorithms: T10, T13, T20, T21, T60
- Directory Block Layout and Padding
- Traversing and Searching Directories
Chapter 5: Extents – Modern Block Mapping
- The Extent Tree as a B+ Tree
- ext4_extent_header and ext4_extent Records
- ext4_extent_idx for Multi-Level Trees
- Uninitialized Extents and Lazy Allocation
- Extent Manipulation: Splitting, Merging, Truncation
Chapter 6: Block Allocation Algorithms
- Group Selection Strategy (mb_group_prealloc_scan)
- The Move Allocator (mballoc)
- Delayed Allocation (delalloc)
- Block Preallocation and Post-readahead
- Fragmentation Avoidance and Defragmentation
Chapter 7: Journaling with JBD2
- Transaction Model and Commit Sequence Numbers
- Writeback Modes: Data, Ordered, Writeback
- The Journal Superblock and Descriptor Blocks
- Journal Replay and Crash Recovery
- Fast Commits (ext4 fast commit feature)
Chapter 8: Extended Attributes, ACLs, and Quotas
- Extended Attribute Storage (Inline vs. EA Blocks)
- The xattr Header and Entry Formats
- POSIX ACLs and the acl_mode Hook
- Project Quotas and User/Group Quotas
- Security xattrs: Trusted, User, and System Namespaces
- The ext4_resize Operation
Chapter 10: Feature Flags and Compatibility
- The Three Feature Flag Categories
- Mount Options and Their Effects
- Checking Feature Flags in Code
Chapter 11: VFS Integration and Kernel Implementation
- The super_operations and inode_operations Tables
- Page Cache Interaction and Writeback
- Filesystem Locking: Per-file Locks, Group Locks, mballoc Locks
- Concurrency: Multi-threaded Allocation and Journaling
- Dirty Page Management and Flush Threads
Chapter 12: Recovery, Corruption Detection, and Repair
- Checksum Offsets and Verification (crc32c)
- The e2fsck Passes: From Structure to Links
- Corruption Detection in Production (errors=continue/remount-ro/panic)
- Backup Superblocks and Redundancy
- Forensic Analysis of ext4 Images
Chapter 13: Performance, Scalability, and Comparisons
- Key Performance Characteristics and Tuning
- Scalability: Filesystem Size, Inode Count, Directory Entries
- Comparison with ext2 and ext3
- Comparison with XFS, Btrfs, ZFS
- Comparison with NTFS, FAT, exFAT
Chapter 14: Implementation Guide
- Building a Minimal ext4 Reader (C)
- Validating Superblocks and Group Descriptors
- Traversing the Extent Tree
- Implementing Block Allocation
- Writing a Journal Replay Engine (Rust)