Pure-Rust partition-table probe and filesystem-magic sniffer over any random-access block source.
Given a BlockRead (a tiny trait: read_at(offset, buf) + size_bytes()),
this crate tells you:
- Is there a GPT or MBR partition table?
- What partitions exist? (start, length, type, label, UUID)
- For each partition, what filesystem signature is at the start?
It does not mount anything, decode files, or write — it's a probe.
- GPT primary header (signature, CRC32 validation, entry array)
- GPT backup header read + validate, with primary/backup mismatch reporting (
gpt::parse_backup,gpt::validate_backupreturningBackupStatus::Ok/Mismatch) - MBR with GPT-protective fallthrough
- FS sniff: ext2/3/4, NTFS, exFAT, FAT16, FAT32, HFS+, APFS, Linux swap, ISO 9660, SquashFS
-
SliceReaderadapter — rebases offsets on a sub-range of anyBlockRead(planned to move intoam-fs-coresince slicing is a generic block-layer concern; this crate will re-export for backwards compatibility) - C ABI for FFI (
partitions_probe,partitions_count,partitions_table_kind,partitions_get,partitions_sniff,partitions_open_slice,partitions_list_free; header ininclude/partitions.h) - LVM / LUKS / mdraid detection
- Logical-partition (extended MBR) chain walking
- GPT writer: protective MBR + primary header + entry array + backup mirror at end of disk, all CRCs computed correctly (
gpt_write::write_gpt) - MBR writer (
mbr::write_mbr, four primary entries) - Mutation API:
add/remove/resizeover an in-memory partition set, with 1 MiB alignment and a first-fit free-space finder (PartitionSet) -
commit(&dev)semantics — writes happen on commit, not on mutation - Round-trip tests: probe → mutate → commit → re-probe matches intent (
tests/mutation.rs) - C ABI for the writer — the existing
partitions_*handle stays read-only; a writable handle is a follow-up - Optional
with_boot_codevariant of the MBR / protective-MBR writer for legacy BIOS boot
use partitions::{probe, sniff, BlockRead, FileBlock};
let dev = FileBlock::open("disk.img")?;
let parts = probe(&dev)?;
for p in &parts {
let kind = sniff(&dev, p)?;
println!("{} bytes @ {} -> {:?}", p.length, p.start, kind);
}src/
lib.rs public API + BlockRead/BlockDevice + FileBlock + SliceReader
error.rs Error / Result
gpt.rs GPT header + entry array parser, backup-header validator
gpt_write.rs GPT writer (protective MBR + primary + backup, CRCs)
mbr.rs MBR parser + writer
mutation.rs PartitionSet — in-memory add/remove/resize + commit
sniff.rs filesystem magic-byte sniffer
probe.rs top-level dispatch (try GPT, fall back to MBR)
tests/
fixtures.rs hand-built GPT/MBR + sniff fixtures
mutation.rs round-trip mutate/commit/re-probe tests
MIT.