liblitho 0.2.0

cli tool to flash/clone the images to storage devices
Documentation
//! Windows storage enumeration via WMI.

use crate::devices::DeviceInfo;
use crate::platform::traits::DeviceInventory;
use anyhow::Result;

use super::devices as win_devices;
use super::WindowsPlatform;

impl DeviceInventory for WindowsPlatform {
    fn list_storage_devices() -> Result<Vec<DeviceInfo>> {
        win_devices::get_storage_devices()
    }

    fn device_size_bytes(path: &str) -> Option<u64> {
        // Prefer WMI enumeration (works without opening the raw device handle).
        if let Ok(devices) = win_devices::get_storage_devices() {
            if let Some(device) = devices
                .iter()
                .find(|d| win_devices::device_path_matches(&d.device_name, path))
            {
                if device.size > 0 {
                    return Some(device.size.saturating_mul(512));
                }
            }
        }
        win_devices::physical_drive_size_bytes(path)
    }

    fn device_size_sectors(path: &str) -> Option<u64> {
        Self::device_size_bytes(path).map(|bytes| bytes / 512)
    }

    fn is_removable(path: &str) -> Result<bool> {
        let devices = win_devices::get_storage_devices()?;
        Ok(devices
            .iter()
            .find(|d| win_devices::device_path_matches(&d.device_name, path))
            .map(|d| d.removable == 1)
            .unwrap_or(true))
    }
}