# phpman > man > SG_OPCODES(8)

[SG_OPCODES(8)](https://www.chedong.com/phpMan.php/man/SGOPCODES/8/markdown)                                 SG3_UTILS                                [SG_OPCODES(8)](https://www.chedong.com/phpMan.php/man/SGOPCODES/8/markdown)



## NAME
       sg_opcodes - report supported SCSI commands or task management functions

## SYNOPSIS
       **sg**___**opcodes**  [_--alpha_]  [_--compact_]  [_--enumerate_] [_--help_] [_--hex_] [_--mask_] [_--mlu_] [_--no-in__‐
       _quiry_] [_--opcode=OP[,SA]_] [_--pdt=DT_] [_--raw_] [_--rctd_] [_--repd_] [_--sa=SA_] [_--tmf_] [_--unsorted_]
       [_--verbose_] [_--version_] _DEVICE_

       **sg**___**opcodes**  [_-a_]  [_-c_]  [_-e_]  [_-H_] [_-m_] [_-M_] [_-n_] [_-o=OP_] [_-p=DT_] [_-q_] [_-R_] [_-s=SA_] [_-t_] [_-u_]
       [_-v_] [_-V_] [_-?_]  _DEVICE_

## DESCRIPTION
       This utility sends a SCSI REPORT SUPPORTED OPERATION CODES or a REPORT SUPPORTED TASK MANAGE‐
       MENT  FUNCTIONS command to the _DEVICE_ and then outputs the response. The default action is to
       report supported operation codes. In this mode it will either list all supported commands  or
       give detailed information on a specific command identified by the _--opcode=OP_ option (perhaps
       with additional information from the _--sa=SA_ option).

       The name of a SCSI command depends on its peripheral device type (e.g. a  disk).  The  REPORT
       SUPPORTED  OPERATION  CODES  and  REPORT SUPPORTED TASK MANAGEMENT FUNCTIONS commands are not
       supported in the MMC command set for CD and DVD devices. This utility does an INQUIRY to  ob‐
       tain the peripheral device type and prints out the vendor, product and revision strings.

       A  similar facility to query supported operation codes previously was available via the CmdDt
       bit in the SCSI INQUIRY command (see [sg_inq(8)](https://www.chedong.com/phpMan.php/man/sginq/8/markdown)). However that facility was made obsolete  and
       replaced  by the REPORT SUPPORTED OPERATION CODES command in SPC-3 (revision 4) during Febru‐
       ary 2002.

       This utility supports two command line syntaxes, the preferred one is shown first in the syn‐
       opsis  and explained in this section. A later section on the old command line syntax outlines
       the second group of options.

## OPTIONS
       Arguments to long options are mandatory for short options as well.

### -a --alpha
              when all supported commands are being listed there is no requirement  for  the  device
              server  (i.e.  the _DEVICE_) to sort the list of commands. When this option is given the
              list of supported commands is sorted by name (alphabetically). When  this  option  and
              the  **--unsorted**  option  are  both  _not_ given then the list of supported commands is
              sorted numerically (first by operation code and then by service action).

### -c --compact
              some command names, especially those associated with some service actions, are getting
              longer.  This  may cause line wrap in the one line per command mode on some terminals.
              When this option is given the opcode and service action fields  are  combined  into  a
              single field with the service action, prefixed by a comma shown directly after the op‐
              code. If there is no service action associated with the command, then  the  comma  and
              the  service  action  are  not shown after the opcode. The CDB size field is not shown
              when this option is given.

### -e --enumerate
              this option prints the name of the SCSI command based on the given opcode,  peripheral
              device  type  and  optionally the service action. If given, _DEVICE_ is ignored. The op‐
              code, peripheral device type and service action default to zero if not given. Thus  if
              this option is the only option given then "Test Unit ready" is output since its opcode
              is 0, it has no service action and it is common to all peripheral device  types  since
              it is defined in the SCSI Primary Commands (SPC) standard(s).

### -h --help
              outputs  the usage message summarizing command line options then exits. Ignores _DEVICE_
              if given.

### -H --hex
              outputs the response in ASCII hexadecimal to stdout.

### -m --mask
              additionally prints out the cdb mask in hex. So a 12 byte cdb  will  have  a  12  byte
              hexadecimal mask. If the hexadecimal is expanded (mentally) to binary then a "1" means
              the corresponding position in the cdb may be set. And "0" means the corresponding  po‐
              sition  in the cdb must not be set. For "0" mask positions that a user tries to set in
              a cdb, the device may either ignore it or report an error, typically with a sense  key
              of "illegal request".

### -M --mlu
              additionally prints out an indication (0 or 1) whether the command effects all logical
              units in the containing target. MLU (Multiple Logical Units) is a bit  in  the  REPORT
              SUPPORTED  OPERATION  CODES  response introduced by proposal 18-045r1 (and possibly in
              spc5r20). Without the option, the default output format which lists all opcodes,  does
              not include a MLU indication.

### -n --no-inquiry
              Prior  to  calling  a SCSI REPORT SUPPORTED OPERATION CODES or a REPORT SUPPORTED TASK
              MANAGEMENT FUNCTIONS command, a SCSI INQUIRY command is performed. The  reason  is  to
              determine  the peripheral device type (pdt) of the _DEVICE_ as this is helpful in trans‐
              lating operation codes to the command names. By default this utility prints a  summary
              of  INQUIRY  command response on stdout. If this option (or the _--raw_ option) is given
              then that summary is not printed on stdout.

### -O --old
              Switch to older style options. Please use as first option.

### -o --opcode
              the _DEVICE_ will be queried for the given operation code (i.e. the _OP_ value)  which  is
              the  first byte of a SCSI command. Optionally, if a _SA_ value is given, it will be used
              as that SCSI command's service action. Note that _OP_ and _OP,0_ are not the  same  thing,
              as  SCSI  does  allow the service action to be 0 (but it is not comman). _OP_ and _SA_ are
              decimal unless prefixed by "0x" or they have a trailing "h".   _OP_  should  be  in  the
              range  0 to 255 (0xff) inclusive. _SA_ should be in the range 0 to 65535 (0xffff) inclu‐
              sive. When this option is not given then all available SCSI commands supported by  the
              _DEVICE_ are listed.

### -p --pdt
              where  _DT_ is the peripheral device type. This is used together with the _--enumerate_ to
              differentiate when a command opcode (and perhaps service action) is shared by multiple
              device types.
              This option may also be used with the _--no-inquiry_ option to suppress this utility do‐
              ing an INQUIRY command since the main reason for doing that is to find the  peripheral
              device type of the _DEVICE_.

### -r --raw
              output the response in binary to stdout. Error messages and warnings, if any, are sent
              to stderr.

### -R --rctd
              set report command timeout descriptor (RCTD) bit in the cdb. The response may  or  may
              not  contain  command  timeout descriptors. If available they are output. If supported
              there are two values: a nominal command timeout and  a  recommended  command  timeout.
              Both  have  units  of  seconds. A value of zero means that no timeout is indicated and
              this is shown in the corresponding decoded output as "-".

### -q --repd
              set read extended parameter data (REPD) bit in the report  task  management  functions
              cdb. 16 bytes rather than the default 4 bytes expected in the response. This was added
              in SPC-4 (revision 26).

### -s --sa
              the _DEVICE_ will be queried for a command with the given service action  (i.e.  the  _SA_
              value).  Used in conjunction with the _--opcode=OP_ option. If this option is not given,
              _--opcode=OP_ is given and the command in question does have a  service  action  then  a
              value  of  0 will be assumed. _SA_ is decimal and expected to be in the range 0 to 65535
              (0xffff) inclusive.

### -t --tmf
              list supported task management functions. This is done with the SCSI REPORT  SUPPORTED
              TASK  MANAGEMENT  FUNCTIONS  command.   When  this option is chosen the _--alpha_, _--op__‐
              _code=OP_, _--rctd_, _--sa=SA_ and _--unsorted_ options are ignored.

### -u --unsorted
              when all supported commands are being listed there is no requirement  for  the  device
              server  (i.e.  the _DEVICE_) to sort the list of commands. When this option is given the
              list of supported commands is in the order given by the _DEVICE_. When  this  option  is
              not  given  the supported commands are sorted numerically (first by operation code and
              then by service action).

### -v --verbose
              increase level of verbosity. Can be used multiple times.

### -V --version
              print out version string then exit.

## NOTES
       As of SPC-5 revision 8 the recognized task management functions are: abort  set,  abort  task
       set,  clear  ACA,  clear  task set, logical unit reset, query task, query asynchronous event,
       query task set, and I_T nexus reset.  In SPC-4 revision 26 target reset and wakeup task  man‐
       agement functions were made obsolete.

       In  the 2.4 series of Linux kernels the _DEVICE_ must be a SCSI generic (sg) device. In the 2.6
       series block devices (e.g. SCSI disks and DVD drives) can  also  be  specified.  For  example
       "sg_opcodes /dev/sda" will work in the 2.6 series kernels.

## EXIT STATUS
       The  exit status of sg_opcodes is 0 when it is successful. Otherwise see the [sg3_utils(8)](https://www.chedong.com/phpMan.php/man/sg3utils/8/markdown) man
       page.

## OLDER COMMAND LINE OPTIONS
       The options in this section were the only ones available prior to sg3_utils  version  1.23  .
       Since then this utility defaults to the newer command line options which can be overridden by
       using _--old_ (or _-O_) as the first option. See the ENVIRONMENT VARIABLES  section  for  another
       way to force the use of these older command line options.

### -a

### -c

### -e

### -H

### -m

### -n

### -N --new
              Switch to the newer style options.

### -o
              byte of a SCSI command. _OP_ is hexadecimal and expected to be in the range 0 to ff  in‐
              clusive.   When this option is not given then all available SCSI commands supported by
              the _DEVICE_ are listed.

### -p

### -q
              _--repd_ in main description.

### -R
              main description.

### -s
              in  conjunction with the _-o=OP_ option. If this option is not given, _-o=OP_ is given and
              the command in question does have a service action then a value of 0 will be  assumed.
              _SA_ is hexadecimal and expected to be in the range 0 to ffff inclusive.

### -t

### -u
              in main description.

### -v

### -V

       **-?**     output usage message. Ignore all other parameters.

## EXAMPLES
       The examples in this page use Linux device names. For suitable device  names  in  other  sup‐
       ported Operating Systems see the [sg3_utils(8)](https://www.chedong.com/phpMan.php/man/sg3utils/8/markdown) man page.

       To  see  the  information about a specific command give its operation code to the '--op=' op‐
       tion. A command line invocation is shown first followed by a typical response:

          # sg_opcodes --op=93h /dev/sdb

         Opcode=0x93
         Command_name: Write [same(16)](https://www.chedong.com/phpMan.php/man/same/16/markdown)
         Command supported [conforming to SCSI standard]
         Usage data: 93 e2 00 00 00 00 ff ff ff ff 00 00 ff ff 00 00

       The next example shows the supported task management functions:

          # sg_opcodes --tmf -n /dev/sdb

       Task Management Functions supported by device:
           Abort task
           Abort task set
           Clear ACA
           Clear task set
           Logical unit reset
           Query task

       Enumerate can be used to look up a SCSI command name in the absence of a device that supports
       that command. The opcode and service action (if required) should be supplied:

          # sg_opcodes --enumerate --op=0x9b,0xa

         SCSI command:
           Read [buffer(16)](https://www.chedong.com/phpMan.php/man/buffer/16/markdown), read data from echo buffer

## ENVIRONMENT VARIABLES
       Since  sg3_utils  version 1.23 the environment variable SG3_UTILS_OLD_OPTS can be given. When
       it is present this utility will expect the older command line options.  So  the  presence  of
       this  environment variable is equivalent to using _--old_ (or _-O_) as the first command line op‐
       tion.

## AUTHOR
       Written by Douglas Gilbert

## REPORTING BUGS
       Report bugs to <dgilbert at interlog dot com>.

## COPYRIGHT
       Copyright © 2004-2021 Douglas Gilbert
       This software is distributed under the GPL version 2. There is NO warranty; not even for MER‐
       CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

## SEE ALSO
       **sg**___**inq(sg3**___**utils)**



sg3_utils-1.46                               March 2020                                [SG_OPCODES(8)](https://www.chedong.com/phpMan.php/man/SGOPCODES/8/markdown)
