tape: minor cleanups
This commit is contained in:
parent
c9d13b0fc4
commit
8ae9f4efc2
|
@ -53,12 +53,17 @@ impl LinuxDriveStatus {
|
||||||
|
|
||||||
impl LinuxTapeDrive {
|
impl LinuxTapeDrive {
|
||||||
|
|
||||||
/// This needs to lock the drive
|
/// Open a tape device
|
||||||
|
///
|
||||||
|
/// This does additional checks:
|
||||||
|
///
|
||||||
|
/// - check if drive is ready (tape loaded)
|
||||||
|
/// - check block size
|
||||||
pub fn open(&self) -> Result<LinuxTapeHandle, Error> {
|
pub fn open(&self) -> Result<LinuxTapeHandle, Error> {
|
||||||
|
|
||||||
let file = open_linux_tape_device(&self.path)?;
|
let file = open_linux_tape_device(&self.path)?;
|
||||||
|
|
||||||
let handle = LinuxTapeHandle { drive_name: self.name.clone(), file };
|
let handle = LinuxTapeHandle::new(file);
|
||||||
|
|
||||||
let drive_status = handle.get_drive_status()?;
|
let drive_status = handle.get_drive_status()?;
|
||||||
println!("drive status: {:?}", drive_status);
|
println!("drive status: {:?}", drive_status);
|
||||||
|
@ -88,17 +93,17 @@ impl LinuxTapeDrive {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Linux Tape device handle
|
||||||
pub struct LinuxTapeHandle {
|
pub struct LinuxTapeHandle {
|
||||||
drive_name: String,
|
|
||||||
file: File,
|
file: File,
|
||||||
//_lock: File,
|
//_lock: File,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LinuxTapeHandle {
|
impl LinuxTapeHandle {
|
||||||
|
|
||||||
/// Return the drive name (useful for log and debug)
|
/// Creates a new instance
|
||||||
pub fn dive_name(&self) -> &str {
|
pub fn new(file: File) -> Self {
|
||||||
&self.drive_name
|
Self { file }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set all options we need/want
|
/// Set all options we need/want
|
||||||
|
@ -372,6 +377,7 @@ fn tape_write_eof_mark(file: &File) -> Result<(), std::io::Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check for correct Major/Minor numbers
|
||||||
pub fn check_tape_is_linux_tape_device(file: &File) -> Result<(), Error> {
|
pub fn check_tape_is_linux_tape_device(file: &File) -> Result<(), Error> {
|
||||||
|
|
||||||
let stat = nix::sys::stat::fstat(file.as_raw_fd())?;
|
let stat = nix::sys::stat::fstat(file.as_raw_fd())?;
|
||||||
|
|
Loading…
Reference in New Issue