gpt::mbr

Struct ProtectiveMBR

Source
pub struct ProtectiveMBR { /* private fields */ }
Expand description

Protective MBR, as defined by GPT.

Implementations§

Source§

impl ProtectiveMBR

Source

pub fn new() -> Self

Create a default protective-MBR object.

Source

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)).

Source

pub fn from_bytes(buf: &[u8], sector_size: LogicalBlockSize) -> Result<Self>

Parse input bytes into a protective-MBR object.

Source

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.

Source

pub fn as_bytes(&self) -> Result<Vec<u8>>

Return the memory representation of this MBR as a byte vector.

Source

pub fn bootcode(&self) -> &[u8; 440]

Return the 440 bytes of BIOS bootcode.

Source

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.

Source

pub fn disk_signature(&self) -> &[u8; 4]

Return the 4 bytes of MBR disk signature.

Source

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.

Source

pub fn partition(&self, partition_index: usize) -> Option<PartRecord>

Returns the given partition (0..=3) or None if the partition index is invalid.

Source

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.

Source

pub fn overwrite_lba0<D: DiskDevice>(&self, device: &mut D) -> Result<usize>

Write a protective MBR to LBA0, overwriting any existing data.

Source

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.

Trait Implementations§

Source§

impl Debug for ProtectiveMBR

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ProtectiveMBR

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.