patches and low-level development discussion
 help / color / mirror / code / Atom feed
blob 15ef4d41e93211ca05d35c4cade0e00ea9d5550b 1644 bytes (raw)
name: tools/spectrum-installer/src/destination_device.rs 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 
// SPDX-License-Identifier: EUPL-1.2+
// SPDX-FileCopyrightText: 2026 Johannes Süllner <johannes.suellner@mailbox.org>

#[derive(Debug, Clone)]
pub struct DestinationDevice {
    pub name: String,
    pub path: String,
    pub size_bytes: u64,
}

impl DestinationDevice {
    pub fn get_destination_devices() -> Result<Vec<DestinationDevice>, &'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)
    }
}

debug log:

solving 15ef4d4 ...
found 15ef4d4 in https://inbox.spectrum-os.org/spectrum-devel/20260204175543.22164-3-johannes.suellner@mailbox.org/

applying [1/1] https://inbox.spectrum-os.org/spectrum-devel/20260204175543.22164-3-johannes.suellner@mailbox.org/
diff --git a/tools/spectrum-installer/src/destination_device.rs b/tools/spectrum-installer/src/destination_device.rs
new file mode 100644
index 0000000..15ef4d4

Checking patch tools/spectrum-installer/src/destination_device.rs...
Applied patch tools/spectrum-installer/src/destination_device.rs cleanly.

index at:
100644 15ef4d41e93211ca05d35c4cade0e00ea9d5550b	tools/spectrum-installer/src/destination_device.rs

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).