Skip to main content

VolumeInfo

Struct VolumeInfo 

pub struct VolumeInfo {
    device_number: u32,
    id: u32,
    path: PathBuf,
    char_device: (u32, u32),
    name: VolumeName,
    kind: VolumeKind,
    alignment: u32,
    usable_leb_size: u32,
    reserved_lebs: u32,
    data_bytes: u64,
    corrupted: bool,
    update_marker: bool,
}
Expand description

Volume of a UBI device, with its attributes from sysfs.

super::DeviceInfo::volume and super::DeviceInfo::volumes return it. The values are a snapshot from the time the volume was read. Read it again for current values.

The methods that open the volume use its device file, /dev/ubi<device>_<id>. Some systems create device files a moment after the kernel attached the device. Wait for VolumeInfo::path to appear if needed.

Fields§

§device_number: u32§id: u32§path: PathBuf§char_device: (u32, u32)§name: VolumeName§kind: VolumeKind§alignment: u32§usable_leb_size: u32§reserved_lebs: u32§data_bytes: u64§corrupted: bool§update_marker: bool

Implementations§

§

impl VolumeInfo

pub const fn device_number(&self) -> u32

Returns the number of the UBI device of the volume.

pub const fn id(&self) -> u32

Returns the volume ID.

pub fn path(&self) -> &Path

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

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

Returns the major and minor number of the character device.

pub const fn name(&self) -> &VolumeName

Returns the name of the volume.

pub const fn kind(&self) -> VolumeKind

Returns the type of the volume.

pub const fn alignment(&self) -> u32

Returns the alignment of the volume.

pub const fn usable_leb_size(&self) -> u32

Returns the bytes of data in a logical eraseblock of the volume. This can be less than the logical eraseblock size of the device because of the alignment.

pub const fn reserved_lebs(&self) -> u32

Returns the logical eraseblocks reserved for the volume.

pub fn reserved_bytes(&self) -> u64

Returns the bytes reserved for the volume.

pub const fn data_bytes(&self) -> u64

Returns the bytes of data in the volume. For a VolumeKind::Dynamic volume, this equals VolumeInfo::reserved_bytes.

pub const fn is_corrupted(&self) -> bool

Returns whether the kernel found the volume corrupted.

pub const fn has_update_marker(&self) -> bool

Returns whether an update of the volume didn’t finish.

pub fn open_read(&self) -> Result<File, DeviceError>

Opens the volume for reading.

§Errors

Returns an error if the device file can’t be opened.

pub fn truncate(&self) -> Result<(), DeviceError>

Removes all data from the volume.

§Errors

Returns an error if the device file can’t be opened or the kernel refuses the update.

pub fn update<R: BufRead>(&self, image: R, size: u64) -> Result<(), DeviceError>

Replaces the content of the volume with the first size bytes of image.

Each chunk that image returns from BufRead::fill_buf is written as is. Wrap a File in a std::io::BufReader. The kernel collects the data into logical eraseblocks, so the chunks can have any size.

If the update fails, the kernel marks the volume corrupted until the next successful update.

§Errors

Returns DeviceError::ImageTooShort if image ends early, and DeviceError::Update if the kernel refuses the update, for example because size exceeds the reserved bytes. Returns another error if reading image or opening the volume fails.

pub(crate) fn read( root: &Path, device_number: u32, id: u32, ) -> Result<Option<Self>, DeviceError>

Returns volume id of device device_number in the sysfs class directory root, or None if there is none.

pub(crate) fn from_dir( sysfs: &SysfsDir, device_number: u32, id: u32, ) -> Result<Self, DeviceError>

Reads volume id of device device_number from its open directory sysfs.

fn open(&self, flags: OFlags) -> Result<OwnedFd, DeviceError>

Opens the device file with flags.

Trait Implementations§

§

impl Clone for VolumeInfo

§

fn clone(&self) -> VolumeInfo

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 VolumeInfo

§

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

Formats the value using the given formatter. Read more
§

impl Eq for VolumeInfo

§

impl PartialEq for VolumeInfo

§

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

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

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

Inequality operator !=. Read more
§

impl StructuralPartialEq for VolumeInfo

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.