Rust ยท single-file image ยท no unsafe tricks
Strata is a file system in Rust that lives entirely inside one container file. A superblock, a bitmap block allocator, inodes, and directory entries, small enough to hold in your head. Here is the real layout, running in your browser.
/docs/notes.txt, add contents, then press mkdir, create file, or delete.Directory tree
Block usage
Operations
What just ran
The same five pieces as the Rust crate, ported line for line into JavaScript over an in-memory block device.
Block 0 stores the layout: block size, block count, and where the bitmap, inode table, and data region each begin.
One bit per block. Creating a file or directory flips bits to used, deleting one flips them back, visible live below.
A fixed-size record per file or directory: a kind, a size, and a flat array of direct block pointers. No indirect blocks.
A directory's data blocks hold fixed-size records mapping a name to an inode number, the same as any other data.
/a/b/c walks one directory at a time from the root, failing with a typed error the moment a component is missing.
A corrupt superblock, an over-length name, or a file past the size cap is rejected, never a crash on bad input.
The same allocator and inode table you just watched update, running on a real file on disk.
# a 16 MiB image (4096 blocks x 4 KiB), a directory, a file, then read it back $ strata --img fs.img format --blocks 4096 --inodes 512 formatted fs.img (4096 blocks, 512 inodes) $ strata --img fs.img mkdir /docs created /docs $ strata --img fs.img put ./notes.txt /docs/notes.txt wrote 40 bytes to /docs/notes.txt $ strata --img fs.img ls /docs file 40 notes.txt $ strata --img fs.img get /docs/notes.txt ./out.txt read 40 bytes from /docs/notes.txt $ strata --img fs.img ls /nope strata: no such file or directory
Every block index and every inode index is checked against the validated superblock before it is used. No buffer is ever sized from a raw on-disk length field.
A wrong-magic image, a truncated file, or a name that's too long comes back as a specific error value, not a panic and not a silent wrong answer.
Everything written to the image is still there the next time it's opened, the same guarantee a real disk-backed file system makes.
Every subcommand maps to one call on the Strata type, so the CLI and the library are the same code path.
Create a new empty image with a given block and inode count, for example --blocks 4096 --inodes 512.
Create a directory, or delete a file or empty directory. Removing a non-empty directory is a typed error, not a crash.
Copy a local file into the image and back out, bounded by the maximum file size the inode's direct pointers allow.
List a directory, printing each entry's kind, size, and name from the directory's own data blocks.
Strata::format and Strata::open, then mkdir, write_file, read_file, list_dir, and remove, each returning a typed Result.
cargo test exercises formatting, allocation and free, path resolution, persistence across reopen, and the bounds checks that keep bad input from panicking.
# build, test, and format an image
cargo build
cargo test
strata --img fs.img format --blocks 4096 --inodes 512