diff --git a/src/api2/types/tape/drive.rs b/src/api2/types/tape/drive.rs index 19eb57fb..067fdeba 100644 --- a/src/api2/types/tape/drive.rs +++ b/src/api2/types/tape/drive.rs @@ -178,6 +178,8 @@ pub struct LinuxDriveAndMediaStatus { pub density: Option, /// 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, diff --git a/src/bin/proxmox-tape.rs b/src/bin/proxmox-tape.rs index 76c58108..8d0157fa 100644 --- a/src/bin/proxmox-tape.rs +++ b/src/bin/proxmox-tape.rs @@ -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")) diff --git a/src/tape/drive/linux_tape.rs b/src/tape/drive/linux_tape.rs index 01497f3f..2e499531 100644 --- a/src/tape/drive/linux_tape.rs +++ b/src/tape/drive/linux_tape.rs @@ -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 { + + 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>,