tape: pmt - re-implement lock/unlock command
This commit is contained in:
		| @ -577,8 +577,7 @@ fn lock(param: Value) -> Result<(), Error> { | |||||||
|  |  | ||||||
|     let mut handle = get_tape_handle(¶m)?; |     let mut handle = get_tape_handle(¶m)?; | ||||||
|  |  | ||||||
|     unimplemented!(); |     handle.lock()?; | ||||||
|     // fixme: handle.mtop(MTCmd::MTLOCK, 1, "lock tape drive door")?; |  | ||||||
|  |  | ||||||
|     Ok(()) |     Ok(()) | ||||||
| } | } | ||||||
| @ -715,8 +714,7 @@ fn unlock(param: Value) -> Result<(), Error> { | |||||||
|  |  | ||||||
|     let mut handle = get_tape_handle(¶m)?; |     let mut handle = get_tape_handle(¶m)?; | ||||||
|  |  | ||||||
|     unimplemented!(); |     handle.unlock()?; | ||||||
|     //handle.mtop(MTCmd::MTUNLOCK, 1, "unlock tape drive door")?; |  | ||||||
|  |  | ||||||
|     Ok(()) |     Ok(()) | ||||||
| } | } | ||||||
|  | |||||||
| @ -220,6 +220,18 @@ impl LtoTapeHandle { | |||||||
|     pub fn volume_statistics(&mut self) -> Result<Lp17VolumeStatistics, Error> { |     pub fn volume_statistics(&mut self) -> Result<Lp17VolumeStatistics, Error> { | ||||||
|         self.sg_tape.volume_statistics() |         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)) | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | |||||||
| @ -189,6 +189,25 @@ impl SgTape { | |||||||
|         Ok(()) |         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> { |     pub fn rewind(&mut self) -> Result<(), Error> { | ||||||
|  |  | ||||||
|         let mut sg_raw = SgRaw::new(&mut self.file, 16)?; |         let mut sg_raw = SgRaw::new(&mut self.file, 16)?; | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user