Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ erofs-cli inspect -i http://example.com/images/system.erofs cat /etc/os-release
### TODO

- [ ] Extended attributes
- [ ] Compressed data (lz4, lzma, deflate)
- [-] Compressed data (lz4, lzma, deflate)
- [ ] Image building (`mkfs.erofs` equivalent)

## License
Expand Down
36 changes: 36 additions & 0 deletions erofs/src/decomp/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//! Basic Z_EROFS decompression support.
//!
//! This roughly follows parts of the Linux kernel implementation
//! (fs/erofs/zmap.c, zdata.c), but is not a 1:1 port.
//!
//! The idea is:
//! 1. VLE index maps logical clusters
//! 2. pclusters - contain compressed data
//! 3. decompression - handled via lz4/lzma/deflate (not implemented here yet)
//!
//! Some details are still incomplete.

#[derive(Debug, Clone, Copy)]
pub struct VLEIndex {

Check failure on line 14 in erofs/src/decomp/mod.rs

View workflow job for this annotation

GitHub Actions / rust

struct `VLEIndex` is never constructed
pub advise: u16, // compression hints (di_advise)
pub cluster_offset: u16, // offset within the decompressed cluster
pub block_addr: u32, // physical block (only meaningful for HEAD entries)
}

impl VLEIndex {
/// Read a VLE index from raw bytes.
/// Expects at least 8 bytes (little-endian layout).
pub fn from_bytes(data: &[u8]) -> crate::Result<Self> {

Check failure on line 23 in erofs/src/decomp/mod.rs

View workflow job for this annotation

GitHub Actions / rust

associated function `from_bytes` is never used
if data.len() < 8 {
return Err(crate::Error::NotSupported(
"VLE index too short".into()
));
}

Ok(Self {
advise: u16::from_le_bytes([data[0], data[1]]),
cluster_offset: u16::from_le_bytes([data[2], data[3]]),
block_addr: u32::from_le_bytes([data[4], data[5], data[6], data[7]]),
})
}
}
2 changes: 2 additions & 0 deletions erofs/src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ impl EroFSCore {
Ok(BlockPlan::Direct { offset, size: len })
}
Layout::CompressedFull | Layout::CompressedCompact => {
// TODO: Implement VLE index parsing and pcluster decompression
// See: decomp module, kernel fs/erofs/zmap.c + zdata.c
Err(Error::NotSupported("compressed compact layout".to_string()))
}
Layout::ChunkBased => {
Expand Down
1 change: 1 addition & 0 deletions erofs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ extern crate std;

pub(crate) mod dirent;
pub(crate) mod filesystem;
pub(crate) mod decomp;

pub mod r#async;
pub mod backend;
Expand Down
Loading