use crate::drive::DeviceResolution;
use crate::error::{Error, Result};
use crate::identity::DriveId;
const SCSI_PERIPHERAL_TYPE_OPTICAL: u8 = 0x05;
pub fn find_drives() -> Vec<(String, DriveId)> {
let mut drives = Vec::new();
let discovered = crate::scsi::list_drives();
for info in discovered {
let path = std::path::Path::new(&info.path);
match crate::scsi::open(path) {
Ok(mut transport) => {
if let Ok(id) = DriveId::from_drive(transport.as_mut()) {
if !id.raw_inquiry.is_empty()
&& (id.raw_inquiry[0] & 0x1F) == SCSI_PERIPHERAL_TYPE_OPTICAL
{
drives.push((info.path.clone(), id));
}
}
}
Err(_) => {
continue;
}
}
}
drives
}
pub fn resolve_device(path: &str) -> Result<(String, DeviceResolution)> {
if !std::path::Path::new(path).exists() {
return Err(Error::DeviceNotFound {
path: path.to_string(),
});
}
Ok((path.to_string(), DeviceResolution::Direct))
}