scsi: introduce scsi_cdb_length and scsi_data_cdb_length

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2012-09-05 17:57:19 +02:00
parent 12ca76fc48
commit bb729f7581
2 changed files with 20 additions and 5 deletions

View File

@ -801,26 +801,39 @@ static int ata_passthrough_16_xfer_size(SCSIDevice *dev, uint8_t *buf)
return xfer * unit; return xfer * unit;
} }
static int scsi_req_length(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf) uint32_t scsi_data_cdb_length(uint8_t *buf)
{
if ((buf[0] >> 5) == 0 && buf[4] == 0) {
return 256;
} else {
return scsi_cdb_length(buf);
}
}
uint32_t scsi_cdb_length(uint8_t *buf)
{ {
switch (buf[0] >> 5) { switch (buf[0] >> 5) {
case 0: case 0:
cmd->xfer = buf[4]; return buf[4];
break; break;
case 1: case 1:
case 2: case 2:
cmd->xfer = lduw_be_p(&buf[7]); return lduw_be_p(&buf[7]);
break; break;
case 4: case 4:
cmd->xfer = ldl_be_p(&buf[10]) & 0xffffffffULL; return ldl_be_p(&buf[10]) & 0xffffffffULL;
break; break;
case 5: case 5:
cmd->xfer = ldl_be_p(&buf[6]) & 0xffffffffULL; return ldl_be_p(&buf[6]) & 0xffffffffULL;
break; break;
default: default:
return -1; return -1;
} }
}
static int scsi_req_length(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf)
{
cmd->xfer = scsi_cdb_length(buf);
switch (buf[0]) { switch (buf[0]) {
case TEST_UNIT_READY: case TEST_UNIT_READY:
case REWIND: case REWIND:

View File

@ -218,6 +218,8 @@ extern const struct SCSISense sense_code_WRITE_PROTECTED;
#define SENSE_CODE(x) sense_code_ ## x #define SENSE_CODE(x) sense_code_ ## x
uint32_t scsi_data_cdb_length(uint8_t *buf);
uint32_t scsi_cdb_length(uint8_t *buf);
int scsi_sense_valid(SCSISense sense); int scsi_sense_valid(SCSISense sense);
int scsi_build_sense(uint8_t *in_buf, int in_len, int scsi_build_sense(uint8_t *in_buf, int in_len,
uint8_t *buf, int len, bool fixed); uint8_t *buf, int len, bool fixed);