USB: gadget: storage: reuse definitions from scsi.h header file
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 USB: gadget: storage: reuse definitions from scsi.h header file
From: Michal Nazarewicz <[email protected]>
This commit changes storage_common.h, file_storage.c and f_mass_storage.c to use definitions of SCSI commands from scsi/scsi.h file instead of redefining the commands in storage_common.c.
scsi/scsi.h header file was missing READ_FORMAT_CAPACITIES and READ_HEADER so this commit also add those to the header.
Signed-off-by Michal Nazarewicz <[email protected]>
Cc Alan Stern <[email protected]>
--- drivers/usb/gadget/f_mass_storage.c | 72 +++++++++++++++++----------------- drivers/usb/gadget/file_storage.c | 74 +++++++++++++++++----------------- drivers/usb/gadget/storage_common.c | 34 +--------------- include/scsi/scsi.h | 2 + 4 files changed, 77 insertions(+), 105 deletions(-)
drivers/usb/gadget/f_mass_storage.c +36 -36
@@ -741,7 +741,7 @@ static int do_read(struct fsg_common *common)/* Get the starting Logical Block Address and check that it's * not too big */ -if (common->cmnd[0 ] ==SC_READ_6 ) +if (common->cmnd[0 ] ==READ_6 ) lba =get_unaligned_be24 (&common->cmnd[1 ]);else { lba =get_unaligned_be32 (&common->cmnd[2 ]);
@@ -879,7 +879,7 @@ static int do_write(struct fsg_common *common)/* Get the starting Logical Block Address and check that it's * not too big */ -if (common->cmnd[0 ] ==SC_WRITE_6 ) +if (common->cmnd[0 ] ==WRITE_6 ) lba =get_unaligned_be24 (&common->cmnd[1 ]);else { lba =get_unaligned_be32 (&common->cmnd[2 ]);
@@ -1186,7 +1186,7 @@ static int do_inquiry(struct fsg_common *common, struct fsg_buffhd *bh)return 36 ; } - buf[0 ] = curlun->cdrom ?TYPE_CDROM :TYPE_DISK ; + buf[0 ] = curlun->cdrom ?TYPE_ROM :TYPE_DISK ; buf[1 ] = curlun->removable ?0x80 :0 ; buf[2 ] =2 ;/* ANSI SCSI level 2 */ buf[3 ] =2 ;/* SCSI-2 INQUIRY data format */
@@ -1353,11 +1353,11 @@ static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh)* The only variable value is the WriteProtect bit. We will fill in * the mode data length later. */ memset (buf,0 ,8 ); -if (mscmnd ==SC_MODE_SENSE_6 ) { +if (mscmnd ==MODE_SENSE ) { buf[2 ] = (curlun->ro ?0x80 :0x00 );/* WP, DPOFUA */ buf +=4 ; limit =255 ; - }else {/* SC_MODE_SENSE_10 */ + }else {/* MODE_SENSE_10 */ buf[3 ] = (curlun->ro ?0x80 :0x00 );/* WP, DPOFUA */ buf +=8 ; limit =65535 ;/* Should really be FSG_BUFLEN */
@@ -1397,7 +1397,7 @@ static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh) }/* Store the mode data length */ -if (mscmnd ==SC_MODE_SENSE_6 ) +if (mscmnd ==MODE_SENSE ) buf0[0 ] = len -1 ;else put_unaligned_be16 (len -2 , buf0);
@@ -1886,7 +1886,7 @@ static int check_command(struct fsg_common *common, int cmnd_size,if (common->lun >=0 && common->lun < common->nluns) { curlun = &common->luns[common->lun]; common->curlun = curlun; -if (common->cmnd[0 ] !=SC_REQUEST_SENSE ) { +if (common->cmnd[0 ] !=REQUEST_SENSE ) { curlun->sense_data =SS_NO_SENSE ; curlun->sense_data_info =0 ; curlun->info_valid =0 ;
@@ -1898,8 +1898,8 @@ static int check_command(struct fsg_common *common, int cmnd_size,/* INQUIRY and REQUEST SENSE commands are explicitly allowed * to use unsupported LUNs; all others may not. */ -if (common->cmnd[0 ] !=SC_INQUIRY && - common->cmnd[0 ] !=SC_REQUEST_SENSE ) { +if (common->cmnd[0 ] !=INQUIRY && + common->cmnd[0 ] !=REQUEST_SENSE ) {DBG (common,"unsupported LUN %d\n" , common->lun);return -EINVAL ; }
@@ -1908,8 +1908,8 @@ static int check_command(struct fsg_common *common, int cmnd_size,/* If a unit attention condition exists, only INQUIRY and * REQUEST SENSE commands are allowed; anything else must fail. */ if (curlun && curlun->unit_attention_data !=SS_NO_SENSE && - common->cmnd[0 ] !=SC_INQUIRY && - common->cmnd[0 ] !=SC_REQUEST_SENSE ) { + common->cmnd[0 ] !=INQUIRY && + common->cmnd[0 ] !=REQUEST_SENSE ) { curlun->sense_data = curlun->unit_attention_data; curlun->unit_attention_data =SS_NO_SENSE ;return -EINVAL ;
@@ -1960,7 +1960,7 @@ static int do_scsi_command(struct fsg_common *common)down_read (&common->filesem);/* We're using the backing file */ switch (common->cmnd[0 ]) { -case SC_INQUIRY : +case INQUIRY : common->data_size_from_cmnd = common->cmnd[4 ]; reply = check_command(common, 6, DATA_DIR_TO_HOST, (1<<4), 0,
@@ -1969,7 +1969,7 @@ static int do_scsi_command(struct fsg_common *common) reply =do_inquiry (common, bh);break ; -case SC_MODE_SELECT_6 : +case MODE_SELECT : common->data_size_from_cmnd = common->cmnd[4 ]; reply = check_command(common, 6, DATA_DIR_FROM_HOST, (1<<1) | (1<<4), 0,
@@ -1978,7 +1978,7 @@ static int do_scsi_command(struct fsg_common *common) reply =do_mode_select (common, bh);break ; -case SC_MODE_SELECT_10 : +case MODE_SELECT_10 : common->data_size_from_cmnd =get_unaligned_be16 (&common->cmnd[7 ]); reply = check_command(common, 10, DATA_DIR_FROM_HOST,
@@ -1988,7 +1988,7 @@ static int do_scsi_command(struct fsg_common *common) reply =do_mode_select (common, bh);break ; -case SC_MODE_SENSE_6 : +case MODE_SENSE : common->data_size_from_cmnd = common->cmnd[4 ]; reply = check_command(common, 6, DATA_DIR_TO_HOST, (1<<1) | (1<<2) | (1<<4), 0,
@@ -1997,7 +1997,7 @@ static int do_scsi_command(struct fsg_common *common) reply =do_mode_sense (common, bh);break ; -case SC_MODE_SENSE_10 : +case MODE_SENSE_10 : common->data_size_from_cmnd =get_unaligned_be16 (&common->cmnd[7 ]); reply = check_command(common, 10, DATA_DIR_TO_HOST,
@@ -2007,7 +2007,7 @@ static int do_scsi_command(struct fsg_common *common) reply =do_mode_sense (common, bh);break ; -case SC_PREVENT_ALLOW_MEDIUM_REMOVAL : +case ALLOW_MEDIUM_REMOVAL : common->data_size_from_cmnd =0 ; reply = check_command(common, 6, DATA_DIR_NONE, (1<<4), 0,
@@ -2016,7 +2016,7 @@ static int do_scsi_command(struct fsg_common *common) reply =do_prevent_allow (common);break ; -case SC_READ_6 : +case READ_6 : i = common->cmnd[4 ]; common->data_size_from_cmnd = (i ==0 ?256 : i) <<9 ; reply = check_command(common, 6, DATA_DIR_TO_HOST,
@@ -2026,7 +2026,7 @@ static int do_scsi_command(struct fsg_common *common) reply =do_read (common);break ; -case SC_READ_10 : +case READ_10 : common->data_size_from_cmnd =get_unaligned_be16 (&common->cmnd[7 ]) <<9 ; reply = check_command(common, 10, DATA_DIR_TO_HOST,
@@ -2036,7 +2036,7 @@ static int do_scsi_command(struct fsg_common *common) reply =do_read (common);break ; -case SC_READ_12 : +case READ_12 : common->data_size_from_cmnd =get_unaligned_be32 (&common->cmnd[6 ]) <<9 ; reply = check_command(common, 12, DATA_DIR_TO_HOST,
@@ -2046,7 +2046,7 @@ static int do_scsi_command(struct fsg_common *common) reply =do_read (common);break ; -case SC_READ_CAPACITY : +case READ_CAPACITY : common->data_size_from_cmnd =8 ; reply = check_command(common, 10, DATA_DIR_TO_HOST, (0xf<<2) | (1<<8), 1,
@@ -2055,7 +2055,7 @@ static int do_scsi_command(struct fsg_common *common) reply =do_read_capacity (common, bh);break ; -case SC_READ_HEADER : +case READ_HEADER :if (!common->curlun || !common->curlun->cdrom) goto unknown_cmnd; common->data_size_from_cmnd =
@@ -2067,7 +2067,7 @@ static int do_scsi_command(struct fsg_common *common) reply =do_read_header (common, bh);break ; -case SC_READ_TOC : +case READ_TOC :if (!common->curlun || !common->curlun->cdrom) goto unknown_cmnd; common->data_size_from_cmnd =
@@ -2079,7 +2079,7 @@ static int do_scsi_command(struct fsg_common *common) reply =do_read_toc (common, bh);break ; -case SC_READ_FORMAT_CAPACITIES : +case READ_FORMAT_CAPACITIES : common->data_size_from_cmnd =get_unaligned_be16 (&common->cmnd[7 ]); reply = check_command(common, 10, DATA_DIR_TO_HOST,
@@ -2089,7 +2089,7 @@ static int do_scsi_command(struct fsg_common *common) reply =do_read_format_capacities (common, bh);break ; -case SC_REQUEST_SENSE : +case REQUEST_SENSE : common->data_size_from_cmnd = common->cmnd[4 ]; reply = check_command(common, 6, DATA_DIR_TO_HOST, (1<<4), 0,
@@ -2098,7 +2098,7 @@ static int do_scsi_command(struct fsg_common *common) reply =do_request_sense (common, bh);break ; -case SC_START_STOP_UNIT : +case START_STOP : common->data_size_from_cmnd =0 ; reply = check_command(common, 6, DATA_DIR_NONE, (1<<1) | (1<<4), 0,
@@ -2107,7 +2107,7 @@ static int do_scsi_command(struct fsg_common *common) reply =do_start_stop (common);break ; -case SC_SYNCHRONIZE_CACHE : +case SYNCHRONIZE_CACHE : common->data_size_from_cmnd =0 ; reply = check_command(common, 10, DATA_DIR_NONE, (0xf<<2) | (3<<7), 1,
@@ -2116,7 +2116,7 @@ static int do_scsi_command(struct fsg_common *common) reply =do_synchronize_cache (common);break ; -case SC_TEST_UNIT_READY : +case TEST_UNIT_READY : common->data_size_from_cmnd =0 ; reply = check_command(common, 6, DATA_DIR_NONE, 0, 1,
@@ -2125,7 +2125,7 @@ static int do_scsi_command(struct fsg_common *common)/* Although optional, this command is used by MS-Windows. We * support a minimal version: BytChk must be 0. */ -case SC_VERIFY : +case VERIFY : common->data_size_from_cmnd =0 ; reply = check_command(common, 10, DATA_DIR_NONE, (1<<1) | (0xf<<2) | (3<<7), 1,
@@ -2134,7 +2134,7 @@ static int do_scsi_command(struct fsg_common *common) reply =do_verify (common);break ; -case SC_WRITE_6 : +case WRITE_6 : i = common->cmnd[4 ]; common->data_size_from_cmnd = (i ==0 ?256 : i) <<9 ; reply = check_command(common, 6, DATA_DIR_FROM_HOST,
@@ -2144,7 +2144,7 @@ static int do_scsi_command(struct fsg_common *common) reply =do_write (common);break ; -case SC_WRITE_10 : +case WRITE_10 : common->data_size_from_cmnd =get_unaligned_be16 (&common->cmnd[7 ]) <<9 ; reply = check_command(common, 10, DATA_DIR_FROM_HOST,
@@ -2154,7 +2154,7 @@ static int do_scsi_command(struct fsg_common *common) reply =do_write (common);break ; -case SC_WRITE_12 : +case WRITE_12 : common->data_size_from_cmnd =get_unaligned_be32 (&common->cmnd[6 ]) <<9 ; reply = check_command(common, 12, DATA_DIR_FROM_HOST,
@@ -2168,10 +2168,10 @@ static int do_scsi_command(struct fsg_common *common)* They don't mean much in this setting. It's left as an exercise * for anyone interested to implement RESERVE and RELEASE in terms * of Posix locks. */ -case SC_FORMAT_UNIT : -case SC_RELEASE : -case SC_RESERVE : -case SC_SEND_DIAGNOSTIC : +case FORMAT_UNIT : +case RELEASE : +case RESERVE : +case SEND_DIAGNOSTIC :/* Fall through */ default :
drivers/usb/gadget/file_storage.c +37 -37
263 lines not on this page · raw message
drivers/usb/gadget/storage_common.c +2 -32
@@ -53,8 +53,9 @@*/ -#include <asm/unaligned.h> #include <linux/usb/storage.h> +#include <scsi/scsi.h> +#include <asm/unaligned.h> /*
@@ -153,10 +154,6 @@/*-------------------------------------------------------------------------*/ -/* SCSI device types */ -#define TYPE_DISK 0x00 -#define TYPE_CDROM 0x05 -/* Bulk-only data structures */ /* Command Block Wrapper */
@@ -208,33 +205,6 @@ struct interrupt_data {/* Length of a SCSI Command Data Block */ #define MAX_COMMAND_SIZE 16 -/* SCSI commands that we recognize */ -#define SC_FORMAT_UNIT 0x04 -#define SC_INQUIRY 0x12 -#define SC_MODE_SELECT_6 0x15 -#define SC_MODE_SELECT_10 0x55 -#define SC_MODE_SENSE_6 0x1a -#define SC_MODE_SENSE_10 0x5a -#define SC_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e -#define SC_READ_6 0x08 -#define SC_READ_10 0x28 -#define SC_READ_12 0xa8 -#define SC_READ_CAPACITY 0x25 -#define SC_READ_FORMAT_CAPACITIES 0x23 -#define SC_READ_HEADER 0x44 -#define SC_READ_TOC 0x43 -#define SC_RELEASE 0x17 -#define SC_REQUEST_SENSE 0x03 -#define SC_RESERVE 0x16 -#define SC_SEND_DIAGNOSTIC 0x1d -#define SC_START_STOP_UNIT 0x1b -#define SC_SYNCHRONIZE_CACHE 0x35 -#define SC_TEST_UNIT_READY 0x00 -#define SC_VERIFY 0x2f -#define SC_WRITE_6 0x0a -#define SC_WRITE_10 0x2a -#define SC_WRITE_12 0xaa -/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */ #define SS_NO_SENSE 0#define SS_COMMUNICATION_FAILURE 0x040800
include/scsi/scsi.h +2 -0
@@ -73,6 +73,7 @@ struct scsi_cmnd;#define SEND_DIAGNOSTIC 0x1d#define ALLOW_MEDIUM_REMOVAL 0x1e +#define READ_FORMAT_CAPACITIES 0x23#define SET_WINDOW 0x24#define READ_CAPACITY 0x25#define READ_10 0x28
@@ -102,6 +103,7 @@ struct scsi_cmnd;#define WRITE_SAME 0x41#define UNMAP 0x42#define READ_TOC 0x43 +#define READ_HEADER 0x44#define LOG_SELECT 0x4c#define LOG_SENSE 0x4d#define XDWRITEREAD_10 0x53
Signature · 1 line
1.7.1