Skip to main content

bb_drivelist/
lib.rs

1//! This is basically a Rust implementation of [Balena's drivelist](https://github.com/balena-io-modules/drivelist).
2//!
3//! - Windows
4//! - Linux
5//! - Macos
6
7mod device;
8
9mod pal;
10
11pub use device::{DeviceDescriptor, MountPoint};
12use thiserror::Error;
13
14pub(crate) type Result<T, E = Error> = std::result::Result<T, E>;
15
16#[derive(Error, Debug)]
17pub enum Error {
18    #[cfg(target_os = "linux")]
19    #[error("Failed to execute lsblk.")]
20    LsblkExecuteError {
21        #[source]
22        source: Option<std::io::Error>,
23    },
24    #[cfg(target_os = "windows")]
25    #[error("Failed to get drive list.")]
26    WindowsError {
27        #[source]
28        #[from]
29        source: windows::core::Error,
30    },
31    #[cfg(target_os = "macos")]
32    #[error("Failed to create DiskArbitration session")]
33    MacosDiskArbitration,
34}
35
36/// Get a list of all drives
37pub fn drive_list() -> crate::Result<Vec<DeviceDescriptor>> {
38    pal::drive_list()
39}