feat: rewrite Windows device detection with native Win32 APIs

Replace PowerShell with Win32 APIs (CreateFileW, DeviceIoControl) for reliable
device enumeration on all Windows editions.

Key improvements:
- Add IOCTL_DISK_GET_DRIVE_GEOMETRY_EX for disk size and geometry
- Add IOCTL_STORAGE_QUERY_PROPERTY for bus type and model detection
- Add drive letter mapping via GetLogicalDrives() and volume extents
- Fix system disk detection (check for C: drive instead of assuming disk 0)
- Add smart stop: halt enumeration after 4 consecutive non-existent drives
- Refactor: extract helpers, reduce code by 26% (475→349 lines)

Error handling:
- Suppress expected errors (1,2,5,21) to eliminate log spam
- Only log unexpected device failures

Fixes device enumeration failures on Windows editions without PowerShell.
This commit is contained in:
SuperKali
2025-12-25 18:46:53 +01:00
parent 224edd1463
commit ab0a9c3959
3 changed files with 374 additions and 129 deletions

View File

@@ -181,7 +181,11 @@ fn get_disk_info(disk_path: &str) -> Result<BlockDevice, String> {
Ok(BlockDevice {
path: disk_path.to_string(),
name: disk_path.split('/').last().unwrap_or(disk_path).to_string(),
name: disk_path
.split('/')
.next_back()
.unwrap_or(disk_path)
.to_string(),
size,
size_formatted: format_size(size),
model,

File diff suppressed because it is too large Load Diff

View File

@@ -55,17 +55,11 @@ pub struct AuthorizationEnvironment {
/// External form for passing authorization between processes
#[repr(C)]
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Default)]
pub struct AuthorizationExternalForm {
pub bytes: [u8; 32],
}
impl Default for AuthorizationExternalForm {
fn default() -> Self {
Self { bytes: [0u8; 32] }
}
}
// Authorization flags
pub const K_AUTHORIZATION_FLAG_INTERACTION_ALLOWED: u32 = 1 << 0;
pub const K_AUTHORIZATION_FLAG_EXTEND_RIGHTS: u32 = 1 << 1;