Skip to main content

hadris_apfs/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2#![allow(async_fn_in_trait)]
3#![deny(missing_docs)]
4
5//! An experimental, read-only APFS container and volume reader.
6//!
7//! The API is outside the Hadris 2.x stability promise and may change in a
8//! minor release. Compressed files, encryption, snapshots and writes are not
9//! supported; see the README for the full scope.
10//!
11//! On-disk structures live in [`types`]. The readers in the `sync` and
12//! `async` modules walk them over a `hadris-storage` block device.
13//!
14//! ```rust,no_run
15//! use std::fs::File;
16//!
17//! use hadris_apfs::sync::Container;
18//! use hadris_storage::sync::SeekBlockDevice;
19//! use hadris_storage::{BlockCount, BlockGeometry, BlockSize};
20//!
21//! let file = File::open("container.img")?;
22//! let sectors = file.metadata()?.len() / 512;
23//! let geometry = BlockGeometry::new(BlockSize::new(512).unwrap(), BlockCount(sectors));
24//! let mut container = Container::open(SeekBlockDevice::new(file, geometry))?;
25//! let latest = container.latest_superblock()?;
26//! for volume in container.volume_superblocks(&latest)? {
27//!     if let Some(entry) = container.resolve_path(&volume, "/notes.txt")? {
28//!         let data = container.read_file(&volume, entry.file_id, 1 << 20)?;
29//!         println!("{}: {} bytes", volume.name()?, data.len());
30//!     }
31//! }
32//! # Ok::<(), Box<dyn std::error::Error>>(())
33//! ```
34
35#[cfg(any(feature = "alloc", feature = "std"))]
36extern crate alloc;
37#[cfg(feature = "std")]
38extern crate std;
39
40/// Error types returned by APFS readers and writers.
41pub mod error;
42pub mod types;
43
44#[cfg(all(feature = "read", feature = "async"))]
45pub mod r#async;
46#[cfg(feature = "read")]
47pub mod read;
48#[cfg(all(feature = "read", feature = "sync"))]
49pub mod sync;
50
51pub use error::{ApfsError, Result};