Struct gpt::GptDisk

source ·
pub struct GptDisk<'a> { /* private fields */ }
Expand description

A GPT disk backed by an arbitrary device.

Implementations§

source§

impl<'a> GptDisk<'a>

source

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.

source

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

source

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).

source

pub fn find_next_partition_id(&self) -> u32

Find next highest partition id.

source

pub fn primary_header(&self) -> Option<&Header>

Retrieve primary header, if any.

source

pub fn backup_header(&self) -> Option<&Header>

Retrieve backup header, if any.

source

pub fn partitions(&self) -> &BTreeMap<u32, Partition>

Retrieve partition entries.

source

pub fn guid(&self) -> &Uuid

Retrieve disk UUID.

source

pub fn logical_block_size(&self) -> &LogicalBlockSize

Retrieve disk logical block size.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

Trait Implementations§

source§

impl<'a> Debug for GptDisk<'a>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for GptDisk<'a>

§

impl<'a> !RefUnwindSafe for GptDisk<'a>

§

impl<'a> !Send for GptDisk<'a>

§

impl<'a> !Sync for GptDisk<'a>

§

impl<'a> Unpin for GptDisk<'a>

§

impl<'a> !UnwindSafe for GptDisk<'a>

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.