Date: Sun, 29 Jan 2017 14:28:29 +0000 (UTC) From: Alexander Motin <mav@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r312950 - stable/11/sbin/camcontrol Message-ID: <201701291428.v0TESTCi011124@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mav Date: Sun Jan 29 14:28:29 2017 New Revision: 312950 URL: https://svnweb.freebsd.org/changeset/base/312950 Log: MFC r312228: Make `camcontrol cmd ... -i ...` return only valid bytes. Previously code ignored resid field and returned extra zeroes in case of data underflow. Now it returns only real bytes received from target. Modified: stable/11/sbin/camcontrol/camcontrol.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sbin/camcontrol/camcontrol.c ============================================================================== --- stable/11/sbin/camcontrol/camcontrol.c Sun Jan 29 13:31:56 2017 (r312949) +++ stable/11/sbin/camcontrol/camcontrol.c Sun Jan 29 14:28:29 2017 (r312950) @@ -4150,7 +4150,7 @@ scsicmd(struct cam_device *device, int a u_int8_t cdb[20]; u_int8_t atacmd[12]; struct get_hook hook; - int c, data_bytes = 0; + int c, data_bytes = 0, valid_bytes; int cdb_len = 0; int atacmd_len = 0; int dmacmd = 0; @@ -4454,16 +4454,20 @@ scsicmd(struct cam_device *device, int a } } + if (cdb_len) + valid_bytes = ccb->csio.dxfer_len - ccb->csio.resid; + else + valid_bytes = ccb->ataio.dxfer_len - ccb->ataio.resid; if (((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) && (arglist & CAM_ARG_CMD_IN) - && (data_bytes > 0)) { + && (valid_bytes > 0)) { if (fd_data == 0) { - buff_decode_visit(data_ptr, data_bytes, datastr, + buff_decode_visit(data_ptr, valid_bytes, datastr, arg_put, NULL); fprintf(stdout, "\n"); } else { ssize_t amt_written; - int amt_to_write = data_bytes; + int amt_to_write = valid_bytes; u_int8_t *buf_ptr = data_ptr; for (amt_written = 0; (amt_to_write > 0) && @@ -4478,7 +4482,7 @@ scsicmd(struct cam_device *device, int a } else if ((amt_written == 0) && (amt_to_write > 0)) { warnx("only wrote %u bytes out of %u", - data_bytes - amt_to_write, data_bytes); + valid_bytes - amt_to_write, valid_bytes); } } }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201701291428.v0TESTCi011124>