From b0a7ab22109f0d2049e7616c1c3a3fe693fc228c Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Wed, 29 Jan 2014 03:30:24 +0000 Subject: [PATCH] Put CDB control byte parsing in one place git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@5246 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_lib.c | 22 +++++++++++++++++++++- scst/src/scst_targ.c | 16 ---------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index c845d4f54..5f065b067 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -6687,7 +6687,7 @@ static int get_cdb_info_write_same16(struct scst_cmd *cmd, } /** - * scst_get_cdb_info_apt() - Parse ATA PASS-THROUGH CDB. + * get_cdb_info_apt() - Parse ATA PASS-THROUGH CDB. * * Parse ATA PASS-THROUGH(12) and ATA PASS-THROUGH(16). See also SAT-3 for a * detailed description of these commands. @@ -6825,6 +6825,7 @@ int scst_get_cdb_info(struct scst_cmd *cmd) int dev_type = cmd->dev->type; int i, res = 0; uint8_t op; + uint8_t control; const struct scst_sdbops *ptr = NULL; TRACE_ENTRY(); @@ -6870,6 +6871,7 @@ int scst_get_cdb_info(struct scst_cmd *cmd) } cmd->cdb_len = SCST_GET_CDB_LEN(op); + control = cmd->cdb[cmd->cdb_len - 1]; cmd->op_name = ptr->info_op_name; cmd->data_direction = ptr->info_data_direction; cmd->op_flags = ptr->info_op_flags | SCST_INFO_VALID; @@ -6879,6 +6881,24 @@ int scst_get_cdb_info(struct scst_cmd *cmd) cmd->len_len = ptr->info_len_len; res = (*ptr->get_cdb_info)(cmd, ptr); + if (unlikely(control & CONTROL_BYTE_NACA_BIT)) { + PRINT_ERROR("NACA bit in control byte CDB is not supported " + "(opcode 0x%02x)", cmd->cdb[0]); + scst_set_cmd_error(cmd, + SCST_LOAD_SENSE(scst_sense_invalid_message)); + res = 1; /* command invalid */ + goto out; + } + + if (unlikely(control & CONTROL_BYTE_LINK_BIT)) { + PRINT_ERROR("Linked commands are not supported " + "(opcode 0x%02x)", cmd->cdb[0]); + scst_set_invalid_field_in_cdb(cmd, cmd->cdb_len-1, + SCST_INVAL_FIELD_BIT_OFFS_VALID | 0); + res = 1; /* command invalid */ + goto out; + } + out: TRACE_EXIT_RES(res); return res; diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index 35be2e746..793aa3b88 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -744,22 +744,6 @@ static int scst_parse_cmd(struct scst_cmd *cmd) cmd->op_flags &= ~SCST_UNKNOWN_LENGTH; } - if (unlikely(cmd->cdb[cmd->cdb_len - 1] & CONTROL_BYTE_NACA_BIT)) { - PRINT_ERROR("NACA bit in control byte CDB is not supported " - "(opcode 0x%02x)", cmd->cdb[0]); - scst_set_cmd_error(cmd, - SCST_LOAD_SENSE(scst_sense_invalid_message)); - goto out_done; - } - - if (unlikely(cmd->cdb[cmd->cdb_len-1] & CONTROL_BYTE_LINK_BIT)) { - PRINT_ERROR("Linked commands are not supported " - "(opcode 0x%02x)", cmd->cdb[0]); - scst_set_invalid_field_in_cdb(cmd, cmd->cdb_len-1, - SCST_INVAL_FIELD_BIT_OFFS_VALID | 0); - goto out_done; - } - if (cmd->dh_data_buf_alloced && unlikely((orig_bufflen > cmd->bufflen))) { PRINT_ERROR("Dev handler supplied data buffer (size %d), "