The functions open, ioctl, write and read
can report errors. In this case their return value is -1 and the
global variable errno is set to the error number.
The errno values are defined in /usr/include/errno.h.
Possible values are:

Note that these symbol values have been shifted right once.
When the status is CHECK_CONDITION, the sense data in the sense
buffer is valid (check especially the additional sense code
and additional sense code qualifier).

The midlevel driver categorizes the returned status from the lowlevel
driver based on the sense key from the device. It suggests some actions
to be taken such as retry, abort or remap. The routine scsi_done from
scsi.c does a very differentiated handling based on host_byte(),
status_byte(), msg_byte() and the suggestion. It then sets the driver
byte to show what it has done. The driver byte is composed out of two
nibbles: the driver status and the suggestion. Each half is composed
from the below values being 'or'ed together (found in scsi.h).