Struct Device

Source
pub struct Device<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> Device<'a>

Source

pub fn check(&self, start: i64, count: i64) -> Option<u64>

Returns the first bad sector if a bad sector was found.

§Binding Note

Not 100% sure if this is what this method does, as libparted’s source code did not document the behavior of the function. Am basing this off the check() method that was documented for Geometry.

Source

pub fn probe(&self) -> Option<DiskType<'_>>

Return the type of partition table detected on dev

Source

pub fn devices<'b>(probe: bool) -> DeviceIter<'b>

Attempts to detect all devices, constructing an Iterator which will contain a list of all of the devices. If you want to use a device that isn’t on the list, use the new() method, or an OS-specific constructor such as new_from_store().

Source

pub fn get<P: AsRef<Path>>(path: P) -> Result<Device<'a>>

Obtains a handle to the device, but does not open it.

Source

pub fn open(&mut self) -> Result<()>

Attempts to open the device.

Source

pub fn new<P: AsRef<Path>>(path: P) -> Result<Device<'a>>

Attempts to get the device of the given path, then attempts to open that device.

Source

pub unsafe fn from_ped_device(device: *mut PedDevice) -> Device<'a>

Source

pub unsafe fn ped_device(&self) -> *mut PedDevice

Source

pub fn external_access<'b>(&'b mut self) -> Result<DeviceExternalAccess<'a, 'b>>

Begins external access mode.

External access mode allows you to safely do I/O on the device. If a device is open, then you should not do any I/O on that device, such as by calling an external program like e2fsck, unless you put it in external access mode. You should not use any libparted commands that do I/O to a device while a device is in external access mode.

§Note:

You should not close a device while it is in external access mode.

Source

pub fn sync(&mut self) -> Result<()>

Flushes all write-behind caches that might be holding up writes.

It is slow because it guarantees cache coherency among all relevant caches.

Source

pub fn sync_fast(&mut self) -> Result<()>

Flushes all write-behind caches that might be holding writes.

It does not ensure cache coherency with other caches.

Source

pub fn is_busy(&self) -> bool

Indicates whether the device is busy.

Source

pub fn write_to_sectors( &mut self, buffer: &[u8], start_sector: i64, sectors: i64, ) -> Result<()>

Attempts to write the data within the buffer to the device, starting at the start_sector, and spanning across sectors.

Source

pub fn get_constraint<'b>(&self) -> Result<Constraint<'b>>

Get a constraint that represents hardware requirements on geometry.

This function will return a constraint representing the limits imposed by the size of the disk. It will not provide any alignment constraints.

Alignment constraint may be desirable when using media that has a physical sector size that is a multiple of the logical sector size, as in this case proper partition alignment can benefit disk performance significantly.

§Note:

When you want a constraint with alignment info, use the following methods:

  • Device::get_minimal_aligned_constraint()
  • Device::get_optimal_aligned_constraint()
Source

pub fn constraint_any<'b>(&self) -> Option<Constraint<'b>>

Return a constraint that any region on the given device will satisfy.

Source

pub fn constraint_from_start_end<'b>( &self, range_start: &Geometry<'_>, range_end: &Geometry<'_>, ) -> Result<Constraint<'b>>

Source

pub fn get_minimal_aligned_constraint<'b>(&self) -> Result<Constraint<'b>>

Get a constraint that represents hardware requirements on geometry and alignment.

This function will return a constraint representing the limits imposed by the size of the disk and the minimal alignment requirements for proper performance of the disk.

Source

pub fn get_optimal_aligned_constraint<'b>(&self) -> Result<Constraint<'b>>

Get a constraint that represents hardware requirements on geometry and alignment.

This function will return a constraint representing the limits imposed by the size of the disk and the alignment requirements for optimal performance of the disk.

Source

pub fn get_minimum_alignment<'b>(&self) -> Option<Alignment<'b>>

Get an alignment that represents minimum hardware requirements on alignment.

When using media that has a physical sector size that is a multiple of the logical sector size, it is desirable to have disk accesses (and thus partitions) properly aligned. Having partitions not aligned to the minimum hardware requirements may lead to a performance penalty.

The returned alignment describes the alignment for the start sector of the partition. The end sector should be aligned too. To get the end sector alignment, decrease the returned alignment’s offset by 1.

Source

pub fn get_optimum_alignment<'b>(&self) -> Option<Alignment<'b>>

Get an alignment that represents the hardware requirements for optimal performance.

The returned alignment describes the alignment for the start sector of the partition. The end sector should be aligned too. To get the end alignment, decrease the returned alignment’s offset by 1.

Source

pub fn clobber(&mut self) -> Result<()>

Remove all identifying signatures of a partition table.

Source

pub fn model(&self) -> &str

Source

pub fn path(&self) -> &Path

Source

pub fn type_(&self) -> DeviceType

Source

pub fn sector_size(&self) -> u64

Source

pub fn phys_sector_size(&self) -> u64

Source

pub fn length(&self) -> u64

Source

pub fn open_count(&self) -> isize

Source

pub fn read_only(&self) -> bool

Source

pub fn external_mode(&self) -> bool

Source

pub fn dirty(&self) -> bool

Source

pub fn boot_dirty(&self) -> bool

Source

pub fn hw_geom(&self) -> CHSGeometry

Source

pub fn bios_geom(&self) -> CHSGeometry

Source

pub fn host(&self) -> i16

Source

pub fn did(&self) -> i16

Trait Implementations§

Source§

impl<'a> Drop for Device<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Device<'a>

§

impl<'a> RefUnwindSafe for Device<'a>

§

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

§

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

§

impl<'a> Unpin for Device<'a>

§

impl<'a> UnwindSafe for Device<'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>,

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.