Strata logo

Rust ยท single-file image ยท no unsafe tricks

A file system
you can read end to end.

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.

Try it below View on GitHub
How to use this playground
Build a file system inside one in-memory image and watch the blocks and bitmap update live.

Directory tree

Block usage

0 / 0 blocks used

Operations

What just ran

How it works

The same five pieces as the Rust crate, ported line for line into JavaScript over an in-memory block device.

1

Superblock

Block 0 stores the layout: block size, block count, and where the bitmap, inode table, and data region each begin.

2

Bitmap allocator

One bit per block. Creating a file or directory flips bits to used, deleting one flips them back, visible live below.

3

Inodes

A fixed-size record per file or directory: a kind, a size, and a flat array of direct block pointers. No indirect blocks.

4

Directory entries

A directory's data blocks hold fixed-size records mapping a name to an inode number, the same as any other data.

5

Path resolution

/a/b/c walks one directory at a time from the root, failing with a typed error the moment a component is missing.

6

Bounded, not panicking

A corrupt superblock, an over-length name, or a file past the size cap is rejected, never a crash on bad input.

Format an image from the command line.

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
Robust by construction

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.

Typed errors

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.

Real persistence

Everything written to the image is still there the next time it's opened, the same guarantee a real disk-backed file system makes.

Six subcommands, one library, real tests.

Every subcommand maps to one call on the Strata type, so the CLI and the library are the same code path.

format

Create a new empty image with a given block and inode count, for example --blocks 4096 --inodes 512.

mkdir, rm

Create a directory, or delete a file or empty directory. Removing a non-empty directory is a typed error, not a crash.

put, get

Copy a local file into the image and back out, bounded by the maximum file size the inode's direct pointers allow.

ls

List a directory, printing each entry's kind, size, and name from the directory's own data blocks.

Library API

Strata::format and Strata::open, then mkdir, write_file, read_file, list_dir, and remove, each returning a typed Result.

Tests

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