// SPDX-License-Identifier: EUPL-1.2+ // SPDX-FileCopyrightText: 2026 Johannes Süllner #[derive(Debug, Clone)] pub struct DestinationDevice { pub name: String, pub path: String, pub size_bytes: u64, } impl DestinationDevice { pub fn get_destination_devices() -> Result, &'static str> { let get_devices_result = blockdev::get_devices(); if let Ok(block_devices) = get_devices_result { let non_system_devices = block_devices.non_system(); let possible_block_devices = non_system_devices .iter() .filter(|device| device.is_disk()) .map(|device| DestinationDevice { name: device.name.clone(), path: format!("/dev/{}", device.name.clone()), size_bytes: device.size, }); Ok(possible_block_devices.collect()) } else { Err("Fail") } } pub fn size_as_human_readable_string(&self) -> String { let mut size_factor: f64 = self.size_bytes as f64; let mut exponent = 0; // base = 1024 while size_factor >= 1000.0 { exponent += 1; size_factor = size_factor / 1000.0; } let unit = match exponent { 0 => "", 1 => "K", 2 => "M", 3 => "G", 4 => "T", 5 => "P", 6 => "E", 7 => "Z", 8 => "Y", 9 => "R", _ => "???", }; format!("{:.2} {}B", size_factor, unit) } }