Skip to content

Commit 146e697

Browse files
committed
Add DeviceType::Unrecognised, MediaType::OtherATA, MediaType::VirtualBox, and MediaType::Unrecognised. Upgrade some dependencies.
1 parent 1630696 commit 146e697

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[package]
22
name = "block-utils"
3-
version = "0.11.1"
3+
version = "0.12.0"
44
authors = ["Chris Holcombe <[email protected]>"]
55
description = "Utilities to work with block devices. Formatting, getting device info, identifying type of device, etc."
6-
edition = '2018'
6+
edition = "2021"
77

88
# These URLs point to more information about the repository.
99
documentation = "https://docs.rs/block-utils"
@@ -13,7 +13,7 @@ readme = "README.md"
1313
license = "MIT"
1414

1515
[dev-dependencies]
16-
nix = "0.23"
16+
nix = "0.26"
1717
tempfile = "3"
1818

1919
[dependencies]
@@ -23,7 +23,7 @@ regex = "1.7"
2323
shellscript = "0.3"
2424
serde = { "version" = "1.0", features = ["derive"] }
2525
serde_json = "1.0"
26-
strum = { version = "0.24", features = ["derive"] }
26+
strum = { version = "0.25", features = ["derive"] }
2727
thiserror = "1.0"
2828
uuid = "1.3"
2929

src/lib.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,25 @@ pub enum MediaType {
227227
Rotational,
228228
/// Special loopback device
229229
Loopback,
230-
// Logical volume device
230+
/// Logical volume device
231231
LVM,
232-
// Software raid device
232+
/// Software raid device
233233
MdRaid,
234-
// NVM Express
234+
/// NVM Express
235235
NVME,
236-
// Ramdisk
236+
/// Ramdisk
237237
Ram,
238+
/// Virtual disk inside a QEMU virtual machine
238239
Virtual,
240+
/// Virtual disk inside a VirtualBox virtual machine
241+
VirtualBox,
242+
/// Unidentified, but vendor value was ATA
243+
OtherATA,
244+
/// Unidentified. While attributes were available in the identification process, none of the rules matched
245+
Unrecognised {
246+
vendor: Option<String>,
247+
},
248+
/// Unidentified, because there were no attributes available for an identification process
239249
Unknown,
240250
}
241251

@@ -245,6 +255,8 @@ pub enum MediaType {
245255
pub enum DeviceType {
246256
Disk,
247257
Partition,
258+
#[strum(default)]
259+
Unrecognised(String),
248260
Unknown,
249261
}
250262

@@ -256,7 +268,7 @@ impl FromStr for DeviceType {
256268
match s.as_ref() {
257269
"disk" => Ok(DeviceType::Disk),
258270
"partition" => Ok(DeviceType::Partition),
259-
_ => Ok(DeviceType::Unknown),
271+
other => Ok(DeviceType::Unrecognised(other.into())),
260272
}
261273
}
262274
}
@@ -972,13 +984,19 @@ fn get_media_type(device: &udev::Device) -> MediaType {
972984
if let Some(vendor) = device.property_value("ID_VENDOR") {
973985
let value = vendor.to_string_lossy();
974986
return match value.as_ref() {
987+
"ATA" => MediaType::OtherATA,
975988
"QEMU" => MediaType::Virtual,
976-
_ => MediaType::Unknown,
989+
"VBOX" => MediaType::VirtualBox,
990+
_ => MediaType::Unrecognised {
991+
vendor: Some(value.into())
992+
},
977993
};
978994
}
979995

980996
// I give up
981-
MediaType::Unknown
997+
MediaType::Unrecognised {
998+
vendor: None
999+
}
9821000
}
9831001

9841002
#[cfg(target_os = "linux")]

0 commit comments

Comments
 (0)