From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup] tools/sgutils2: add size workaround for mode_sense
Date: Tue, 27 Apr 2021 10:17:01 +0200 [thread overview]
Message-ID: <20210427081701.9583-1-d.csapak@proxmox.com> (raw)
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>
---
src/tools/sgutils2.rs | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/tools/sgutils2.rs b/src/tools/sgutils2.rs
index 96625301..6ee19ff2 100644
--- a/src/tools/sgutils2.rs
+++ b/src/tools/sgutils2.rs
@@ -757,10 +757,14 @@ pub fn scsi_mode_sense<F: AsRawFd, P: Endian>(
let mut reader = &data[..];
let head: ModeParameterHeader = unsafe { reader.read_be_value()? };
-
- 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);
+ let expected_len = head.mode_data_len as usize + 2;
+
+ if data.len() < expected_len {
+ bail!("wrong mode_data_len: got {}, expected {}", data.len(), expected_len);
+ } else if data.len() > expected_len {
+ // Note: Quantum hh7 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 {
--
2.20.1
reply other threads:[~2021-04-27 8:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210427081701.9583-1-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox