Struct devicemapper::Device

source ·
pub struct Device {
    pub major: u32,
    pub minor: u32,
}
Expand description

A struct containing the device’s major and minor numbers

Also allows conversion to/from a single 64bit dev_t value.

Fields§

§major: u32

Device major number

§minor: u32

Device minor number

Implementations§

The Linux kernel’s kdev_t encodes major/minor values as mmmM MMmm.

Make a Device from a kdev_t.

Examples found in repository?
src/core/dm.rs (line 551)
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
    pub fn table_deps(&self, id: &DevId<'_>, options: DmOptions) -> DmResult<Vec<Device>> {
        let mut hdr = options.to_ioctl_hdr(Some(id), DmFlags::DM_QUERY_INACTIVE_TABLE)?;

        let (_, data_out) = self.do_ioctl(dmi::DM_TABLE_DEPS_CMD as u8, &mut hdr, None)?;

        if data_out.is_empty() {
            Ok(vec![])
        } else {
            let result = &data_out[..];
            let target_deps = unsafe { &*(result.as_ptr() as *const dmi::Struct_dm_target_deps) };

            let dev_slc = unsafe {
                slice::from_raw_parts(
                    result[size_of::<dmi::Struct_dm_target_deps>()..].as_ptr() as *const u64,
                    target_deps.count as usize,
                )
            };

            // Note: The DM target_deps struct reserves 64 bits for each entry
            // but only 32 bits is used by kernel "huge" dev_t encoding.
            Ok(dev_slc
                .iter()
                .map(|d| Device::from_kdev_t(*d as u32))
                .collect())
        }
    }
More examples
Hide additional examples
src/core/deviceinfo.rs (line 74)
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
    fn try_from(ioctl: dmi::Struct_dm_ioctl) -> DmResult<Self> {
        let uuid = str_from_c_str(&ioctl.uuid as &[c_char]).ok_or_else(|| {
            errors::Error::InvalidArgument("Devicemapper UUID is not null terminated".to_string())
        })?;
        let uuid = if uuid.is_empty() {
            None
        } else {
            Some(DmUuidBuf::new(uuid.to_string())?)
        };
        let name = str_from_c_str(&ioctl.name as &[c_char]).ok_or_else(|| {
            errors::Error::InvalidArgument("Devicemapper name is not null terminated".to_string())
        })?;
        let name = if name.is_empty() {
            None
        } else {
            Some(DmNameBuf::new(name.to_string())?)
        };
        Ok(DeviceInfo {
            version: Version::new(
                u64::from(ioctl.version[0]),
                u64::from(ioctl.version[1]),
                u64::from(ioctl.version[2]),
            ),
            data_size: ioctl.data_size,
            data_start: ioctl.data_start,
            target_count: ioctl.target_count,
            open_count: ioctl.open_count,
            flags: DmFlags::from_bits_truncate(ioctl.flags),
            event_nr: ioctl.event_nr,
            // dm_ioctl struct reserves 64 bits for device but kernel "huge"
            // encoding is only 32 bits.
            dev: Device::from_kdev_t(ioctl.dev as u32),
            uuid,
            name,
        })
    }

Convert to a kdev_t. Return None if values are not expressible as a kdev_t.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Display format is the device number in “:” format

Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
The associated error which can be returned from parsing.
Parses a string s to return a value of this type. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.