Expand description
Library of GPT disk data types.
§GPT disk components
┌───┬───────┬─────────────────┬─────────┬───────────────────┬─────────┐
│MBR│Primary│Primary partition│Partition│Secondary partition│Secondary│
│ │header │entry array │data │entry array │header │
└───┴───────┴─────────────────┴─────────┴───────────────────┴─────────┘
- The first block of the disk contains a protective MBR. See
MasterBootRecord::protective_mbr
. - The second block of the disk contains the primary GPT header. See
GptHeader
. - Additional blocks after the header contain the partition entry
array. See
GptPartitionEntry
andGptPartitionEntryArray
. - At the end of the disk is a secondary GPT header and partition entry array.
§Endianness
The UEFI Specification specifies that data structures are little
endian (section 1.8.1 “Data Structure Descriptions”). Unless
otherwise noted, all fields in this library are little endian. This
is true even when running the code on a big-endian architecture; the
U16Le
, U32Le
, U64Le
, and LbaLe
types help enforce
this. The little-endian convention is also used for Display
implementations. This means bytes within each field will appear
reversed when compared with a flat hex dump of GPT data.
§Features
bytemuck
: Implements bytemuck’sPod
andZeroable
traits for many of the types in this crate. Also enables some methods that rely on byte access.std
: Currently has no effect.
§Examples
Construct a GPT header:
use gpt_disk_types::{guid, Crc32, GptHeader, LbaLe, U32Le};
let header = GptHeader {
header_crc32: Crc32(U32Le::from_u32(0xa4877843)),
my_lba: LbaLe::from_u64(1),
alternate_lba: LbaLe::from_u64(8191),
first_usable_lba: LbaLe::from_u64(34),
last_usable_lba: LbaLe::from_u64(8158),
disk_guid: guid!("57a7feb6-8cd5-4922-b7bd-c78b0914e870"),
partition_entry_lba: LbaLe::from_u64(2),
number_of_partition_entries: U32Le::from_u32(128),
partition_entry_array_crc32: Crc32(U32Le::from_u32(0x9206adff)),
..Default::default()
};
Construct a GPT partition entry:
use gpt_disk_types::{guid, GptPartitionEntry, GptPartitionType, LbaLe};
let entry = GptPartitionEntry {
partition_type_guid: GptPartitionType(guid!(
"ccf0994f-f7e0-4e26-a011-843e38aa2eac"
)),
unique_partition_guid: guid!("37c75ffd-8932-467a-9c56-8cf1f0456b12"),
starting_lba: LbaLe::from_u64(2048),
ending_lba: LbaLe::from_u64(4096),
attributes: Default::default(),
name: "hello world!".parse().unwrap(),
};
Re-exports§
Macros§
Structs§
- Block
Size - Size of a block in bytes.
- Chs
- Legacy MBR cylinder/head/sector.
- Crc32
- 32-bit CRC (cyclic redundancy check).
- Disk
Geometry - Legacy disk geometry used for converting between
Lba
andChs
. - GptHeader
- GPT header that appears near the start and end of a GPT-formatted disk.
- GptHeader
Revision - GPT header revision.
- GptHeader
Signature - GPT header signature.
- GptPartition
Attributes - Partition attribute bits.
- GptPartition
Entry - An entry within the GPT partition array.
- GptPartition
Entry Array - Storage for a GPT partition entry array.
- GptPartition
Entry Array Layout - Disk layout of a GPT partition entry array.
- GptPartition
Entry Size - Size in bytes of entries in the partition entry array.
- GptPartition
Entry Size Error - Error returned by
GptPartitionEntrySize::new
. - GptPartition
Name - Human readable partition label encoded as a null-terminated UCS-2 string.
- GptPartition
Type - Unique ID representing the type of a partition.
- Guid
- Globally-unique identifier.
- Lba
- Logical block address.
- LbaLe
- Logical block address stored as a
U64Le
. - LbaRange
Inclusive - Inclusive range of logical block addresses.
- Master
Boot Record - Legacy master boot record.
- MbrPartition
Record - Legacy MBR partition record.
- U16Le
- 16-bit unsigned integer stored as a little-endian.
- U32Le
- 32-bit unsigned integer stored as a little-endian.
- U64Le
- 64-bit unsigned integer stored as a little-endian.
Enums§
- GptPartition
Entry Array Error - Errors used by
GptPartitionEntryArray
. - GptPartition
Name From StrError - Error type for
GptPartitionName::from_str
. - GptPartition
Name SetChar Error - Error type for
GptPartitionName::set_char
. - Guid
From StrError - Error type for
Guid::try_parse
andGuid::from_str
.