From 80ea23e1b9f5167a1e52d50f8f261b982febb487 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 7 Apr 2021 16:52:11 +0200 Subject: [PATCH] tape: pmt - implement options command --- src/bin/pmt.rs | 56 +++++++++++++++++++++++++++++++++++++++ src/tape/drive/lto/mod.rs | 12 ++++++++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/bin/pmt.rs b/src/bin/pmt.rs index a1a6a612..fe0b4c34 100644 --- a/src/bin/pmt.rs +++ b/src/bin/pmt.rs @@ -800,6 +800,61 @@ fn weof(count: Option, param: Value) -> Result<(), Error> { Ok(()) } +#[api( + input: { + properties: { + drive: { + schema: DRIVE_NAME_SCHEMA, + optional: true, + }, + device: { + schema: LTO_DRIVE_PATH_SCHEMA, + optional: true, + }, + compression: { + description: "Enable/disable compression.", + type: bool, + optional: true, + }, + blocksize: { + description: "Set tape drive block_length (0 is variable length).", + type: u32, + minimum: 0, + maximum: 0x80_00_00, + optional: true, + }, + buffer_mode: { + description: "Use drive buffer.", + type: bool, + optional: true, + }, + defaults: { + description: "Set default options", + type: bool, + optional: true, + }, + }, + }, +)] +/// Set varios drive options +fn options( + compression: Option, + blocksize: Option, + buffer_mode: Option, + defaults: Option, + param: Value, +) -> Result<(), Error> { + + let mut handle = get_tape_handle(¶m)?; + + if let Some(true) = defaults { + handle.set_default_options()?; + } + + handle.set_drive_options(compression, blocksize, buffer_mode)?; + + Ok(()) +} fn main() -> Result<(), Error> { @@ -832,6 +887,7 @@ fn main() -> Result<(), Error> { .insert("fsr", std_cmd(&API_METHOD_FSR).arg_param(&["count"])) .insert("load", std_cmd(&API_METHOD_LOAD)) .insert("lock", std_cmd(&API_METHOD_LOCK)) + .insert("options", std_cmd(&API_METHOD_OPTIONS)) .insert("rewind", std_cmd(&API_METHOD_REWIND)) .insert("scan", CliCommand::new(&API_METHOD_SCAN)) .insert("status", std_cmd(&API_METHOD_STATUS)) diff --git a/src/tape/drive/lto/mod.rs b/src/tape/drive/lto/mod.rs index ef5d8865..c7ea0b27 100644 --- a/src/tape/drive/lto/mod.rs +++ b/src/tape/drive/lto/mod.rs @@ -109,11 +109,21 @@ impl LtoTapeHandle { let block_length = Some(0); // variable length mode let buffer_mode = Some(true); // Always use drive buffer - self.sg_tape.set_drive_options(compression, block_length, buffer_mode)?; + self.set_drive_options(compression, block_length, buffer_mode)?; Ok(()) } + /// Set driver options + pub fn set_drive_options( + &mut self, + compression: Option, + block_length: Option, + buffer_mode: Option, + ) -> Result<(), Error> { + self.sg_tape.set_drive_options(compression, block_length, buffer_mode) + } + /// Write a single EOF mark without flushing buffers pub fn write_filemarks(&mut self, count: usize) -> Result<(), std::io::Error> { self.sg_tape.write_filemarks(count, false)