File: sg_raw.8

package info (click to toggle)
sg3-utils 1.44-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 7,056 kB
  • sloc: ansic: 93,218; sh: 7,607; cpp: 2,947; makefile: 447
file content (218 lines) | stat: -rw-r--r-- 10,913 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
.TH SG_RAW "8" "May 2018" "sg3_utils\-1.43" SG3_UTILS
.SH NAME
sg_raw \- send arbitrary SCSI command to a device
.SH SYNOPSIS
.B sg_raw
[\fI\-\-binary\fR] [\fI\-\-cmdfile=CF\fR] [\fI\-\-enumerate\fR]
[\fI\-\-help\fR] [\fI\-\-infile=IFILE\fR] [\fI\-\-nosense\fR]
[\fI\-\-outfile=OFILE\fR] [\fI\-\-readonly\fR] [\fI\-\-request=RLEN\fR]
[\fI\-\-send=SLEN\fR] [\fI\-\-skip=KLEN\fR] [\fI\-\-timeout=SECS\fR]
[\fI\-\-verbose\fR] [\fI\-\-version\fR] \fIDEVICE\fR [CDB0 CDB1 ...]
.SH DESCRIPTION
This utility sends an arbitrary SCSI command (between 6 and 256 bytes) to
the \fIDEVICE\fR. There may be no associated data transfer; or data may be
read from a file and sent to the \fIDEVICE\fR; or data may be received from
the \fIDEVICE\fR and then displayed or written to a file. If supported
by the pass through, bidirectional commands may be sent (i.e. containing
both data to be sent to the \fIDEVICE\fR and received from the
\fIDEVICE\fR).
.PP
The SCSI command may be between 6 and 256 bytes long. Each command byte is
specified in plain hex format (00..FF) without a prefix or suffix. The
command can be given either on the command line or via the
\fI\-\-cmdfile=CF\fR option. See EXAMPLES section below.
.PP
The commands pass through a generic SCSI interface which is implemented
for several operating systems including Linux, FreeBSD and Windows.
.PP
Experimental support has been added to send NVMe Admin commands to the
\fIDEVICE\fR. Since all NVMe commands are 64 bytes long it is more
convenient to use the \fI\-\-cmdfile=CF\fR option rather than type the
64 bytes of the NVMe command on the command line. See the section on
NVME below.
.SH OPTIONS
Arguments to long options are mandatory for short options as well.
The options are arranged in alphabetical order based on the long
option name.
.TP
\fB\-b\fR, \fB\-\-binary\fR
Dump data in binary form, even when writing to stdout.
.TP
\fB\-c\fR, \fB\-\-cmdfile\fR=\fICF\fR
\fICF\fR is the name of a file which contains the command to be executed.
Without this option the command must be given on the command line, after
the options and the \fIDEVICE\fR.
.TP
\fB\-h\fR, \fB\-\-help\fR
Display usage information and exit.
.TP
\fB\-i\fR, \fB\-\-infile\fR=\fIIFILE\fR
Read data from \fIIFILE\fR instead of stdin. This option is ignored if
\fB\-\-send\fR is not specified.
.TP
\fB\-n\fR, \fB\-\-nosense\fR
Don't display SCSI Sense information.
.TP
\fB\-o\fR, \fB\-\-outfile\fR=\fIOFILE\fR
Write data received from the \fIDEVICE\fR to \fIOFILE\fR. The data is
written in binary. By default, data is dumped in hex format to stdout.
If \fIOFILE\fR is '\-' then data is dumped in binary to stdout.
This option is ignored if \fI\-\-request\fR is not specified.
.TP
\fB\-R\fR, \fB\-\-readonly\fR
Open \fIDEVICE\fR read\-only. The default (without this option) is to open
it read\-write.
.TP
\fB\-r\fR, \fB\-\-request\fR=\fIRLEN\fR
Expect to receive up to \fIRLEN\fR bytes of data from the \fIDEVICE\fR.
\fIRLEN\fR may be suffixed with 'k' to use kilobytes (1024 bytes) instead
of bytes. \fIRLEN\fR is decimal unless it has a leading '0x' or a
trailing 'h'.
.br
If \fIRLEN\fR is too small (i.e. either smaller than indicated by the
cdb (typically the "allocation length" field) and/or smaller than the
\fIDEVICE\fR tries to send back) then the HBA driver may complain. Making
\fIRLEN\fR larger than required should cause no problems. Most
SCSI "data\-in" commands return a data block that contains (in its early
bytes) a length that the \fIDEVICE\fR would "like" to send back if
the "allocation length" field in the cdb is large enough. In practice, the
\fIDEVICE\fR will return no more bytes than indicated in the "allocation
length" field of the cdb.
.TP
\fB\-s\fR, \fB\-\-send\fR=\fISLEN\fR
Read \fISLEN\fR bytes of data, either from stdin or from a file, and send
them to the \fIDEVICE\fR. In the SCSI transport, \fISLEN\fR becomes the
length (in bytes) of the "data\-out" buffer. \fISLEN\fR is decimal unless
it has a leading '0x' or a trailing 'h'.
.br
It is the responsibility of the user to make sure that the "data\-out"
length implied or stated in the cdb matches \fISLEN\fR. Note that some
common SCSI commands such as WRITE(10) have a "transfer length" field whose
units are logical blocks (which are often 512 bytes long).
.TP
\fB\-k\fR, \fB\-\-skip\fR=\fIKLEN\fR
Skip the first \fIKLEN\fR bytes of the input file or stream. This option
is ignored if \fI\-\-send\fR is not specified. If \fI\-\-send\fR is given
and this option is not given, then zero bytes are skipped.
.TP
\fB\-t\fR, \fB\-\-timeout\fR=\fISECS\fR
Wait up to \fISECS\fR seconds for command completion (default: 20).
Note that if a command times out the operating system may start by
aborting the command and if that is unsuccessful it may attempt
to reset the device.
.TP
\fB\-v\fR, \fB\-\-verbose\fR
Increase level of verbosity. Can be used multiple times.
.TP
\fB\-V\fR, \fB\-\-version\fR
Display version and license information and exit.
.SH NOTES
The sg_inq utility can be used to send an INQUIRY command to a device
to determine its peripheral device type (e.g. '1' for a streaming
device (tape drive)) which determines which SCSI command sets a device
should support (e.g. SPC and SSC). The sg_vpd utility reads and decodes
a device's Vital Product Pages which may contain useful information.
.PP
The ability to send more than a 16 byte CDB (in some cases 12 byte CDB)
may be restricted by the pass\-through interface, the low level driver
or the transport. In the Linux series 3 kernels, the bsg driver can
handle longer CDBs, block devices (e.g. /dev/sdc) accessed via the
SG_IO ioctl cannot handle CDBs longer than 16 bytes, and the sg driver
can handle longer CDBs from lk 3.17 .
.PP
The CDB command name defined by T10 for the given CDB is shown if
the '\-vv' option is given. The command line syntax still needs to be
correct, so /dev/null may be used for the \fIDEVICE\fR since the CDB
command name decoding is done before the \fIDEVICE\fR is checked.
.SH NVME SUPPORT
Support for NVMe (a.k.a. NVM Express) is currently experimental. NVMe
concepts map reasonably well to the SCSI architecture. A SCSI logical
unit (LU) is similar to a NVMe namespace (although LUN 0 is very common
in SCSI while namespace IDs start at 1). A SCSI target device is similar
to a NVMe controller. SCSI commands vary from 6 to 260 bytes long (although
SCSI command descriptor blocks (cdb_s) longer than 32 bytes are uncommon)
while all NVMe commands are currently 64 bytes long. The SCSI architecture
makes a clear distinction between an initiator (often called a HBA) and
a target (device) while (at least on the PCIe transport) the NVMe
controller plays both roles. At this time this utility only
supports "Admin" commands (i.e. it does not support the I/O (or "NVM")
command set). Admin commands are sent to submission queue 0 while non\-admin
commands are sent to submissions greater than 0.
.PP
One significant difference is that SCSI uses a big endian representation
for integers that are longer than 8 bits (i.e. longer than 1 byte) while
NVMe uses a little endian representation (like most things that have
originated from the Intel organisation). NVMe specifications talk about
Words (16 bits), Double Words (32 bits) and sometimes Quad Words (64
bits) and has tighter alignment requirements than SCSI.
.PP
One difference that impacts this utility is that NVMe places pointers to
host memory in its commands while SCSI leaves this detail to whichever
transport it is using (e.g. SAS, iSCSI, SRP). Since this utility takes
the command from the user (either on the command line or in a file named
\fICF\fR) but this utility allocates a data\-in or data\-out buffer as
required, the user does not know in advance what the address of that
buffer will be. Some special addresses have been introduced to help with
this problem: the address 0xfffffffffffffffe is interpreted as "use the
data\-in buffer's address" while 0xfffffffffffffffd is interpreted as "use
the data\-out buffer's address". Since NVMe uses little endian notation
then that first address appears in the NVMe command byte stream as "fe"
followed by seven "ff"s. A similar arrangement is made for the length
of that buffer, but since that is a 32 byte quantity, the first 4
bytes (all "ff"s) are removed.
.PP
Two command file examples can be found in the examples directory of this
package's source tarball: nvme_identify_ctl.hex and nvme_dev_self_test.hex .
.SH EXAMPLES
These examples, apart from the last one, use Linux device names. For
suitable device names in other supported Operating Systems see the
sg3_utils(8) man page.
.TP
sg_raw /dev/scd0 1b 00 00 00 02 00
Eject the medium in CD drive /dev/scd0.
.TP
sg_raw \-r 1k /dev/sg0 12 00 00 00 60 00
Perform an INQUIRY on /dev/sg0 and dump the response data (up to
1024 bytes) to stdout.
.TP
sg_raw \-s 512 \-i i512.bin /dev/sda 3b 02 00 00 00 00 00 02 00 00
Showing an example of writing 512 bytes to a sector on a disk
is a little dangerous. Instead this example will read i512.bin (assumed
to be 512 bytes long) and use the SCSI WRITE BUFFER command to send
it to the "data" buffer (that is mode 2). This is a safe operation.
.TP
sg_raw \-r 512 \-o o512.bin /dev/sda 3c 02 00 00 00 00 00 02 00 00
This will use the SCSI READ BUFFER command to read 512 bytes from
the "data" buffer (i.e. mode 2) then write it to the o512.bin file.
When used in conjunction with the previous example, if both commands
work then 'cmp i512.bin o512.bin' should show a match.
.TP
sg_raw \-\-infile=urandom.bin \-\-send=512 \-\-request=512 \-\-outfile=out.bin "/dev/bsg/7:0:0:0" 53 00 00 00 00 00 00 00 01 00
This is a bidirectional XDWRITEREAD(10) command being sent via a Linux
bsg device. Note that data is being read from "urandom.bin" and sent
to the device (data\-out) while resulting data (data\-in) is placed
in the "out.bin" file. Also note the length of both is 512 bytes
which corresponds to the transfer length of 1 (block) in the cdb (i.e.
the second last byte).
.TP
sg_raw.exe PhysicalDrive1 a1 0c 0e 00 00 00 00 00 00 e0 00 00
This example is from Windows and shows a ATA STANDBY IMMEDIATE command
being sent to PhysicalDrive1. That ATA command is contained within
the SCSI ATA PASS\-THROUGH(12) command (see the SAT or SAT\-2 standard at
http://www.t10.org). Notice that the STANDBY IMMEDIATE command does not
send or receive any additional data, however if it fails sense data
should be returned and displayed.
.SH EXIT STATUS
The exit status of sg_raw is 0 when it is successful. Otherwise see
the sg3_utils(8) man page.
.SH AUTHOR
Written by Ingo van Lil
.SH "REPORTING BUGS"
Report bugs to <inguin at gmx dot de>.
.SH COPYRIGHT
Copyright \(co 2001\-2018 Ingo van Lil
.br
This software is distributed under the GPL version 2. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
.SH "SEE ALSO"
.B sg_inq, sg_vpd, sg3_utils (sg3_utils), plscsi