tools/sgutils2: add size workaround for mode_sense

Some drives will always return the number of bytes given in the
allocation_length field, but correctly report the data len in the mode
sense header. Simply ignore the excess data.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2021-04-27 10:17:01 +02:00 committed by Dietmar Maurer
parent 12509a6d9e
commit 8fd1e10830

View File

@ -728,10 +728,15 @@ pub fn scsi_mode_sense<F: AsRawFd, P: Endian>(
let mut reader = &data[..];
let head: ModeParameterHeader = unsafe { reader.read_be_value()? };
let expected_len = head.mode_data_len as usize + 2;
if (head.mode_data_len as usize + 2) != data.len() {
let len = head.mode_data_len;
bail!("wrong mode_data_len: {}, expected {}", len, data.len() - 2);
if data.len() < expected_len {
bail!("wrong mode_data_len: got {}, expected {}", data.len(), expected_len);
} else if data.len() > expected_len {
// Note: Some hh7 drives returns the allocation_length
// instead of real data_len
let header_size = std::mem::size_of::<ModeParameterHeader>();
reader = &data[header_size..expected_len];
}
if disable_block_descriptor && head.block_descriptior_len != 0 {