Crate buf_fs

Source
Expand description

§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");

Structs§

Clock
A monotonically increasing clock emulator.
Device
A MBR FAT-16 compatible device emulator.
Dir
A directory representation
File
A file representation.
FilePath
A file path, without its contents.
FileSystem
A FAT16, virtual filesystem.

Enums§

DirOrFile
The contents of a directory, being a directory or a file.