Skip to main content

BlkidPartlist

Struct BlkidPartlist 

Source
pub struct BlkidPartlist<'a>(/* private fields */);
Expand description

A handle for traversing a list of partitions.

Implementations§

Source§

impl<'a> BlkidPartlist<'a>

Source

pub fn number_of_partitions(&mut self) -> Result<c_int>

Get the number of partitions in the list.

Examples found in repository?
examples/is_owned.rs (line 44)
32fn main() -> Result<(), Box<dyn Error>> {
33    let path = env::args()
34        .nth(1)
35        .ok_or_else(|| ExampleError::new("Path of device to check required as argument"))?;
36
37    let mut probe = BlkidProbe::new_from_filename(Path::new(&path))?;
38    probe.enable_superblocks(true)?;
39    probe.enable_partitions(true)?;
40    probe.do_safeprobe()?;
41
42    let partitions = probe
43        .get_partitions()
44        .and_then(|mut list| list.number_of_partitions());
45    let detected_use = probe.lookup_value("TYPE");
46
47    if partitions.as_ref().map(|num| *num > 0).unwrap_or(false) || detected_use.is_ok() {
48        println!("In use");
49        if let Ok(num) = partitions {
50            println!("{num} partitions found on block device");
51        }
52        if let Ok(ty) = detected_use {
53            println!("Device determined to be of type {ty}");
54        }
55    } else {
56        println!("Free");
57    }
58
59    Ok(())
60}
Source

pub fn get_table(&mut self) -> Result<BlkidParttable<'a>>

Get the partition table for a list of partitions.

Source

pub fn get_partition(&mut self, index: c_int) -> Result<BlkidPartition<'a>>

Get a partition at the given index of the list.

Source

pub fn get_partition_by_partno( &mut self, num: c_int, ) -> Result<BlkidPartition<'a>>

Get a partition by the number listed in the partition table. Correctly handles “out-of-order” partition tables.

Source

pub fn get_partition_by_devno( &mut self, dev: &BlkidDevno, ) -> Result<BlkidPartition<'a>>

Get a partition using the device number of a partition.

Auto Trait Implementations§

§

impl<'a> Freeze for BlkidPartlist<'a>

§

impl<'a> RefUnwindSafe for BlkidPartlist<'a>

§

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

§

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

§

impl<'a> Unpin for BlkidPartlist<'a>

§

impl<'a> UnwindSafe for BlkidPartlist<'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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.