From 28ca805905f51dfd38a9c89adde80ab417b2bba6 Mon Sep 17 00:00:00 2001
From: dpgilbert <dpgilbert@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Fri, 23 Mar 2007 03:46:44 +0000
Subject: [PATCH] when reporting output resid and use it to trim output

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@2383 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 sm5/os_linux.cpp | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/sm5/os_linux.cpp b/sm5/os_linux.cpp
index a0ce9c890..d1db635c8 100644
--- a/sm5/os_linux.cpp
+++ b/sm5/os_linux.cpp
@@ -87,9 +87,9 @@ typedef unsigned long long u8;
 
 #define ARGUSED(x) ((void)(x))
 
-static const char *filenameandversion="$Id: os_linux.cpp,v 1.91 2007/03/21 20:33:02 chrfranke Exp $";
+static const char *filenameandversion="$Id: os_linux.cpp,v 1.92 2007/03/23 03:46:44 dpgilbert Exp $";
 
-const char *os_XXXX_c_cvsid="$Id: os_linux.cpp,v 1.91 2007/03/21 20:33:02 chrfranke Exp $" \
+const char *os_XXXX_c_cvsid="$Id: os_linux.cpp,v 1.92 2007/03/23 03:46:44 dpgilbert Exp $" \
 ATACMDS_H_CVSID CONFIG_H_CVSID INT64_H_CVSID OS_LINUX_H_CVSID SCSICMDS_H_CVSID UTILITY_H_CVSID;
 
 // to hold onto exit code for atexit routine
@@ -855,24 +855,29 @@ static int sg_io_cmnd_io(int dev_fd, struct scsi_cmnd_io * iop, int report,
                  strerror(errno));
         return -errno;
     }
+    iop->resid = io_hdr.resid;
+    iop->scsi_status = io_hdr.status;
     if (report > 0) {
         pout("  scsi_status=0x%x, host_status=0x%x, driver_status=0x%x\n"
-             "  info=0x%x  duration=%d milliseconds\n", io_hdr.status,
+             "  info=0x%x  duration=%d milliseconds  resid=%d\n", io_hdr.status,
              io_hdr.host_status, io_hdr.driver_status, io_hdr.info,
-             io_hdr.duration);
+             io_hdr.duration, io_hdr.resid);
         if (report > 1) {
             if (DXFER_FROM_DEVICE == iop->dxfer_dir) {
-                int trunc = (iop->dxfer_len > 256) ? 1 : 0;
-
-                pout("  Incoming data, len=%d%s:\n", (int)iop->dxfer_len,
-                     (trunc ? " [only first 256 bytes shown]" : ""));
-                dStrHex((const char*)iop->dxferp,
-                        (trunc ? 256 : iop->dxfer_len) , 1);
+                int trunc, len;
+
+		len = iop->dxfer_len - iop->resid;
+		trunc = (len > 256) ? 1 : 0;
+                if (len > 0) {
+                    pout("  Incoming data, len=%d%s:\n", len,
+                         (trunc ? " [only first 256 bytes shown]" : ""));
+                    dStrHex((const char*)iop->dxferp, (trunc ? 256 : len),
+                            1);
+                } else
+                    pout("  Incoming data trimmed to nothing by resid\n");
             }
         }
     }
-    iop->resid = io_hdr.resid;
-    iop->scsi_status = io_hdr.status;
 
     if (io_hdr.info | SG_INFO_CHECK) { /* error or warning */
         int masked_driver_status = (LSCSI_DRIVER_MASK & io_hdr.driver_status);
-- 
GitLab