diff --git a/src/tape/drive/linux_tape.rs b/src/tape/drive/linux_tape.rs index 0fb7e67a..cef914bb 100644 --- a/src/tape/drive/linux_tape.rs +++ b/src/tape/drive/linux_tape.rs @@ -67,13 +67,22 @@ impl LinuxTapeDrive { /// - check if it is a non-rewinding tape device /// - check if drive is ready (tape loaded) /// - check block size + /// - for autoloader only, try to reload ejected tapes pub fn open(&self) -> Result { let file = open_linux_tape_device(&self.path)?; let mut handle = LinuxTapeHandle::new(file); - let drive_status = handle.get_drive_status()?; + let mut drive_status = handle.get_drive_status()?; + + if !drive_status.tape_is_ready() { + // for autoloader only, try to reload ejected tapes + if self.changer.is_some() { + let _ = handle.mtload(); // just try, ignore error + drive_status = handle.get_drive_status()?; + } + } if !drive_status.tape_is_ready() { bail!("tape not ready (no tape loaded)"); @@ -158,6 +167,17 @@ impl LinuxTapeHandle { Ok(()) } + fn mtload(&mut self) -> Result<(), Error> { + + let cmd = mtop { mt_op: MTCmd::MTLOAD, mt_count: 1, }; + + unsafe { + mtioctop(self.file.as_raw_fd(), &cmd) + }.map_err(|err| format_err!("MTLOAD failed - {}", err))?; + + Ok(()) + } + fn forward_space_count_files(&mut self, count: i32) -> Result<(), Error> { let cmd = mtop { mt_op: MTCmd::MTFSF, mt_count: count, };