Skip to main content

Device

Struct Device 

pub struct Device {
    index: u32,
    mtd: u32,
    owned: bool,
}
Available on crate feature linux and (Android or Linux) only.
Expand description

UBI device attached to an MTD device.

A device attached through Device::attach is detached again when it’s dropped. A device returned by Device::find was attached by someone else and stays attached.

use std::fs::File;
use std::io::BufReader;

use flashkit_mtd::Partition;
use flashkit_ubi::{Device, Volume};

let partition = Partition::find("system")?;
let device = Device::attach_or_find(partition.index)?;
let volume = Volume::open(&device, 0)?;
let image = File::open("system.ubifs")?;
let size = image.metadata()?.len();
volume.update(BufReader::new(image), size)?;

Fields§

§index: u32§mtd: u32§owned: bool

Whether this handle attached the device and detaches it on drop.

Implementations§

§

impl Device

pub fn find(mtd: u32) -> Result<Option<Self>, DeviceError>

Returns the UBI device attached to MTD device mtd, if any.

§Errors

Returns an error if the UBI devices in sysfs can’t be read.

pub fn attach(mtd: u32) -> Result<Self, DeviceError>

Attaches MTD device mtd to UBI.

The kernel picks the UBI device number. The device is detached again when the returned handle is dropped.

§Errors

Returns an error if the UBI control device can’t be opened or the kernel refuses to attach, for example because mtd is attached already.

pub fn attach_or_find(mtd: u32) -> Result<Self, DeviceError>

Returns the UBI device of MTD device mtd, attaching it if needed.

§Errors

Returns an error if Device::find or Device::attach fails.

pub const fn index(&self) -> u32

Returns the UBI device number.

pub const fn mtd(&self) -> u32

Returns the index of the MTD device.

pub const fn is_owned(&self) -> bool

Returns whether dropping this handle detaches the device.

pub const fn keep_attached(&mut self)

Keeps the device attached when this handle is dropped.

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

Detaches the device, whether this handle attached it or not.

§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 mounted.

fn request_detach(&self) -> Result<(), DeviceError>

Trait Implementations§

§

impl Debug for Device

§

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

Formats the value using the given formatter. Read more
§

impl Drop for Device

§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

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
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 = !

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.