A pure Rust library for reading and building EROFS (Enhanced Read-Only File System) images.
Note: This library aims to provide essential parsing and building capabilities for common use cases, not a full reimplementation of erofs-utils.
- no_std support with
allocfor embedded systems - Zero-copy parsing via mmap (std) or byte slices (no_std)
- Directory traversal and file reading
- Multiple data layouts: flat plain, flat inline, chunk-based
use std::io::Read;
use erofs_rs::{EroFS, backend::MmapImage};
fn main() -> erofs_rs::Result<()> {
let image = MmapImage::new_from_path("system.erofs")?;
let fs = EroFS::new(image)?;
// Read file
let mut file = fs.open("/etc/os-release")?;
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;
// List directory
for entry in fs.read_dir("/usr/bin")? {
println!("{}", entry?.dir_entry.file_name());
}
Ok(())
}#![no_std]
extern crate alloc;
use erofs_rs::{EroFS, backend::SliceImage};
fn main() -> erofs_rs::Result<()> {
// Assuming you have the EROFS image data in memory
let image_data: &'static [u8] = include_bytes!("system.erofs");
let fs = EroFS::new(SliceImage::new(image_data))?;
// List directory entries
for entry in fs.read_dir("/etc")? {
let entry = entry?;
// Process directory entry...
}
// Walk directory tree
for entry in fs.walk_dir("/")? {
let entry = entry?;
// Process each file/directory...
}
Ok(())
}std(default): Enables standard library support, including mmap backendopendal: Enables async I/O via Apache OpenDAL, supporting remote backends (HTTP, S3, etc.)- Without
std: Operates inno_stdmode withalloc
# Standard usage (default)
[dependencies]
erofs-rs = "0.1"
# Async with OpenDAL
[dependencies]
erofs-rs = { version = "0.1", features = ["opendal"] }
# no_std with alloc
[dependencies]
erofs-rs = { version = "0.1", default-features = false }# Dump superblock info
erofs-cli dump image.erofs
# List directory
erofs-cli inspect -i image.erofs ls /
# Read file content
erofs-cli inspect -i image.erofs cat /etc/passwd
# Convert to tar
erofs-cli convert image.erofs -o out.tar
# Remote images via HTTP (async OpenDAL backend)
erofs-cli dump http://example.com/images/system.erofs
erofs-cli inspect -i http://example.com/images/system.erofs ls /
erofs-cli inspect -i http://example.com/images/system.erofs cat /etc/os-release- Superblock / inode / dirent parsing
- Flat plain layout
- Flat inline layout
- Chunk-based layout (without chunk indexes)
- Directory walk (
walk_dir) - Convert to tar archive
- Extended attributes
- Compressed data (lz4, lzma, deflate)
- Image building (
mkfs.erofsequivalent)
MIT OR Apache-2.0