Skip to main content

Mbr

Struct Mbr 

Source
pub struct Mbr {
    pub bootstrap_code: [u8; 440],
    pub disk_signature: [u8; 4],
    pub copy_protected: [u8; 2],
    pub partitions: [PartitionEntry; 4],
    pub boot_signature: [u8; 2],
}
Expand description

Master Boot Record structure (512 bytes).

Fields§

§bootstrap_code: [u8; 440]

Bootstrap code area (440 bytes).

§disk_signature: [u8; 4]

32-bit disk signature.

§copy_protected: [u8; 2]

Copy protected bytes.

§partitions: [PartitionEntry; 4]

Partition table entries.

§boot_signature: [u8; 2]

Boot signature bytes ([0x55, 0xAA]).

Implementations§

Source§

impl Mbr

Source

pub const SIZE: usize = 512

Size of MBR in bytes.

Source

pub const MINIMUM_START_BLOCK: Size = 2048

Standard partition alignment block offset.

Source

pub fn new_with_signature(disk_signature: u32) -> Self

Create a new empty MBR with a specified 32-bit disk signature.

Source

pub fn from_bytes(data: &[u8]) -> Result<Self>

Parse an MBR from a 512-byte raw sector.

Source

pub fn to_bytes(&self) -> Result<[u8; 512]>

Encode the MBR into a 512-byte sector.

Source

pub fn read_from_device(device: &impl DirectBlockDevice) -> Result<Self>

Read and parse the MBR from a block device.

Source

pub fn write_to_device(&self, device: &impl DirectBlockDevice) -> Result<()>

Write the MBR to sector 0 of a block device.

Source

pub fn is_valid(&self) -> bool

Check if the MBR signature matches [0x55, 0xAA].

Source

pub fn get_disk_signature(&self) -> u32

Get the 32-bit disk signature.

Source

pub fn validate(&self) -> Result<()>

Validate MBR signature, partition overlaps, and single-bootable rule.

Source

pub fn format_disk_with_signature_and_partition<'a, D: DirectBlockDevice>( device: &'a D, disk_signature: u32, partition_type: PartitionKind, ) -> Result<PartitionDevice<'a, D>>

Format a disk with a specific disk signature and single partition, returning a PartitionDevice.

Source

pub fn find_or_create_partition_with_signature<'a, D: DirectBlockDevice>( device: &'a D, target_signature: u32, partition_type: PartitionKind, ) -> Result<PartitionDevice<'a, D>>

Find an existing partition with the specified disk signature, or format the disk.

Trait Implementations§

Source§

impl Clone for Mbr

Source§

fn clone(&self) -> Mbr

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Mbr

Source§

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

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

impl Display for Mbr

Source§

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

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

impl PartialEq for Mbr

Source§

fn eq(&self, other: &Mbr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Mbr

Source§

impl StructuralPartialEq for Mbr

Auto Trait Implementations§

§

impl Freeze for Mbr

§

impl RefUnwindSafe for Mbr

§

impl Send for Mbr

§

impl Sync for Mbr

§

impl Unpin for Mbr

§

impl UnsafeUnpin for Mbr

§

impl UnwindSafe for Mbr

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.