From a3b4b5b50e5b9aee6f528faad31cc1e75469104b Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 23 Apr 2021 07:54:42 +0200 Subject: [PATCH] tape: define and use MediumType enum --- src/tape/drive/lto/sg_tape.rs | 3 ++- src/tools/sgutils2.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/tape/drive/lto/sg_tape.rs b/src/tape/drive/lto/sg_tape.rs index a6f66cc0..2d94653f 100644 --- a/src/tape/drive/lto/sg_tape.rs +++ b/src/tape/drive/lto/sg_tape.rs @@ -47,6 +47,7 @@ use crate::{ SenseInfo, ScsiError, InquiryInfo, + MediumType, ModeParameterHeader, ModeBlockDescriptor, alloc_page_aligned_buffer, @@ -209,7 +210,7 @@ impl SgTape { sg_raw.set_timeout(Self::SCSI_TAPE_DEFAULT_TIMEOUT); let mut cmd = Vec::new(); - if head.medium_type >= 0x58 { // FORMAT requires LTO5 or newer) + if MediumType::is_lto5_or_newer(head.medium_type) { // FORMAT requires LTO5 or newer) cmd.extend(&[0x04, 0, 0, 0, 0, 0]); sg_raw.do_command(&cmd)?; if !fast { diff --git a/src/tools/sgutils2.rs b/src/tools/sgutils2.rs index 5096cc65..5273173f 100644 --- a/src/tools/sgutils2.rs +++ b/src/tools/sgutils2.rs @@ -219,6 +219,38 @@ pub struct InquiryInfo { pub revision: String, } +#[repr(u8)] +pub enum MediumType { + /// Unknown (no media loaded) + Unknown = 0x00, + Ultrium1Data = 0x18, + Ultrium2Data = 0x28, + Ultrium3Data = 0x38, + Ultrium3Worm = 0x3C, + Ultrium4Data = 0x48, + Ultrium4Worm = 0x4C, + Ultrium5Data = 0x58, + Ultrium5Worm = 0x5C, + Ultrium6Data = 0x68, + Ultrium6Worm = 0x6C, + Ultrium7Data = 0x78, + Ultrium7Worm = 0x7C, + Ultrium8Data = 0x88, + Ultrium8Worm = 0x8C, +} + +impl MediumType { + + pub fn is_lto5_or_newer(medium_type: u8) -> bool { + medium_type >= Self::Ultrium5Data as u8 + } + + pub fn is_worm(medium_type: u8) -> bool { + (medium_type & 0x0F) == 0x0C + } + +} + #[repr(C, packed)] #[derive(Endian, Debug, Copy, Clone)] pub struct ModeParameterHeader {