diff --git a/src/utils/link/pcie.rs b/src/utils/link/pcie.rs index 4bd031e4..cee2d73b 100644 --- a/src/utils/link/pcie.rs +++ b/src/utils/link/pcie.rs @@ -1,4 +1,5 @@ use crate::utils::link::LinkData; +use crate::utils::read_parsed; use anyhow::{Context, Error, anyhow, bail}; use log::trace; use process_data::pci_slot::PciSlot; @@ -38,20 +39,20 @@ impl LinkData { let path = path.as_ref(); trace!("Reading PCIe link data for {path:?}…"); - let current_pcie_speed_raw = std::fs::read_to_string(path.join("current_link_speed")) + let current_pcie_speed_raw = read_parsed::(path.join("current_link_speed")) .map(|x| x.trim().to_string()) .context("Could not read current link speed")?; - let current_pcie_width_raw = std::fs::read_to_string(path.join("current_link_width")) + let current_pcie_width_raw = read_parsed::(path.join("current_link_width")) .map(|x| x.trim().to_string()) .context("Could not read current link width")?; //Consider max values as optional - let max_pcie_speed_raw = std::fs::read_to_string(path.join("max_link_speed")) + let max_pcie_speed_raw = read_parsed::(path.join("max_link_speed")) .map(|x| x.trim().to_string()) .context("Could not read max link speed"); - let max_pcie_width_raw = std::fs::read_to_string(path.join("max_link_width")) + let max_pcie_width_raw = read_parsed::(path.join("max_link_width")) .map(|x| x.trim().to_string()) .context("Could not read max link width"); diff --git a/src/utils/link/sata.rs b/src/utils/link/sata.rs index 0985c170..3f6012ec 100644 --- a/src/utils/link/sata.rs +++ b/src/utils/link/sata.rs @@ -1,6 +1,7 @@ use crate::utils::drive::AtaSlot; use crate::utils::link::LinkData; use crate::utils::link::sata::SataSpeed::{Sata150, Sata300, Sata600}; +use crate::utils::read_parsed; use anyhow::{Context, Error, anyhow}; use log::trace; use std::fmt::{Display, Formatter}; @@ -21,11 +22,11 @@ impl LinkData { let ata_link_path = Path::new("/sys/class/ata_link").join(format!("link{}", ata_slot.ata_link)); - let current_sata_speed_raw = std::fs::read_to_string(ata_link_path.join("sata_spd")) + let current_sata_speed_raw = read_parsed::(ata_link_path.join("sata_spd")) .map(|x| x.trim().to_string()) .context("Could not read sata_spd")?; - let max_sata_speed_raw = std::fs::read_to_string(ata_link_path.join("sata_spd_max")) + let max_sata_speed_raw = read_parsed::(ata_link_path.join("sata_spd_max")) .map(|x| x.trim().to_string()) .context("Could not read sata_spd_max"); diff --git a/src/utils/link/usb.rs b/src/utils/link/usb.rs index e5d6d0ac..ce91ca96 100644 --- a/src/utils/link/usb.rs +++ b/src/utils/link/usb.rs @@ -1,5 +1,6 @@ use crate::utils::drive::UsbSlot; use crate::utils::link::LinkData; +use crate::utils::read_parsed; use crate::utils::units::convert_speed_bits_decimal_with_places; use anyhow::{Context, Error, anyhow}; use log::trace; @@ -27,12 +28,12 @@ impl LinkData { let usb_bus_path = Path::new("/sys/bus/usb/devices/").join(format!("usb{}", usb_slot.usb_bus)); - let max_usb_port_speed_raw = std::fs::read_to_string(usb_bus_path.join("speed")) + let max_usb_port_speed_raw = read_parsed::(usb_bus_path.join("speed")) .map(|x| x.trim().to_string()) .context("Could not read usb port speed"); let usb_device_speed = - std::fs::read_to_string(usb_bus_path.join(&usb_slot.usb_device).join("speed")) + read_parsed::(usb_bus_path.join(&usb_slot.usb_device).join("speed")) .map(|x| x.trim().to_string()) .context("Could not read usb device speed")?;