Hadris CPIO
A Rust implementation of the CPIO archive format (newc/SVR4) with support for no-std environments, streaming reads, and archive creation.
Features
- Read & Write Support - Stream entries from existing archives, create new ones
- No-std Compatible - Use in bootloaders, kernels, and embedded systems
- newc Format - Both
070701(standard) and070702(CRC) variants - Full Entry Types - Regular files, directories, symlinks, hard links, device nodes, FIFOs
- Filesystem Scanning - Build archives directly from a host directory tree
Quick Start
Reading an Archive
use File;
use BufReader;
use CpioArchiveReader;
let file = open?;
let mut reader = new;
while let Some = reader.next_entry_alloc?
Creating an Archive from a Directory
use File;
use BufWriter;
use ;
let tree = from_fs?;
let out = new;
let _out = new.finish?;
Building an Archive Programmatically
use ;
let mut tree = new;
tree.add;
tree.add;
tree.add;
let buf = new.finish?;
Feature Flags
| Feature | Description | Dependencies |
|---|---|---|
read |
Streaming archive reader | None |
alloc |
Heap allocation without full std | alloc crate |
std |
Full standard library support | std, alloc |
sync |
Synchronous archive API | hadris-io/sync |
async |
Asynchronous archive API | hadris-io/async |
write |
Archive creation | alloc, read |
Default features: std, sync, read, write
std selects platform integration but does not select an I/O mode. Custom
configurations should enable sync, async, or both explicitly.
For Bootloaders (minimal footprint)
[]
= { = "2.1.0", = false, = ["read", "sync"] }
For Kernels with Heap (no-std + alloc)
[]
= { = "2.1.0", = false, = ["read", "alloc", "sync"] }
For Desktop Applications (full features)
[]
= "2.1.0" # Uses default features
Archive Format
This crate implements the "new" (newc) ASCII CPIO format, which is the format used by:
- Linux initramfs images (
gen_init_cpio) - RPM package payloads
- The
cpio -H newccommand
Each entry consists of a 110-byte ASCII header, a NUL-terminated filename, and file data. All sections are padded to 4-byte boundaries. The archive ends with a TRAILER!!! sentinel.
Two magic numbers are supported:
070701- Standard newc format070702- newc with per-file CRC checksums
No-std Compatibility
The crate is designed for no-std environments:
- Core reading requires only the
readfeature (zero allocations withnext_entry_with_buf) - Allocating reader requires
alloc(usesVecfor filenames and data) - Writing and filesystem scanning require
allocandstdrespectively - All I/O uses
hadris-iotraits instead ofstd::io
Interoperability
Archives created with this crate are compatible with:
- GNU cpio (
cpio -t,cpio -i) - Linux kernel initramfs loader
- RPM tools
Specification References
cpio(5)man page- Linux kernel
usr/gen_init_cpio.c - RPM file format specification
Documentation
License
This project is licensed under the MIT license.