thape: add read_tapedev_options, display driver options with status command
This commit is contained in:
parent
f9fcac51a5
commit
d0f11b66f7
@ -178,6 +178,8 @@ pub struct LinuxDriveAndMediaStatus {
|
||||
pub density: Option<TapeDensity>,
|
||||
/// Status flags
|
||||
pub status: String,
|
||||
/// Linux Driver Options
|
||||
pub options: String,
|
||||
/// Tape Alert Flags
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub alert_flags: Option<String>,
|
||||
|
@ -707,6 +707,7 @@ async fn status(param: Value) -> Result<(), Error> {
|
||||
.column(ColumnConfig::new("blocksize"))
|
||||
.column(ColumnConfig::new("density"))
|
||||
.column(ColumnConfig::new("status"))
|
||||
.column(ColumnConfig::new("options"))
|
||||
.column(ColumnConfig::new("alert-flags"))
|
||||
.column(ColumnConfig::new("file-number"))
|
||||
.column(ColumnConfig::new("block-number"))
|
||||
|
@ -282,6 +282,8 @@ impl LinuxTapeHandle {
|
||||
|
||||
let drive_status = self.get_drive_status()?;
|
||||
|
||||
let options = read_tapedev_options(&self.file)?;
|
||||
|
||||
let alert_flags = self.tape_alert_flags()
|
||||
.map(|flags| format!("{:?}", flags))
|
||||
.ok();
|
||||
@ -290,6 +292,7 @@ impl LinuxTapeHandle {
|
||||
blocksize: drive_status.blocksize,
|
||||
density: drive_status.density,
|
||||
status: format!("{:?}", drive_status.status),
|
||||
options: format!("{:?}", options),
|
||||
alert_flags,
|
||||
file_number: drive_status.file_number,
|
||||
block_number: drive_status.block_number,
|
||||
@ -685,6 +688,33 @@ pub fn open_linux_tape_device(
|
||||
Ok(file)
|
||||
}
|
||||
|
||||
/// Read Linux tape device options from /sys
|
||||
pub fn read_tapedev_options(file: &File) -> Result<SetDrvBufferOptions, Error> {
|
||||
|
||||
let stat = nix::sys::stat::fstat(file.as_raw_fd())?;
|
||||
|
||||
let devnum = stat.st_rdev;
|
||||
|
||||
let major = unsafe { libc::major(devnum) };
|
||||
let minor = unsafe { libc::minor(devnum) };
|
||||
|
||||
let path = format!("/sys/dev/char/{}:{}/options", major, minor);
|
||||
|
||||
let options = proxmox::tools::fs::file_read_firstline(&path)?;
|
||||
|
||||
let options = options.trim();
|
||||
|
||||
let options = match options.strip_prefix("0x") {
|
||||
Some(rest) => rest,
|
||||
None => bail!("unable to parse '{}'", path),
|
||||
};
|
||||
|
||||
let options = i32::from_str_radix(&options, 16)?;
|
||||
|
||||
Ok(SetDrvBufferOptions::from_bits_truncate(options))
|
||||
}
|
||||
|
||||
|
||||
/// like BlockedWriter, but writes EOF mark on finish
|
||||
pub struct TapeWriterHandle<'a> {
|
||||
writer: BlockedWriter<&'a mut File>,
|
||||
|
Loading…
Reference in New Issue
Block a user