tape: pmt - implement options command

This commit is contained in:
Dietmar Maurer 2021-04-07 16:52:11 +02:00
parent 5d6379f8db
commit 80ea23e1b9
2 changed files with 67 additions and 1 deletions

View File

@ -800,6 +800,61 @@ fn weof(count: Option<usize>, 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<bool>,
blocksize: Option<u32>,
buffer_mode: Option<bool>,
defaults: Option<bool>,
param: Value,
) -> Result<(), Error> {
let mut handle = get_tape_handle(&param)?;
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))

View File

@ -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<bool>,
block_length: Option<u32>,
buffer_mode: Option<bool>,
) -> 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)