[pbs-devel] [PATCH proxmox-backup v2] tools/sgutils2: improve error messages

Dominik Csapak d.csapak at proxmox.com
Mon Apr 26 15:20:25 CEST 2021


include the expected and unexpected sizes in the error message,
so that it's easier to debug in case of an error

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
change from v1:
* use local variable to prevent UB warning (borrow of packed fields)
 src/tools/sgutils2.rs | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/tools/sgutils2.rs b/src/tools/sgutils2.rs
index 5273173f..96625301 100644
--- a/src/tools/sgutils2.rs
+++ b/src/tools/sgutils2.rs
@@ -759,18 +759,21 @@ pub fn scsi_mode_sense<F: AsRawFd, P: Endian>(
         let head: ModeParameterHeader = unsafe { reader.read_be_value()? };
 
         if (head.mode_data_len as usize + 2) != data.len() {
-            bail!("wrong mode_data_len");
+            let len = head.mode_data_len;
+            bail!("wrong mode_data_len: {}, expected {}", len, data.len() - 2);
         }
 
         if disable_block_descriptor && head.block_descriptior_len != 0 {
-            bail!("wrong block_descriptior_len");
+            let len = head.block_descriptior_len;
+            bail!("wrong block_descriptior_len: {}, expected 0", len);
         }
 
         let mut block_descriptor: Option<ModeBlockDescriptor> = None;
 
         if !disable_block_descriptor {
             if head.block_descriptior_len != 8 {
-                bail!("wrong block_descriptior_len");
+                let len = head.block_descriptior_len;
+                bail!("wrong block_descriptior_len: {}, expected 8", len);
             }
 
             block_descriptor = Some(unsafe { reader.read_be_value()? });
-- 
2.20.1






More information about the pbs-devel mailing list