https://github.com/suhteevah/btrfs-nostd
no_std btrfs filesystem with read/write support in Rust
https://github.com/suhteevah/btrfs-nostd
bare-metal btrfs embedded filesystem no-std operating-system osdev rust
Last synced: 9 days ago
JSON representation
no_std btrfs filesystem with read/write support in Rust
- Host: GitHub
- URL: https://github.com/suhteevah/btrfs-nostd
- Owner: suhteevah
- License: apache-2.0
- Created: 2026-04-02T16:47:53.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2026-06-08T08:02:02.000Z (15 days ago)
- Last Synced: 2026-06-08T10:04:48.225Z (15 days ago)
- Topics: bare-metal, btrfs, embedded, filesystem, no-std, operating-system, osdev, rust
- Language: Rust
- Size: 74.2 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# btrfs-nostd
[](https://rust-embedded.github.io/book/)
[](LICENSE-MIT)
A `no_std` btrfs filesystem implementation in pure Rust with read and write support.
Designed for bare-metal, embedded, and OS kernel environments where the Rust standard
library is not available. The only dependency is `log` for optional diagnostic output.
## Features
- **Superblock** parsing and validation (primary at 0x10000, mirrors supported)
- **B-tree traversal** with binary search (search, walk, collect)
- **B-tree modification** (insert into leaf, leaf splitting with COW semantics)
- **CRC32C checksums** (Castagnoli) for superblock, metadata nodes, and directory name hashing
- **Chunk mapping** -- logical to physical address translation via sys_chunk_array bootstrap and full chunk tree
- **Inode items** -- read/write metadata (size, mode, timestamps, permissions, uid/gid)
- **Directory entries** -- DIR_ITEM (hash-keyed O(1) lookup) and DIR_INDEX (ordered iteration)
- **File extents** -- inline data (small files in B-tree leaves), regular extents, prealloc, hole detection
- **High-level API** -- `read_file`, `write_file`, `mkdir`, `list_dir`, path resolution
## Usage
Add to your `Cargo.toml`:
```toml
[dependencies]
btrfs-nostd = "0.1"
```
Implement the `BlockDevice` trait for your storage backend:
```rust
use btrfs_nostd::{BtrFs, BlockDevice, BtrfsError};
struct RamDisk {
data: Vec,
}
impl BlockDevice for RamDisk {
fn read_bytes(&self, offset: u64, buf: &mut [u8]) -> Result<(), BtrfsError> {
let start = offset as usize;
let end = start + buf.len();
if end > self.data.len() {
return Err(BtrfsError::IoError);
}
buf.copy_from_slice(&self.data[start..end]);
Ok(())
}
fn write_bytes(&self, offset: u64, buf: &[u8]) -> Result<(), BtrfsError> {
// For a real implementation, write to your storage
Err(BtrfsError::IoError)
}
}
// Mount and use:
let device = RamDisk { data: disk_image };
let fs = BtrFs::mount(device).expect("mount failed");
let contents = fs.read_file(b"/hello.txt").expect("read failed");
let entries = fs.list_dir(b"/").expect("listdir failed");
```
## Supported on-disk structures
| Structure | Read | Write |
|-----------|------|-------|
| Superblock | Yes | Yes |
| B-tree nodes (leaf + internal) | Yes | Yes |
| Chunk items / stripe mapping | Yes | Yes |
| Inode items | Yes | Yes |
| Directory items (DIR_ITEM, DIR_INDEX) | Yes | Yes |
| File extents (inline) | Yes | Yes |
| File extents (regular) | Yes | Partial |
| File extents (prealloc) | Yes | No |
| Compressed extents | No | No |
## Limitations
- Single-device only (uses first stripe for RAID configurations)
- No compression support (zlib, LZO, ZSTD extents return an error)
- Large file writes currently use inline extents (no data extent allocation)
- No extent tree updates (free space tracking)
- No transaction/journal support
- File overwrite creates a new inode rather than updating in-place
- Leaf splitting during writes is detected but not yet wired into the write path
## Architecture
The crate is organized into focused modules:
- `superblock` -- On-disk superblock layout, parsing, serialization
- `key` -- B-tree key types and ordering
- `item` -- Tree node headers, leaf items, internal node key pointers
- `tree` -- B-tree search, walk, insert, split operations
- `chunk` -- Chunk/stripe mapping, logical-to-physical address resolution
- `crc32c` -- Software CRC32C (Castagnoli polynomial) implementation
- `inode` -- Inode item metadata
- `dir` -- Directory entry parsing, creation, name hashing
- `extent` -- File extent items (inline, regular, prealloc)
- `readwrite` -- High-level `BtrFs` type tying everything together
## License
Licensed under either of
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or )
- MIT license ([LICENSE-MIT](LICENSE-MIT) or )
at your option.
## Contributing
Contributions welcome! Please open an issue or pull request on GitHub.