Skip to content

Commit

Permalink
Add DeviceType::Unrecognised, MediaType::OtherATA, MediaType::Virtual…
Browse files Browse the repository at this point in the history
…Box, and MediaType::Unrecognised. Upgrade some dependencies.
  • Loading branch information
iamjpotts committed Jan 9, 2024
1 parent 1630696 commit 146e697
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "block-utils"
version = "0.11.1"
version = "0.12.0"
authors = ["Chris Holcombe <xfactor973@gmail.com>"]
description = "Utilities to work with block devices. Formatting, getting device info, identifying type of device, etc."
edition = '2018'
edition = "2021"

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

[dev-dependencies]
nix = "0.23"
nix = "0.26"
tempfile = "3"

[dependencies]
Expand All @@ -23,7 +23,7 @@ regex = "1.7"
shellscript = "0.3"
serde = { "version" = "1.0", features = ["derive"] }
serde_json = "1.0"
strum = { version = "0.24", features = ["derive"] }
strum = { version = "0.25", features = ["derive"] }
thiserror = "1.0"
uuid = "1.3"

Expand Down
32 changes: 25 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,25 @@ pub enum MediaType {
Rotational,
/// Special loopback device
Loopback,
// Logical volume device
/// Logical volume device
LVM,
// Software raid device
/// Software raid device
MdRaid,
// NVM Express
/// NVM Express
NVME,
// Ramdisk
/// Ramdisk
Ram,
/// Virtual disk inside a QEMU virtual machine
Virtual,
/// Virtual disk inside a VirtualBox virtual machine
VirtualBox,
/// Unidentified, but vendor value was ATA
OtherATA,
/// Unidentified. While attributes were available in the identification process, none of the rules matched
Unrecognised {
vendor: Option<String>,
},
/// Unidentified, because there were no attributes available for an identification process
Unknown,
}

Expand All @@ -245,6 +255,8 @@ pub enum MediaType {
pub enum DeviceType {
Disk,
Partition,
#[strum(default)]
Unrecognised(String),
Unknown,
}

Expand All @@ -256,7 +268,7 @@ impl FromStr for DeviceType {
match s.as_ref() {
"disk" => Ok(DeviceType::Disk),
"partition" => Ok(DeviceType::Partition),
_ => Ok(DeviceType::Unknown),
other => Ok(DeviceType::Unrecognised(other.into())),
}
}
}
Expand Down Expand Up @@ -972,13 +984,19 @@ fn get_media_type(device: &udev::Device) -> MediaType {
if let Some(vendor) = device.property_value("ID_VENDOR") {
let value = vendor.to_string_lossy();
return match value.as_ref() {
"ATA" => MediaType::OtherATA,
"QEMU" => MediaType::Virtual,
_ => MediaType::Unknown,
"VBOX" => MediaType::VirtualBox,
_ => MediaType::Unrecognised {
vendor: Some(value.into())
},
};
}

// I give up
MediaType::Unknown
MediaType::Unrecognised {
vendor: None
}
}

#[cfg(target_os = "linux")]
Expand Down

0 comments on commit 146e697

Please sign in to comment.