pub struct GptDisk<'a> { /* private fields */ }
Expand description
A GPT disk backed by an arbitrary device.
Implementations§
source§impl<'a> GptDisk<'a>
impl<'a> GptDisk<'a>
sourcepub fn add_partition(
&mut self,
name: &str,
size: u64,
part_type: Type,
flags: u64,
part_alignment: Option<u64>,
) -> Result<u32>
pub fn add_partition( &mut self, name: &str, size: u64, part_type: Type, flags: u64, part_alignment: Option<u64>, ) -> Result<u32>
Add another partition to this disk. This tries to find the optimum partition location with the lowest block device. Returns the new partition id if there was sufficient room to add the partition. Size is specified in bytes.
sourcepub fn remove_partition(
&mut self,
id: Option<u32>,
partguid: Option<Uuid>,
) -> Result<u32>
pub fn remove_partition( &mut self, id: Option<u32>, partguid: Option<Uuid>, ) -> Result<u32>
remove partition from this disk. This tries to find the partition based on either a given partition number (id) or a partition guid. Returns the partition id if the partition is removed
sourcepub fn find_free_sectors(&self) -> Vec<(u64, u64)>
pub fn find_free_sectors(&self) -> Vec<(u64, u64)>
Find free space on the disk. Returns a tuple of (starting_lba, length in lba’s).
sourcepub fn find_next_partition_id(&self) -> u32
pub fn find_next_partition_id(&self) -> u32
Find next highest partition id.
sourcepub fn primary_header(&self) -> Option<&Header>
pub fn primary_header(&self) -> Option<&Header>
Retrieve primary header, if any.
sourcepub fn backup_header(&self) -> Option<&Header>
pub fn backup_header(&self) -> Option<&Header>
Retrieve backup header, if any.
sourcepub fn partitions(&self) -> &BTreeMap<u32, Partition>
pub fn partitions(&self) -> &BTreeMap<u32, Partition>
Retrieve partition entries.
sourcepub fn logical_block_size(&self) -> &LogicalBlockSize
pub fn logical_block_size(&self) -> &LogicalBlockSize
Retrieve disk logical block size.
sourcepub fn update_disk_device(
&mut self,
device: DiskDeviceObject<'a>,
writable: bool,
) -> DiskDeviceObject<'_>
pub fn update_disk_device( &mut self, device: DiskDeviceObject<'a>, writable: bool, ) -> DiskDeviceObject<'_>
Change the disk device that we are reading/writing from/to. Returns the previous disk device.
sourcepub fn update_guid(&mut self, uuid: Option<Uuid>) -> Result<&Self>
pub fn update_guid(&mut self, uuid: Option<Uuid>) -> Result<&Self>
Update disk UUID.
If no UUID is specified, a new random one is generated.
No changes are recorded to disk until write()
is called.
sourcepub fn update_partitions(
&mut self,
pp: BTreeMap<u32, Partition>,
) -> Result<&Self>
pub fn update_partitions( &mut self, pp: BTreeMap<u32, Partition>, ) -> Result<&Self>
Update current partition table.
No changes are recorded to disk until write()
is called.
sourcepub fn update_partitions_safe(
&mut self,
pp: BTreeMap<u32, Partition>,
) -> Result<&Self>
pub fn update_partitions_safe( &mut self, pp: BTreeMap<u32, Partition>, ) -> Result<&Self>
Update current partition table without touching backups
No changes are recorded to disk until write()
is called.
sourcepub fn update_partitions_embedded(
&mut self,
pp: BTreeMap<u32, Partition>,
num_parts: u32,
) -> Result<&Self>
pub fn update_partitions_embedded( &mut self, pp: BTreeMap<u32, Partition>, num_parts: u32, ) -> Result<&Self>
Update current partition table.
Allows for changing the partition count, use with caution.
No changes are recorded to disk until write()
is called.
sourcepub fn write(self) -> Result<DiskDeviceObject<'a>>
pub fn write(self) -> Result<DiskDeviceObject<'a>>
Persist state to disk, consuming this disk object.
This is a destructive action, as it overwrite headers and partitions entries on disk. All writes are flushed to disk before returning the underlying DiskDeviceObject.
sourcepub fn write_inplace(&mut self) -> Result<()>
pub fn write_inplace(&mut self) -> Result<()>
Persist state to disk, leaving this disk object intact.
This is a destructive action, as it overwrites headers and partitions entries on disk. All writes are flushed to disk before returning.