SCSI Operation Codes

USB Mass Storage 是 USB host侧遇到最多的场景,基于 Bulk传输,使用 SCSI协议进行资源交互。当然 UFS也用到 SCSI协议,在使用 UFS的系统,我们插入 U盘经常生成的 dev节点是 /dev/sdb或者是 /dev/sde 。前面的如 /dev/sda、/dev/sdc这些节点可能就被 UFS占用了,识别 log可能就变成 “sd 1:0:0:0: [sde] …”。

在读写有坏块的 U盘时,不免会打印下面的 log。通过 opcode,就可以清楚是什么操作报的错。这里 opcode=0x28,即 READ(10)。

1
sd 0:0:0:0: [sda] tag#0 CDB: opcode=0x28 28 00 00 00 2b 09 00 00 1d 00

我们还可以阅读 SCSI的 manual,确定这次的 READ(10) 想从 LBA 0x2b0900 读多 0x1d * block size的数据回来。

READ10

USB Mass Storage 常用的 SCSI Operation Codes 包括下面这些:

指令代码指令名称指令说明
0x00Test Unit Ready查询设备是否ready
0x03Request Sense主机请求设备返回执行结果,及获取状态信息
0x12Inquiry获取设备信息
0x1AMode Sense(6)向host传输参数
0x5AMode Sense(10)向host传输参数
0x25Read Capacity(10)读取设备容量
0x28Read(10)Host从设备读取数据
0x2AWrite(10)Host写数据到存储设备
0x23Read Format Capacity查询当前容量及可用空间
0x15Mode Select(6)允许Host对外部设备设置参数
0x55Mode Select(10)允许Host对外部设备设置参数
0x1EPrevent/Allow Medium Removal禁止/允许存储介质移动
0x1BStart/Stop Uint启动/停止存储单元电源(写保护)
0xA0Report LUNs索取设备的LUN数和LUN清单
0x2FVerify在存储中验证数据

下面是全部的 SCSI Operation Codes:

CodeCommand
00TEST UNIT READY (mandatory)
01RECALIBRATE or REWIND
03REQUEST SENSE (mandatory except RBC)
04FORMAT UNIT
05READ BLOCK LIMITS
07REASSIGN BLOCKS
07INITIALIZE ELEMENT STATUS
08READ (6)
0AWRITE (6)
0BSEEK (6)
0FREAD REVERSE (6)
10WRITE FILEMARKS (6)
11SPACE (6)
12INQUIRY (mandatory)
13VERIFY(6)
14RECOVER BUFFERED DATA
15MODE SELECT (6)
16RESERVE (6)
17RELEASE (6)
18COPY
19ERASE (6)
1AMODE SENSE (6)
1BSTART/STOP UNIT
1BLOAD UNLOAD
1CRECEIVE DIAGNOSTIC RESULTS
1DSEND DIAGNOSTIC
1EPREVENT/ALLOW MEDIUM REMOVAL
23READ FORMAT CAPACITIES (MMC)
24SET WINDOW
25READ CAPACITY (10)
28READ (10)
29READ GENERATION
2AWRITE (10)
2BSEEK (10)
2CERASE (10)
2DREAD UPDATED BLOCK
2EWRITE AND VERIFY (10)
2FVERIFY (10)
30SEARCH DATA HIGH (10)
31SEARCH DATA EQUAL (10)
32SEARCH DATA LOW (10)
33SET LIMITS (10)
34PRE-FETCH (10)
35SYNCHRONIZE CACHE (10)
36LOCK/UNLOCK CACHE (10)
37READ DEFECT DATA (10)
37INITIALIZE ELEMENT STATUS WITH RANGE
38MEDIUM SCAN
39COMPARE
3ACOPY AND VERIFY
3BWRITE BUFFER
3CREAD BUFFER
3DUPDATE BLOCK
3EREAD LONG
3FWRITE LONG
40CHANGE DEFINITION
41WRITE SAME (10)
44REPORT DENSITY SUPPORT
45PLAY AUDIO (10)
46GET CONFIGURATION
47PLAY AUDIO MSF
48AUDIO TRACK INDEX (not mentioned in T10 overview)
49AUDIO TRACK RELATIVE 10 (not mentioned in T10 overview)
4AGET EVENT STATUS NOTIFICATION
4BPAUSE / RESUME
4CLOG SELECT
4DLOG SENSE
50XDWRITE (10)
51XPWRITE (10) /READ DISC INFORMATION CDB (in mmc5r02c 6.22.2)/
52XDREAD (10)
53XDWRITEREAD (10)
54SEND OPC INFORMATION
55MODE SELECT (10)
56RESERVE (10)
57RELEASE (10)
58REPAIR TRACK
5AMODE SENSE (10)
5BCLOSE TRACK / SESSION
5CREAD BUFFER CAPACITY
5DSEND CUE SHEET
5EPERSISTENT RESERVE IN
5FPERSISTENT RESERVE OUT
7EEXTENDED CDB
7FVARIABLE LENGTH CDB
80XDWRITE EXTENDED (16)
80WRITE FILEMARKS (16)
81REBUILD (16)
81READ REVERSE (16)
82REGENERATE (16)
83EXTENDED COPY
84RECEIVE COPY RESULTS
85ATA COMMAND PASS THROUGH (16)
86ACCESS CONTROL IN
87ACCESS CONTROL OUT
88READ (16)
89COMPARE AND WRITE
8AWRITE (16)
8BORWRITE
8CREAD ATTRIBUTE
8DWRITE ATTRIBUTE
8EWRITE AND VERIFY (16)
8FVERIFY (16)
90PRE-FETCH (16)
91SYNCHRONIZE CACHE (16)
91SPACE (16)
92LOCK UNLOCK CACHE (16)
93WRITE SAME (16)
9ESERVICE ACTION IN (16)
9FSERVICE ACTION OUT (16)
A0REPORT LUNS
A1ATA COMMAND PASS THROUGH (12)
A2SECURITY PROTOCOL IN
A2SEND EVENT (not mentioned in T10 overview)
A3MAINTENANCE IN
A4MAINTENANCE OUT (REPORT_KEY)
A5MOVE MEDIUM
A5PLAY AUDIO 12 (not mentioned in T10 overview)
A6EXCHANGE MEDIUM
A7MOVE MEDIUM ATTACHED
A8READ (12)
A9SERVICE ACTION OUT (12)
A9AUDIO TRACK RELATIVE 12 (not mentioned in T10 overview)
AAWRITE (12)
ABSERVICE ACTION IN (12)
ACERASE (12)
ADREAD DVD STRUCTURE
AEWRITE AND VERIFY (12)
AFVERIFY (12)
B0SEARCH DATA HIGH (12)
B1SEARCH DATA EQUAL (12)
B2SEARCH DATA LOW (12)
B3SET LIMITS (12)
B4READ ELEMENT STATUS ATTACHED
B5SECURITY PROTOCOL OUT
B6SEND VOLUME TAG
B7READ DEFECT DATA (12)
B8READ ELEMENT STATUS
B9READ CD MSF
BAREDUNDANCY GROUP (IN)
BBREDUNDANCY GROUP (OUT)
BCSPARE (IN)
BCPLAY CD (not mentioned in T10 overview)
BDSPARE (OUT)
BEVOLUME SET (IN)
BFVOLUME SET (OUT)

上述部分内容来自 wikiymangu 和 SCSI Commands Reference Manual。更多SCSI 相关推荐查看 SCSI Commands Reference Manual、t10.org


SCSI Operation Codes
http://xxxdk.xyz/xxx/2020/03/SCSI-Operation-Codes/
作者
sni
发布于
2020年3月20日
许可协议