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
impl PartitionSet
Sourcepub fn from_probe(dev: &dyn BlockRead) -> Result<Self>
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.
Sourcepub fn empty_gpt(disk_size: u64) -> Self
pub fn empty_gpt(disk_size: u64) -> Self
Empty GPT table sized for disk_size bytes. Generates a v4 disk GUID.
Sourcepub fn add(
&mut self,
start_hint: Option<u64>,
length: u64,
type_id: PartitionTypeId,
label: Option<String>,
) -> Result<usize>
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.
Sourcepub fn remove(&mut self, target: PartitionRef) -> Result<()>
pub fn remove(&mut self, target: PartitionRef) -> Result<()>
Remove a partition. Returns Error::Invalid if the ref doesn’t
match anything.
Sourcepub fn resize(&mut self, target: PartitionRef, new_length: u64) -> Result<()>
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.
Sourcepub fn commit(&self, dev: &dyn BlockDevice) -> Result<()>
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
impl Clone for PartitionSet
Source§fn clone(&self) -> PartitionSet
fn clone(&self) -> PartitionSet
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more