mbr/lib.rs
1//! # mbr-core
2//!
3//! Pure-Rust, read-only Master Boot Record (MBR) parser. Decodes the on-disk
4//! structures — the 512-byte boot sector, the four primary partition entries,
5//! Extended Boot Record (EBR) chains, CHS/LBA geometry, GPT and VBR
6//! cross-validation primitives, boot-code identity, and filesystem
7//! fingerprints — with no I/O beyond a caller-supplied [`Read`] + [`Seek`].
8//!
9//! This crate is the structure-decode layer. It deliberately contains **no**
10//! anomaly findings: the forensic analyzer that turns these structures into
11//! graded observations lives in the sibling `mbr-forensic` crate, which
12//! re-exports every type here.
13//!
14//! [`Read`]: std::io::Read
15//! [`Seek`]: std::io::Seek
16//!
17//! ```no_run
18//! use mbr::parse_mbr_sector;
19//!
20//! // Pure parsing from a 512-byte buffer (no I/O required):
21//! let buf = [0u8; 512];
22//! let sector = parse_mbr_sector(&buf)?;
23//! # Ok::<(), mbr::Error>(())
24//! ```
25#![cfg_attr(test, allow(clippy::unwrap_used, clippy::expect_used))]
26
27pub mod boot_code;
28pub mod carve;
29pub mod diag;
30pub mod disk_signature;
31pub mod ebr;
32pub mod gpt;
33pub mod mbr;
34pub mod partition;
35pub mod signature;
36pub mod vbr;
37
38pub use boot_code::{identify as identify_boot_code, BootCodeId};
39pub use disk_signature::{find_signature_collisions, SignatureCollision};
40pub use ebr::{walk_ebr_chain, EbrChain, EbrEntry};
41pub use mbr::{parse_mbr_sector, MbrSector, SECTOR_SIZE};
42pub use partition::{Chs, ChsConsistency, PartitionEntry, PartitionFamily, TypeCode};
43pub use signature::{detect as detect_fs, DetectedFs};
44
45/// Crate-level error type.
46#[derive(Debug, thiserror::Error)]
47pub enum Error {
48 #[error("sector too short: expected 512 bytes, got {0}")]
49 TooShort(usize),
50 #[error("invalid MBR boot signature: expected 0x55AA, got 0x{0:04X}")]
51 BadSignature(u16),
52 #[error("I/O error: {0}")]
53 Io(#[from] std::io::Error),
54}