Struct DeviceInfo
pub struct DeviceInfo {}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
impl DeviceInfo
pub fn all() -> Devices ⓘ
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>
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>
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
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>
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 ⓘ
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>
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>
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 char_device(&self) -> (u32, u32)
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
pub const fn mtd_number(&self) -> u32
Returns the number of the MTD device.
pub const fn min_io_size(&self) -> u32
pub const fn min_io_size(&self) -> u32
Returns the minimum I/O size in bytes.
pub const fn max_volumes(&self) -> u32
pub const fn max_volumes(&self) -> u32
Returns the largest number of volumes.
pub const fn total_blocks(&self) -> u32
pub const fn total_blocks(&self) -> u32
Returns the number of good physical eraseblocks.
pub const fn available_blocks(&self) -> u32
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
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
pub const fn bad_blocks(&self) -> u32
Returns the number of bad physical eraseblocks.
pub const fn max_erase_count(&self) -> u32
pub const fn max_erase_count(&self) -> u32
Returns the highest erase counter.
pub const fn read_only(&self) -> Option<bool>
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>
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>
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>
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>
pub(crate) fn open_control() -> Result<OwnedFd, DeviceError>
Opens the UBI control device.
Trait Implementations§
§impl Clone for DeviceInfo
impl Clone for DeviceInfo
§fn clone(&self) -> DeviceInfo
fn clone(&self) -> DeviceInfo
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more