Merge pull request #138 from kevinmehall/info-cleanup
Canonicalize sysfs paths, remove BusInfo::parent_path
This commit is contained in:
commit
7730be5f86
4 changed files with 7 additions and 20 deletions
|
|
@ -9,7 +9,7 @@ fn main() {
|
|||
|
||||
fn inspect_device(dev: DeviceInfo) {
|
||||
println!(
|
||||
"Device {:03}.{:03} ({:04x}:{:04x}) {} {}",
|
||||
"Device {}.{:03} ({:04x}:{:04x}) {} {}",
|
||||
dev.bus_id(),
|
||||
dev.device_address(),
|
||||
dev.vendor_id(),
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ fn main() {
|
|||
|
||||
fn inspect_device(dev: DeviceInfo) {
|
||||
println!(
|
||||
"Device {:03}.{:03} ({:04x}:{:04x}) {} {}",
|
||||
"Device {}.{:03} ({:04x}:{:04x}) {} {}",
|
||||
dev.bus_id(),
|
||||
dev.device_address(),
|
||||
dev.vendor_id(),
|
||||
|
|
|
|||
|
|
@ -479,9 +479,6 @@ pub struct BusInfo {
|
|||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
pub(crate) path: SysfsPath,
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
pub(crate) parent_path: SysfsPath,
|
||||
|
||||
/// The phony root hub device
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
pub(crate) root_hub: DeviceInfo,
|
||||
|
|
@ -535,12 +532,6 @@ impl BusInfo {
|
|||
&self.path.0
|
||||
}
|
||||
|
||||
/// *(Linux-only)* Sysfs path for the parent controller
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
pub fn parent_sysfs_path(&self) -> &std::path::Path {
|
||||
&self.parent_path.0
|
||||
}
|
||||
|
||||
/// *(Linux-only)* Bus number.
|
||||
///
|
||||
/// On Linux, the `bus_id` is an integer and this provides the value as `u8`.
|
||||
|
|
@ -664,7 +655,6 @@ impl std::fmt::Debug for BusInfo {
|
|||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
{
|
||||
s.field("sysfs_path", &self.path);
|
||||
s.field("parent_sysfs_path", &self.parent_path);
|
||||
s.field("busnum", &self.busnum);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -137,6 +137,8 @@ pub fn list_devices() -> impl MaybeFuture<Output = Result<impl Iterator<Item = D
|
|||
return None;
|
||||
}
|
||||
|
||||
let path = path.canonicalize().ok()?;
|
||||
|
||||
probe_device(SysfsPath(path))
|
||||
.inspect_err(|e| warn!("{e}; ignoring device"))
|
||||
.ok()
|
||||
|
|
@ -154,6 +156,8 @@ pub fn list_root_hubs() -> Result<impl Iterator<Item = DeviceInfo>, Error> {
|
|||
return None;
|
||||
}
|
||||
|
||||
let path = path.canonicalize().ok()?;
|
||||
|
||||
probe_device(SysfsPath(path))
|
||||
.inspect_err(|e| warn!("{e}; ignoring root hub"))
|
||||
.ok()
|
||||
|
|
@ -164,20 +168,13 @@ pub fn list_buses() -> impl MaybeFuture<Output = Result<impl Iterator<Item = Bus
|
|||
Ready((|| {
|
||||
Ok(list_root_hubs()?.filter_map(|rh| {
|
||||
// get the parent by following the absolute symlink; root hub in /bus/usb is a symlink to a dir in parent bus
|
||||
let parent_path = rh
|
||||
.path
|
||||
.0
|
||||
.canonicalize()
|
||||
.ok()
|
||||
.and_then(|p| p.parent().map(|p| SysfsPath(p.to_owned())))?;
|
||||
let parent_path = rh.path.0.parent().map(|p| SysfsPath(p.to_owned()))?;
|
||||
|
||||
debug!("Probing parent device {:?}", parent_path.0);
|
||||
let driver = parent_path.readlink_attr_filename("driver").ok();
|
||||
|
||||
Some(BusInfo {
|
||||
bus_id: rh.bus_id.to_owned(),
|
||||
path: rh.path.to_owned(),
|
||||
parent_path: parent_path.to_owned(),
|
||||
busnum: rh.busnum,
|
||||
controller_type: driver.as_ref().and_then(|p| UsbControllerType::from_str(p)),
|
||||
driver,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue