|
|
dc245c |
From 704e0f6448f4a9ce0c4c9a030679ab97a37850e8 Mon Sep 17 00:00:00 2001
|
|
|
dc245c |
From: Ronnie Sahlberg <ronniesahlberg@gmail.com>
|
|
|
dc245c |
Date: Sun, 12 May 2013 13:57:15 -0700
|
|
|
dc245c |
Subject: [RHEL7 libiscsi PATCH 08/18] SCSI: add a safe function to read a byte from the datain
|
|
|
dc245c |
buffer and use it throughout the unmarshalling code
|
|
|
dc245c |
|
|
|
dc245c |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
dc245c |
(cherry-picked from upstream commit 704e0f6448f4a9ce0c4c9a030679ab97a37850e8)
|
|
|
dc245c |
---
|
|
|
dc245c |
lib/scsi-lowlevel.c | 302 ++++++++++++++++++++++++++++------------------------
|
|
|
dc245c |
1 file changed, 163 insertions(+), 139 deletions(-)
|
|
|
dc245c |
|
|
|
dc245c |
diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c
|
|
|
dc245c |
index 85f7b1d..1f51f32 100644
|
|
|
dc245c |
--- a/lib/scsi-lowlevel.c
|
|
|
dc245c |
+++ b/lib/scsi-lowlevel.c
|
|
|
dc245c |
@@ -274,6 +274,16 @@ task_get_uint16(struct scsi_task *task, int offset)
|
|
|
dc245c |
}
|
|
|
dc245c |
}
|
|
|
dc245c |
|
|
|
dc245c |
+static inline uint8_t
|
|
|
dc245c |
+task_get_uint8(struct scsi_task *task, int offset)
|
|
|
dc245c |
+{
|
|
|
dc245c |
+ if (offset <= task->datain.size - 1) {
|
|
|
dc245c |
+ return task->datain.data[offset];
|
|
|
dc245c |
+ } else {
|
|
|
dc245c |
+ return 0;
|
|
|
dc245c |
+ }
|
|
|
dc245c |
+}
|
|
|
dc245c |
+
|
|
|
dc245c |
inline void
|
|
|
dc245c |
scsi_set_uint64(unsigned char *c, uint64_t v)
|
|
|
dc245c |
{
|
|
|
dc245c |
@@ -501,49 +511,49 @@ scsi_readtoc_desc_unmarshall(struct scsi_task *task, struct scsi_readtoc_list *l
|
|
|
dc245c |
switch(scsi_readtoc_format(task)) {
|
|
|
dc245c |
case SCSI_READ_TOC:
|
|
|
dc245c |
list->desc[i].desc.toc.adr
|
|
|
dc245c |
- = task->datain.data[4+8*i+1] & 0xf0;
|
|
|
dc245c |
+ = task_get_uint8(task, 4 + 8 * i + 1) & 0xf0;
|
|
|
dc245c |
list->desc[i].desc.toc.control
|
|
|
dc245c |
- = task->datain.data[4+8*i+1] & 0x0f;
|
|
|
dc245c |
+ = task_get_uint8(task, 4 + 8 * i + 1) & 0x0f;
|
|
|
dc245c |
list->desc[i].desc.toc.track
|
|
|
dc245c |
- = task->datain.data[4+8*i+2];
|
|
|
dc245c |
+ = task_get_uint8(task, 4 + 8 * i + 2);
|
|
|
dc245c |
list->desc[i].desc.toc.lba
|
|
|
dc245c |
= task_get_uint32(task, 4 + 8 * i + 4);
|
|
|
dc245c |
break;
|
|
|
dc245c |
case SCSI_READ_SESSION_INFO:
|
|
|
dc245c |
list->desc[i].desc.ses.adr
|
|
|
dc245c |
- = task->datain.data[4+8*i+1] & 0xf0;
|
|
|
dc245c |
+ = task_get_uint8(task, 4 + 8 * i + 1) & 0xf0;
|
|
|
dc245c |
list->desc[i].desc.ses.control
|
|
|
dc245c |
- = task->datain.data[4+8*i+1] & 0x0f;
|
|
|
dc245c |
+ = task_get_uint8(task, 4 + 8 * i + 1) & 0x0f;
|
|
|
dc245c |
list->desc[i].desc.ses.first_in_last
|
|
|
dc245c |
- = task->datain.data[4+8*i+2];
|
|
|
dc245c |
+ = task_get_uint8(task, 4 + 8 * i + 2);
|
|
|
dc245c |
list->desc[i].desc.ses.lba
|
|
|
dc245c |
= task_get_uint32(task, 4 + 8 * i + 4);
|
|
|
dc245c |
break;
|
|
|
dc245c |
case SCSI_READ_FULL_TOC:
|
|
|
dc245c |
list->desc[i].desc.full.session
|
|
|
dc245c |
- = task->datain.data[4+11*i+0] & 0xf0;
|
|
|
dc245c |
+ = task_get_uint8(task, 4 + 11 * i + 0) & 0xf0;
|
|
|
dc245c |
list->desc[i].desc.full.adr
|
|
|
dc245c |
- = task->datain.data[4+11*i+1] & 0xf0;
|
|
|
dc245c |
+ = task_get_uint8(task, 4 + 11 * i + 1) & 0xf0;
|
|
|
dc245c |
list->desc[i].desc.full.control
|
|
|
dc245c |
- = task->datain.data[4+11*i+1] & 0x0f;
|
|
|
dc245c |
+ = task_get_uint8(task, 4 + 11 * i + 1) & 0x0f;
|
|
|
dc245c |
list->desc[i].desc.full.tno
|
|
|
dc245c |
- = task->datain.data[4+11*i+2];
|
|
|
dc245c |
+ = task_get_uint8(task, 4 + 11 * i + 2);
|
|
|
dc245c |
list->desc[i].desc.full.point
|
|
|
dc245c |
- = task->datain.data[4+11*i+3];
|
|
|
dc245c |
+ = task_get_uint8(task, 4 + 11 * i + 3);
|
|
|
dc245c |
list->desc[i].desc.full.min
|
|
|
dc245c |
- = task->datain.data[4+11*i+4];
|
|
|
dc245c |
+ = task_get_uint8(task, 4 + 11 * i + 4);
|
|
|
dc245c |
list->desc[i].desc.full.sec
|
|
|
dc245c |
- = task->datain.data[4+11*i+5];
|
|
|
dc245c |
+ = task_get_uint8(task, 4 + 11 * i + 5);
|
|
|
dc245c |
list->desc[i].desc.full.frame
|
|
|
dc245c |
- = task->datain.data[4+11*i+6];
|
|
|
dc245c |
+ = task_get_uint8(task, 4 + 11 * i + 6);
|
|
|
dc245c |
list->desc[i].desc.full.zero
|
|
|
dc245c |
- = task->datain.data[4+11*i+7];
|
|
|
dc245c |
+ = task_get_uint8(task, 4 + 11 * i + 7);
|
|
|
dc245c |
list->desc[i].desc.full.pmin
|
|
|
dc245c |
- = task->datain.data[4+11*i+8];
|
|
|
dc245c |
+ = task_get_uint8(task, 4 + 11 * i + 8);
|
|
|
dc245c |
list->desc[i].desc.full.psec
|
|
|
dc245c |
- = task->datain.data[4+11*i+9];
|
|
|
dc245c |
+ = task_get_uint8(task, 4 + 11 * i + 9);
|
|
|
dc245c |
list->desc[i].desc.full.pframe
|
|
|
dc245c |
- = task->datain.data[4+11*i+10];
|
|
|
dc245c |
+ = task_get_uint8(task, 4 + 11 * i + 10);
|
|
|
dc245c |
break;
|
|
|
dc245c |
default:
|
|
|
dc245c |
break;
|
|
|
dc245c |
@@ -580,8 +590,8 @@ scsi_readtoc_datain_unmarshall(struct scsi_task *task)
|
|
|
dc245c |
}
|
|
|
dc245c |
|
|
|
dc245c |
list->num = num_desc;
|
|
|
dc245c |
- list->first = task->datain.data[2];
|
|
|
dc245c |
- list->last = task->datain.data[3];
|
|
|
dc245c |
+ list->first = task_get_uint8(task, 2);
|
|
|
dc245c |
+ list->last = task_get_uint8(task, 3);
|
|
|
dc245c |
|
|
|
dc245c |
for (i = 0; i < num_desc; i++) {
|
|
|
dc245c |
scsi_readtoc_desc_unmarshall(task, list, i);
|
|
|
dc245c |
@@ -655,12 +665,12 @@ scsi_serviceactionin_datain_unmarshall(struct scsi_task *task)
|
|
|
dc245c |
rc16->returned_lba = task_get_uint32(task, 0);
|
|
|
dc245c |
rc16->returned_lba = (rc16->returned_lba << 32) | task_get_uint32(task, 4);
|
|
|
dc245c |
rc16->block_length = task_get_uint32(task, 8);
|
|
|
dc245c |
- rc16->p_type = (task->datain.data[12] >> 1) & 0x07;
|
|
|
dc245c |
- rc16->prot_en = task->datain.data[12] & 0x01;
|
|
|
dc245c |
- rc16->p_i_exp = (task->datain.data[13] >> 4) & 0x0f;
|
|
|
dc245c |
- rc16->lbppbe = task->datain.data[13] & 0x0f;
|
|
|
dc245c |
- rc16->lbpme = !!(task->datain.data[14] & 0x80);
|
|
|
dc245c |
- rc16->lbprz = !!(task->datain.data[14] & 0x40);
|
|
|
dc245c |
+ rc16->p_type = (task_get_uint8(task, 12) >> 1) & 0x07;
|
|
|
dc245c |
+ rc16->prot_en = task_get_uint8(task, 12) & 0x01;
|
|
|
dc245c |
+ rc16->p_i_exp = (task_get_uint8(task, 13) >> 4) & 0x0f;
|
|
|
dc245c |
+ rc16->lbppbe = task_get_uint8(task, 13) & 0x0f;
|
|
|
dc245c |
+ rc16->lbpme = !!(task_get_uint8(task, 14) & 0x80);
|
|
|
dc245c |
+ rc16->lbprz = !!(task_get_uint8(task, 14) & 0x40);
|
|
|
dc245c |
rc16->lalba = task_get_uint16(task, 14) & 0x3fff;
|
|
|
dc245c |
return rc16;
|
|
|
dc245c |
}
|
|
|
dc245c |
@@ -694,7 +704,7 @@ scsi_serviceactionin_datain_unmarshall(struct scsi_task *task)
|
|
|
dc245c |
|
|
|
dc245c |
gls->descriptors[i].num_blocks = task_get_uint32(task, 8 + i * sizeof(struct scsi_lba_status_descriptor) + 8);
|
|
|
dc245c |
|
|
|
dc245c |
- gls->descriptors[i].provisioning = task->datain.data[8 + i * sizeof(struct scsi_lba_status_descriptor) + 12] & 0x0f;
|
|
|
dc245c |
+ gls->descriptors[i].provisioning = task_get_uint8(task, 8 + i * sizeof(struct scsi_lba_status_descriptor) + 12) & 0x0f;
|
|
|
dc245c |
}
|
|
|
dc245c |
|
|
|
dc245c |
return gls;
|
|
|
dc245c |
@@ -771,7 +781,7 @@ scsi_persistentreservein_datain_unmarshall(struct scsi_task *task)
|
|
|
dc245c |
rr->reserved = 1;
|
|
|
dc245c |
rr->reservation_key =
|
|
|
dc245c |
task_get_uint64(task, 8);
|
|
|
dc245c |
- rr->pr_type = task->datain.data[21] & 0xff;
|
|
|
dc245c |
+ rr->pr_type = task_get_uint8(task, 21) & 0xff;
|
|
|
dc245c |
}
|
|
|
dc245c |
|
|
|
dc245c |
return rr;
|
|
|
dc245c |
@@ -782,12 +792,12 @@ scsi_persistentreservein_datain_unmarshall(struct scsi_task *task)
|
|
|
dc245c |
return NULL;
|
|
|
dc245c |
}
|
|
|
dc245c |
rc->length = task_get_uint16(task, 0);
|
|
|
dc245c |
- rc->crh = !!(task->datain.data[2] & 0x10);
|
|
|
dc245c |
- rc->sip_c = !!(task->datain.data[2] & 0x08);
|
|
|
dc245c |
- rc->atp_c = !!(task->datain.data[2] & 0x04);
|
|
|
dc245c |
- rc->ptpl_c = !!(task->datain.data[2] & 0x01);
|
|
|
dc245c |
- rc->tmv = !!(task->datain.data[3] & 0x80);
|
|
|
dc245c |
- rc->allow_commands = task->datain.data[3] >> 4;
|
|
|
dc245c |
+ rc->crh = !!(task_get_uint8(task, 2) & 0x10);
|
|
|
dc245c |
+ rc->sip_c = !!(task_get_uint8(task, 2) & 0x08);
|
|
|
dc245c |
+ rc->atp_c = !!(task_get_uint8(task, 2) & 0x04);
|
|
|
dc245c |
+ rc->ptpl_c = !!(task_get_uint8(task, 2) & 0x01);
|
|
|
dc245c |
+ rc->tmv = !!(task_get_uint8(task, 3) & 0x80);
|
|
|
dc245c |
+ rc->allow_commands = task_get_uint8(task, 3) >> 4;
|
|
|
dc245c |
rc->persistent_reservation_type_mask = task_get_uint16(task, 4);
|
|
|
dc245c |
|
|
|
dc245c |
return rc;
|
|
|
dc245c |
@@ -1003,14 +1013,14 @@ static int
|
|
|
dc245c |
scsi_inquiry_datain_getfullsize(struct scsi_task *task)
|
|
|
dc245c |
{
|
|
|
dc245c |
if (scsi_inquiry_evpd_set(task) == 0) {
|
|
|
dc245c |
- return task->datain.data[4] + 5;
|
|
|
dc245c |
+ return task_get_uint8(task, 4) + 5;
|
|
|
dc245c |
}
|
|
|
dc245c |
|
|
|
dc245c |
switch (scsi_inquiry_page_code(task)) {
|
|
|
dc245c |
case SCSI_INQUIRY_PAGECODE_SUPPORTED_VPD_PAGES:
|
|
|
dc245c |
case SCSI_INQUIRY_PAGECODE_BLOCK_DEVICE_CHARACTERISTICS:
|
|
|
dc245c |
case SCSI_INQUIRY_PAGECODE_UNIT_SERIAL_NUMBER:
|
|
|
dc245c |
- return task->datain.data[3] + 4;
|
|
|
dc245c |
+ return task_get_uint8(task, 3) + 4;
|
|
|
dc245c |
case SCSI_INQUIRY_PAGECODE_DEVICE_IDENTIFICATION:
|
|
|
dc245c |
case SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS:
|
|
|
dc245c |
case SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING:
|
|
|
dc245c |
@@ -1030,28 +1040,28 @@ scsi_inquiry_unmarshall_standard(struct scsi_task *task)
|
|
|
dc245c |
return NULL;
|
|
|
dc245c |
}
|
|
|
dc245c |
|
|
|
dc245c |
- inq->qualifier = (task->datain.data[0]>>5)&0x07;
|
|
|
dc245c |
- inq->device_type = task->datain.data[0]&0x1f;
|
|
|
dc245c |
- inq->rmb = !!(task->datain.data[1]&0x80);
|
|
|
dc245c |
- inq->version = task->datain.data[2];
|
|
|
dc245c |
- inq->normaca = !!(task->datain.data[3]&0x20);
|
|
|
dc245c |
- inq->hisup = !!(task->datain.data[3]&0x10);
|
|
|
dc245c |
- inq->response_data_format = task->datain.data[3]&0x0f;
|
|
|
dc245c |
+ inq->qualifier = (task_get_uint8(task, 0) >> 5) & 0x07;
|
|
|
dc245c |
+ inq->device_type = task_get_uint8(task, 0) & 0x1f;
|
|
|
dc245c |
+ inq->rmb = !!(task_get_uint8(task, 1) & 0x80);
|
|
|
dc245c |
+ inq->version = task_get_uint8(task, 2);
|
|
|
dc245c |
+ inq->normaca = !!(task_get_uint8(task, 3) & 0x20);
|
|
|
dc245c |
+ inq->hisup = !!(task_get_uint8(task, 3) & 0x10);
|
|
|
dc245c |
+ inq->response_data_format = task_get_uint8(task, 3) & 0x0f;
|
|
|
dc245c |
|
|
|
dc245c |
- inq->additional_length = task->datain.data[4];
|
|
|
dc245c |
+ inq->additional_length = task_get_uint8(task, 4);
|
|
|
dc245c |
|
|
|
dc245c |
- inq->sccs = !!(task->datain.data[5]&0x80);
|
|
|
dc245c |
- inq->acc = !!(task->datain.data[5]&0x40);
|
|
|
dc245c |
- inq->tpgs = (task->datain.data[5]>>4)&0x03;
|
|
|
dc245c |
- inq->threepc = !!(task->datain.data[5]&0x08);
|
|
|
dc245c |
- inq->protect = !!(task->datain.data[5]&0x01);
|
|
|
dc245c |
+ inq->sccs = !!(task_get_uint8(task, 5) & 0x80);
|
|
|
dc245c |
+ inq->acc = !!(task_get_uint8(task, 5) & 0x40);
|
|
|
dc245c |
+ inq->tpgs = (task_get_uint8(task, 5) >> 4) & 0x03;
|
|
|
dc245c |
+ inq->threepc = !!(task_get_uint8(task, 5) & 0x08);
|
|
|
dc245c |
+ inq->protect = !!(task_get_uint8(task, 5) & 0x01);
|
|
|
dc245c |
|
|
|
dc245c |
- inq->encserv = !!(task->datain.data[6]&0x40);
|
|
|
dc245c |
- inq->multip = !!(task->datain.data[6]&0x10);
|
|
|
dc245c |
- inq->addr16 = !!(task->datain.data[6]&0x01);
|
|
|
dc245c |
- inq->wbus16 = !!(task->datain.data[7]&0x20);
|
|
|
dc245c |
- inq->sync = !!(task->datain.data[7]&0x10);
|
|
|
dc245c |
- inq->cmdque = !!(task->datain.data[7]&0x02);
|
|
|
dc245c |
+ inq->encserv = !!(task_get_uint8(task, 6) & 0x40);
|
|
|
dc245c |
+ inq->multip = !!(task_get_uint8(task, 6) & 0x10);
|
|
|
dc245c |
+ inq->addr16 = !!(task_get_uint8(task, 6) & 0x01);
|
|
|
dc245c |
+ inq->wbus16 = !!(task_get_uint8(task, 7) & 0x20);
|
|
|
dc245c |
+ inq->sync = !!(task_get_uint8(task, 7) & 0x10);
|
|
|
dc245c |
+ inq->cmdque = !!(task_get_uint8(task, 7) & 0x02);
|
|
|
dc245c |
|
|
|
dc245c |
memcpy(&inq->vendor_identification[0],
|
|
|
dc245c |
&task->datain.data[8], 8);
|
|
|
dc245c |
@@ -1060,9 +1070,9 @@ scsi_inquiry_unmarshall_standard(struct scsi_task *task)
|
|
|
dc245c |
memcpy(&inq->product_revision_level[0],
|
|
|
dc245c |
&task->datain.data[32], 4);
|
|
|
dc245c |
|
|
|
dc245c |
- inq->clocking = (task->datain.data[56]>>2)&0x03;
|
|
|
dc245c |
- inq->qas = !!(task->datain.data[56]&0x02);
|
|
|
dc245c |
- inq->ius = !!(task->datain.data[56]&0x01);
|
|
|
dc245c |
+ inq->clocking = (task_get_uint8(task, 56) >> 2) & 0x03;
|
|
|
dc245c |
+ inq->qas = !!(task_get_uint8(task, 56) & 0x02);
|
|
|
dc245c |
+ inq->ius = !!(task_get_uint8(task, 56) & 0x01);
|
|
|
dc245c |
|
|
|
dc245c |
return inq;
|
|
|
dc245c |
}
|
|
|
dc245c |
@@ -1079,11 +1089,11 @@ scsi_inquiry_unmarshall_supported_pages(struct scsi_task *task)
|
|
|
dc245c |
if (inq == NULL) {
|
|
|
dc245c |
return NULL;
|
|
|
dc245c |
}
|
|
|
dc245c |
- inq->qualifier = (task->datain.data[0]>>5)&0x07;
|
|
|
dc245c |
- inq->device_type = task->datain.data[0]&0x1f;
|
|
|
dc245c |
- inq->pagecode = task->datain.data[1];
|
|
|
dc245c |
+ inq->qualifier = (task_get_uint8(task, 0) >> 5) & 0x07;
|
|
|
dc245c |
+ inq->device_type = task_get_uint8(task, 0) & 0x1f;
|
|
|
dc245c |
+ inq->pagecode = task_get_uint8(task, 1);
|
|
|
dc245c |
|
|
|
dc245c |
- inq->num_pages = task->datain.data[3];
|
|
|
dc245c |
+ inq->num_pages = task_get_uint8(task, 3);
|
|
|
dc245c |
inq->pages = scsi_malloc(task, inq->num_pages);
|
|
|
dc245c |
if (inq->pages == NULL) {
|
|
|
dc245c |
free (inq);
|
|
|
dc245c |
@@ -1101,17 +1111,17 @@ scsi_inquiry_unmarshall_unit_serial_number(struct scsi_task* task)
|
|
|
dc245c |
if (inq == NULL) {
|
|
|
dc245c |
return NULL;
|
|
|
dc245c |
}
|
|
|
dc245c |
- inq->qualifier = (task->datain.data[0]>>5)&0x07;
|
|
|
dc245c |
- inq->device_type = task->datain.data[0]&0x1f;
|
|
|
dc245c |
- inq->pagecode = task->datain.data[1];
|
|
|
dc245c |
+ inq->qualifier = (task_get_uint8(task, 0) >> 5) & 0x07;
|
|
|
dc245c |
+ inq->device_type = task_get_uint8(task, 0) & 0x1f;
|
|
|
dc245c |
+ inq->pagecode = task_get_uint8(task, 1);
|
|
|
dc245c |
|
|
|
dc245c |
- inq->usn = scsi_malloc(task, task->datain.data[3]+1);
|
|
|
dc245c |
+ inq->usn = scsi_malloc(task, task_get_uint8(task, 3) + 1);
|
|
|
dc245c |
if (inq->usn == NULL) {
|
|
|
dc245c |
free(inq);
|
|
|
dc245c |
return NULL;
|
|
|
dc245c |
}
|
|
|
dc245c |
- memcpy(inq->usn, &task->datain.data[4], task->datain.data[3]);
|
|
|
dc245c |
- inq->usn[task->datain.data[3]] = 0;
|
|
|
dc245c |
+ memcpy(inq->usn, &task->datain.data[4], task_get_uint8(task, 3));
|
|
|
dc245c |
+ inq->usn[task_get_uint8(task, 3)] = 0;
|
|
|
dc245c |
return inq;
|
|
|
dc245c |
}
|
|
|
dc245c |
|
|
|
dc245c |
@@ -1119,16 +1129,16 @@ static struct scsi_inquiry_device_identification *
|
|
|
dc245c |
scsi_inquiry_unmarshall_device_identification(struct scsi_task *task)
|
|
|
dc245c |
{
|
|
|
dc245c |
struct scsi_inquiry_device_identification *inq = scsi_malloc(task,
|
|
|
dc245c |
- sizeof(*inq));
|
|
|
dc245c |
+ sizeof(*inq));
|
|
|
dc245c |
int remaining = task_get_uint16(task, 2);
|
|
|
dc245c |
unsigned char *dptr;
|
|
|
dc245c |
|
|
|
dc245c |
if (inq == NULL) {
|
|
|
dc245c |
return NULL;
|
|
|
dc245c |
}
|
|
|
dc245c |
- inq->qualifier = (task->datain.data[0]>>5)&0x07;
|
|
|
dc245c |
- inq->device_type = task->datain.data[0]&0x1f;
|
|
|
dc245c |
- inq->pagecode = task->datain.data[1];
|
|
|
dc245c |
+ inq->qualifier = (task_get_uint8(task, 0) >> 5) & 0x07;
|
|
|
dc245c |
+ inq->device_type = task_get_uint8(task, 0) & 0x1f;
|
|
|
dc245c |
+ inq->pagecode = task_get_uint8(task, 1);
|
|
|
dc245c |
|
|
|
dc245c |
dptr = &task->datain.data[4];
|
|
|
dc245c |
while (remaining > 0) {
|
|
|
dc245c |
@@ -1183,12 +1193,12 @@ scsi_inquiry_unmarshall_block_limits(struct scsi_task *task)
|
|
|
dc245c |
if (inq == NULL) {
|
|
|
dc245c |
return NULL;
|
|
|
dc245c |
}
|
|
|
dc245c |
- inq->qualifier = (task->datain.data[0]>>5)&0x07;
|
|
|
dc245c |
- inq->device_type = task->datain.data[0]&0x1f;
|
|
|
dc245c |
- inq->pagecode = task->datain.data[1];
|
|
|
dc245c |
+ inq->qualifier = (task_get_uint8(task, 0) >> 5) & 0x07;
|
|
|
dc245c |
+ inq->device_type = task_get_uint8(task, 0) & 0x1f;
|
|
|
dc245c |
+ inq->pagecode = task_get_uint8(task, 1);
|
|
|
dc245c |
|
|
|
dc245c |
- inq->wsnz = task->datain.data[4] & 0x01;
|
|
|
dc245c |
- inq->max_cmp = task->datain.data[5];
|
|
|
dc245c |
+ inq->wsnz = task_get_uint8(task, 4) & 0x01;
|
|
|
dc245c |
+ inq->max_cmp = task_get_uint8(task, 5);
|
|
|
dc245c |
inq->opt_gran = task_get_uint16(task, 6);
|
|
|
dc245c |
inq->max_xfer_len = task_get_uint32(task, 8);
|
|
|
dc245c |
inq->opt_xfer_len = task_get_uint32(task, 12);
|
|
|
dc245c |
@@ -1196,7 +1206,7 @@ scsi_inquiry_unmarshall_block_limits(struct scsi_task *task)
|
|
|
dc245c |
inq->max_unmap = task_get_uint32(task, 20);
|
|
|
dc245c |
inq->max_unmap_bdc = task_get_uint32(task, 24);
|
|
|
dc245c |
inq->opt_unmap_gran = task_get_uint32(task, 28);
|
|
|
dc245c |
- inq->ugavalid = !!(task->datain.data[32]&0x80);
|
|
|
dc245c |
+ inq->ugavalid = !!(task_get_uint8(task, 32)&0x80);
|
|
|
dc245c |
inq->unmap_gran_align = task_get_uint32(task, 32) & 0x7fffffff;
|
|
|
dc245c |
inq->max_ws_len = task_get_uint32(task, 36);
|
|
|
dc245c |
inq->max_ws_len = (inq->max_ws_len << 32)
|
|
|
dc245c |
@@ -1213,9 +1223,9 @@ scsi_inquiry_unmarshall_block_device_characteristics(struct scsi_task *task)
|
|
|
dc245c |
if (inq == NULL) {
|
|
|
dc245c |
return NULL;
|
|
|
dc245c |
}
|
|
|
dc245c |
- inq->qualifier = (task->datain.data[0]>>5)&0x07;
|
|
|
dc245c |
- inq->device_type = task->datain.data[0]&0x1f;
|
|
|
dc245c |
- inq->pagecode = task->datain.data[1];
|
|
|
dc245c |
+ inq->qualifier = (task_get_uint8(task, 0) >> 5) & 0x07;
|
|
|
dc245c |
+ inq->device_type = task_get_uint8(task, 0) & 0x1f;
|
|
|
dc245c |
+ inq->pagecode = task_get_uint8(task, 1);
|
|
|
dc245c |
|
|
|
dc245c |
inq->medium_rotation_rate = task_get_uint16(task, 4);
|
|
|
dc245c |
return inq;
|
|
|
dc245c |
@@ -1229,18 +1239,18 @@ scsi_inquiry_unmarshall_logical_block_provisioning(struct scsi_task *task)
|
|
|
dc245c |
if (inq == NULL) {
|
|
|
dc245c |
return NULL;
|
|
|
dc245c |
}
|
|
|
dc245c |
- inq->qualifier = (task->datain.data[0]>>5)&0x07;
|
|
|
dc245c |
- inq->device_type = task->datain.data[0]&0x1f;
|
|
|
dc245c |
- inq->pagecode = task->datain.data[1];
|
|
|
dc245c |
+ inq->qualifier = (task_get_uint8(task, 0) >> 5) & 0x07;
|
|
|
dc245c |
+ inq->device_type = task_get_uint8(task, 0) & 0x1f;
|
|
|
dc245c |
+ inq->pagecode = task_get_uint8(task, 1);
|
|
|
dc245c |
|
|
|
dc245c |
- inq->threshold_exponent = task->datain.data[4];
|
|
|
dc245c |
- inq->lbpu = !!(task->datain.data[5] & 0x80);
|
|
|
dc245c |
- inq->lbpws = !!(task->datain.data[5] & 0x40);
|
|
|
dc245c |
- inq->lbpws10 = !!(task->datain.data[5] & 0x20);
|
|
|
dc245c |
- inq->lbprz = !!(task->datain.data[5] & 0x04);
|
|
|
dc245c |
- inq->anc_sup = !!(task->datain.data[5] & 0x02);
|
|
|
dc245c |
- inq->dp = !!(task->datain.data[5] & 0x01);
|
|
|
dc245c |
- inq->provisioning_type = task->datain.data[6] & 0x07;
|
|
|
dc245c |
+ inq->threshold_exponent = task_get_uint8(task, 4);
|
|
|
dc245c |
+ inq->lbpu = !!(task_get_uint8(task, 5) & 0x80);
|
|
|
dc245c |
+ inq->lbpws = !!(task_get_uint8(task, 5) & 0x40);
|
|
|
dc245c |
+ inq->lbpws10 = !!(task_get_uint8(task, 5) & 0x20);
|
|
|
dc245c |
+ inq->lbprz = !!(task_get_uint8(task, 5) & 0x04);
|
|
|
dc245c |
+ inq->anc_sup = !!(task_get_uint8(task, 5) & 0x02);
|
|
|
dc245c |
+ inq->dp = !!(task_get_uint8(task, 5) & 0x01);
|
|
|
dc245c |
+ inq->provisioning_type = task_get_uint8(task, 6) & 0x07;
|
|
|
dc245c |
|
|
|
dc245c |
return inq;
|
|
|
dc245c |
}
|
|
|
dc245c |
@@ -2062,7 +2072,7 @@ scsi_modesense6_datain_getfullsize(struct scsi_task *task)
|
|
|
dc245c |
{
|
|
|
dc245c |
int len;
|
|
|
dc245c |
|
|
|
dc245c |
- len = task->datain.data[0] + 1;
|
|
|
dc245c |
+ len = task_get_uint8(task, 0) + 1;
|
|
|
dc245c |
|
|
|
dc245c |
return len;
|
|
|
dc245c |
}
|
|
|
dc245c |
@@ -2070,59 +2080,73 @@ scsi_modesense6_datain_getfullsize(struct scsi_task *task)
|
|
|
dc245c |
static void
|
|
|
dc245c |
scsi_parse_mode_caching(struct scsi_task *task, int pos, struct scsi_mode_page *mp)
|
|
|
dc245c |
{
|
|
|
dc245c |
- mp->caching.ic = task->datain.data[pos] & 0x80;
|
|
|
dc245c |
- mp->caching.abpf = task->datain.data[pos] & 0x40;
|
|
|
dc245c |
- mp->caching.cap = task->datain.data[pos] & 0x20;
|
|
|
dc245c |
- mp->caching.disc = task->datain.data[pos] & 0x10;
|
|
|
dc245c |
- mp->caching.size = task->datain.data[pos] & 0x08;
|
|
|
dc245c |
- mp->caching.wce = task->datain.data[pos] & 0x04;
|
|
|
dc245c |
- mp->caching.mf = task->datain.data[pos] & 0x02;
|
|
|
dc245c |
- mp->caching.rcd = task->datain.data[pos] & 0x01;
|
|
|
dc245c |
-
|
|
|
dc245c |
- mp->caching.demand_read_retention_priority = (task->datain.data[pos+1] >> 4) & 0x0f;
|
|
|
dc245c |
- mp->caching.write_retention_priority = task->datain.data[pos+1] & 0x0f;
|
|
|
dc245c |
-
|
|
|
dc245c |
- mp->caching.disable_prefetch_transfer_length = task_get_uint16(task, pos + 2);
|
|
|
dc245c |
+ mp->caching.ic = task_get_uint8(task, pos) & 0x80;
|
|
|
dc245c |
+ mp->caching.abpf = task_get_uint8(task, pos) & 0x40;
|
|
|
dc245c |
+ mp->caching.cap = task_get_uint8(task, pos) & 0x20;
|
|
|
dc245c |
+ mp->caching.disc = task_get_uint8(task, pos) & 0x10;
|
|
|
dc245c |
+ mp->caching.size = task_get_uint8(task, pos) & 0x08;
|
|
|
dc245c |
+ mp->caching.wce = task_get_uint8(task, pos) & 0x04;
|
|
|
dc245c |
+ mp->caching.mf = task_get_uint8(task, pos) & 0x02;
|
|
|
dc245c |
+ mp->caching.rcd = task_get_uint8(task, pos) & 0x01;
|
|
|
dc245c |
+
|
|
|
dc245c |
+ mp->caching.demand_read_retention_priority =
|
|
|
dc245c |
+ (task_get_uint8(task, pos + 1) >> 4) & 0x0f;
|
|
|
dc245c |
+ mp->caching.write_retention_priority =
|
|
|
dc245c |
+ task_get_uint8(task, pos + 1) & 0x0f;
|
|
|
dc245c |
+
|
|
|
dc245c |
+ mp->caching.disable_prefetch_transfer_length =
|
|
|
dc245c |
+ task_get_uint16(task, pos + 2);
|
|
|
dc245c |
mp->caching.minimum_prefetch = task_get_uint16(task, pos + 4);
|
|
|
dc245c |
mp->caching.maximum_prefetch = task_get_uint16(task, pos + 6);
|
|
|
dc245c |
mp->caching.maximum_prefetch_ceiling = task_get_uint16(task, pos + 8);
|
|
|
dc245c |
|
|
|
dc245c |
- mp->caching.fsw = task->datain.data[pos+10] & 0x80;
|
|
|
dc245c |
- mp->caching.lbcss = task->datain.data[pos+10] & 0x40;
|
|
|
dc245c |
- mp->caching.dra = task->datain.data[pos+10] & 0x20;
|
|
|
dc245c |
- mp->caching.nv_dis = task->datain.data[pos+10] & 0x01;
|
|
|
dc245c |
+ mp->caching.fsw = task_get_uint8(task, pos + 10) & 0x80;
|
|
|
dc245c |
+ mp->caching.lbcss = task_get_uint8(task, pos + 10) & 0x40;
|
|
|
dc245c |
+ mp->caching.dra = task_get_uint8(task, pos + 10) & 0x20;
|
|
|
dc245c |
+ mp->caching.nv_dis = task_get_uint8(task, pos + 10) & 0x01;
|
|
|
dc245c |
|
|
|
dc245c |
- mp->caching.number_of_cache_segments = task->datain.data[pos+11];
|
|
|
dc245c |
+ mp->caching.number_of_cache_segments = task_get_uint8(task, pos + 11);
|
|
|
dc245c |
mp->caching.cache_segment_size = task_get_uint16(task, pos + 12);
|
|
|
dc245c |
}
|
|
|
dc245c |
|
|
|
dc245c |
static void
|
|
|
dc245c |
scsi_parse_mode_disconnect_reconnect(struct scsi_task *task, int pos, struct scsi_mode_page *mp)
|
|
|
dc245c |
{
|
|
|
dc245c |
- mp->disconnect_reconnect.buffer_full_ratio = task->datain.data[pos];
|
|
|
dc245c |
- mp->disconnect_reconnect.buffer_empty_ratio = task->datain.data[pos+1];
|
|
|
dc245c |
- mp->disconnect_reconnect.bus_inactivity_limit = task_get_uint16(task, pos + 2);
|
|
|
dc245c |
- mp->disconnect_reconnect.disconnect_time_limit = task_get_uint16(task, pos + 4);
|
|
|
dc245c |
- mp->disconnect_reconnect.connect_time_limit = task_get_uint16(task, pos + 6);
|
|
|
dc245c |
- mp->disconnect_reconnect.maximum_burst_size = task_get_uint16(task, pos + 8);
|
|
|
dc245c |
- mp->disconnect_reconnect.emdp = task->datain.data[pos+10] & 0x80;
|
|
|
dc245c |
- mp->disconnect_reconnect.fair_arbitration = (task->datain.data[pos+10]>>4) & 0x0f;
|
|
|
dc245c |
- mp->disconnect_reconnect.dimm = task->datain.data[pos+10] & 0x08;
|
|
|
dc245c |
- mp->disconnect_reconnect.dtdc = task->datain.data[pos+10] & 0x07;
|
|
|
dc245c |
- mp->disconnect_reconnect.first_burst_size = task_get_uint16(task, pos + 12);
|
|
|
dc245c |
+ mp->disconnect_reconnect.buffer_full_ratio =
|
|
|
dc245c |
+ task_get_uint8(task, pos);
|
|
|
dc245c |
+ mp->disconnect_reconnect.buffer_empty_ratio =
|
|
|
dc245c |
+ task_get_uint8(task, pos + 1);
|
|
|
dc245c |
+ mp->disconnect_reconnect.bus_inactivity_limit =
|
|
|
dc245c |
+ task_get_uint16(task, pos + 2);
|
|
|
dc245c |
+ mp->disconnect_reconnect.disconnect_time_limit =
|
|
|
dc245c |
+ task_get_uint16(task, pos + 4);
|
|
|
dc245c |
+ mp->disconnect_reconnect.connect_time_limit =
|
|
|
dc245c |
+ task_get_uint16(task, pos + 6);
|
|
|
dc245c |
+ mp->disconnect_reconnect.maximum_burst_size =
|
|
|
dc245c |
+ task_get_uint16(task, pos + 8);
|
|
|
dc245c |
+ mp->disconnect_reconnect.emdp =
|
|
|
dc245c |
+ task_get_uint8(task, pos + 10) & 0x80;
|
|
|
dc245c |
+ mp->disconnect_reconnect.fair_arbitration =
|
|
|
dc245c |
+ (task_get_uint8(task, pos + 10) >> 4) & 0x0f;
|
|
|
dc245c |
+ mp->disconnect_reconnect.dimm =
|
|
|
dc245c |
+ task_get_uint8(task, pos + 10) & 0x08;
|
|
|
dc245c |
+ mp->disconnect_reconnect.dtdc =
|
|
|
dc245c |
+ task_get_uint8(task, pos + 10) & 0x07;
|
|
|
dc245c |
+ mp->disconnect_reconnect.first_burst_size =
|
|
|
dc245c |
+ task_get_uint16(task, pos + 12);
|
|
|
dc245c |
}
|
|
|
dc245c |
|
|
|
dc245c |
static void
|
|
|
dc245c |
scsi_parse_mode_informational_exceptions_control(struct scsi_task *task, int pos, struct scsi_mode_page *mp)
|
|
|
dc245c |
{
|
|
|
dc245c |
- mp->iec.perf = task->datain.data[pos] & 0x80;
|
|
|
dc245c |
- mp->iec.ebf = task->datain.data[pos] & 0x20;
|
|
|
dc245c |
- mp->iec.ewasc = task->datain.data[pos] & 0x10;
|
|
|
dc245c |
- mp->iec.dexcpt = task->datain.data[pos] & 0x08;
|
|
|
dc245c |
- mp->iec.test = task->datain.data[pos] & 0x04;
|
|
|
dc245c |
- mp->iec.ebackerr = task->datain.data[pos] & 0x02;
|
|
|
dc245c |
- mp->iec.logerr = task->datain.data[pos] & 0x01;
|
|
|
dc245c |
- mp->iec.mrie = task->datain.data[pos+1] & 0x0f;
|
|
|
dc245c |
+ mp->iec.perf = task_get_uint8(task, pos) & 0x80;
|
|
|
dc245c |
+ mp->iec.ebf = task_get_uint8(task, pos) & 0x20;
|
|
|
dc245c |
+ mp->iec.ewasc = task_get_uint8(task, pos) & 0x10;
|
|
|
dc245c |
+ mp->iec.dexcpt = task_get_uint8(task, pos) & 0x08;
|
|
|
dc245c |
+ mp->iec.test = task_get_uint8(task, pos) & 0x04;
|
|
|
dc245c |
+ mp->iec.ebackerr = task_get_uint8(task, pos) & 0x02;
|
|
|
dc245c |
+ mp->iec.logerr = task_get_uint8(task, pos) & 0x01;
|
|
|
dc245c |
+ mp->iec.mrie = task_get_uint8(task, pos + 1) & 0x0f;
|
|
|
dc245c |
mp->iec.interval_timer = task_get_uint32(task, pos + 2);
|
|
|
dc245c |
mp->iec.report_count = task_get_uint32(task, pos + 6);
|
|
|
dc245c |
}
|
|
|
dc245c |
@@ -2146,10 +2170,10 @@ scsi_modesense_datain_unmarshall(struct scsi_task *task)
|
|
|
dc245c |
return NULL;
|
|
|
dc245c |
}
|
|
|
dc245c |
|
|
|
dc245c |
- ms->mode_data_length = task->datain.data[0];
|
|
|
dc245c |
- ms->medium_type = task->datain.data[1];
|
|
|
dc245c |
- ms->device_specific_parameter = task->datain.data[2];
|
|
|
dc245c |
- ms->block_descriptor_length = task->datain.data[3];
|
|
|
dc245c |
+ ms->mode_data_length = task_get_uint8(task, 0);
|
|
|
dc245c |
+ ms->medium_type = task_get_uint8(task, 1);
|
|
|
dc245c |
+ ms->device_specific_parameter = task_get_uint8(task, 2);
|
|
|
dc245c |
+ ms->block_descriptor_length = task_get_uint8(task, 3);
|
|
|
dc245c |
ms->pages = NULL;
|
|
|
dc245c |
|
|
|
dc245c |
if (ms->mode_data_length + 1 > task->datain.size) {
|
|
|
dc245c |
@@ -2164,18 +2188,18 @@ scsi_modesense_datain_unmarshall(struct scsi_task *task)
|
|
|
dc245c |
if (mp == NULL) {
|
|
|
dc245c |
return ms;
|
|
|
dc245c |
}
|
|
|
dc245c |
- mp->ps = task->datain.data[pos] & 0x80;
|
|
|
dc245c |
- mp->spf = task->datain.data[pos] & 0x40;
|
|
|
dc245c |
- mp->page_code = task->datain.data[pos] & 0x3f;
|
|
|
dc245c |
+ mp->ps = task_get_uint8(task, pos) & 0x80;
|
|
|
dc245c |
+ mp->spf = task_get_uint8(task, pos) & 0x40;
|
|
|
dc245c |
+ mp->page_code = task_get_uint8(task, pos) & 0x3f;
|
|
|
dc245c |
pos++;
|
|
|
dc245c |
|
|
|
dc245c |
if (mp->spf) {
|
|
|
dc245c |
- mp->subpage_code = task->datain.data[pos++];
|
|
|
dc245c |
+ mp->subpage_code = task_get_uint8(task, pos++);
|
|
|
dc245c |
mp->len = task_get_uint16(task, pos);
|
|
|
dc245c |
pos += 2;
|
|
|
dc245c |
} else {
|
|
|
dc245c |
mp->subpage_code = 0;
|
|
|
dc245c |
- mp->len = task->datain.data[pos++];
|
|
|
dc245c |
+ mp->len = task_get_uint8(task, pos++);
|
|
|
dc245c |
}
|
|
|
dc245c |
|
|
|
dc245c |
switch (mp->page_code) {
|
|
|
dc245c |
--
|
|
|
dc245c |
1.8.1.4
|
|
|
dc245c |
|