pub struct ProtectiveMBR { /* private fields */ }
Expand description
Protective MBR, as defined by GPT.
Implementations§
Source§impl ProtectiveMBR
impl ProtectiveMBR
Sourcepub fn with_lb_size(lb_size: u32) -> Self
pub fn with_lb_size(lb_size: u32) -> Self
Create a protective-MBR object with a specific protective partition size (in LB). The protective partition size should be the size of the disk - 1 (because the protective partition always begins at LBA 1 (the second sector)).
Sourcepub fn from_bytes(buf: &[u8], sector_size: LogicalBlockSize) -> Result<Self>
pub fn from_bytes(buf: &[u8], sector_size: LogicalBlockSize) -> Result<Self>
Parse input bytes into a protective-MBR object.
Sourcepub fn from_disk<D: DiskDevice>(
device: &mut D,
sector_size: LogicalBlockSize,
) -> Result<Self>
pub fn from_disk<D: DiskDevice>( device: &mut D, sector_size: LogicalBlockSize, ) -> Result<Self>
Read the LBA0 of a disk device and parse it into a protective-MBR object.
Sourcepub fn as_bytes(&self) -> Result<Vec<u8>>
pub fn as_bytes(&self) -> Result<Vec<u8>>
Return the memory representation of this MBR as a byte vector.
Sourcepub fn set_bootcode(&mut self, bootcode: [u8; 440]) -> &Self
pub fn set_bootcode(&mut self, bootcode: [u8; 440]) -> &Self
Set the 440 bytes of BIOS bootcode.
This only changes the in-memory state, without overwriting any on-disk data.
Sourcepub fn disk_signature(&self) -> &[u8; 4]
pub fn disk_signature(&self) -> &[u8; 4]
Return the 4 bytes of MBR disk signature.
Sourcepub fn set_disk_signature(&mut self, sig: [u8; 4]) -> &Self
pub fn set_disk_signature(&mut self, sig: [u8; 4]) -> &Self
Set the 4 bytes of MBR disk signature.
This only changes the in-memory state, without overwriting any on-disk data.
Sourcepub fn partition(&self, partition_index: usize) -> Option<PartRecord>
pub fn partition(&self, partition_index: usize) -> Option<PartRecord>
Returns the given partition (0..=3) or None if the partition index is invalid.
Sourcepub fn set_partition(
&mut self,
partition_index: usize,
partition: PartRecord,
) -> Option<PartRecord>
pub fn set_partition( &mut self, partition_index: usize, partition: PartRecord, ) -> Option<PartRecord>
Set the data for the given partition. Returns the previous partition record or None if the partition index is invalid.
This only changes the in-memory state, without overwriting any on-disk data.
Sourcepub fn overwrite_lba0<D: DiskDevice>(&self, device: &mut D) -> Result<usize>
pub fn overwrite_lba0<D: DiskDevice>(&self, device: &mut D) -> Result<usize>
Write a protective MBR to LBA0, overwriting any existing data.
Sourcepub fn update_conservative<D: DiskDevice>(
&self,
device: &mut D,
) -> Result<usize>
pub fn update_conservative<D: DiskDevice>( &self, device: &mut D, ) -> Result<usize>
Update LBA0, preserving most bytes of any existing MBR.
This overwrites the four MBR partition records and the well-known signature, leaving all other MBR bits as-is.