tape: remove MediumType struct, which is only valid on IBM drives

HP drives do not return this information.

Note: This breaks format on WORM media, because we have not way
to detect WOREM media (how?).
This commit is contained in:
Dietmar Maurer 2021-04-27 09:32:07 +02:00
parent 4a0132382a
commit 73cef112eb
2 changed files with 24 additions and 56 deletions

View File

@ -47,7 +47,6 @@ use crate::{
SenseInfo, SenseInfo,
ScsiError, ScsiError,
InquiryInfo, InquiryInfo,
MediumType,
ModeParameterHeader, ModeParameterHeader,
ModeBlockDescriptor, ModeBlockDescriptor,
alloc_page_aligned_buffer, alloc_page_aligned_buffer,
@ -201,9 +200,10 @@ impl SgTape {
pub fn format_media(&mut self, fast: bool) -> Result<(), Error> { pub fn format_media(&mut self, fast: bool) -> Result<(), Error> {
// get info about loaded media first // 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. // We cannot FORMAT WORM media! Instead we check if its empty.
self.move_to_eom(false)?; self.move_to_eom(false)?;
@ -212,8 +212,9 @@ impl SgTape {
bail!("format failed - detected WORM media with data."); bail!("format failed - detected WORM media with data.");
} }
Ok(()) return Ok(());
} else { }
*/
self.rewind()?; self.rewind()?;
@ -221,8 +222,8 @@ impl SgTape {
sg_raw.set_timeout(Self::SCSI_TAPE_DEFAULT_TIMEOUT); sg_raw.set_timeout(Self::SCSI_TAPE_DEFAULT_TIMEOUT);
let mut cmd = Vec::new(); let mut cmd = Vec::new();
if MediumType::is_lto5_or_newer(head.medium_type) { // FORMAT requires LTO5 or newer) if block_descriptor.density_code >= 0x58 { // FORMAT requires LTO5 or newer
cmd.extend(&[0x04, 0, 0, 0, 0, 0]); cmd.extend(&[0x04, 0, 0, 0, 0, 0]); // FORMAT
sg_raw.do_command(&cmd)?; sg_raw.do_command(&cmd)?;
if !fast { if !fast {
self.erase_media(false)?; // overwrite everything self.erase_media(false)?; // overwrite everything
@ -234,7 +235,6 @@ impl SgTape {
Ok(()) Ok(())
} }
}
/// Lock/Unlock drive door /// Lock/Unlock drive door
pub fn set_medium_removal(&mut self, allow: bool) -> Result<(), ScsiError> { pub fn set_medium_removal(&mut self, allow: bool) -> Result<(), ScsiError> {

View File

@ -219,38 +219,6 @@ pub struct InquiryInfo {
pub revision: String, 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)] #[repr(C, packed)]
#[derive(Endian, Debug, Copy, Clone)] #[derive(Endian, Debug, Copy, Clone)]
pub struct ModeParameterHeader { pub struct ModeParameterHeader {