SG_IO residual count
The SG_IO residual count is a signed byte count reporting the difference between the requested data-transfer length and the length actually transferred through the Linux SCSI generic v3 interface.
The ABI defines resid as dxfer_len minus actual transferred bytes. It is not a command status or the length of sense data; sb_len_wr reports the latter. [1]
Linux v6.12's block-device SG_IO completion copies SCSI and host status into separate fields. Its system-call result can remain successful while those fields report a problem. Inspect the complete response before interpreting transferred data. [2]
A positive residual need not mean failure when the command permits a shorter response. Conversely, the historical SG HOWTO warns that unsupported or inaccurate reporting can yield misleading values, including zero. That warning is not a measurement of current adapters: validate the reporting path and the command's expected length. [3]
Relations
- related
- SCSI, SCSI CHECK CONDITION, SCSI deferred error
Citations
- Linux v6.12: sg_io_hdr fields and SG_INFO status mask
- Linux v6.12: scsi_complete_sghdr_rq and sg_io in scsi_ioctl.c
- Douglas Gilbert, Linux SCSI Generic HOWTO, section 6.20: resid (historical driver caveat)
Further reading
Sources & caveats
- Source review of Linux v6.12 and the historical SG HOWTO. No commands sent to hardware, no driver-validation experiment and no measured failure rate.