From 1c6a617d5158236bb76e22a4d58ad461612a3ad2 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 5 Jan 2019 22:12:35 +0000 Subject: [PATCH] scst_lib: Also intercept READ CAPACITY(16) The scst_block_generic_dev_done() function parses the READ CAPACITY response. Add support for parsing the READ CAPACITY(16) response. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7863 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_lib.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 4210ac811..6c45eb287 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -12332,6 +12332,7 @@ int scst_block_generic_dev_done(struct scst_cmd *cmd, { int opcode = cmd->cdb[0]; int res = SCST_CMD_STATE_DEFAULT; + int sect_sz_off; TRACE_ENTRY(); @@ -12348,33 +12349,29 @@ int scst_block_generic_dev_done(struct scst_cmd *cmd, * simplest, yet sufficient way for that. */ - if (unlikely(opcode == READ_CAPACITY)) { + if (unlikely(opcode == READ_CAPACITY || + (opcode == SERVICE_ACTION_IN_16 && + cmd->cdb[1] == SAI_READ_CAPACITY_16))) { if (scst_cmd_completed_good(cmd)) { /* Always keep track of disk capacity */ int buffer_size, sector_size, sh; uint8_t *buffer; buffer_size = scst_get_buf_full(cmd, &buffer); - if (unlikely(buffer_size < 8)) { - if (buffer_size != 0) { - PRINT_ERROR("%s: Unable to get cmd " - "buffer (%d)", __func__, - buffer_size); - } + sect_sz_off = opcode == READ_CAPACITY ? 4 : 8; + if (buffer_size < sect_sz_off + 4) goto out; - } - - sector_size = get_unaligned_be32(&buffer[4]); + sector_size = get_unaligned_be32(&buffer[sect_sz_off]); scst_put_buf_full(cmd, buffer); - if (sector_size != 0) + if (sector_size != 0) { sh = scst_calc_block_shift(sector_size); - else - sh = 0; - set_block_shift(cmd, sh); - TRACE_DBG("block_shift %d", sh); + set_block_shift(cmd, sh); + TRACE_DBG("block_shift %d", sh); + } else { + PRINT_ERROR("Sector size in %s response is 0", + cmd->op_name); + } } - } else /* ToDo: add READ CAPACITY(16) here */ { - /* It's all good */ } TRACE_DBG("cmd->is_send_status=%x, cmd->resp_data_len=%d, "