Struct gpt::mbr::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>,

§

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>,

§

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.