diff --git a/src/bin/pmt.rs b/src/bin/pmt.rs index 8b4b8a1c..38a52167 100644 --- a/src/bin/pmt.rs +++ b/src/bin/pmt.rs @@ -96,6 +96,37 @@ fn get_tape_handle(param: &Value) -> Result { bail!("no drive/device specified"); } +#[api( + input: { + properties: { + drive: { + schema: DRIVE_NAME_SCHEMA, + optional: true, + }, + device: { + schema: LINUX_DRIVE_PATH_SCHEMA, + optional: true, + }, + count: { + description: "File mark count.", + type: i32, + minimum: 1 + }, + }, + }, +)] +/// Backward space count files (position before file mark). +/// +/// The tape is positioned on the last block of the previous file. +fn bsf(count: i32, param: Value) -> Result<(), Error> { + + let mut handle = get_tape_handle(¶m)?; + + handle.backward_space_count_files(count)?; + + Ok(()) +} + #[api( input: { properties: { @@ -456,6 +487,7 @@ fn main() -> Result<(), Error> { }; let cmd_def = CliCommandMap::new() + .insert("bsf", std_cmd(&API_METHOD_BSF)) .insert("cartridge-memory", std_cmd(&API_METHOD_CARTRIDGE_MEMORY)) .insert("eject", std_cmd(&API_METHOD_EJECT)) .insert("eod", std_cmd(&API_METHOD_EOD)) diff --git a/src/tape/drive/linux_tape.rs b/src/tape/drive/linux_tape.rs index 9f829fe1..4ecac13f 100644 --- a/src/tape/drive/linux_tape.rs +++ b/src/tape/drive/linux_tape.rs @@ -217,6 +217,19 @@ impl LinuxTapeHandle { Ok(()) } + pub fn backward_space_count_files(&mut self, count: i32) -> Result<(), Error> { + + let cmd = mtop { mt_op: MTCmd::MTBSF, mt_count: count, }; + + unsafe { + mtioctop(self.file.as_raw_fd(), &cmd) + }.map_err(|err| { + format_err!("backward space {} files failed - {}", count, err) + })?; + + Ok(()) + } + /// Set tape compression feature pub fn set_compression(&self, on: bool) -> Result<(), Error> {