diff --git a/src/tape/drive/lto/sg_tape.rs b/src/tape/drive/lto/sg_tape.rs index 5e0161e5..61ccadf8 100644 --- a/src/tape/drive/lto/sg_tape.rs +++ b/src/tape/drive/lto/sg_tape.rs @@ -47,7 +47,6 @@ use crate::{ SenseInfo, ScsiError, InquiryInfo, - MediumType, ModeParameterHeader, ModeBlockDescriptor, alloc_page_aligned_buffer, @@ -201,9 +200,10 @@ impl SgTape { pub fn format_media(&mut self, fast: bool) -> Result<(), Error> { // get info about loaded media first - let (head, _, _) = self.read_compression_page()?; + let (_head, block_descriptor, _) = self.read_compression_page()?; - if MediumType::is_worm(head.medium_type) { + /* todo: howto detect WORM media? + if MediumType::is_worm(xx) { // We cannot FORMAT WORM media! Instead we check if its empty. self.move_to_eom(false)?; @@ -212,28 +212,28 @@ impl SgTape { bail!("format failed - detected WORM media with data."); } - Ok(()) - } else { - - self.rewind()?; - - let mut sg_raw = SgRaw::new(&mut self.file, 16)?; - sg_raw.set_timeout(Self::SCSI_TAPE_DEFAULT_TIMEOUT); - let mut cmd = Vec::new(); - - 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 { - self.erase_media(false)?; // overwrite everything - } - } else { - // try rewind/erase instead - self.erase_media(fast)? - } - - Ok(()) + return Ok(()); } + */ + + self.rewind()?; + + let mut sg_raw = SgRaw::new(&mut self.file, 16)?; + sg_raw.set_timeout(Self::SCSI_TAPE_DEFAULT_TIMEOUT); + let mut cmd = Vec::new(); + + if block_descriptor.density_code >= 0x58 { // FORMAT requires LTO5 or newer + cmd.extend(&[0x04, 0, 0, 0, 0, 0]); // FORMAT + sg_raw.do_command(&cmd)?; + if !fast { + self.erase_media(false)?; // overwrite everything + } + } else { + // try rewind/erase instead + self.erase_media(fast)? + } + + Ok(()) } /// Lock/Unlock drive door diff --git a/src/tools/sgutils2.rs b/src/tools/sgutils2.rs index 96625301..a5393655 100644 --- a/src/tools/sgutils2.rs +++ b/src/tools/sgutils2.rs @@ -219,38 +219,6 @@ 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 {