tape: fix scsi volume_statistics and cartridge_memory for quantum drives
This commit is contained in:
parent
70d00e0149
commit
5ef4c7bcd3
|
@ -115,7 +115,7 @@ fn read_tape_mam<F: AsRawFd>(file: &mut F) -> Result<Vec<u8>, Error> {
|
||||||
.map(|v| v.to_vec())
|
.map(|v| v.to_vec())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read Medium auxiliary memory attributes (cartridge memory) using raw SCSI command.
|
/// Read Medium auxiliary memory attributes (cartridge memory) using raw SCSI command.
|
||||||
pub fn read_mam_attributes<F: AsRawFd>(file: &mut F) -> Result<Vec<MamAttribute>, Error> {
|
pub fn read_mam_attributes<F: AsRawFd>(file: &mut F) -> Result<Vec<MamAttribute>, Error> {
|
||||||
|
|
||||||
let data = read_tape_mam(file)?;
|
let data = read_tape_mam(file)?;
|
||||||
|
@ -131,8 +131,12 @@ fn decode_mam_attributes(data: &[u8]) -> Result<Vec<MamAttribute>, Error> {
|
||||||
|
|
||||||
let expected_len = data_len as usize;
|
let expected_len = data_len as usize;
|
||||||
|
|
||||||
if reader.len() != expected_len {
|
|
||||||
|
if reader.len() < expected_len {
|
||||||
bail!("read_mam_attributes: got unexpected data len ({} != {})", reader.len(), expected_len);
|
bail!("read_mam_attributes: got unexpected data len ({} != {})", reader.len(), expected_len);
|
||||||
|
} else if reader.len() > expected_len {
|
||||||
|
// Note: Quantum hh7 returns the allocation_length instead of real data_len
|
||||||
|
reader = &data[4..expected_len+4];
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut list = Vec::new();
|
let mut list = Vec::new();
|
||||||
|
|
|
@ -27,8 +27,8 @@ pub fn read_volume_statistics<F: AsRawFd>(file: &mut F) -> Result<Lp17VolumeSta
|
||||||
|
|
||||||
fn sg_read_volume_statistics<F: AsRawFd>(file: &mut F) -> Result<Vec<u8>, Error> {
|
fn sg_read_volume_statistics<F: AsRawFd>(file: &mut F) -> Result<Vec<u8>, Error> {
|
||||||
|
|
||||||
let buffer_size = 8192;
|
let alloc_len: u16 = 8192;
|
||||||
let mut sg_raw = SgRaw::new(file, buffer_size)?;
|
let mut sg_raw = SgRaw::new(file, alloc_len as usize)?;
|
||||||
|
|
||||||
let mut cmd = Vec::new();
|
let mut cmd = Vec::new();
|
||||||
cmd.push(0x4D); // LOG SENSE
|
cmd.push(0x4D); // LOG SENSE
|
||||||
|
@ -38,7 +38,7 @@ fn sg_read_volume_statistics<F: AsRawFd>(file: &mut F) -> Result<Vec<u8>, Error>
|
||||||
cmd.push(0);
|
cmd.push(0);
|
||||||
cmd.push(0);
|
cmd.push(0);
|
||||||
cmd.push(0);
|
cmd.push(0);
|
||||||
cmd.push((buffer_size >> 8) as u8); cmd.push(0); // alloc len
|
cmd.extend(&alloc_len.to_be_bytes()); // alloc len
|
||||||
cmd.push(0u8); // control byte
|
cmd.push(0u8); // control byte
|
||||||
|
|
||||||
sg_raw.do_command(&cmd)
|
sg_raw.do_command(&cmd)
|
||||||
|
@ -142,8 +142,13 @@ fn decode_volume_statistics(data: &[u8]) -> Result<Lp17VolumeStatistics, Error>
|
||||||
|
|
||||||
let page_len: u16 = unsafe { reader.read_be_value()? };
|
let page_len: u16 = unsafe { reader.read_be_value()? };
|
||||||
|
|
||||||
if (page_len as usize + 4) != data.len() {
|
let page_len = page_len as usize;
|
||||||
|
|
||||||
|
if (page_len + 4) > data.len() {
|
||||||
bail!("invalid page length");
|
bail!("invalid page length");
|
||||||
|
} else {
|
||||||
|
// Note: Quantum hh7 returns the allocation_length instead of real data_len
|
||||||
|
reader = &data[4..page_len+4];
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut stat = Lp17VolumeStatistics::default();
|
let mut stat = Lp17VolumeStatistics::default();
|
||||||
|
|
Loading…
Reference in New Issue