$ show sysprog21/simplefs
simplefs is a Linux kernel module that implements a simple extent-based filesystem for educational use, accompanied by a userspace mkfs.simplefs formatter. The kernel component registers a VFS filesystem type and implements superblock, inode, file, and directory operations. The on-disk layout is a fixed 4 KiB block format: superblock, inode store, inode free bitmap, block free bitmap, and data blocks. Inodes are 72 bytes and point to an extent-index block; regular files use extents of up to 8 contiguous blocks (maximum file size around 10.65 MiB), while directories use a hashed ring of extents to support up to 40,920 entries. Functionally, the filesystem supports create, lookup, unlink, rename, hard links, symbolic links, mkdir, rmdir, and read/write. File I/O is implemented through both traditional VFS page-cache helpers and simpler direct buffer-head read/write paths, making the code a useful teaching reference for how Linux VFS callbacks and buffer management interact. External journaling is supported via the kernel's jbd2 subsystem, mounted with a journal_path or journal_dev option, though only extent metadata is journaled and the journal size is currently hardcoded. Entry points are module_init/module_exit in fs.c, the mount path through simplefs_fill_super in super.c, and main() in mkfs.c. Dependencies are Linux kernel headers, jbd2, block-device APIs, and a Linux or macOS host for mkfs. The repository includes shell-based integration tests that exercise maximum directory fill, large-file behavior, remount persistence, random create/delete, and free-block reclamation, plus CI jobs for formatting and macOS mkfs verification. The code maintains compatibility macros spanning Linux 5.10 through 7.3, reflecting active upkeep.
The LLM identified 4 files worth highlighting for reuse:
Implements simplefs_ext_search, which uses two binary searches over a fixed-capacity extent array: first to locate the first unused slot as a boundary, then to find the extent containing a requested logical block. It returns the insertion point when no match is found, unifying lookup and allocation in one function. This is a clean, self-contained pattern that can be lifted into any extent-based filesystem or block allocator to replace linear extent scans.
Header-only allocation helpers built on the Linux bitmap API. get_first_free_bits scans for a run of consecutive free bits and clears them in one operation, treating bit set as free; get_free_blocks extends this to allocate physically contiguous blocks and zero them. The error-by-zero convention and careful rollback on buffer failure make this a compact, reusable pattern for contiguous resource allocation in any kernel resource manager (blocks, inodes, IDs).
A portable filesystem formatter that writes superblock, inode store, and both free bitmaps in a single pass. It detects block device size using Linux BLKGETSIZE64 and macOS DKIOCGETBLOCKCOUNT/DKIOCGETBLOCKSIZE ioctls, uses explicit little-endian conversions for on-disk structures, and validates minimum image size. The structure is a good template for initializing a fixed-layout disk image and can be adapted to other simple filesystem projects with minimal effort.
A compact FNV-1a 64-bit hash folded to 32 bits for directory entry placement. It is dependency-light, deterministic, and trivially reusable as a generic string hash for hash-based indexing or bucket selection outside simplefs. The 64-to-32 bit fold is a small but non-obvious touch that improves hash mixing.