Skip to main content

DeviceInfo

Struct DeviceInfo 

pub struct DeviceInfo {
Show 14 fields number: u32, root: &'static Path, path: PathBuf, char_device: (u32, u32), mtd_number: u32, leb_size: u32, min_io_size: u32, max_volumes: u32, total_blocks: u32, available_blocks: u32, reserved_for_bad: u32, bad_blocks: u32, max_erase_count: u32, read_only: Option<bool>,
}
Expand description

UBI device attached to an MTD device, with its attributes from sysfs.

The values are a snapshot from the time the device was read. Read it again for current values.

use flashkit_ubi_linux::DeviceInfo;

let device = match DeviceInfo::by_mtd(3)? {
    Some(device) => device,
    None => DeviceInfo::attach(3).run()?,
};
for volume in device.volumes() {
    let volume = volume?;
    println!("{}: {} bytes", volume.name(), volume.data_bytes());
}

Fields§

§number: u32§root: &'static Path§path: PathBuf§char_device: (u32, u32)§mtd_number: u32§leb_size: u32§min_io_size: u32§max_volumes: u32§total_blocks: u32§available_blocks: u32§reserved_for_bad: u32§bad_blocks: u32§max_erase_count: u32§read_only: Option<bool>

Implementations§

§

impl DeviceInfo

pub fn all() -> Devices ⓘ

Returns an iterator over all UBI devices in the order of their numbers.

Without the UBI driver, there are none.

pub fn by_number(number: u32) -> Result<Option<Self>, DeviceError>

Returns the UBI device with number number, as in /dev/ubi<number>, or None if there is none.

§Errors

Returns an error if sysfs can’t be read.

pub fn by_mtd(mtd_number: u32) -> Result<Option<Self>, DeviceError>

Returns the UBI device attached to MTD device mtd_number, or None if there is none.

§Errors

Returns an error if sysfs can’t be read.

pub const fn attach(mtd_number: u32) -> AttachOptions

Returns the options for attaching MTD device mtd_number to UBI.

Set the options and call AttachOptions::run to attach the device.

pub fn detach(self) -> Result<(), DeviceError>

Detaches the device from its MTD device.

§Errors

Returns an error if the UBI control device can’t be opened or the kernel refuses to detach, for example because a volume is open.

pub fn volumes(&self) -> Volumes ⓘ

Returns an iterator over the volumes of the device in the order of their IDs.

pub fn volume(&self, id: u32) -> Result<Option<VolumeInfo>, DeviceError>

Returns volume id of the device, or None if there is none.

§Errors

Returns an error if sysfs can’t be read.

pub fn volume_by_name( &self, name: &[u8], ) -> Result<Option<VolumeInfo>, DeviceError>

Returns the volume of the device named name, or None if there is none.

§Errors

Returns an error if sysfs can’t be read.

pub const fn number(&self) -> u32

Returns the number of the device.

pub fn path(&self) -> &Path

Returns the path of the character device, /dev/ubi<number>.

pub const fn char_device(&self) -> (u32, u32)

Returns the major and minor number of the character device.

pub const fn mtd_number(&self) -> u32

Returns the number of the MTD device.

pub const fn leb_size(&self) -> u32

Returns the size of a logical eraseblock in bytes.

pub const fn min_io_size(&self) -> u32

Returns the minimum I/O size in bytes.

pub const fn max_volumes(&self) -> u32

Returns the largest number of volumes.

pub const fn total_blocks(&self) -> u32

Returns the number of good physical eraseblocks.

pub const fn available_blocks(&self) -> u32

Returns the number of physical eraseblocks that new or larger volumes can use.

pub const fn reserved_for_bad(&self) -> u32

Returns the number of physical eraseblocks reserved for blocks that go bad.

pub const fn bad_blocks(&self) -> u32

Returns the number of bad physical eraseblocks.

pub const fn max_erase_count(&self) -> u32

Returns the highest erase counter.

pub const fn read_only(&self) -> Option<bool>

Returns whether the device switched to read-only mode after an error, or None if the kernel doesn’t report it.

pub(crate) fn read( root: &'static Path, number: u32, ) -> Result<Option<Self>, DeviceError>

Returns the device number in the sysfs class directory root, or None if there is none.

fn from_dir( sysfs: &SysfsDir, root: &'static Path, number: u32, ) -> Result<Self, DeviceError>

Reads device number from its open directory sysfs in the class directory root.

fn by_mtd_in( root: &'static Path, mtd_number: u32, ) -> Result<Option<Self>, DeviceError>

Returns the device attached to mtd_number in the sysfs class directory root.

pub(crate) fn open_control() -> Result<OwnedFd, DeviceError>

Opens the UBI control device.

Trait Implementations§

§

impl Clone for DeviceInfo

§

fn clone(&self) -> DeviceInfo

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for DeviceInfo

§

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

Formats the value using the given formatter. Read more
§

impl Eq for DeviceInfo

§

impl PartialEq for DeviceInfo

§

fn eq(&self, other: &DeviceInfo) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

impl StructuralPartialEq for DeviceInfo

Auto Trait Implementations§

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.