Struct devicemapper::Device
source · 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: u32Device major number
minor: u32Device minor number
Implementations§
source§impl Device
impl Device
The Linux kernel’s kdev_t encodes major/minor values as mmmM MMmm.
sourcepub fn from_kdev_t(val: u32) -> Device
pub fn from_kdev_t(val: u32) -> Device
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
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,
})
}