diff --git a/src/api2/types/tape/drive.rs b/src/api2/types/tape/drive.rs index e42072e9..d2e565a1 100644 --- a/src/api2/types/tape/drive.rs +++ b/src/api2/types/tape/drive.rs @@ -117,8 +117,6 @@ pub struct MamAttribute { #[api()] #[derive(Serialize,Deserialize,Copy,Clone,Debug)] pub enum TapeDensity { - /// No tape loaded - None, /// LTO1 LTO1, /// LTO2 @@ -144,7 +142,6 @@ impl TryFrom for TapeDensity { fn try_from(value: u8) -> Result { let density = match value { - 0x00 => TapeDensity::None, 0x40 => TapeDensity::LTO1, 0x42 => TapeDensity::LTO2, 0x44 => TapeDensity::LTO3, @@ -164,23 +161,30 @@ impl TryFrom for TapeDensity { properties: { density: { type: TapeDensity, + optional: true, }, }, )] #[derive(Serialize,Deserialize)] #[serde(rename_all = "kebab-case")] /// Drive/Media status for Linux SCSI drives. +/// +/// Media related data is optional - only set if there is a medium +/// loaded. pub struct LinuxDriveAndMediaStatus { /// Block size (0 is variable size) pub blocksize: u32, /// Tape density - pub density: TapeDensity, + #[serde(skip_serializing_if="Option::is_none")] + pub density: Option, /// Status flags pub status: String, /// Current file number - pub file_number: i32, + #[serde(skip_serializing_if="Option::is_none")] + pub file_number: Option, /// Current block number - pub block_number: i32, + #[serde(skip_serializing_if="Option::is_none")] + pub block_number: Option, /// Medium Manufacture Date (epoch) #[serde(skip_serializing_if="Option::is_none")] pub manufactured: Option, diff --git a/src/tape/drive/linux_tape.rs b/src/tape/drive/linux_tape.rs index 4b44ce2d..a35ec71d 100644 --- a/src/tape/drive/linux_tape.rs +++ b/src/tape/drive/linux_tape.rs @@ -41,10 +41,10 @@ use crate::{ #[derive(Debug)] pub struct LinuxDriveStatus { pub blocksize: u32, - pub density: TapeDensity, pub status: GMTStatusFlags, - pub file_number: i32, - pub block_number: i32, + pub density: Option, + pub file_number: Option, + pub block_number: Option, } impl LinuxDriveStatus { @@ -244,8 +244,6 @@ impl LinuxTapeHandle { bail!("MTIOCGET failed - {}", err); } - println!("{:?}", status); - let gmt = GMTStatusFlags::from_bits_truncate(status.mt_gstat); let blocksize; @@ -258,14 +256,24 @@ impl LinuxTapeHandle { let density = ((status.mt_dsreg & MT_ST_DENSITY_MASK) >> MT_ST_DENSITY_SHIFT) as u8; - let density = TapeDensity::try_from(density)?; - Ok(LinuxDriveStatus { blocksize, - density, status: gmt, - file_number: status.mt_fileno, - block_number: status.mt_blkno, + density: if density != 0 { + Some(TapeDensity::try_from(density)?) + } else { + None + }, + file_number: if status.mt_fileno > 0 { + Some(status.mt_fileno as u32) + } else { + None + }, + block_number: if status.mt_blkno > 0 { + Some(status.mt_blkno as u32) + } else { + None + }, }) }