Skip to main content

Crate hadris_part

Crate hadris_part 

Source
Expand description

Partition table support for MBR, GPT, and Hybrid MBR.

This crate provides types and utilities for working with disk partition tables:

  • MBR (Master Boot Record): Legacy BIOS partition table format supporting up to 4 primary partitions. See the mbr module.

  • GPT (GUID Partition Table): Modern UEFI partition table format supporting up to 128 partitions with GUIDs for type identification. See the gpt module.

  • Hybrid MBR: A non-standard configuration that combines GPT with MBR entries for dual BIOS/UEFI compatibility. See the hybrid module.

§Features

  • std (default): Enables standard library support and includes alloc.
  • read (default): Enables reading partition tables via *ReadExt traits.
  • alloc: Enables heap allocation for Vec-based APIs (e.g., GptDisk, PartitionTable).
  • write: Enables writing partition tables (requires alloc + read).
  • sync / async: Synchronous or asynchronous I/O traits (via hadris-io).
  • crc: Enables CRC32 verification/calculation for GPT headers (via the crc crate).
  • rand: Enables random GUID generation (via the rand crate).

std does not select an I/O mode. The default feature set enables sync explicitly; custom configurations should enable sync, async, or both.

§Examples

§Creating a protective MBR for a GPT disk

use hadris_part::mbr::MasterBootRecord;

// Create a protective MBR for a 1TB disk (in 512-byte sectors)
let disk_sectors = 1_953_525_168u64; // ~1TB
let mbr = MasterBootRecord::protective(disk_sectors);

assert!(mbr.has_valid_signature());
assert!(mbr.get_partition_table().is_protective());

§Working with GPT partition entries

use hadris_part::gpt::{Guid, GptPartitionEntry};

// Create an EFI System Partition entry
let esp = GptPartitionEntry::new(
    Guid::EFI_SYSTEM,
    Guid::UNUSED, // Would normally be a unique GUID
    2048,         // Start at 1MB (2048 * 512 bytes)
    206847,       // ~100MB partition
);

assert!(!esp.is_unused());
assert_eq!(esp.size_sectors(), 204800);

Re-exports§

pub use error::Error;
pub use error::Result;
pub use geometry::DiskGeometry;
pub use geometry::validate_partition_alignment;
pub use gpt::GptHeader;
pub use gpt::GptPartitionEntry;
pub use gpt::Guid;
pub use mbr::Chs;
pub use mbr::MasterBootRecord;
pub use mbr::MbrPartition;
pub use mbr::MbrPartitionTable;
pub use mbr::MbrPartitionType;
pub use scheme::PartitionInfo;
pub use scheme::PartitionSchemeType;
pub use scheme::PartitionType;
pub use scheme::GptDisk;alloc
pub use scheme::PartitionTable;alloc
pub use sync::*;sync

Modules§

asyncasync
Asynchronous partition table API.
error
Error types for partition operations.
geometry
Disk geometry and alignment utilities.
gpt
GPT (GUID Partition Table) types.
hybrid
Hybrid MBR support for dual BIOS/UEFI bootable disks.
mbr
MBR (Master Boot Record) partition table types.
scheme
Unified partition scheme handling.
syncsync
Synchronous partition table API.

Structs§

Le
An integer stored in little-endian byte order.

Traits§

GptDiskReadExtalloc and read
Extension trait for reading GptDisk from I/O sources.
GptDiskWriteExtalloc and write
Extension trait for writing GptDisk to I/O sinks.
GptHeaderReadExtread
Extension trait for reading/writing GptHeader from/to I/O sources.
GptHeaderWriteExtwrite
Extension trait for writing GptHeader to I/O sinks.
MasterBootRecordReadExtread
Extension trait for reading MasterBootRecord from I/O sources.
MasterBootRecordWriteExtwrite
Extension trait for writing MasterBootRecord to I/O sinks.
PartitionInfoTrait
Trait for types that represent partition information.
PartitionTableRead
Trait for partition table types that support reading.
PartitionTableReadExtalloc and read
Extension trait for reading PartitionTable from I/O sources.
PartitionTableWriteExtalloc and write
Extension trait for writing PartitionTable to I/O sinks.