Commit a485b234 authored by Fam Zheng's avatar Fam Zheng Committed by Paolo Bonzini

scsi: Introduce scsi_sense_buf_to_errno

This recognizes the "fixed" and "descriptor" format sense data, extracts
the sense key/asc/ascq fields then converts them to an errno.
Signed-off-by: 's avatarFam Zheng <famz@redhat.com>
Message-Id: <20170821141008.19383-4-famz@redhat.com>
Signed-off-by: 's avatarPaolo Bonzini <pbonzini@redhat.com>
parent 5efa3c04
......@@ -15,5 +15,6 @@
#define QEMU_SCSI_H
int scsi_sense_to_errno(int key, int asc, int ascq);
int scsi_sense_buf_to_errno(const uint8_t *sense, size_t sense_size);
#endif
......@@ -58,3 +58,33 @@ int scsi_sense_to_errno(int key, int asc, int ascq)
return EIO;
}
}
int scsi_sense_buf_to_errno(const uint8_t *sense, size_t sense_size)
{
int key, asc, ascq;
if (sense_size < 1) {
return EIO;
}
switch (sense[0]) {
case 0x70: /* Fixed format sense data. */
if (sense_size < 14) {
return EIO;
}
key = sense[2] & 0xF;
asc = sense[12];
ascq = sense[13];
break;
case 0x72: /* Descriptor format sense data. */
if (sense_size < 4) {
return EIO;
}
key = sense[1] & 0xF;
asc = sense[2];
ascq = sense[3];
break;
default:
return EIO;
break;
}
return scsi_sense_to_errno(key, asc, ascq);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment