Skip to main content

PartitionSet

Struct PartitionSet 

Source
pub struct PartitionSet {
    pub table_kind: TableKind,
    pub partitions: Vec<Partition>,
    pub disk_size: u64,
    pub disk_guid: [u8; 16],
}
Expand description

In-memory mutable partition set. All edits stay in this struct until commit writes them back.

Fields§

§table_kind: TableKind§partitions: Vec<Partition>§disk_size: u64§disk_guid: [u8; 16]

Disk GUID for the GPT header. Ignored when table_kind == Mbr.

Implementations§

Source§

impl PartitionSet

Source

pub fn from_probe(dev: &dyn BlockRead) -> Result<Self>

Probe the device and return its current partition set, ready for editing. The disk GUID for GPT is read from the on-disk header; for MBR it is left at all-zeros and unused.

Source

pub fn empty_gpt(disk_size: u64) -> Self

Empty GPT table sized for disk_size bytes. Generates a v4 disk GUID.

Source

pub fn empty_mbr(disk_size: u64) -> Self

Empty MBR table sized for disk_size bytes.

Source

pub fn add( &mut self, start_hint: Option<u64>, length: u64, type_id: PartitionTypeId, label: Option<String>, ) -> Result<usize>

Add a partition. start_hint = None triggers a first-fit search at 1 MiB alignment. A non-None hint that isn’t already aligned is rounded up to the next 1 MiB boundary, and length is rounded up to the next sector if it isn’t already a multiple of 512.

Returns the index of the newly added partition.

Source

pub fn remove(&mut self, target: PartitionRef) -> Result<()>

Remove a partition. Returns Error::Invalid if the ref doesn’t match anything.

Source

pub fn resize(&mut self, target: PartitionRef, new_length: u64) -> Result<()>

Resize a partition. The new length is rounded up to a sector multiple and re-validated against the device bounds and other partitions.

Source

pub fn commit(&self, dev: &dyn BlockDevice) -> Result<()>

Serialise to disk. Dispatches to the GPT or MBR writer depending on table_kind, then flushes the device.

Trait Implementations§

Source§

impl Clone for PartitionSet

Source§

fn clone(&self) -> PartitionSet

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 PartitionSet

Source§

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

Formats the value using the given formatter. 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> 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, 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.