Struct Device
pub struct Device {
index: u32,
mtd: u32,
owned: bool,
}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: boolWhether this handle attached the device and detaches it on drop.
Implementations§
§impl Device
impl Device
pub fn find(mtd: u32) -> Result<Option<Self>, DeviceError>
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>
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>
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 keep_attached(&mut self)
pub const fn keep_attached(&mut self)
Keeps the device attached when this handle is dropped.
pub fn detach(self) -> Result<(), DeviceError>
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.