diff --git a/src/bin/pmt.rs b/src/bin/pmt.rs index 7183dfe58..15fa591df 100644 --- a/src/bin/pmt.rs +++ b/src/bin/pmt.rs @@ -577,8 +577,7 @@ fn lock(param: Value) -> Result<(), Error> { let mut handle = get_tape_handle(¶m)?; - unimplemented!(); - // fixme: handle.mtop(MTCmd::MTLOCK, 1, "lock tape drive door")?; + handle.lock()?; Ok(()) } @@ -715,8 +714,7 @@ fn unlock(param: Value) -> Result<(), Error> { let mut handle = get_tape_handle(¶m)?; - unimplemented!(); - //handle.mtop(MTCmd::MTUNLOCK, 1, "unlock tape drive door")?; + handle.unlock()?; Ok(()) } diff --git a/src/tape/drive/lto/mod.rs b/src/tape/drive/lto/mod.rs index f33049abb..de997cde1 100644 --- a/src/tape/drive/lto/mod.rs +++ b/src/tape/drive/lto/mod.rs @@ -220,6 +220,18 @@ impl LtoTapeHandle { pub fn volume_statistics(&mut self) -> Result { self.sg_tape.volume_statistics() } + + /// Lock the drive door + pub fn lock(&mut self) -> Result<(), Error> { + self.sg_tape.set_medium_removal(false) + .map_err(|err| format_err!("lock door failed - {}", err)) + } + + /// Unlock the drive door + pub fn unlock(&mut self) -> Result<(), Error> { + self.sg_tape.set_medium_removal(true) + .map_err(|err| format_err!("unlock door failed - {}", err)) + } } diff --git a/src/tape/drive/lto/sg_tape.rs b/src/tape/drive/lto/sg_tape.rs index 681263ea7..19c6aabf3 100644 --- a/src/tape/drive/lto/sg_tape.rs +++ b/src/tape/drive/lto/sg_tape.rs @@ -189,6 +189,25 @@ impl SgTape { Ok(()) } + /// Lock/Unlock drive door + pub fn set_medium_removal(&mut self, allow: bool) -> Result<(), ScsiError> { + + let mut sg_raw = SgRaw::new(&mut self.file, 16)?; + sg_raw.set_timeout(Self::SCSI_TAPE_DEFAULT_TIMEOUT); + let mut cmd = Vec::new(); + cmd.extend(&[0x1E, 0, 0, 0]); + if allow { + cmd.push(0); + } else { + cmd.push(1); + } + cmd.push(0); // control + + sg_raw.do_command(&cmd)?; + + Ok(()) + } + pub fn rewind(&mut self) -> Result<(), Error> { let mut sg_raw = SgRaw::new(&mut self.file, 16)?;