Repository navigation
5.1 On Disk Format and Operations
Relevant source files
This section details the on-disk format, initialization, and core data manipulation routines of CodaFS, the synchronous, block-aligned filesystem designed for CadenzaOS. CodaFS operates directly on block devices without an intervening Virtual File System (VFS) layer, caching, or buffering abstractions src/kernel/fs/coda_fs.zig12-13 It defines explicit on-disk data structures for the superblock, file metadata (FileMeta), directory entries (DirEntry), and disk space management via extents.
Sources: src/kernel/fs/coda_fs.zig:1-13
The filesystem superblock is read at mount time and written during formatting (mkfs) src/kernel/fs/coda_fs.zig53-54 It dictates global parameters including block dimensions, the extent allocator region, and the root directory's physical location.
Key magic numbers and structural definitions from src/kernel/fs/coda_fs.zig:
-
CODA_MAGIC:0x434F44415F465331(ASCIICODA_FS1) src/kernel/fs/coda_fs.zig34 -
CODA_VERSION:1src/kernel/fs/coda_fs.zig35 -
FLAG_DIRTY:1 << 0src/kernel/fs/coda_fs.zig36
The Superblock structure layout is serialized verbatim to disk via block-writing routines:
pub const Superblock = struct {
magic: u64,
flags: u64,
version: u32,
block_size: u32,
total_blocks: u64,
policy: conf.SystemPolicy,
_pad: [7]u8,
latency_threshold_ns: u64,
sm_start_block: u64,
sm_block_count: u64,
root_dir_extent_start: u64,
root_dir_extent_blocks: u64,
reserved: [128]u8,
};
src/kernel/fs/coda_fs.zig67-86
Sources: src/kernel/fs/coda_fs.zig:30-86
File and directory metadata are decoupled from directory index entries. A file is represented by a FileMeta structure pointing to up to MAX_EXTENTS contiguous physical block ranges (Extent).
Constants and structures in src/kernel/fs/coda_file.zig:
-
MAX_EXTENTS:8(maximum extents tracked per file) -
MAX_NAME:64(maximum filename length in bytes)
FileType distinguishes between regular files and directories (FileType.File and FileType.Directory).
Sources: src/kernel/fs/coda_file.zig:1-48
Directories are stored as flat arrays of DirEntry records residing within allocated data blocks.
A DirEntry binds a filename to its corresponding metadata location.
An in-memory view of a directory block is managed by the Directory struct, providing core lookup and mutation operations:
-
lookup(name): Iterates through entries to find a match wherename_lenand byte sequences align. -
addEntry(entry): Inserts a new entry into the first available slot (name_len == 0). -
renameEntry(old_name, new_name): Verifies existence, name constraints, and updates string buffers. -
removeEntry(name): Unimplemented stub returningerror.NotImplemented.

Sources: src/kernel/fs/coda_file.zig:49-150
The CodaFs struct maintains the runtime mount context, binding an underlying block device to the parsed superblock, space manager, and root directory src/kernel/fs/coda_fs.zig110-117
- Reads the superblock from
conf.SB_LBAsrc/kernel/fs/coda_fs.zig132-133 - Validates
sb.magic == CODA_MAGICsrc/kernel/fs/coda_fs.zig135 - Initializes the
SpaceManagerviaSpaceManager.initFromDisk(...)src/kernel/fs/coda_fs.zig137-142 - Constructs an unpopulated root directory handle src/kernel/fs/coda_fs.zig144-154
- Validates device block sizes against
conf.BASE_IO_BUF_SIZEsrc/kernel/fs/coda_fs.zig161 - Establishes layout offsets for the superblock, space manager region (
sm_start_block,16blocks), and data storage src/kernel/fs/coda_fs.zig165-168 - Invokes
SpaceManager.initFresh(...)to mark allocation bitmaps src/kernel/fs/coda_fs.zig173-178 - Allocates a 4-block root directory extent src/kernel/fs/coda_fs.zig180

Sources: src/kernel/fs/coda_fs.zig:110-186
Path resolution traverses hierarchical directory structures block by block to map symbolic paths to physical PathResult records containing starting LBAs, block lengths, and type flags src/kernel/fs/coda_fs.zig88-93
Because CodaFS bypasses complex VFS caching layers, all read and write transactions execute synchronously against the underlying BlockDevice implementation using raw block offsets.
Sources: src/kernel/fs/coda_fs.zig:88-93, src/kernel/fs/coda_fs.zig:1-13
- Overview
- Getting Started and Build System
- Kernel Configuration and Global State
- Project Governance and Contributing
- Boot and Early Kernel Initialization
- Bootloader Stages and Linking
- kmain Boot Sequence
- Splash Screen and Branding
- Interrupts, Scheduling, and Syscalls
- IDT, PIC, APIC and IRQ Stubs
- Scheduler and Task Lifecycle
- System Call Interface
- Demonstration Tasks
- CodaFS Filesystem and Storage
- On-Disk Format and Operations
- Space Manager and Block Devices
- Binary Format and Program Loading
- Shell, Terminal, and Display
- Shell Command Pipeline
- Terminal, Input Devices and Prompts
- Display: VGA, Framebuffer, Console and Serial