From 11c0ef4db8be648696f712cbe47ce94b551958b4 Mon Sep 17 00:00:00 2001 From: slonkazoid Date: Thu, 1 Aug 2024 21:21:49 +0300 Subject: [PATCH] fix recursive device_path algorithm --- src/device_path.rs | 41 +++++++++++++++++++++-------------------- src/main.rs | 1 + 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/device_path.rs b/src/device_path.rs index bff33a9..a0d8024 100644 --- a/src/device_path.rs +++ b/src/device_path.rs @@ -9,28 +9,29 @@ fn recurse_device_path( mut uuid: Option, mut path: Option, ) -> (Option, Option) { + match dbg!(&a.info) { + DevicePathInfo::HardDrive { + partition_signature, + signature_type, + .. + } => { + if matches!(signature_type, DevicePathInfoHardDriveSignatureType::Guid) { + let mut sig = [0u8; 16]; + partition_signature + .as_slice() + .read_exact(&mut sig) + .expect("expected 128-bit Guid"); + uuid = Some(fixup_uuid(u128::from_be_bytes(sig))); + } + } + DevicePathInfo::FilePath { path: _path } => { + path = Some(_path.clone()); + } + _ => {} + } + match a.next { Some(next) => { - match &next.info { - DevicePathInfo::HardDrive { - partition_signature, - signature_type, - .. - } => { - if matches!(signature_type, DevicePathInfoHardDriveSignatureType::Guid) { - let mut sig = [0u8; 16]; - partition_signature - .as_slice() - .read_exact(&mut sig) - .expect("expected 128-bit Guid"); - uuid = Some(fixup_uuid(u128::from_be_bytes(sig))); - } - } - DevicePathInfo::FilePath { path: _path } => { - path = Some(_path.clone()); - } - _ => {} - } return recurse_device_path(*next, uuid, path); } None => return (uuid, path), diff --git a/src/main.rs b/src/main.rs index dd7b53c..aca3cf2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -122,6 +122,7 @@ fn main() -> eyre::Result<()> { && let Some(device_path) = device_path { let (uuid, path) = traverse_device_path(device_path); + eprintln!("devicepath uuid: {uuid:?}, path: {path:?}"); let windows_path_str = if let Some(windows_path_str) = path { windows_path_str