tape: implement rewind

This commit is contained in:
Dietmar Maurer 2020-12-09 17:43:38 +01:00
parent 583a68a446
commit 5fb694e8c0
2 changed files with 60 additions and 0 deletions

View File

@ -141,7 +141,33 @@ pub fn erase_media(drive: String, fast: Option<bool>) -> Result<(), Error> {
Ok(())
}
#[api(
input: {
properties: {
drive: {
schema: DRIVE_ID_SCHEMA,
},
},
},
)]
/// Rewind tape
pub fn rewind(drive: String) -> Result<(), Error> {
let (config, _digest) = config::drive::config()?;
let mut drive = open_drive(&config, &drive)?;
drive.rewind()?;
Ok(())
}
pub const SUBDIRS: SubdirMap = &[
(
"rewind",
&Router::new()
.put(&API_METHOD_REWIND)
),
(
"erase-media",
&Router::new()

View File

@ -93,9 +93,43 @@ fn erase_media(
Ok(())
}
#[api(
input: {
properties: {
drive: {
schema: DRIVE_ID_SCHEMA,
optional: true,
},
},
},
)]
/// Rewind tape
fn rewind(
mut param: Value,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<(), Error> {
let (config, _digest) = config::drive::config()?;
param["drive"] = lookup_drive_name(&param, &config)?.into();
let info = &api2::tape::drive::API_METHOD_REWIND;
match info.handler {
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
_ => unreachable!(),
};
Ok(())
}
fn main() {
let cmd_def = CliCommandMap::new()
.insert(
"rewind",
CliCommand::new(&API_METHOD_REWIND)
.completion_cb("drive", complete_drive_name)
)
.insert(
"erase",
CliCommand::new(&API_METHOD_ERASE_MEDIA)