#fs

no-std buf-fs

A buffer based, in-memory filesystem

3 releases

Uses new Rust 2024

0.1.2 May 11, 2025
0.1.1 May 6, 2025
0.1.0 May 3, 2025

#207 in Embedded development

Download history 83/week @ 2025-04-27 147/week @ 2025-05-04 433/week @ 2025-05-11 403/week @ 2025-05-18

1,066 downloads per month

MIT/Apache

37KB
835 lines

buf-fs

crates.io Documentation License

A buffer based, in-memory, no_std filesystem.

This crate mimics a file system, operating entirely within memory. By establishing a Fat (File Allocation Table) partition within a byte buffer, it exposes an API resembling that of a traditional filesystem to its users.

Example

use buf_fs::FileSystem;

let size = 4 * 1024 * 1024;
let mut fs = FileSystem::new(size).unwrap();

let data = b"foo";

fs.mkdir("/var/share/baz").unwrap();

fs.open("/var/share/data.bin")
    .unwrap()
    .update(|b| b.extend(data))
    .save(&mut fs)
    .unwrap();

fs.open("/var/share/bar.bin")
    .unwrap()
    .update(|b| b.extend(data))
    .save(&mut fs)
    .unwrap();

assert_eq!(fs.open("/var/share/data.bin").unwrap().contents, data);

let contents = fs.ls("/var/share").unwrap();

assert_eq!(contents.len(), 3);

// FAT-16 is always uppercase.
// It's a TODO to support ext4
assert_eq!(contents[0].path().as_str(), "BAZ");
assert_eq!(contents[1].path().as_str(), "BAR.BIN");
assert_eq!(contents[2].path().as_str(), "DATA.BIN");

Dependencies

~1.5MB
~26K SLoC