From 44cb5d60c5aa6403faa838c84f689e335529c428 Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 00:36:28 +0100 Subject: [PATCH 01/25] iscsi.h: include as iscsi_data gained a size_t member Signed-off-by: Arne Redlich --- include/iscsi.h | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/include/iscsi.h b/include/iscsi.h index 5ee61c2..3aadafd 100644 --- a/include/iscsi.h +++ b/include/iscsi.h @@ -18,6 +18,7 @@ #define __iscsi_h__ #include +#include #if defined(WIN32) #define EXTERN __declspec( dllexport ) @@ -740,8 +741,8 @@ iscsi_unmap_task(struct iscsi_context *iscsi, int lun, int anchor, int group, iscsi_command_cb cb, void *private_data); EXTERN struct scsi_task * -iscsi_readtoc_task(struct iscsi_context *iscsi, int lun, int msf, int format, - int track_session, int maxsize, +iscsi_readtoc_task(struct iscsi_context *iscsi, int lun, int msf, int format, + int track_session, int maxsize, iscsi_command_cb cb, void *private_data); EXTERN struct scsi_task * @@ -754,7 +755,7 @@ iscsi_release6_task(struct iscsi_context *iscsi, int lun, EXTERN struct scsi_task * iscsi_report_supported_opcodes_task(struct iscsi_context *iscsi, int lun, - int return_timeouts, int maxsize, + int return_timeouts, int maxsize, iscsi_command_cb cb, void *private_data); /* @@ -970,7 +971,7 @@ iscsi_scsi_cancel_all_tasks(struct iscsi_context *iscsi); /* * This function is to set the debugging level where level is - * + * * 0 = disabled (default) * 1 = errors only * 2 = connection related info @@ -994,39 +995,39 @@ EXTERN void iscsi_log_to_stderr(int level, const char *message); * This function is to set the TCP_USER_TIMEOUT option. It has to be called after iscsi * context creation. The value given in ms is then applied each time a new socket is created. */ -EXTERN void +EXTERN void iscsi_set_tcp_user_timeout(struct iscsi_context *iscsi, int timeout_ms); /* * This function is to set the TCP_KEEPIDLE option. It has to be called after iscsi - * context creation. + * context creation. */ -EXTERN void +EXTERN void iscsi_set_tcp_keepidle(struct iscsi_context *iscsi, int value); /* * This function is to set the TCP_KEEPCNT option. It has to be called after iscsi - * context creation. + * context creation. */ -EXTERN void +EXTERN void iscsi_set_tcp_keepcnt(struct iscsi_context *iscsi, int value); /* * This function is to set the TCP_KEEPINTVL option. It has to be called after iscsi - * context creation. + * context creation. */ -EXTERN void +EXTERN void iscsi_set_tcp_keepintvl(struct iscsi_context *iscsi, int value); /* * This function is to set the TCP_SYNCNT option. It has to be called after iscsi - * context creation. + * context creation. */ -EXTERN void +EXTERN void iscsi_set_tcp_syncnt(struct iscsi_context *iscsi, int value); /* - * This function is to set the interface that outbound connections for this socket are bound to. + * This function is to set the interface that outbound connections for this socket are bound to. * You max specify more than one interface here separated by comma. */ EXTERN void From 76aa2693c45be238f62098a112f1acad6c8f4bd6 Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 21:31:11 +0100 Subject: [PATCH 02/25] scsi-lowlevel: remove scsi_reportluns_params Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 6 +--- lib/scsi-lowlevel.c | 63 ++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 38 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index 38787c1..88b8682 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,9 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_reportluns_params { - int report_type; -}; struct scsi_read6_params { uint32_t lba; uint32_t num_blocks; @@ -337,7 +334,6 @@ struct scsi_task { struct scsi_verify12_params verify12; struct scsi_verify16_params verify16; struct scsi_readcapacity10_params readcapacity10; - struct scsi_reportluns_params reportluns; struct scsi_inquiry_params inquiry; struct scsi_modesense6_params modesense6; struct scsi_serviceactionin_params serviceactionin; @@ -780,7 +776,7 @@ struct scsi_op_timeout_descriptor { uint8_t command_specific; uint32_t nominal_processing_timeout; uint32_t recommended_timeout; - + }; struct scsi_command_descriptor { uint8_t op_code; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index fa14533..cf7be32 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -210,8 +210,6 @@ scsi_reportluns_cdb(int report_type, int alloc_len) } task->expxferlen = alloc_len; - task->params.reportluns.report_type = report_type; - return task; } @@ -307,7 +305,7 @@ scsi_cdb_readtoc(int msf, int format, int track_session, uint16_t alloc_len) { struct scsi_task *task; - if (format != SCSI_READ_TOC && format != SCSI_READ_SESSION_INFO + if (format != SCSI_READ_TOC && format != SCSI_READ_SESSION_INFO && format != SCSI_READ_FULL_TOC){ fprintf(stderr, "Read TOC format %d not fully supported yet\n", format); return NULL; @@ -366,35 +364,35 @@ scsi_readtoc_desc_unmarshall(struct scsi_task *task, struct scsi_readtoc_list *l { switch(task->params.readtoc.format){ case SCSI_READ_TOC: - list->desc[i].desc.toc.adr + list->desc[i].desc.toc.adr = task->datain.data[4+8*i+1] & 0xf0; - list->desc[i].desc.toc.control + list->desc[i].desc.toc.control = task->datain.data[4+8*i+1] & 0x0f; - list->desc[i].desc.toc.track + list->desc[i].desc.toc.track = task->datain.data[4+8*i+2]; - list->desc[i].desc.toc.lba + list->desc[i].desc.toc.lba = ntohl(*(uint32_t *)&task->datain.data[4+8*i+4]); break; case SCSI_READ_SESSION_INFO: - list->desc[i].desc.ses.adr + list->desc[i].desc.ses.adr = task->datain.data[4+8*i+1] & 0xf0; - list->desc[i].desc.ses.control + list->desc[i].desc.ses.control = task->datain.data[4+8*i+1] & 0x0f; - list->desc[i].desc.ses.first_in_last + list->desc[i].desc.ses.first_in_last = task->datain.data[4+8*i+2]; - list->desc[i].desc.ses.lba + list->desc[i].desc.ses.lba = ntohl(*(uint32_t *)&task->datain.data[4+8*i+4]); break; case SCSI_READ_FULL_TOC: - list->desc[i].desc.full.session + list->desc[i].desc.full.session = task->datain.data[4+11*i+0] & 0xf0; - list->desc[i].desc.full.adr + list->desc[i].desc.full.adr = task->datain.data[4+11*i+1] & 0xf0; - list->desc[i].desc.full.control + list->desc[i].desc.full.control = task->datain.data[4+11*i+1] & 0x0f; - list->desc[i].desc.full.tno + list->desc[i].desc.full.tno = task->datain.data[4+11*i+2]; - list->desc[i].desc.full.point + list->desc[i].desc.full.point = task->datain.data[4+11*i+3]; list->desc[i].desc.full.min = task->datain.data[4+11*i+4]; @@ -404,7 +402,7 @@ scsi_readtoc_desc_unmarshall(struct scsi_task *task, struct scsi_readtoc_list *l = task->datain.data[4+11*i+6]; list->desc[i].desc.full.zero = task->datain.data[4+11*i+7]; - list->desc[i].desc.full.pmin + list->desc[i].desc.full.pmin = task->datain.data[4+11*i+8]; list->desc[i].desc.full.psec = task->datain.data[4+11*i+9]; @@ -426,7 +424,7 @@ scsi_readtoc_datain_unmarshall(struct scsi_task *task) if (task->datain.size < 4) { return NULL; } - + /* Do we have all data? */ data_len = scsi_readtoc_datain_getfullsize(task) - 2; if(task->datain.size < data_len) { @@ -434,7 +432,7 @@ scsi_readtoc_datain_unmarshall(struct scsi_task *task) } /* Remove header size (4) to get bytes in descriptor list */ - num_desc = (data_len - 4) / 8; + num_desc = (data_len - 4) / 8; list = scsi_malloc(task, offsetof(struct scsi_readtoc_list, desc) + sizeof(struct scsi_readtoc_desc) * num_desc); @@ -445,11 +443,11 @@ scsi_readtoc_datain_unmarshall(struct scsi_task *task) list->num = num_desc; list->first = task->datain.data[2]; list->last = task->datain.data[3]; - + for (i = 0; i < num_desc; i++) { scsi_readtoc_desc_unmarshall(task, list, i); } - + return list; } @@ -468,10 +466,10 @@ scsi_cdb_reserve6(void) memset(task, 0, sizeof(struct scsi_task)); task->cdb[0] = SCSI_OPCODE_RESERVE6; - + task->cdb_size = 6; task->xfer_dir = SCSI_XFER_NONE; - + return task; } /* @@ -489,7 +487,7 @@ scsi_cdb_release6(void) memset(task, 0, sizeof(struct scsi_task)); task->cdb[0] = SCSI_OPCODE_RELEASE6; - + task->cdb_size = 6; task->xfer_dir = SCSI_XFER_NONE; @@ -568,7 +566,7 @@ scsi_maintenancein_datain_getfullsize(struct scsi_task *task) { switch (task->params.maintenancein.sa) { - case SCSI_REPORT_SUPPORTED_OP_CODES: + case SCSI_REPORT_SUPPORTED_OP_CODES: return ntohl(*(uint32_t *)&(task->datain.data[0])) + 4; default: return -1; @@ -600,7 +598,7 @@ scsi_maintenancein_datain_unmarshall(struct scsi_task *task) return NULL; } /* Does the descriptor include command timeout info? */ - return_timeouts = task->params.maintenancein.params.reportsupported.return_timeouts; + return_timeouts = task->params.maintenancein.params.reportsupported.return_timeouts; /* Size of descriptor depends on whether timeout included. */ desc_size = sizeof (struct scsi_command_descriptor); @@ -608,7 +606,7 @@ scsi_maintenancein_datain_unmarshall(struct scsi_task *task) desc_size += sizeof (struct scsi_op_timeout_descriptor); } rsoc->num_descriptors = len / desc_size; - + desc = &rsoc->descriptors[0]; datain = (struct scsi_command_descriptor *)&task->datain.data[4]; @@ -619,9 +617,9 @@ scsi_maintenancein_datain_unmarshall(struct scsi_task *task) if (return_timeouts) { desc->to[0].descriptor_length = ntohs(datain->to[0].descriptor_length); desc->to[0].command_specific = datain->to[0].command_specific; - desc->to[0].nominal_processing_timeout + desc->to[0].nominal_processing_timeout = ntohl(datain->to[0].nominal_processing_timeout); - desc->to[0].recommended_timeout + desc->to[0].recommended_timeout = ntohl(datain->to[0].recommended_timeout); } desc = (struct scsi_command_descriptor *)((char *)desc + desc_size); @@ -1812,7 +1810,7 @@ scsi_modesense_datain_unmarshall(struct scsi_task *task) pos = 4 + ms->block_descriptor_length; while (pos < task->datain.size) { struct scsi_mode_page *mp; - + mp = scsi_malloc(task, sizeof(struct scsi_mode_page)); if (mp == NULL) { return ms; @@ -1875,7 +1873,7 @@ scsi_cdb_startstopunit(int immed, int pcm, int pc, int no_flush, int loej, int s if (immed) { task->cdb[1] |= 0x01; } - task->cdb[3] |= pcm & 0x0f; + task->cdb[3] |= pcm & 0x0f; task->cdb[4] |= (pc << 4) & 0xf0; if (no_flush) { task->cdb[4] |= 0x04; @@ -2545,7 +2543,7 @@ scsi_task_get_data_in_buffer(struct scsi_task *task, uint32_t pos, ssize_t *coun /* someone issued a read but did not provide enough user buffers for all the data. * maybe someone tried to read just 512 bytes off a MMC device? */ - return NULL; + return NULL; } } @@ -2555,4 +2553,3 @@ scsi_task_get_data_in_buffer(struct scsi_task *task, uint32_t pos, ssize_t *coun return &sdb->data[pos]; } - From d95e811ccf7d584262fc007e369b77d0dee55932 Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 21:34:08 +0100 Subject: [PATCH 03/25] scsi-lowlevel: remove scsi_read6_params Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 5 ----- lib/scsi-lowlevel.c | 3 --- 2 files changed, 8 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index 88b8682..5f0c739 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,10 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_read6_params { - uint32_t lba; - uint32_t num_blocks; -}; struct scsi_read10_params { uint32_t lba; uint32_t num_blocks; @@ -316,7 +312,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_read6_params read6; struct scsi_read10_params read10; struct scsi_read12_params read12; struct scsi_read16_params read16; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index cf7be32..fe6218d 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -1024,9 +1024,6 @@ scsi_cdb_read6(uint32_t lba, uint32_t xferlen, int blocksize) } task->expxferlen = xferlen; - task->params.read6.lba = lba; - task->params.read6.num_blocks = num_blocks; - return task; } From f955449ecc4367bfaca72397b67f97d2065b0bd3 Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 21:35:37 +0100 Subject: [PATCH 04/25] scsi-lowlevel: remove scsi_read10_params Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 5 ----- lib/scsi-lowlevel.c | 3 --- 2 files changed, 8 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index 5f0c739..ccda6cb 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,10 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_read10_params { - uint32_t lba; - uint32_t num_blocks; -}; struct scsi_read12_params { uint32_t lba; uint32_t num_blocks; @@ -312,7 +308,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_read10_params read10; struct scsi_read12_params read12; struct scsi_read16_params read16; struct scsi_write10_params write10; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index fe6218d..cfbb6b5 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -1067,9 +1067,6 @@ scsi_cdb_read10(uint32_t lba, uint32_t xferlen, int blocksize, int rdprotect, in } task->expxferlen = xferlen; - task->params.read10.lba = lba; - task->params.read10.num_blocks = xferlen/blocksize; - return task; } From 17eff2d8d9a95f841d28b6436cd0b9ef3212f86a Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 21:37:05 +0100 Subject: [PATCH 05/25] scsi-lowlevel: remove scsi_read12_params Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 5 ----- lib/scsi-lowlevel.c | 3 --- 2 files changed, 8 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index ccda6cb..72763b3 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,10 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_read12_params { - uint32_t lba; - uint32_t num_blocks; -}; struct scsi_read16_params { uint64_t lba; uint32_t num_blocks; @@ -308,7 +304,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_read12_params read12; struct scsi_read16_params read16; struct scsi_write10_params write10; struct scsi_write12_params write12; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index cfbb6b5..283b2af 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -1110,9 +1110,6 @@ scsi_cdb_read12(uint32_t lba, uint32_t xferlen, int blocksize, int rdprotect, in } task->expxferlen = xferlen; - task->params.read12.lba = lba; - task->params.read12.num_blocks = xferlen/blocksize; - return task; } From daed6117c84d555f4cdf9dc6fa4e65c5d5b4948d Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 21:38:35 +0100 Subject: [PATCH 06/25] scsi-lowlevel: remove scsi_read16_params Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 5 ----- lib/scsi-lowlevel.c | 3 --- 2 files changed, 8 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index 72763b3..3b7b4e2 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,10 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_read16_params { - uint64_t lba; - uint32_t num_blocks; -}; struct scsi_write10_params { uint32_t lba; uint32_t num_blocks; @@ -304,7 +300,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_read16_params read16; struct scsi_write10_params write10; struct scsi_write12_params write12; struct scsi_write16_params write16; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index 283b2af..44fae9f 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -1154,9 +1154,6 @@ scsi_cdb_read16(uint64_t lba, uint32_t xferlen, int blocksize, int rdprotect, in } task->expxferlen = xferlen; - task->params.read16.lba = lba; - task->params.read16.num_blocks = xferlen/blocksize; - return task; } From 1ca5f447fca19632d4a426af983ed8eb1b3c6ab3 Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 21:40:27 +0100 Subject: [PATCH 07/25] scsi-lowlevel: remove scsi_write10_params Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 5 ----- lib/scsi-lowlevel.c | 3 --- 2 files changed, 8 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index 3b7b4e2..5545921 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,10 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_write10_params { - uint32_t lba; - uint32_t num_blocks; -}; struct scsi_write12_params { uint32_t lba; uint32_t num_blocks; @@ -300,7 +296,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_write10_params write10; struct scsi_write12_params write12; struct scsi_write16_params write16; struct scsi_startstopunit_params startstopunit; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index 44fae9f..15be3ae 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -1197,9 +1197,6 @@ scsi_cdb_write10(uint32_t lba, uint32_t xferlen, int blocksize, int wrprotect, i } task->expxferlen = xferlen; - task->params.write10.lba = lba; - task->params.write10.num_blocks = xferlen/blocksize; - return task; } From f95d86f7627c78233d9f1275a9a98ebe238bc4e4 Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 21:41:53 +0100 Subject: [PATCH 08/25] scsi-lowlevel: remove scsi_write12_params Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 5 ----- lib/scsi-lowlevel.c | 3 --- 2 files changed, 8 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index 5545921..06695b9 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,10 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_write12_params { - uint32_t lba; - uint32_t num_blocks; -}; struct scsi_write16_params { uint64_t lba; uint32_t num_blocks; @@ -296,7 +292,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_write12_params write12; struct scsi_write16_params write16; struct scsi_startstopunit_params startstopunit; struct scsi_preventallow_params preventallow; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index 15be3ae..005beca 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -1240,9 +1240,6 @@ scsi_cdb_write12(uint32_t lba, uint32_t xferlen, int blocksize, int wrprotect, i } task->expxferlen = xferlen; - task->params.write12.lba = lba; - task->params.write12.num_blocks = xferlen/blocksize; - return task; } From 3ec1a2147fbc8885b5920c24f061db26e795a8e9 Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 21:43:15 +0100 Subject: [PATCH 09/25] scsi-lowlevel: remove scsi_write16_params Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 5 ----- lib/scsi-lowlevel.c | 3 --- 2 files changed, 8 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index 06695b9..bdf590b 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,10 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_write16_params { - uint64_t lba; - uint32_t num_blocks; -}; struct scsi_startstopunit_params { int immed; int pcm; @@ -292,7 +288,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_write16_params write16; struct scsi_startstopunit_params startstopunit; struct scsi_preventallow_params preventallow; struct scsi_orwrite_params orwrite; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index 005beca..dbb1d24 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -1284,9 +1284,6 @@ scsi_cdb_write16(uint64_t lba, uint32_t xferlen, int blocksize, int wrprotect, i } task->expxferlen = xferlen; - task->params.write16.lba = lba; - task->params.write16.num_blocks = xferlen/blocksize; - return task; } From a02cd53cfcfa19d059b59c5155e7c1eb35e2a065 Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 21:45:02 +0100 Subject: [PATCH 10/25] scsi-lowlevel: remove scsi_startstopunit_params Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 9 --------- lib/scsi-lowlevel.c | 7 ------- 2 files changed, 16 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index bdf590b..d25f905 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,14 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_startstopunit_params { - int immed; - int pcm; - int pc; - int no_flush; - int loej; - int start; -}; struct scsi_preventallow_params { int prevent; }; @@ -288,7 +280,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_startstopunit_params startstopunit; struct scsi_preventallow_params preventallow; struct scsi_orwrite_params orwrite; struct scsi_compareandwrite_params compareandwrite; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index dbb1d24..2f70aa9 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -1869,13 +1869,6 @@ scsi_cdb_startstopunit(int immed, int pcm, int pc, int no_flush, int loej, int s task->xfer_dir = SCSI_XFER_NONE; task->expxferlen = 0; - task->params.startstopunit.immed = immed; - task->params.startstopunit.pcm = pcm; - task->params.startstopunit.pc = pc; - task->params.startstopunit.no_flush = no_flush; - task->params.startstopunit.loej = loej; - task->params.startstopunit.start = start; - return task; } From 8f513c23f5ae34302fbb804f17267bdeb4465cc4 Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 21:46:52 +0100 Subject: [PATCH 11/25] scsi-lowlevel: remove scsi_preventallow_params Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 4 ---- lib/scsi-lowlevel.c | 2 -- 2 files changed, 6 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index d25f905..9075d04 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,9 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_preventallow_params { - int prevent; -}; struct scsi_orwrite_params { uint64_t lba; uint32_t num_blocks; @@ -280,7 +277,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_preventallow_params preventallow; struct scsi_orwrite_params orwrite; struct scsi_compareandwrite_params compareandwrite; struct scsi_writeverify10_params writeverify10; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index 2f70aa9..667c4ec 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -1894,8 +1894,6 @@ scsi_cdb_preventallow(int prevent) task->xfer_dir = SCSI_XFER_NONE; task->expxferlen = 0; - task->params.preventallow.prevent = prevent; - return task; } From 9f7f7f1e0d6a8b38dc709d2c98a205f9751ff7c8 Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 21:48:17 +0100 Subject: [PATCH 12/25] scsi-lowlevel: remove scsi_orwrite_params Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 5 ----- lib/scsi-lowlevel.c | 3 --- 2 files changed, 8 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index 9075d04..f6891b7 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,10 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_orwrite_params { - uint64_t lba; - uint32_t num_blocks; -}; struct scsi_compareandwrite_params { uint64_t lba; uint32_t num_blocks; @@ -277,7 +273,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_orwrite_params orwrite; struct scsi_compareandwrite_params compareandwrite; struct scsi_writeverify10_params writeverify10; struct scsi_writeverify12_params writeverify12; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index 667c4ec..289b804 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -1328,9 +1328,6 @@ scsi_cdb_orwrite(uint64_t lba, uint32_t xferlen, int blocksize, int wrprotect, i } task->expxferlen = xferlen; - task->params.orwrite.lba = lba; - task->params.orwrite.num_blocks = xferlen/blocksize; - return task; } From 8169c3e280e51b86fc1a6eb3f3511273b9f3675e Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 21:51:10 +0100 Subject: [PATCH 13/25] scsi-lowlevel: remove scsi_compareandwrite_params Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 5 ----- lib/scsi-lowlevel.c | 3 --- 2 files changed, 8 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index f6891b7..e14cd9f 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,10 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_compareandwrite_params { - uint64_t lba; - uint32_t num_blocks; -}; struct scsi_writeverify10_params { uint32_t lba; uint32_t num_blocks; @@ -273,7 +269,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_compareandwrite_params compareandwrite; struct scsi_writeverify10_params writeverify10; struct scsi_writeverify12_params writeverify12; struct scsi_writeverify16_params writeverify16; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index 289b804..4fa13bb 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -1371,9 +1371,6 @@ scsi_cdb_compareandwrite(uint64_t lba, uint32_t xferlen, int blocksize, int wrpr } task->expxferlen = xferlen; - task->params.compareandwrite.lba = lba; - task->params.compareandwrite.num_blocks = xferlen/blocksize; - return task; } From fff2527cda32b5dfc688cfb642f3c8f641a651ee Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 21:52:34 +0100 Subject: [PATCH 14/25] scsi-lowlevel: remove scsi_writeverify10_params Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 5 ----- lib/scsi-lowlevel.c | 3 --- 2 files changed, 8 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index e14cd9f..c18ff1d 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,10 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_writeverify10_params { - uint32_t lba; - uint32_t num_blocks; -}; struct scsi_writeverify12_params { uint32_t lba; uint32_t num_blocks; @@ -269,7 +265,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_writeverify10_params writeverify10; struct scsi_writeverify12_params writeverify12; struct scsi_writeverify16_params writeverify16; struct scsi_verify10_params verify10; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index 4fa13bb..7c497aa 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -2132,9 +2132,6 @@ scsi_cdb_writeverify10(uint32_t lba, uint32_t xferlen, int blocksize, int wrprot } task->expxferlen = xferlen; - task->params.writeverify10.lba = lba; - task->params.writeverify10.num_blocks = xferlen/blocksize; - return task; } From a262d07c4bddb9352deb4a496338c0b6d947a1b8 Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 21:53:44 +0100 Subject: [PATCH 15/25] scsi-lowlevel: remove scsi_writeverify12_params Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 5 ----- lib/scsi-lowlevel.c | 3 --- 2 files changed, 8 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index c18ff1d..a2477a6 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,10 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_writeverify12_params { - uint32_t lba; - uint32_t num_blocks; -}; struct scsi_writeverify16_params { uint64_t lba; uint32_t num_blocks; @@ -265,7 +261,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_writeverify12_params writeverify12; struct scsi_writeverify16_params writeverify16; struct scsi_verify10_params verify10; struct scsi_verify12_params verify12; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index 7c497aa..aff626a 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -2172,9 +2172,6 @@ scsi_cdb_writeverify12(uint32_t lba, uint32_t xferlen, int blocksize, int wrprot } task->expxferlen = xferlen; - task->params.writeverify12.lba = lba; - task->params.writeverify12.num_blocks = xferlen/blocksize; - return task; } From 1dbdd0479513539f46bb458c818159b38ed84f45 Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 21:55:01 +0100 Subject: [PATCH 16/25] scsi-lowlevel: remove scsi_writeverify16_params Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 5 ----- lib/scsi-lowlevel.c | 3 --- 2 files changed, 8 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index a2477a6..14702f0 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,10 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_writeverify16_params { - uint64_t lba; - uint32_t num_blocks; -}; struct scsi_verify10_params { uint32_t lba; uint32_t num_blocks; @@ -261,7 +257,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_writeverify16_params writeverify16; struct scsi_verify10_params verify10; struct scsi_verify12_params verify12; struct scsi_verify16_params verify16; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index aff626a..80d0dff 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -2213,9 +2213,6 @@ scsi_cdb_writeverify16(uint64_t lba, uint32_t xferlen, int blocksize, int wrprot } task->expxferlen = xferlen; - task->params.writeverify16.lba = lba; - task->params.writeverify16.num_blocks = xferlen/blocksize; - return task; } From 10fd2f560b9a041545fc5742949151a475bd6d3c Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 21:57:00 +0100 Subject: [PATCH 17/25] scsi-lowlevel: remove scsi_verify10_params Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 8 -------- lib/scsi-lowlevel.c | 6 ------ 2 files changed, 14 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index 14702f0..46328ab 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,13 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_verify10_params { - uint32_t lba; - uint32_t num_blocks; - int vprotect; - int dpo; - int bytchk; -}; struct scsi_verify12_params { uint32_t lba; uint32_t num_blocks; @@ -257,7 +250,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_verify10_params verify10; struct scsi_verify12_params verify12; struct scsi_verify16_params verify16; struct scsi_readcapacity10_params readcapacity10; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index 80d0dff..a559757 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -1411,12 +1411,6 @@ scsi_cdb_verify10(uint32_t lba, uint32_t xferlen, int vprotect, int dpo, int byt } task->expxferlen = xferlen; - task->params.verify10.lba = lba; - task->params.verify10.num_blocks = xferlen/blocksize; - task->params.verify10.vprotect = vprotect; - task->params.verify10.dpo = dpo; - task->params.verify10.bytchk = bytchk; - return task; } From de67d86e6413c0551a313897842457c6e3883578 Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 21:58:30 +0100 Subject: [PATCH 18/25] scsi-lowlevel: remove scsi_verify12_params Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 8 -------- lib/scsi-lowlevel.c | 6 ------ 2 files changed, 14 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index 46328ab..ddb82b8 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,13 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_verify12_params { - uint32_t lba; - uint32_t num_blocks; - int vprotect; - int dpo; - int bytchk; -}; struct scsi_verify16_params { uint64_t lba; uint32_t num_blocks; @@ -250,7 +243,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_verify12_params verify12; struct scsi_verify16_params verify16; struct scsi_readcapacity10_params readcapacity10; struct scsi_inquiry_params inquiry; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index a559757..7021173 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -1451,12 +1451,6 @@ scsi_cdb_verify12(uint32_t lba, uint32_t xferlen, int vprotect, int dpo, int byt } task->expxferlen = xferlen; - task->params.verify12.lba = lba; - task->params.verify12.num_blocks = xferlen/blocksize; - task->params.verify12.vprotect = vprotect; - task->params.verify12.dpo = dpo; - task->params.verify12.bytchk = bytchk; - return task; } From 188505a72d53952385f80a888585f84bb9008abe Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 21:59:42 +0100 Subject: [PATCH 19/25] scsi-lowlevel: remove scsi_verify16_params Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 8 -------- lib/scsi-lowlevel.c | 6 ------ 2 files changed, 14 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index ddb82b8..eb21049 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,13 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_verify16_params { - uint64_t lba; - uint32_t num_blocks; - int vprotect; - int dpo; - int bytchk; -}; struct scsi_readcapacity10_params { int lba; int pmi; @@ -243,7 +236,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_verify16_params verify16; struct scsi_readcapacity10_params readcapacity10; struct scsi_inquiry_params inquiry; struct scsi_modesense6_params modesense6; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index 7021173..203b3c0 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -1492,12 +1492,6 @@ scsi_cdb_verify16(uint64_t lba, uint32_t xferlen, int vprotect, int dpo, int byt } task->expxferlen = xferlen; - task->params.verify16.lba = lba; - task->params.verify16.num_blocks = xferlen/blocksize; - task->params.verify16.vprotect = vprotect; - task->params.verify16.dpo = dpo; - task->params.verify16.bytchk = bytchk; - return task; } From b5a9ba6159d8957bb59da77b46d1b3cf31cce211 Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 22:04:57 +0100 Subject: [PATCH 20/25] scsi-lowlevel: remove scsi_readcapacity10_params Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 5 ----- lib/scsi-lowlevel.c | 10 ---------- 2 files changed, 15 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index eb21049..5f8d646 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,10 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_readcapacity10_params { - int lba; - int pmi; -}; struct scsi_inquiry_params { int evpd; int page_code; @@ -236,7 +232,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_readcapacity10_params readcapacity10; struct scsi_inquiry_params inquiry; struct scsi_modesense6_params modesense6; struct scsi_serviceactionin_params serviceactionin; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index 203b3c0..4f979a5 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -262,7 +262,6 @@ scsi_reportluns_datain_unmarshall(struct scsi_task *task) return list; } - /* * READCAPACITY10 */ @@ -289,14 +288,9 @@ scsi_cdb_readcapacity10(int lba, int pmi) task->xfer_dir = SCSI_XFER_READ; task->expxferlen = 8; - task->params.readcapacity10.lba = lba; - task->params.readcapacity10.pmi = pmi; - return task; } - - /* * READTOC */ @@ -702,10 +696,6 @@ scsi_readcapacity10_datain_unmarshall(struct scsi_task *task) return rc10; } - - - - /* * INQUIRY */ From 5f414317dc9813e70fdf61cdf4b4f001636f7e77 Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 22:46:04 +0100 Subject: [PATCH 21/25] scsi-lowlevel: remove scsi_inquiry_params and refactor INQUIRY data-in unmarshalling Split the INQUIRY data-in unmarshalling into smaller chunks, fixing some potential memory leaks along the way. Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 5 - lib/scsi-lowlevel.c | 457 ++++++++++++++++++++++------------------ 2 files changed, 250 insertions(+), 212 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index 5f8d646..156da26 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,10 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_inquiry_params { - int evpd; - int page_code; -}; struct scsi_modesense6_params { int dbd; int pc; @@ -232,7 +228,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_inquiry_params inquiry; struct scsi_modesense6_params modesense6; struct scsi_serviceactionin_params serviceactionin; struct scsi_readtoc_params readtoc; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index 4f979a5..640f9f5 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -728,12 +728,21 @@ scsi_cdb_inquiry(int evpd, int page_code, int alloc_len) } task->expxferlen = alloc_len; - task->params.inquiry.evpd = evpd; - task->params.inquiry.page_code = page_code; - return task; } +static inline int +scsi_inquiry_evpd_set(const struct scsi_task *task) +{ + return task->cdb[1] & 0x1; +} + +static inline uint8_t +scsi_inquiry_page_code(const struct scsi_task *task) +{ + return task->cdb[2]; +} + /* * parse the data in blob and calculate the size of a full * inquiry datain structure @@ -741,11 +750,11 @@ scsi_cdb_inquiry(int evpd, int page_code, int alloc_len) static int scsi_inquiry_datain_getfullsize(struct scsi_task *task) { - if (task->params.inquiry.evpd == 0) { + if (scsi_inquiry_evpd_set(task) == 0) { return task->datain.data[4] + 5; } - switch (task->params.inquiry.page_code) { + switch (scsi_inquiry_page_code(task)) { case SCSI_INQUIRY_PAGECODE_SUPPORTED_VPD_PAGES: case SCSI_INQUIRY_PAGECODE_BLOCK_DEVICE_CHARACTERISTICS: case SCSI_INQUIRY_PAGECODE_UNIT_SERIAL_NUMBER: @@ -759,217 +768,251 @@ scsi_inquiry_datain_getfullsize(struct scsi_task *task) } } +static struct scsi_inquiry_standard * +scsi_inquiry_unmarshall_standard(struct scsi_task *task) +{ + struct scsi_inquiry_standard *inq = scsi_malloc(task, sizeof(*inq)); + if (inq == NULL) { + return NULL; + } + + inq->qualifier = (task->datain.data[0]>>5)&0x07; + inq->device_type = task->datain.data[0]&0x1f; + inq->rmb = !!(task->datain.data[1]&0x80); + inq->version = task->datain.data[2]; + inq->normaca = !!(task->datain.data[3]&0x20); + inq->hisup = !!(task->datain.data[3]&0x10); + inq->response_data_format = task->datain.data[3]&0x0f; + + inq->additional_length = task->datain.data[4]; + + inq->sccs = !!(task->datain.data[5]&0x80); + inq->acc = !!(task->datain.data[5]&0x40); + inq->tpgs = (task->datain.data[5]>>4)&0x03; + inq->threepc = !!(task->datain.data[5]&0x08); + inq->protect = !!(task->datain.data[5]&0x01); + + inq->encserv = !!(task->datain.data[6]&0x40); + inq->multip = !!(task->datain.data[6]&0x10); + inq->addr16 = !!(task->datain.data[6]&0x01); + inq->wbus16 = !!(task->datain.data[7]&0x20); + inq->sync = !!(task->datain.data[7]&0x10); + inq->cmdque = !!(task->datain.data[7]&0x02); + + memcpy(&inq->vendor_identification[0], + &task->datain.data[8], 8); + memcpy(&inq->product_identification[0], + &task->datain.data[16], 16); + memcpy(&inq->product_revision_level[0], + &task->datain.data[32], 4); + + inq->clocking = (task->datain.data[56]>>2)&0x03; + inq->qas = !!(task->datain.data[56]&0x02); + inq->ius = !!(task->datain.data[56]&0x01); + + return inq; +} + +static struct scsi_inquiry_supported_pages * +scsi_inquiry_unmarshall_supported_pages(struct scsi_task *task) +{ + struct scsi_inquiry_supported_pages *inq = scsi_malloc(task, + sizeof(*inq)); + if (inq == NULL) { + return NULL; + } + inq->qualifier = (task->datain.data[0]>>5)&0x07; + inq->device_type = task->datain.data[0]&0x1f; + inq->pagecode = task->datain.data[1]; + + inq->num_pages = task->datain.data[3]; + inq->pages = scsi_malloc(task, inq->num_pages); + if (inq->pages == NULL) { + free (inq); + return NULL; + } + memcpy(inq->pages, &task->datain.data[4], inq->num_pages); + return inq; +} + +static struct scsi_inquiry_unit_serial_number * +scsi_inquiry_unmarshall_unit_serial_number(struct scsi_task* task) +{ + struct scsi_inquiry_unit_serial_number *inq = scsi_malloc(task, + sizeof(*inq)); + if (inq == NULL) { + return NULL; + } + inq->qualifier = (task->datain.data[0]>>5)&0x07; + inq->device_type = task->datain.data[0]&0x1f; + inq->pagecode = task->datain.data[1]; + + inq->usn = scsi_malloc(task, task->datain.data[3]+1); + if (inq->usn == NULL) { + free(inq); + return NULL; + } + memcpy(inq->usn, &task->datain.data[4], task->datain.data[3]); + inq->usn[task->datain.data[3]] = 0; + return inq; +} + +static struct scsi_inquiry_device_identification * +scsi_inquiry_unmarshall_device_identification(struct scsi_task *task) +{ + struct scsi_inquiry_device_identification *inq = scsi_malloc(task, + sizeof(*inq)); + int remaining = ntohs(*(uint16_t *)&task->datain.data[2]); + unsigned char *dptr; + + if (inq == NULL) { + return NULL; + } + inq->qualifier = (task->datain.data[0]>>5)&0x07; + inq->device_type = task->datain.data[0]&0x1f; + inq->pagecode = task->datain.data[1]; + + dptr = &task->datain.data[4]; + while (remaining > 0) { + struct scsi_inquiry_device_designator *dev = + scsi_malloc(task, sizeof(*dev)); + if (dev == NULL) { + goto err; + } + + dev->next = inq->designators; + inq->designators = dev; + + dev->protocol_identifier = (dptr[0]>>4) & 0x0f; + dev->code_set = dptr[0] & 0x0f; + dev->piv = !!(dptr[1]&0x80); + dev->association = (dptr[1]>>4)&0x03; + dev->designator_type = dptr[1]&0x0f; + + dev->designator_length = dptr[3]; + dev->designator = scsi_malloc(task, dev->designator_length + 1); + if (dev->designator == NULL) { + goto err; + } + dev->designator[dev->designator_length] = 0; + memcpy(dev->designator, &dptr[4], + dev->designator_length); + + remaining -= 4; + remaining -= dev->designator_length; + + dptr += dev->designator_length + 4; + } + return inq; + + err: + while (inq->designators) { + struct scsi_inquiry_device_designator *dev = inq->designators; + inq->designators = dev->next; + free(dev->designator); + free(dev); + } + + free(inq); + return NULL; +} + +static struct scsi_inquiry_block_limits * +scsi_inquiry_unmarshall_block_limits(struct scsi_task *task) +{ + struct scsi_inquiry_block_limits *inq = scsi_malloc(task, + sizeof(*inq)); + if (inq == NULL) { + return NULL; + } + inq->qualifier = (task->datain.data[0]>>5)&0x07; + inq->device_type = task->datain.data[0]&0x1f; + inq->pagecode = task->datain.data[1]; + + inq->wsnz = task->datain.data[4] & 0x01; + inq->max_cmp = task->datain.data[5]; + inq->opt_gran = ntohs(*(uint16_t *)&task->datain.data[6]); + inq->max_xfer_len = ntohl(*(uint32_t *)&task->datain.data[8]); + inq->opt_xfer_len = ntohl(*(uint32_t *)&task->datain.data[12]); + inq->max_prefetch = ntohl(*(uint32_t *)&task->datain.data[16]); + inq->max_unmap = ntohl(*(uint32_t *)&task->datain.data[20]); + inq->max_unmap_bdc = ntohl(*(uint32_t *)&task->datain.data[24]); + inq->opt_unmap_gran = ntohl(*(uint32_t *)&task->datain.data[28]); + inq->ugavalid = !!(task->datain.data[32]&0x80); + inq->unmap_gran_align = ntohl(*(uint32_t *)&task->datain.data[32]) & 0x7fffffff; + inq->max_ws_len = ntohl(*(uint32_t *)&task->datain.data[36]); + inq->max_ws_len = (inq->max_ws_len << 32) | ntohl(*(uint32_t *)&task->datain.data[40]); + + return inq; +} + +static struct scsi_inquiry_block_device_characteristics * +scsi_inquiry_unmarshall_block_device_characteristics(struct scsi_task *task) +{ + struct scsi_inquiry_block_device_characteristics *inq = + scsi_malloc(task, sizeof(*inq)); + if (inq == NULL) { + return NULL; + } + inq->qualifier = (task->datain.data[0]>>5)&0x07; + inq->device_type = task->datain.data[0]&0x1f; + inq->pagecode = task->datain.data[1]; + + inq->medium_rotation_rate = ntohs(*(uint16_t *)&task->datain.data[4]); + return inq; +} + +struct scsi_inquiry_logical_block_provisioning * +scsi_inquiry_unmarshall_logical_block_provisioning(struct scsi_task *task) +{ + struct scsi_inquiry_logical_block_provisioning *inq = + scsi_malloc(task, sizeof(*inq)); + if (inq == NULL) { + return NULL; + } + inq->qualifier = (task->datain.data[0]>>5)&0x07; + inq->device_type = task->datain.data[0]&0x1f; + inq->pagecode = task->datain.data[1]; + + inq->threshold_exponent = task->datain.data[4]; + inq->lbpu = !!(task->datain.data[5] & 0x80); + inq->lbpws = !!(task->datain.data[5] & 0x40); + inq->lbpws10 = !!(task->datain.data[5] & 0x20); + inq->lbprz = !!(task->datain.data[5] & 0x04); + inq->anc_sup = !!(task->datain.data[5] & 0x02); + inq->dp = !!(task->datain.data[5] & 0x01); + inq->provisioning_type = task->datain.data[6] & 0x07; + + return inq; +} + /* * unmarshall the data in blob for inquiry into a structure */ static void * scsi_inquiry_datain_unmarshall(struct scsi_task *task) { - if (task->params.inquiry.evpd == 0) { - struct scsi_inquiry_standard *inq; - - /* standard inquiry */ - inq = scsi_malloc(task, sizeof(struct scsi_inquiry_standard)); - if (inq == NULL) { - return NULL; - } - - inq->qualifier = (task->datain.data[0]>>5)&0x07; - inq->device_type = task->datain.data[0]&0x1f; - inq->rmb = !!(task->datain.data[1]&0x80); - inq->version = task->datain.data[2]; - inq->normaca = !!(task->datain.data[3]&0x20); - inq->hisup = !!(task->datain.data[3]&0x10); - inq->response_data_format = task->datain.data[3]&0x0f; - - inq->additional_length = task->datain.data[4]; - - inq->sccs = !!(task->datain.data[5]&0x80); - inq->acc = !!(task->datain.data[5]&0x40); - inq->tpgs = (task->datain.data[5]>>4)&0x03; - inq->threepc = !!(task->datain.data[5]&0x08); - inq->protect = !!(task->datain.data[5]&0x01); - - inq->encserv = !!(task->datain.data[6]&0x40); - inq->multip = !!(task->datain.data[6]&0x10); - inq->addr16 = !!(task->datain.data[6]&0x01); - inq->wbus16 = !!(task->datain.data[7]&0x20); - inq->sync = !!(task->datain.data[7]&0x10); - inq->cmdque = !!(task->datain.data[7]&0x02); - - memcpy(&inq->vendor_identification[0], - &task->datain.data[8], 8); - memcpy(&inq->product_identification[0], - &task->datain.data[16], 16); - memcpy(&inq->product_revision_level[0], - &task->datain.data[32], 4); - - inq->clocking = (task->datain.data[56]>>2)&0x03; - inq->qas = !!(task->datain.data[56]&0x02); - inq->ius = !!(task->datain.data[56]&0x01); - - return inq; + if (scsi_inquiry_evpd_set(task) == 0) { + return scsi_inquiry_unmarshall_standard(task); } - if (task->params.inquiry.page_code - == SCSI_INQUIRY_PAGECODE_SUPPORTED_VPD_PAGES) { - struct scsi_inquiry_supported_pages *inq; - - inq = scsi_malloc(task, - sizeof(struct scsi_inquiry_supported_pages)); - if (inq == NULL) { - return NULL; - } - inq->qualifier = (task->datain.data[0]>>5)&0x07; - inq->device_type = task->datain.data[0]&0x1f; - inq->pagecode = task->datain.data[1]; - - inq->num_pages = task->datain.data[3]; - inq->pages = scsi_malloc(task, inq->num_pages); - if (inq->pages == NULL) { - return NULL; - } - memcpy(inq->pages, &task->datain.data[4], inq->num_pages); - return inq; - } else if (task->params.inquiry.page_code - == SCSI_INQUIRY_PAGECODE_UNIT_SERIAL_NUMBER) { - struct scsi_inquiry_unit_serial_number *inq; - - inq = scsi_malloc(task, - sizeof(struct scsi_inquiry_unit_serial_number)); - if (inq == NULL) { - return NULL; - } - inq->qualifier = (task->datain.data[0]>>5)&0x07; - inq->device_type = task->datain.data[0]&0x1f; - inq->pagecode = task->datain.data[1]; - - inq->usn = scsi_malloc(task, task->datain.data[3]+1); - if (inq->usn == NULL) { - return NULL; - } - memcpy(inq->usn, &task->datain.data[4], task->datain.data[3]); - inq->usn[task->datain.data[3]] = 0; - return inq; - } else if (task->params.inquiry.page_code - == SCSI_INQUIRY_PAGECODE_DEVICE_IDENTIFICATION) { - struct scsi_inquiry_device_identification *inq; - int remaining = ntohs(*(uint16_t *)&task->datain.data[2]); - unsigned char *dptr; - - inq = scsi_malloc(task, - sizeof(struct scsi_inquiry_device_identification)); - if (inq == NULL) { - return NULL; - } - inq->qualifier = (task->datain.data[0]>>5)&0x07; - inq->device_type = task->datain.data[0]&0x1f; - inq->pagecode = task->datain.data[1]; - - dptr = &task->datain.data[4]; - while (remaining > 0) { - struct scsi_inquiry_device_designator *dev; - - dev = scsi_malloc(task, - sizeof(struct scsi_inquiry_device_designator)); - if (dev == NULL) { - return NULL; - } - - dev->next = inq->designators; - inq->designators = dev; - - dev->protocol_identifier = (dptr[0]>>4) & 0x0f; - dev->code_set = dptr[0] & 0x0f; - dev->piv = !!(dptr[1]&0x80); - dev->association = (dptr[1]>>4)&0x03; - dev->designator_type = dptr[1]&0x0f; - - dev->designator_length = dptr[3]; - dev->designator = scsi_malloc(task, - dev->designator_length+1); - if (dev->designator == NULL) { - return NULL; - } - dev->designator[dev->designator_length] = 0; - memcpy(dev->designator, &dptr[4], - dev->designator_length); - - remaining -= 4; - remaining -= dev->designator_length; - - dptr += dev->designator_length + 4; - } - return inq; - } else if (task->params.inquiry.page_code - == SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS) { - struct scsi_inquiry_block_limits *inq; - - inq = scsi_malloc(task, - sizeof(struct scsi_inquiry_block_limits)); - if (inq == NULL) { - return NULL; - } - inq->qualifier = (task->datain.data[0]>>5)&0x07; - inq->device_type = task->datain.data[0]&0x1f; - inq->pagecode = task->datain.data[1]; - - inq->wsnz = task->datain.data[4] & 0x01; - inq->max_cmp = task->datain.data[5]; - inq->opt_gran = ntohs(*(uint16_t *)&task->datain.data[6]); - inq->max_xfer_len = ntohl(*(uint32_t *)&task->datain.data[8]); - inq->opt_xfer_len = ntohl(*(uint32_t *)&task->datain.data[12]); - inq->max_prefetch = ntohl(*(uint32_t *)&task->datain.data[16]); - inq->max_unmap = ntohl(*(uint32_t *)&task->datain.data[20]); - inq->max_unmap_bdc = ntohl(*(uint32_t *)&task->datain.data[24]); - inq->opt_unmap_gran = ntohl(*(uint32_t *)&task->datain.data[28]); - inq->ugavalid = !!(task->datain.data[32]&0x80); - inq->unmap_gran_align = ntohl(*(uint32_t *)&task->datain.data[32]) & 0x7fffffff; - inq->max_ws_len = ntohl(*(uint32_t *)&task->datain.data[36]); - inq->max_ws_len = (inq->max_ws_len << 32) | ntohl(*(uint32_t *)&task->datain.data[40]); - - return inq; - } else if (task->params.inquiry.page_code - == SCSI_INQUIRY_PAGECODE_BLOCK_DEVICE_CHARACTERISTICS) { - struct scsi_inquiry_block_device_characteristics *inq; - - inq = scsi_malloc(task, - sizeof(struct scsi_inquiry_block_device_characteristics)); - if (inq == NULL) { - return NULL; - } - inq->qualifier = (task->datain.data[0]>>5)&0x07; - inq->device_type = task->datain.data[0]&0x1f; - inq->pagecode = task->datain.data[1]; - - inq->medium_rotation_rate = ntohs(*(uint16_t *)&task->datain.data[4]); - return inq; - } else if (task->params.inquiry.page_code - == SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING) { - struct scsi_inquiry_logical_block_provisioning *inq; - - inq = scsi_malloc(task, - sizeof(struct scsi_inquiry_logical_block_provisioning)); - if (inq == NULL) { - return NULL; - } - inq->qualifier = (task->datain.data[0]>>5)&0x07; - inq->device_type = task->datain.data[0]&0x1f; - inq->pagecode = task->datain.data[1]; - - inq->threshold_exponent = task->datain.data[4]; - inq->lbpu = !!(task->datain.data[5] & 0x80); - inq->lbpws = !!(task->datain.data[5] & 0x40); - inq->lbpws10 = !!(task->datain.data[5] & 0x20); - inq->lbprz = !!(task->datain.data[5] & 0x04); - inq->anc_sup = !!(task->datain.data[5] & 0x02); - inq->dp = !!(task->datain.data[5] & 0x01); - inq->provisioning_type = task->datain.data[6] & 0x07; - - return inq; + switch (scsi_inquiry_page_code(task)) + { + case SCSI_INQUIRY_PAGECODE_SUPPORTED_VPD_PAGES: + return scsi_inquiry_unmarshall_supported_pages(task); + case SCSI_INQUIRY_PAGECODE_UNIT_SERIAL_NUMBER: + return scsi_inquiry_unmarshall_unit_serial_number(task); + case SCSI_INQUIRY_PAGECODE_DEVICE_IDENTIFICATION: + return scsi_inquiry_unmarshall_device_identification(task); + case SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS: + return scsi_inquiry_unmarshall_block_limits(task); + case SCSI_INQUIRY_PAGECODE_BLOCK_DEVICE_CHARACTERISTICS: + return scsi_inquiry_unmarshall_block_device_characteristics(task); + case SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING: + return scsi_inquiry_unmarshall_logical_block_provisioning(task); + default: + return NULL; } - - return NULL; } /* From fa158865d2f18be4bd144122dc55bbc6e5fc3786 Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 22:47:14 +0100 Subject: [PATCH 22/25] scsi-lowlevel: remove scsi_modesense6_params Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 7 ------- lib/scsi-lowlevel.c | 5 ----- 2 files changed, 12 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index 156da26..f371755 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,12 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_modesense6_params { - int dbd; - int pc; - int page_code; - int sub_page_code; -}; struct scsi_serviceactionin_params { enum scsi_service_action_in sa; }; @@ -228,7 +222,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_modesense6_params modesense6; struct scsi_serviceactionin_params serviceactionin; struct scsi_readtoc_params readtoc; struct scsi_maintenancein_params maintenancein; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index 640f9f5..b605516 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -1684,11 +1684,6 @@ scsi_cdb_modesense6(int dbd, enum scsi_modesense_page_control pc, } task->expxferlen = alloc_len; - task->params.modesense6.dbd = dbd; - task->params.modesense6.pc = pc; - task->params.modesense6.page_code = page_code; - task->params.modesense6.sub_page_code = sub_page_code; - return task; } From 551298adfb0f0483a49122c1465fbd8f8630d61a Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 22:57:59 +0100 Subject: [PATCH 23/25] scsi-lowlevel: remove scsi_serviceactionin_params and plug potential memleaks Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 4 ---- lib/scsi-lowlevel.c | 47 +++++++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index f371755..f6e662c 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,9 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_serviceactionin_params { - enum scsi_service_action_in sa; -}; struct scsi_readtoc_params { int msf; int format; @@ -222,7 +219,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_serviceactionin_params serviceactionin; struct scsi_readtoc_params readtoc; struct scsi_maintenancein_params maintenancein; } params; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index b605516..c31b7aa 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -488,6 +488,11 @@ scsi_cdb_release6(void) return task; } +static inline uint8_t +scsi_serviceactionin_sa(const struct scsi_task *task) +{ + return task->cdb[1]; +} /* * service_action_in unmarshall @@ -495,14 +500,10 @@ scsi_cdb_release6(void) static void * scsi_serviceactionin_datain_unmarshall(struct scsi_task *task) { - struct scsi_readcapacity16 *rc16; - struct scsi_get_lba_status *gls; - int32_t len; - int i; - - switch (task->params.serviceactionin.sa) { - case SCSI_READCAPACITY16: - rc16 = scsi_malloc(task, sizeof(struct scsi_readcapacity16)); + switch (scsi_serviceactionin_sa(task)) { + case SCSI_READCAPACITY16: { + struct scsi_readcapacity16 *rc16 = scsi_malloc(task, + sizeof(*rc16)); if (rc16 == NULL) { return NULL; } @@ -517,20 +518,27 @@ scsi_serviceactionin_datain_unmarshall(struct scsi_task *task) rc16->lbprz = !!(task->datain.data[14] & 0x40); rc16->lalba = ntohs(*(uint16_t *)&(task->datain.data[14])) & 0x3fff; return rc16; - case SCSI_GET_LBA_STATUS: - len = ntohl(*(uint32_t *)&(task->datain.data[0])); + } + case SCSI_GET_LBA_STATUS: { + struct scsi_get_lba_status *gls = scsi_malloc(task, + sizeof(*gls)); + int32_t len = ntohl(*(uint32_t *)&(task->datain.data[0])); + int i; + + if (gls == NULL) { + return NULL; + } + if (len > task->datain.size - 4) { len = task->datain.size - 4; } len = len / 16; - gls = scsi_malloc(task, sizeof(struct scsi_get_lba_status)); - if (gls == NULL) { - return NULL; - } gls->num_descriptors = len; - gls->descriptors = scsi_malloc(task, sizeof(struct scsi_lba_status_descriptor) * gls->num_descriptors); + gls->descriptors = scsi_malloc(task, + sizeof(*gls->descriptors) * len); if (gls->descriptors == NULL) { + free(gls); return NULL; } @@ -546,8 +554,9 @@ scsi_serviceactionin_datain_unmarshall(struct scsi_task *task) return gls; } - - return NULL; + default: + return NULL; + } } @@ -2056,8 +2065,6 @@ scsi_cdb_serviceactionin16(enum scsi_service_action_in sa, uint32_t xferlen) } task->expxferlen = xferlen; - task->params.serviceactionin.sa = sa; - return task; } @@ -2100,8 +2107,6 @@ scsi_cdb_get_lba_status(uint64_t starting_lba, uint32_t alloc_len) } task->expxferlen = alloc_len; - task->params.serviceactionin.sa = SCSI_GET_LBA_STATUS; - return task; } From 8baa843d7327c21afc937abe7f623a223f5e7f80 Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 23:16:45 +0100 Subject: [PATCH 24/25] scsi-lowlevel: remove scsi_readtoc_params and fix READ TOC format field Set the format field in the READ TOC CDB (lower nibble of byte 2). Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 8 -------- lib/scsi-lowlevel.c | 17 ++++++++++++----- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index f6e662c..8c4fb08 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -176,13 +176,6 @@ struct scsi_readtoc_list { struct scsi_readtoc_desc desc[0]; }; -struct scsi_readtoc_params { - int msf; - int format; - int track_session; -}; - - struct scsi_report_supported_params { int return_timeouts; }; @@ -219,7 +212,6 @@ struct scsi_task { int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; union { - struct scsi_readtoc_params readtoc; struct scsi_maintenancein_params maintenancein; } params; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index c31b7aa..ba48b57 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -317,6 +317,8 @@ scsi_cdb_readtoc(int msf, int format, int track_session, uint16_t alloc_len) task->cdb[1] |= 0x02; } + task->cdb[2] = format & 0xf; + /* Prevent invalid setting of Track/Session Number */ if (format == SCSI_READ_TOC || format == SCSI_READ_FULL_TOC) { task->cdb[6] = 0xff & track_session; @@ -332,10 +334,6 @@ scsi_cdb_readtoc(int msf, int format, int track_session, uint16_t alloc_len) } task->expxferlen = alloc_len; - task->params.readtoc.msf = msf; - task->params.readtoc.format = format; - task->params.readtoc.track_session = track_session; - return task; } @@ -353,10 +351,16 @@ scsi_readtoc_datain_getfullsize(struct scsi_task *task) return toc_data_len; } +static inline enum scsi_readtoc_fmt +scsi_readtoc_format(const struct scsi_task *task) +{ + return task->cdb[2] & 0xf; +} + static void scsi_readtoc_desc_unmarshall(struct scsi_task *task, struct scsi_readtoc_list *list, int i) { - switch(task->params.readtoc.format){ + switch(scsi_readtoc_format(task)) { case SCSI_READ_TOC: list->desc[i].desc.toc.adr = task->datain.data[4+8*i+1] & 0xf0; @@ -403,8 +407,11 @@ scsi_readtoc_desc_unmarshall(struct scsi_task *task, struct scsi_readtoc_list *l list->desc[i].desc.full.pframe = task->datain.data[4+11*i+10]; break; + default: + break; } } + /* * unmarshall the data in blob for read TOC into a structure */ From 5194d13e73cf2aa295389467a44c5e50cde607c7 Mon Sep 17 00:00:00 2001 From: Arne Redlich Date: Sun, 18 Nov 2012 23:28:32 +0100 Subject: [PATCH 25/25] scsi-lowlevel: remove scsi_maintenancein_params and finally scsi_task->params too Signed-off-by: Arne Redlich --- include/scsi-lowlevel.h | 10 ---------- lib/scsi-lowlevel.c | 22 ++++++++++++++-------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index 8c4fb08..3b28b7a 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -180,13 +180,6 @@ struct scsi_report_supported_params { int return_timeouts; }; -struct scsi_maintenancein_params { - enum scsi_maintenance_in sa; - union { - struct scsi_report_supported_params reportsupported; - } params; -}; - struct scsi_sense { unsigned char error_type; enum scsi_sense_key key; @@ -211,9 +204,6 @@ struct scsi_task { int xfer_dir; int expxferlen; unsigned char cdb[SCSI_CDB_MAX_SIZE]; - union { - struct scsi_maintenancein_params maintenancein; - } params; enum scsi_residual residual_status; int residual; diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index ba48b57..9f4ffe2 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -566,6 +566,17 @@ scsi_serviceactionin_datain_unmarshall(struct scsi_task *task) } } +static inline int +scsi_maintenancein_return_timeouts(const struct scsi_task *task) +{ + return task->cdb[2] & 0x80; +} + +static inline uint8_t +scsi_maintenancein_sa(const struct scsi_task *task) +{ + return task->cdb[1]; +} /* * parse the data in blob and calculate the size of a full maintenancein @@ -575,16 +586,14 @@ static int scsi_maintenancein_datain_getfullsize(struct scsi_task *task) { - switch (task->params.maintenancein.sa) { + switch (scsi_maintenancein_sa(task)) { case SCSI_REPORT_SUPPORTED_OP_CODES: return ntohl(*(uint32_t *)&(task->datain.data[0])) + 4; default: return -1; } - } - /* * maintenance_in unmarshall */ @@ -596,7 +605,7 @@ scsi_maintenancein_datain_unmarshall(struct scsi_task *task) uint32_t len, i; int return_timeouts, desc_size; - switch (task->params.maintenancein.sa) { + switch (scsi_maintenancein_sa(task)) { case SCSI_REPORT_SUPPORTED_OP_CODES: if (task->datain.size < 4) { return NULL; @@ -608,7 +617,7 @@ scsi_maintenancein_datain_unmarshall(struct scsi_task *task) return NULL; } /* Does the descriptor include command timeout info? */ - return_timeouts = task->params.maintenancein.params.reportsupported.return_timeouts; + return_timeouts = scsi_maintenancein_return_timeouts(task); /* Size of descriptor depends on whether timeout included. */ desc_size = sizeof (struct scsi_command_descriptor); @@ -674,9 +683,6 @@ scsi_cdb_report_supported_opcodes(int return_timeouts, uint32_t alloc_len) } task->expxferlen = alloc_len; - task->params.maintenancein.sa = SCSI_REPORT_SUPPORTED_OP_CODES; - task->params.maintenancein.params.reportsupported.return_timeouts = return_timeouts; - return task; }