1SG_RAW(8)                          SG3_UTILS                         SG_RAW(8)
2
3
4

NAME

6       sg_raw - send arbitrary SCSI command to a device
7

SYNOPSIS

9       sg_raw [OPTIONS] DEVICE CDB0 CDB1 ...
10

DESCRIPTION

12       This  utility sends an arbitrary SCSI command (between 6 and 256 bytes)
13       to the DEVICE. There may be no associated data transfer; or data may be
14       read  from  a file and sent to the DEVICE; or data may be received from
15       the DEVICE and then displayed or written to a file. If supported by the
16       pass  through, bidirectional commands may be sent (i.e. containing both
17       data to be sent to the DEVICE and received from the DEVICE).
18
19       The SCSI command may be between 6 and 256 bytes long. Each command byte
20       is  specified  in plain hex format (00..FF) without a prefix or suffix.
21       See EXAMPLES section below.
22
23       The commands pass through a generic SCSI interface which is implemented
24       for several operating systems including Linux, FreeBSD and Windows.
25

OPTIONS

27       Arguments to long options are mandatory for short options as well.
28
29       -b, --binary
30              Dump data in binary form, even when writing to stdout.
31
32       -h, --help
33              Display usage information and exit.
34
35       -i, --infile=IFILE
36              Read data from IFILE instead of stdin. This option is ignored if
37              --send is not specified.
38
39       -k, --skip=LEN
40              Skip the first LEN bytes of  the  input  file  or  stream.  This
41              option is ignored if --send is not specified.
42
43       -n, --nosense
44              Don't display SCSI Sense information.
45
46       -o, --outfile=OFILE
47              Write  data received from the DEVICE to OFILE. The data is writ‐
48              ten in binary. By default, data is dumped in hex format to  std‐
49              out.   If  OFILE is '-' then data is dumped in binary to stdout.
50              This option is ignored if --request is not specified.
51
52       -r, --request=RLEN
53              Expect to receive up to RLEN bytes  of  data  from  the  DEVICE.
54              RLEN  may  be  suffixed  with  'k' to use kilobytes (1024 bytes)
55              instead of bytes. RLEN is decimal unless it has a  leading  '0x'
56              or a trailing 'h'.
57              If  RLEN is too small (i.e. either smaller than indicated by the
58              cdb (typically the "allocation  length"  field)  and/or  smaller
59              than the DEVICE tries to send back) then the HBA driver may com‐
60              plain. Making RLEN larger than required should  cause  no  prob‐
61              lems. Most SCSI "data-in" commands return a data block that con‐
62              tains (in its early bytes) a length that the DEVICE would "like"
63              to  send  back  if  the  "allocation length" field in the cdb is
64              large enough. In practice, the DEVICE will return no more  bytes
65              than indicated in the "allocation length" field of the cdb.
66
67       -R, --readonly
68              Open  DEVICE  read-only. The default (without this option) is to
69              open it read-write.
70
71       -s, --send=SLEN
72              Read SLEN bytes of data, either from stdin or from a  file,  and
73              send them to the DEVICE. In the SCSI transport, SLEN becomes the
74              length (in bytes) of the  "data-out"  buffer.  SLEN  is  decimal
75              unless it has a leading '0x' or a trailing 'h'.
76              It  is  the  responsibility  of  the  user to make sure that the
77              "data-out" length implied or stated in  the  cdb  matches  SLEN.
78              Note  that  some  common  SCSI commands such as WRITE(10) have a
79              "transfer length" field whose units are  logical  blocks  (which
80              are often 512 bytes long).
81
82       -t, --timeout=SEC
83              Wait  up  to  SEC  seconds for command completion (default: 20).
84              Note that if a command times out the operating system may  start
85              by  aborting  the  command  and  if  that is unsuccessful it may
86              attempt to reset the device.
87
88       -v, --verbose
89              Increase level of verbosity. Can be used multiple times.
90
91       -V, --version
92              Display version and license information and exit.
93

NOTES

95       The sg_inq utility can be used to send an INQUIRY command to  a  device
96       to  determine  its  peripheral  device  type  (e.g. '1' for a streaming
97       device (tape drive)) which determines which SCSI command sets a  device
98       should  support (e.g. SPC and SSC). The sg_vpd utility probes the Vital
99       Product Pages of a devices which may contain useful information.
100
101       The ability to send more than a 16 byte CDB (in some cases 12 byte CDB)
102       may  be  restricted by the pass-through interface, the low level driver
103       or the transport. In the Linux series 3 kernels,  the  bsg  driver  can
104       handle  longer  CDBs,  block  devices  (e.g. /dev/sdc) accessed via the
105       SG_IO ioctl cannot handle CDBs longer than 16 bytes, and the sg  driver
106       can handle longer CDBs from lk 3.17 .
107
108       The  CDB  command name defined by T10 for the given CDB is shown if the
109       '-vv' option is given. The command line syntax still needs to  be  cor‐
110       rect,  so  /dev/null  may  be used for the DEVICE since the CDB command
111       name decoding is done before the DEVICE is checked.
112

EXAMPLES

114       These examples, apart from the last one, use Linux  device  names.  For
115       suitable  device  names  in  other  supported Operating Systems see the
116       sg3_utils(8) man page.
117
118       sg_raw /dev/scd0 1b 00 00 00 02 00
119              Eject the medium in CD drive /dev/scd0.
120
121       sg_raw -r 1k /dev/sg0 12 00 00 00 60 00
122              Perform an INQUIRY on /dev/sg0 and dump the response data (up to
123              1024 bytes) to stdout.
124
125       sg_raw -s 512 -i i512.bin /dev/sda 3b 02 00 00 00 00 00 02 00 00
126              Showing an example of writing 512 bytes to a sector on a disk is
127              a little dangerous. Instead  this  example  will  read  i512.bin
128              (assumed  to  be  512  bytes long) and use the SCSI WRITE BUFFER
129              command to send it to the "data" buffer (that is mode  2).  This
130              is a safe operation.
131
132       sg_raw -r 512 -o o512.bin /dev/sda 3c 02 00 00 00 00 00 02 00 00
133              This  will  use  the  SCSI READ BUFFER command to read 512 bytes
134              from the "data" buffer (i.e.  mode  2)  then  write  it  to  the
135              o512.bin file.  When used in conjunction with the previous exam‐
136              ple, if both commands work then 'cmp i512.bin  o512.bin'  should
137              show a match.
138
139       sg_raw  --infile=urandom.bin --send=512 --request=512 --outfile=out.bin
140       "/dev/bsg/7:0:0:0" 53 00 00 00 00 00 00 00 01 00
141              This is a bidirectional XDWRITEREAD(10) command being sent via a
142              Linux  bsg  device.  Note  that  data  is being read from "uran‐
143              dom.bin" and sent to the device (data-out) while resulting  data
144              (data-in)  is placed in the "out.bin" file. Also note the length
145              of both is 512 bytes which corresponds to the transfer length of
146              1 (block) in the cdb (i.e.  the second last byte).
147
148       sg_raw.exe PhysicalDrive1 a1 0c 0e 00 00 00 00 00 00 e0 00 00
149              This  example  is from Windows and shows a ATA STANDBY IMMEDIATE
150              command being sent to PhysicalDrive1. That ATA command  is  con‐
151              tained within the SCSI ATA PASS-THROUGH(12) command (see the SAT
152              or  SAT-2  standard  at  http://www.t10.org).  Notice  that  the
153              STANDBY  IMMEDIATE  command  does  not send or receive any addi‐
154              tional data, however if it fails sense data should  be  returned
155              and displayed.
156

EXIT STATUS

158       The exit status of sg_raw is 0 when it is successful. Otherwise see the
159       sg3_utils(8) man page.
160

AUTHOR

162       Written by Ingo van Lil
163

REPORTING BUGS

165       Report bugs to <inguin at gmx dot de>.
166
168       Copyright © 2001-2015 Ingo van Lil
169       This software is distributed under the GPL version 2. There is NO  war‐
170       ranty;  not  even  for MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR‐
171       POSE.
172

SEE ALSO

174       sg_inq, sg_vpd, sg3_utils (sg3_utils), plscsi
175
176
177
178sg3_utils-1.42                   November 2015                       SG_RAW(8)
Impressum