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

NAME

6       sg3_utils - a package of utilities for sending SCSI commands
7

SYNOPSIS

9       sg_*  [--dry-run] [--enumerate] [--help] [--hex] [--in=FN] [--inhex=FN]
10       [--maxlen=LEN]   [--raw]   [--timeout=SECS]   [--verbose]   [--version]
11       [OTHER_OPTIONS] DEVICE
12

DESCRIPTION

14       sg3_utils  is  a  package  of  utilities that send SCSI commands to the
15       given DEVICE via a SCSI pass through interface  provided  by  the  host
16       operating system.
17
18       The  names  of  all utilities start with "sg" and most start with "sg_"
19       often followed by the name, or a shortening of the name,  of  the  SCSI
20       command  that  they send. For example the "sg_verify" utility sends the
21       SCSI VERIFY command. A mapping between SCSI commands and the  sg3_utils
22       utilities  that  issue  them  is shown in the COVERAGE file. The sg_raw
23       utility can be used to send an arbitrary SCSI command (supplied on  the
24       command line) to the given DEVICE.
25
26       sg_decode_sense can be used to decode SCSI sense data given on the com‐
27       mand line or in a file. sg_raw -vvv will output the T10 name of a given
28       SCSI CDB which is most often 16 bytes or less in length.
29
30       SCSI draft standards can be found at http://www.t10.org . The standards
31       themselves can be purchased from ANSI  and  other  standards  organiza‐
32       tions.   A  good  overview  of  various  SCSI  standards can be seen in
33       http://www.t10.org/scsi-3.htm with the SCSI command sets in  the  upper
34       part of the diagram. The highest level (i.e. most abstract) document is
35       the SCSI Architecture Model (SAM) with  SAM-5  being  the  most  recent
36       standard  (ANSI INCITS 515-2016) with the most recent draft being SAM-6
37       revision 4 . SCSI commands in common with all device types can be found
38       in  SCSI Primary Commands (SPC) of which SPC-4 is the most recent stan‐
39       dard (ANSI INCITS 513-2015). The most recent SPC draft is  SPC-5  revi‐
40       sion  21. Block device specific commands (e.g. as used by disks) are in
41       SBC, those for tape drives in SSC, those for SCSI enclosures in SES and
42       those for CD/DVD/BD drives in MMC.
43
44       It  is  becoming more common to control ATA disks with the SCSI command
45       set.  This involves the translation of SCSI commands  to  their  corre‐
46       sponding  ATA  equivalents  (and  that  is an imperfect mapping in some
47       cases). The relevant standard is called SCSI to ATA  Translation  (SAT,
48       SAT-2  and SAT-3) are now standards at INCITS(ANSI) and ISO while SAT-4
49       is at the draft stage.  The logic to perform the command translation is
50       often called a SAT Layer or SATL and may be within an operating system,
51       in host bus adapter firmware or in an external device (e.g.  associated
52       with a SAS expander). See http://www.t10.org for more information.
53
54       There  is  some  support  for SCSI tape devices but not for their basic
55       operation. The reader is referred to the "mt" utility.
56
57       There are two generations of command line option usage. The newer util‐
58       ities (written since July 2004) use the getopt_long() function to parse
59       command line options. With that function, each option has two represen‐
60       tations: a short form (e.g. '-v') and a longer form (e.g. '--verbose').
61       If an argument is required then it follows a space (optionally) in  the
62       short  form and a "=" in the longer form (e.g. in the sg_verify utility
63       '-l  2a6h'  and  '--lba=2a6h'   are   equivalent).   Note   that   with
64       getopt_long(), short form options can be elided, for example: '-all' is
65       equivalent to '-a -l  -l'.   The  DEVICE  argument  may  appear  after,
66       between or prior to any options.
67
68       The older utilities, including as sg_inq, sg_logs, sg_modes, sg_opcode,
69       sg_rbuff,  sg_readcap, sg_senddiag, sg_start and sg_turs had individual
70       command  line  processing code typically based on a single "-" followed
71       by one or more characters. If an argument is needed then it  follows  a
72       "="  (  e.g.  '-p=1f'  in  sg_modes  with its older interface). Various
73       options can be elided as long as it is not  ambiguous  (e.g.  '-vv'  to
74       increase the verbosity).
75
76       Over  time  the  command line interface of these older utilities became
77       messy and overloaded with options. So in  sg3_utils  version  1.23  the
78       command  line  interface  of  these older utilities was altered to have
79       both a cleaner getopt_long() interface and their  older  interface  for
80       backward  compatibility.   By  default  these older utilities use their
81       getopt_long() based interface.  The getopt_long() is  a  GNU  extension
82       (i.e.  not  yet POSIX certified) but more recent command line utilities
83       tend  to  use  it.   That   can   be   overridden   by   defining   the
84       SG3_UTILS_OLD_OPTS environment variable or using '-O' or '--old' as the
85       first command line option. The man pages of the older  utilities  docu‐
86       ments the details.
87
88       Several  sg3_utils  utilities  are  based  on the Unix dd command (e.g.
89       sg_dd) and permit copying data at the level of SCSI READ and WRITE com‐
90       mands. sg_dd is tightly bound to Linux and hence is not ported to other
91       OSes. A more generic utility (than sg_dd) called ddpt in a  package  of
92       the same name has been ported to other OSes.
93

ENVIRONMENT VARIABLES

95       The  SG3_UTILS_OLD_OPTS environment variable is explained in the previ‐
96       ous section. It is only for backward compatibility of the command  line
97       options for older utilities.
98
99       The  SG3_UTILS_DSENSE  environment  variable may be set to a number. If
100       that number is non-zero then descriptor sense is set in the  SNTL  (the
101       small SCSI to NVMe Translation Layer within the underlying library).
102
103       Several  utilities  have  their  own environment variable setting (e.g.
104       sg_persist has SG_PERSIST_IN_RDONLY). See individual utility man  pages
105       for more information.
106
107       There    is    a    Linux    specific   environment   variable   called
108       SG3_UTILS_LINUX_NANO that if defined and the sg driver in the system is
109       4.0.30 or later, will show command durations in nanoseconds rather than
110       the default milliseconds.  Command durations are typically  only  shown
111       if --verbose is used 3 or more times. Due to an interface problem (a 32
112       bit integer that should be 64 bits with the benefit of  hindsight)  the
113       maximum  duration  that  can be represented in nanoseconds is about 4.2
114       seconds. If longer durations may occur then don't define this  environ‐
115       ment variable (or undefine it).
116

LINUX DEVICE NAMING

118       Most  disk  block devices have names like /dev/sda, /dev/sdb, /dev/sdc,
119       etc.  SCSI disks in Linux have always had names like that but in recent
120       Linux kernels it has become more common for many other disks (including
121       SATA disks and USB storage devices) to be named like  that.  Partitions
122       within  a  disk  are specified by a number appended to the device name,
123       starting at 1 (e.g. /dev/sda1 ).
124
125       Tape drives are named /dev/st<num> or /dev/nst<num> where <num>  starts
126       at  zero. Additionally one letter from this list: "lma" may be appended
127       to  the  name.  CD,  DVD  and  BD  readers  (and  writers)  are   named
128       /dev/sr<num> where <num> start at zero. There are less used SCSI device
129       type names, the dmesg and the lsscsi commands may help to find  if  any
130       are attached to a running system.
131
132       There  is  also  a  SCSI  device  driver which offers alternate generic
133       access to SCSI devices. It uses names of the  form  /dev/sg<num>  where
134       <num>  starts at zero. The "lsscsi -g" command may be useful in finding
135       these and which generic name corresponds to a device  type  name  (e.g.
136       /dev/sg2 may correspond to /dev/sda). In the lk 2.6 series a block SCSI
137       generic  driver  was  introduced  and  its  names  are  of   the   form
138       /dev/bsg/<h:c:t:l>  where h, c, t and l are numbers. Again see the lss‐
139       csi command to find the correspondence between that  SCSI  tuple  (i.e.
140       <h:c:t:l>) and alternate device names.
141
142       Prior  to  the  Linux  kernel 2.6 series these utilities could only use
143       generic device names (e.g. /dev/sg1 ). In almost all cases in the Linux
144       kernel 2.6 series, any device name can be used by these utilities.
145
146       Very  little  has  changed in Linux device naming in the Linux kernel 3
147       and 4 series.
148

WINDOWS DEVICE NAMING

150       Storage and related devices can have several device names  in  Windows.
151       Probably the most common in the volume name (e.g. "D:"). There are also
152       a "class" device  names  such  as  "PhysicalDrive<n>",  "CDROM<n>"  and
153       "TAPE<n>". <n> is an integer starting at 0 allocated in ascending order
154       as devices are discovered (and sometimes rediscovered).
155
156       Some storage devices have a SCSI lower level device name  which  starts
157       with  a  SCSI  (pseudo) adapter name of the form "SCSI<n>:". To this is
158       added sub-addressing in the form of a "bus" number, a "target"  identi‐
159       fier and a LUN (Logical Unit Number). The "bus" number is also known as
160       a "PathId".  These are assembled to form a device  name  of  the  form:
161       "SCSI<n>:<bus>,<target>,<lun>". The trailing ",<lun>" may be omitted in
162       which case a LUN of zero is assumed. This lower level device name  can‐
163       not often be used directly since Windows blocks attempts to use it if a
164       class driver has "claimed" the device.  There  are  SCSI  device  types
165       (e.g.   Automation/Drive  interface  type)  for which there is no class
166       driver. At least two transports ("bus types" in  Windows  jargon):  USB
167       and IEEE 1394 do not have a "scsi" device names of this form.
168
169       In  keeping  with DOS file system conventions, the various device names
170       can be given in upper, lower or mixed case. Since "PhysicalDrive<n>" is
171       tedious to write, a shortened form of "PD<n>" is permitted by all util‐
172       ities in this package.
173
174       A single device (e.g. a disk) can have many device names. For  example:
175       "PD0"  can  also  be "C:", "D:" and "SCSI0:0,1,0". The two volume names
176       reflect that the disk has two partitions on it.  Disk  partitions  that
177       are not recognized by Windows are not usually given a volume name. How‐
178       ever Vista does show a volume name for a disk which has  no  partitions
179       recognized by it and when selected invites the user to format it (which
180       may be rather unfriendly to other OSes).
181
182       These utilities assume a given device  name  is  in  the  Win32  device
183       namespace.  To make that explicit "\\.\" can be prepended to the device
184       names mentioned in this section. Beware that  backslash  is  an  escape
185       character  in  Unix  like  shells  and the C programming language. In a
186       shell like Msys (from MinGW) each backslash may need to be typed twice.
187
188       The sg_scan utility within this package lists out Windows device  names
189       in a form that is suitable for other utilities in this package to use.
190

FREEBSD DEVICE NAMING

192       SCSI  disks have block names of the form /dev/da<num> where <num> is an
193       integer starting at zero. The "da" is replaced by "sa"  for  SCSI  tape
194       drives  and "cd" for SCSI CD/DVD/BD drives. Each SCSI device has a cor‐
195       responding pass-through device name of the  form  /dev/pass<num>  where
196       <num>  is an integer starting at zero. The "camcontrol devlist" command
197       may be useful for finding out which SCSI device names are available and
198       the correspondence between class and pass-through names.
199

SOLARIS DEVICE NAMING

201       SCSI  device  names below the /dev directory have a form like: c5t4d3s2
202       where the number following "c" is the controller (HBA) number, the num‐
203       ber  following  "t" is the target number (from the SCSI parallel inter‐
204       face days) and the number following "d" is the LUN. Following  the  "s"
205       is  the  slice number which is related to a partition and by convention
206       "s2" is the whole disk.
207
208       OpenSolaris also has a c5t4d3p2 form where the number following the "p"
209       is  the  partition number apart from "p0" which is the whole disk. So a
210       whole disk may be referred to as either c5t4d3, c5t4d3s2 or c5t4d3p0 .
211
212       And these device names are duplicated in  the  /dev/dsk  and  /dev/rdsk
213       directories.  The former is the block device name and the latter is for
214       "raw" (or char device) access which is  what  sg3_utils  needs.  So  in
215       OpenSolaris  something  of  the form 'sg_inq /dev/rdsk/c5t4d3p0' should
216       work.  If it doesn't work then add  a  '-vvv'  option  for  more  debug
217       information.   Trying this form 'sg_inq /dev/dsk/c5t4d3p0' (note "rdsk"
218       changed to "dsk") will result in an "inappropriate  ioctl  for  device"
219       error.
220
221       The device names within the /dev directory are typically symbolic links
222       to much longer topological names in the /device directory.  In  Solaris
223       cd/dvd/bd  drives  seem  to be treated as disks and so are found in the
224       /dev/rdsk directory. Tape drives appear in the /dev/rmt directory.
225
226       There is also a sgen (SCSI generic) driver which by  default  does  not
227       attach  to  any  device.  See the /kernel/drv/sgen.conf file to control
228       what is attached. Any attached device will have a device  name  of  the
229       form /dev/scsi/c5t4d3 .
230
231       Listing available SCSI devices in Solaris seems to be a challenge. "Use
232       the 'format' command" advice works but seems a very  dangerous  way  to
233       list devices. [It does prompt again before doing any damage.] 'devfsadm
234       -Cv' cleans out the clutter in the /dev/rdsk  directory,  only  leaving
235       what is "live". The "cfgadm -v" command looks promising.
236

NVME SUPPORT

238       NVMe (or NVM Express) is a relatively new storage transport and command
239       set. The level of abstraction of the NVMe command set is somewhat lower
240       the  SCSI  command sets, closer to the level of abstraction of ATA (and
241       SATA) command sets. NVMe claims to be designed with  flash  and  modern
242       "solid state" storage in mind, something unheard of when SCSI was orig‐
243       inally developed in the 1980s.
244
245       The SCSI command sets' advantage is the length of time they  have  been
246       in  place  and the existing tools (like these) to support it. Plus SCSI
247       command sets level of abstraction is both and advantage  and  disadvan‐
248       tage.  Recently  the NVME-MI (Management Interface) designers decide to
249       use the SCSI Enclosure Services (SES-3) standard "as is" with the addi‐
250       tion of two tunnelling NVME-MI commands: SES Send and SES Receive. This
251       means after the OS interface differences are taken  into  account,  the
252       sg_ses,  sg_ses_microcode  and  sg_senddiag  utilities can be used on a
253       NVMe device that supports a newer version of NVME-MI.
254
255       The NVME-MI SES Send and SES Receive commands correspond  to  the  SCSI
256       SEND  DIAGNOSTIC  and RECEIVE DIAGNOSTIC RESULTS commands respectively.
257       There are however a few other commands that need to be translated,  the
258       most  important  of which is the SCSI INQUIRY command to the NVMe Iden‐
259       tify controller/namespace. Starting in  version  1.43  these  utilities
260       contain  a  small SNTL (SCSI to NVMe Translation Layer) to take care of
261       these details.
262
263       As a side effect of this "juggling"  if  the  sg_inq  utility  is  used
264       (without  the  --page=  option)  on  a NVMe DEVICE then the actual NVMe
265       Identifier (controller and possibly namespace)  responses  are  decoded
266       and  output.  However if 'sg_inq --page=sinq <device>' is given for the
267       same DEVICE then parts of the NVMe Identify  controller  and  namespace
268       response  are  translated  to a SCSI standard INQUIRY response which is
269       then decoded and output.
270
271       Apart from the special case with the sg_inq, all other utilities in the
272       package  assume  they  are  talking  to  a  SCSI  device and decode any
273       response accordingly. One easy way for  users  to  see  the  underlying
274       device is a NVMe device is the standard INQUIRY response Vendor Identi‐
275       fication field of "NVMe    " (an 8 character long string with 4  spaces
276       to the right).
277
278       The  following  SCSI  commands  are  currently  supported  by  the SNTL
279       library: INQUIRY, MODE SELECT(10), MODE SENSE(10), READ CAPACITY(10 and
280       16),  RECEIVE  DIAGNOSTIC  RESULTS,  REQUEST SENSE, REPORT LUNS, REPORT
281       SUPPORTED OPERATION CODES, REPORT SUPPORTED TASK MANAGEMENT  FUNCTIONS,
282       SEND DIAGNOSTICS, and TEST UNIT READY.
283

EXIT STATUS

285       To  aid  scripts  that  call these utilities, the exit status is set to
286       indicate success (0) or failure (1 or more).  Note  that  some  of  the
287       lower values correspond to the SCSI sense key values.
288
289       The exit status values listed below can be given to the sg_decode_sense
290       utility (which is found in this package) as follows:
291         sg_decode_sense --err=<exit_status>
292       and a short explanatory string will be output to stdout.
293
294       The exit status values are:
295
296       0      success. Also used for some utilities  that  wish  to  return  a
297              boolean  value  for  the  "true"  case  (and  that  no error has
298              occurred). The false case is conveyed by exit status 36.
299
300       1      syntax error. Either illegal command line options, options  with
301              bad arguments or a combination of options that is not permitted.
302
303       2      the  DEVICE  reports  that  it  is  not  ready for the operation
304              requested.  The DEVICE may be in the process of  becoming  ready
305              (e.g.   spinning  up  but  not at speed) so the utility may work
306              after a wait. In Linux the DEVICE  may  be  temporarily  blocked
307              while error recovery is taking place.
308
309       3      the  DEVICE  reports  a  medium  or  hardware  error (or a blank
310              check). For example an attempt to read a corrupted  block  on  a
311              disk will yield this value.
312
313       5      the DEVICE reports an "illegal request" with an additional sense
314              code other than "invalid command operation code". This is  often
315              a  supported  command with a field set requesting an unsupported
316              capability. For commands that require a "service  action"  field
317              this  value  can  indicate  that  the  command with that service
318              action value is not supported.
319
320       6      the DEVICE reports a "unit attention"  condition.  This  usually
321              indicates  that something unrelated to the requested command has
322              occurred (e.g. a device reset) potentially  before  the  current
323              SCSI  command  was sent. The requested command has not been exe‐
324              cuted by the device. Note that  unit  attention  conditions  are
325              usually only reported once by a device.
326
327       7      the DEVICE reports a "data protect" sense key. This implies some
328              mechanism has blocked writes (or  possibly  all  access  to  the
329              media).
330
331       9      the  DEVICE  reports an illegal request with an additional sense
332              code of "invalid command operation code"  which  means  that  it
333              doesn't support the requested command.
334
335       10     the  DEVICE  reports a "copy aborted". This implies another com‐
336              mand or  device  problem  has  stopped  a  copy  operation.  The
337              EXTENDED  COPY  family of commands (including WRITE USING TOKEN)
338              may return this sense key.
339
340       11     the DEVICE reports an aborted command.  In  some  cases  aborted
341              commands  can  be  retried  immediately  (e.g.  if the transport
342              aborted the command due to congestion).
343
344       14     the DEVICE reports a miscompare sense key.  VERIFY  and  COMPARE
345              AND WRITE commands may report this.
346
347       15     the  utility is unable to open, close or use the given DEVICE or
348              some other file. The given file name could be incorrect or there
349              may be permission problems. Adding the '-v' option may give more
350              information.
351
352       17     a SCSI "Illegal request" sense code received with a  flag  indi‐
353              cating  the  Info  field  is  valid. This is often a LBA but its
354              meaning is command specific.
355
356       18     the DEVICE reports a medium or hardware error (or a blank check)
357              with  a flag indicating the Info field is valid. This is often a
358              LBA (of the first encountered error) but its meaning is  command
359              specific.
360
361       20     the  DEVICE  reports it has a check condition but "no sense" and
362              non-zero information in its additional sense codes. Some polling
363              commands  (e.g.  REQUEST SENSE) can receive this response. There
364              may be useful information in the sense data such as  a  progress
365              indication.
366
367       21     the  DEVICE  reports  a "recovered error". The requested command
368              was successful. Most likely a utility will  report  a  recovered
369              error  to stderr and continue, probably leaving the utility with
370              an exit status of 0 .
371
372       22     the DEVICE reports that the current command  or  its  parameters
373              imply  a  logical block address (LBA) that is out of range. This
374              happens surprisingly often when trying to access the last  block
375              on  a  storage device; either a classic "off by one" logic error
376              or a misreading of the response from READ CAPACITY(10 or 16)  in
377              which  the  address  of the last block rather than the number of
378              blocks on the DEVICE is returned. Since  LBAs  are  origin  zero
379              they  range from 0 to n-1 where n is the number of blocks on the
380              DEVICE, so the LBA of the last block is one less than the  total
381              number of blocks.
382
383       24     the DEVICE reports a SCSI status of "reservation conflict". This
384              means access to the DEVICE with the  current  command  has  been
385              blocked  because another machine (HBA or SCSI "initiator") holds
386              a reservation on this DEVICE. On modern  SCSI  systems  this  is
387              related  to the use of the PERSISTENT RESERVATION family of com‐
388              mands.
389
390       25     the DEVICE reports a SCSI status of "condition  met".  Currently
391              only the PRE-FETCH command (see SBC-4) yields this status.
392
393       26     the  DEVICE  reports a SCSI status of "busy". SAM-6 defines this
394              status as the logical unit is temporarily unable  to  process  a
395              command. It is recommended to re-issue the command.
396
397       27     the DEVICE reports a SCSI status of "task set full".
398
399       28     the  DEVICE  reports a SCSI status of "ACA active". ACA is "auto
400              contingent allegiance" and is seldom used.
401
402       29     the DEVICE reports a SCSI status of "task aborted". SAM-5  says:
403              "This status shall be returned if a command is aborted by a com‐
404              mand or task management function on another I_T  nexus  and  the
405              Control mode page TAS bit is set to one".
406
407       31     error  involving  two  or more command line options. They may be
408              contradicting, select an unsupported mode, or a required  option
409              (given the context) is missing.
410
411       32     there  is  a  logic error in the utility. It corresponds to code
412              comments like "shouldn't/can't get  here".  Perhaps  the  author
413              should be informed.
414
415       33     the command sent to DEVICE has timed out.
416
417       34     this  is  a Windows only exit status and indicates that the Win‐
418              dows error number (32 bits) cannot meaningfully be mapped to  an
419              equivalent  Unix  error  number  returned  as the exit status (7
420              bits).
421
422       36     no error has occurred plus the utility wants to convey a boolean
423              value  of false. The corresponding true value is conveyed by a 0
424              exit status.
425
426       40     the command sent to DEVICE has  received  an  "aborted  command"
427              sense  key  with an additional sense code of 0x10. This group is
428              related to problems with protection information (PI or DIF). For
429              example  this  error  may  occur when reading a block on a drive
430              that has never been written (or is unmapped) if that  drive  was
431              formatted with type 1, 2 or 3 protection.
432
433       41     the  command  sent  to  DEVICE has received an "aborted command"
434              sense key with an additional sense code of 0x10 (as  with  error
435              code) plus a flag indicating the Info field is valid.
436
437       48     this  is an internal message indicating a NVMe status field (SF)
438              is other than zero after a command has been executed (i.e. some‐
439              thing went wrong).  Work in this area is currently experimental.
440
441       49     low  level driver reports a response's residual count (i.e. num‐
442              ber of bytes actually received  by  HBA  is  'requested_bytes  -
443              residual_count') that is
444
445       50     OS system calls that fail often return a small integer number to
446              help. In Unix these are called "errno" values where 0 implies no
447              error.  These  error  codes set aside 51 to 96 for mapping these
448              errno values but that may not be sufficient. Higher errno values
449              that cannot be mapped are all mapped to this value (i.e. 50).
450              Note that an errno value of 0 is mapped to error code 0.
451
452       50 + <os_error_number>
453              OS system calls that fail often return a small integer number to
454              help indicate what the error is. For example in Unix the inabil‐
455              ity  of  a  system  call to allocate memory returns (in 'errno')
456              ENOMEM which often is associated with  the  integer  12.  So  62
457              (i.e.  '50  + 12') may be returned by a utility in this case. It
458              is  also  possible  that  a  utility  in  this  package  reports
459              50+ENOMEM when it can't allocate memory, not necessarily from an
460              OS system call. In recent versions of Linux the file showing the
461              mapping  between symbolic constants (e.g. ENOMEM) and the corre‐
462              sponding  integer  is  in   the   kernel   source   code   file:
463              include/uapi/asm-generic/errno-base.h
464              Note that errno values that are greater than or equal to 47 can‐
465              not fit in range provided. Instead they are all mapped to 50  as
466              discussed in the previous entry.
467
468       97     a SCSI command response failed sanity checks.
469
470       98     the  DEVICE  reports  it  has  a  check  condition but the error
471              doesn't fit into any of the above categories.
472
473       99     any errors that can't be categorized into values  1  to  98  may
474              yield  this  value. This includes transport and operating system
475              errors after the command has been sent to the device.
476
477       100-125
478              these error codes are used by the ddpt utility  which  uses  the
479              sg3_utils library. They are mainly specialized error codes asso‐
480              ciated with offloaded copies.
481
482       126    the utility was found but could  not  be  executed.  That  might
483              occur if the executable does not have execute permissions.
484
485       127    This  is the exit status for utility not found. That might occur
486              when a script calls a utility in this package but the PATH envi‐
487              ronment  variable  has  not  been properly set up, so the script
488              cannot find the executable.
489
490       128 + <signum>
491              If a signal kills a utility then the exit status is 128 plus the
492              signal number. For example if a segmentation fault occurs then a
493              utility is typically killed by SIGSEGV which according to 'man 7
494              signal'  has an associated signal number of 11; so the exit sta‐
495              tus will be 139 .
496
497       255    the utility tried to yield an exit status of 255 or larger. That
498              should not happen; given here for completeness.
499
500       Most  of  the  error  conditions  reported above will be repeatable (an
501       example of one that is not is "unit attention") so the utility  can  be
502       run again with the '-v' option (or several) to obtain more information.
503

COMMON OPTIONS

505       Arguments  to  long options are mandatory for short options as well. In
506       the short form an argument to an option uses zero or more spaces  as  a
507       separator (i.e. the short form does not use "=" as a separator).
508
509       If  an option takes a numeric argument then that argument is assumed to
510       be decimal unless otherwise indicated (e.g.  with  a  leading  "0x",  a
511       trailing "h" or as noted in the usage message).
512
513       Some  options are used uniformly in most of the utilities in this pack‐
514       age. Those options are listed below. Note that there  are  some  excep‐
515       tions.
516
517       -d, --dry-run
518              utilities  that  can cause lots of user data to be lost or over‐
519              written sometimes have  a  --dry-run  option.  Device  modifying
520              actions  are typically bypassed (or skipped) to implement a pol‐
521              icy of "do no harm".  This allows complex command  line  invoca‐
522              tions  to  be  tested  before the action required (e.g. format a
523              disk) is performed. The --dry-run option  has  become  a  common
524              feature  of  many command line utilities (e.g.  the Unix 'patch'
525              command), not just those from this package.
526              Note that most hyphenated option names in this package also  can
527              be   given  with  an  underscore  rather  than  a  hyphen  (e.g.
528              --dry_run).
529
530       -e, --enumerate
531              some utilities (e.g. sg_ses and sg_vpd) store a lot of  informa‐
532              tion  in  internal tables. This option will output that informa‐
533              tion in some readable form (e.g. sorted by an acronym or by page
534              number)  then exit. Note that with this option DEVICE is ignored
535              (as are most other options) and no SCSI IO takes place,  so  the
536              invoker does not need any elevated permissions.
537
538       -h, -?, --help
539              output the usage message then exit. In a few older utilities the
540              '-h' option requests hexadecimal output. In these cases the '-?'
541              option will output the usage message then exit.
542
543       -H, --hex
544              for  SCSI  commands that yield a non-trivial response, print out
545              that response in ASCII hexadecimal. To produce hexadecimal  that
546              can  be  parsed  by  other  utilities  (e.g.  without a relative
547              address to the left and without trailing ASCII) use this  option
548              three or four times.
549
550       -i, --in=FN
551              many  SCSI commands fetch a significant amount of data (returned
552              in the data-in buffer) which several of these  utilities  decode
553              (e.g. sg_vpd and sg_logs). To separate the two steps of fetching
554              the data from a SCSI device and then decoding  it,  this  option
555              has  been  added. The first step (fetching the data) can be done
556              using the --hex or --raw option and redirecting the command line
557              output  to  a  file (often done with ">" in Unix based operating
558              systems). The difference between --hex and  --raw  is  that  the
559              former produces output in ASCII hexadecimal while --raw produces
560              its output in "raw" binary.
561              The second step (i.e. decoding the SCSI response data  now  held
562              in  a file) can be done using this --in=FN option where the file
563              name is FN. If "-" is used for FN then stdin is  assumed,  again
564              this  allows for command line redirection (or piping). That file
565              (or stdin) is assumed to contain ASCII  hexadecimal  unless  the
566              --raw  option  is  also  given in which case it is assumed to be
567              binary. Notice that the meaning of the --raw option is "flipped"
568              when used with --in=FN to act on the input, typically it acts on
569              the output data.
570              Since the structure of the data returned by SCSI commands varies
571              considerably  then  the  usage information or the manpage of the
572              utility being used should be checked. In some  cases  --hex  may
573              need  to  be used multiple times (and is more conveniently given
574              as '-HH' or '-HHH).
575
576       -i, --inhex=FN
577              This option has the same or similar  functionality  as  --in=FN.
578              And  perhaps 'inhex' is more descriptive since by default, ASCII
579              hexadecimal is expected in the contents of  file:  FN.  Alterna‐
580              tively the short form option may be -I or -X. See the "FORMAT OF
581              FILES CONTAINING ASCII HEX" section below for more information.
582
583       -m, --maxlen=LEN
584              several important SCSI commands (e.g. INQUIRY  and  MODE  SENSE)
585              have  response lengths that vary depending on many factors, only
586              some of which these utilities take  into  account.  The  maximum
587              response  length  is  typically  specified  in  the  'allocation
588              length' field of the cdb. In the absence of this option, several
589              utilities use a default allocation length (sometimes recommended
590              in the SCSI draft standards) or a "double fetch" strategy.   See
591              sg_logs(8)  for  its  description  of a "double fetch" strategy.
592              These techniques are imperfect and in  the  presence  of  faulty
593              SCSI  targets  can  cause  problems  (e.g. some USB mass storage
594              devices freeze if they  receive  an  INQUIRY  allocation  length
595              other  than  36).  Also  use of this option disables any "double
596              fetch" strategy that may have otherwise been used.
597
598       -r, --raw
599              for SCSI commands that yield a non-trivial response, output that
600              response  in  binary to stdout. If any error messages or warning
601              are produced they are usually sent to stderr so as to not inter‐
602              fere with the output from this option.
603              Some  utilities  that  consume  data to send to the DEVICE along
604              with the  SCSI  command,  use  this  option.  Alternatively  the
605              --in=FN option causes DEVICE to be ignored and the response data
606              (to be decoded) fetched from a file named  FN.  In  these  cases
607              this option may indicate that binary data can be read from stdin
608              or from a nominated file (e.g. FN).
609
610       -t, --timeout=SECS
611              utilities that  issue  potentially  long-running  SCSI  commands
612              often have a --timeout=SECS option. This typically instructs the
613              operating system to abort the SCSI command in question once  the
614              timeout  expires.  Aborting  SCSI  commands is typically a messy
615              business and in the case of format like commands may  leave  the
616              device  in  a "format corrupt" state requiring another long-run‐
617              ning re-initialization command to be sent. The  argument,  SECS,
618              is  usually  in  seconds and the short form of the option may be
619              something other than -t since the timeout option  was  typically
620              added  later  as storage devices grew in size and initialization
621              commands took longer. Since many utilities had  relatively  long
622              internal command timeouts before this option was introduced, the
623              actual command timeout given to the  operating  systems  is  the
624              higher of the internal timeout and SECS.
625              Many  long  running SCSI commands have an IMMED bit which causes
626              the command to finish relatively quickly but the  initialization
627              process to continue. In such cases the REQUEST SENSE command can
628              be used to monitor progress with its progress  indication  field
629              (see  the  sg_requests  and  sg_turs utilities).  Utilities that
630              send such SCSI command either have an --immed option or a --wait
631              option which is the logical inverse of the "immediate" action.
632
633       -v, --verbose
634              increase  the  level  of  verbosity, (i.e. debug output). Can be
635              used multiple times to further  increase  verbosity.  The  addi‐
636              tional  output  caused  by  this option is almost always sent to
637              stderr.
638
639       -V, --version
640              print the version string and then exit. Each utility has its own
641              version number and date of last code change.
642

NUMERIC ARGUMENTS

644       Many  utilities  have command line options that take numeric arguments.
645       These numeric arguments can be  large  values  (e.g.  a  logical  block
646       address  (LBA)  on  a  disk)  and  can  be inconvenient to enter in the
647       default decimal representation. So various  other  representations  are
648       permitted.
649
650       Multiplicative suffixes are accepted. They are one, two or three letter
651       strings appended directly after the number to which they apply:
652
653          c C         *1
654          w W         *2
655          b B         *512
656          k K KiB     *1024
657          KB kB       *1000
658          m M MiB     *1048576
659          MB mB       *1000000
660          g G GiB     *(2^30)
661          GB gB       *(10^9)
662          t T TiB     *(2^40)
663          TB          *(10^12)
664          p P PiB     *(2^50)
665          PB          *(10^15)
666
667       An example is "2k" for 2048. The large tera and peta suffixes are  only
668       available for numeric arguments that might require 64 bits to represent
669       internally.
670
671       These multiplicative suffixes are  compatible  with  GNU's  dd  command
672       (since 2002) which claims compliance with SI and with IEC 60027-2.
673
674       A  suffix of the form "x<n>" multiplies the preceding number by <n>. An
675       example is "2x33" for "66". The left argument cannot  be  '0'  as  '0x'
676       will  be interpreted as hexadecimal number prefix (see below). The left
677       argument to the multiplication must end in a hexadecimal digit (i.e.  0
678       to  f)  and  the  whole  expression cannot have any embedded whitespace
679       (e.g.  spaces). An ugly example: "0xfx0x2" for 30.
680
681       A suffix of the form "+<n>" adds the preceding number to <n>. An  exam‐
682       ple is "3+1k" for "1027". The left argument to the addition must end in
683       a hexadecimal digit (i.e. 0 to f) and the whole expression cannot  have
684       any  embedded  whitespace (e.g. spaces). Another example: "0xf+0x2" for
685       17.
686
687       Alternatively numerical arguments can be given  in  hexadecimal.  There
688       are  two syntaxes. The number can be preceded by either "0x" or "0X" as
689       found in the C programming language. The second hexadecimal representa‐
690       tion is a trailing "h" or "H" as found in (storage) standards. When hex
691       numbers are given, multipliers cannot be used. For example the  decimal
692       value "256" can be given as "0x100" or "100h".
693

FORMAT OF FILES CONTAINING ASCII HEX

695       Such  a file is assumed to contain a sequence of one or two digit ASCII
696       hexadecimal values separated by  whitespace.  "Whitespace  consists  of
697       either spaces, tabs, blank lines, or any combination thereof". Each one
698       or two digit ASCII hex pair is decoded into a byte (i.e. 8  bits).  The
699       following will be decoded to valid (ascending valued) bytes: '0', '01',
700       '3', 'c', 'F', '4a', 'cC', 'ff'.  Lines containing only whitespace  are
701       ignored.  The  contents  of  any  line  containing a hash mark ('#') is
702       ignored from that point until the end of that line. Users  are  encour‐
703       aged  to  use hash marks to introduce comments in hex files. The author
704       uses the extension'.hex' on such files. Examples can be  found  in  the
705       'inhex' directory.
706

MICROCODE AND FIRMWARE

708       There  are  two  standardized  methods  for downloading microcode (i.e.
709       device firmware) to a SCSI device. The more general  way  is  with  the
710       SCSI WRITE BUFFER command, see the sg_write_buffer utility. SCSI enclo‐
711       sures have their own  method  based  on  the  Download  microcode  con‐
712       trol/status diagnostic page, see the sg_ses_microcode utility.
713

SCRIPTS, EXAMPLES and UTILS

715       There are several bash shell scripts in the 'scripts' subdirectory that
716       invoke compiled utilities (e.g. sg_readcap).  Several  of  the  scripts
717       start  with  'scsi_' rather than 'sg_'. One purpose of these scripts is
718       to call the same utility (e.g. sg_readcap) on multiple devices. Most of
719       the basic compiled utilities only allow one device as an argument. Some
720       distributions install these scripts in a more visible  directory  (e.g.
721       /usr/bin).  Some of these scripts have man page entries. See the README
722       file in the 'scripts' subdirectory.
723
724       There is some example C code plus examples of  complex  invocations  in
725       the 'examples' subdirectory. There is also a README file. The example C
726       may be a simpler example of how to use a  SCSI  pass-through  in  Linux
727       than  the main utilities (found in the 'src' subdirectory). This is due
728       to the fewer abstraction layers (e.g. they don't  worry  the  MinGW  in
729       Windows may open a file in text rather than binary mode).
730
731       Some utilities that the author has found useful have been placed in the
732       'utils' subdirectory.
733

WEB SITE

735       There    is    a    web    page    discussing    this    package     at
736       http://sg.danny.cz/sg/sg3_utils.html  .  The device naming used by this
737       package   on   various   operating    systems    is    discussed    at:
738       http://sg.danny.cz/sg/device_name.html  . There is a git code mirror at
739       https://github.com/hreinecke/sg3_utils . The principle code  repository
740       uses  subversion  and  is  on  the author's equipment. The author keeps
741       track of this via the subversion revision number which is an  ascending
742       integer  (currently  at  774  for this package). The github mirror gets
743       updated periodically from the author's  repository.  Depending  on  the
744       time  of update, the above Downloads section at sg.danny.cz may be more
745       up to date than the github mirror.
746

AUTHORS

748       Written by Douglas Gilbert. Some utilities have been  contributed,  see
749       the CREDITS file and individual source files (in the 'src' directory).
750

REPORTING BUGS

752       Report bugs to <dgilbert at interlog dot com>.
753
755       Copyright © 1999-2020 Douglas Gilbert
756       Some utilities are distributed under a GPL version 2 license while oth‐
757       ers, usually more recent ones, are under a FreeBSD license.  The  files
758       that are common to almost all utilities and thus contain the most reus‐
759       able    code,    namely     sg_lib.[hc],     sg_cmds_basic.[hc]     and
760       sg_cmds_extra.[hc]  are  under a FreeBSD license. There is NO warranty;
761       not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
762

SEE ALSO

764       sdparm(sdparm), ddpt(ddpt), lsscsi(lsscsi), dmesg(1), mt(1)
765
766
767
768sg3_utils-1.45                   February 2020                    SG3_UTILS(8)
Impressum