pub fn get_block_dev_properties(
device_path: impl AsRef<Path>,
) -> BlockResult<HashMap<String, String>> {
let syspath = device_path
.as_ref()
.file_name()
.map(PathBuf::from)
.ok_or_else(|| {
BlockUtilsError::new(format!(
"Unable to get file_name on device {:?}",
device_path.as_ref()
))
})?;
let udev_device = udev::Device::from_syspath(&syspath)?; //HERE
Ok(udev_device
.clone()
.properties()
.map(|property| {
let key = property.name().to_string_lossy().to_string();
let value = property.value().to_string_lossy().to_string();
(key, value)
})
.collect()) // We can't return iterator because `udev_device` doesn't live long enough
}
udev::Device::from_syspath expects full syspath like /sys/block/loop0 instead of just a sysname loop0 like in udevadm CLI.
udevadm CLI expects sysname and found exact syspath automatically.
So, these functions get_block_dev_properties and get_block_dev_property doesn't work properly.
And I'm not sure how to fix it right now. As far as I understand, this path can lay not only in /sys/block/$dev but also in other /sys/ subdirectories.
Unfortunately I don't have enough time right now so I'm going to investigate it over the next few weeks.
I've found one another bug in my last PR.
udev::Device::from_syspath
expects full syspath like/sys/block/loop0
instead of just a sysnameloop0
like inudevadm
CLI.udevadm
CLI expects sysname and found exact syspath automatically. So, these functionsget_block_dev_properties
andget_block_dev_property
doesn't work properly.And I'm not sure how to fix it right now. As far as I understand, this path can lay not only in
/sys/block/$dev
but also in other/sys/
subdirectories.Unfortunately I don't have enough time right now so I'm going to investigate it over the next few weeks.