Inspect an MBR or GPT image
[dependencies]
hadris-part = "2.1.0"
use hadris_part::{
PartitionInfoTrait, PartitionTable, PartitionTableReadExt,
};
use std::fs::File;
fn main() -> hadris_part::Result<()> {
let mut disk = File::open("disk.img")?;
let table = PartitionTable::read_from(&mut disk, 512)?;
for partition in table.partitions() {
println!(
"#{}: LBA {} ({} sectors)",
partition.index,
partition.start_lba,
partition.size_sectors,
);
}
Ok(())
}
Use a real logical block size instead of assuming 512 bytes when the backing
device reports different geometry. Enable the crc feature when GPT CRC
validation is required.
The returned start and size values are expressed in logical blocks. To open a filesystem safely, convert them with checked arithmetic and create a bounded partition view. See Open FAT inside a partition.