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 CpioReader;
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 writer = new;
let mut out = new;
writer.write?;
Building an Archive Programmatically
use ;
let mut tree = new;
tree.add;
tree.add;
tree.add;
let writer = new;
let mut buf = Vecnew;
writer.write?;
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 |
write |
Archive creation | alloc, read |
Default features: std, read, write
For Bootloaders (minimal footprint)
[]
= { = "1.0", = false, = ["read"] }
For Kernels with Heap (no-std + alloc)
[]
= { = "1.0", = false, = ["read", "alloc"] }
For Desktop Applications (full features)
[]
= { = "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
License
This project is licensed under the MIT license.