home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit v2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Unix / HOWTOs / SCSI-PRO < prev    next >
Text File  |  1999-11-04  |  131KB  |  2,223 lines

  1.   The Linux SCSI programming HOWTO
  2.   Heiko Ei▀feldt heiko@colossus.escape.de
  3.   v1.5, 7 May 1996
  4.  
  5.   This document deals with programming the Linux generic SCSI interface.
  6.  
  7.   1.  What's New?
  8.  
  9.   Newer kernels have changed the interface a bit. This affects a section
  10.   formerly entitled 'rescanning the devices'. Now it is possible to
  11.   add/remove SCSI devices on the fly.
  12.  
  13.   Since kernel 1.3.98 some important header files have been moved/split
  14.   (sg.h and scsi.h).
  15.  
  16.   Some stupid bugs have been replaced by newer ones.
  17.  
  18.   2.  Introduction
  19.  
  20.   This document is a guide to the installation and programming of the
  21.   Linux generic SCSI interface.
  22.  
  23.   It covers kernel prerequisites, device mappings, and basic interaction
  24.   with devices. Some simple C programming examples are included.
  25.   General knowledge of the SCSI command set is required; for more
  26.   information on the SCSI standard and related information, see the
  27.   appendix to this document.
  28.  
  29.   Note the plain text version of this document lacks cross references
  30.   (they show up as ``'').
  31.  
  32.   3.  What Is The Generic SCSI Interface?
  33.  
  34.   The generic SCSI interface has been implemented to provide general
  35.   SCSI access to (possibly exotic) pieces of SCSI hardware. It was
  36.   developed by Lawrence Foard ( entropy@world.std.com) and sponsored by
  37.   Killy Corporation (see the comments in scsi/sg.h).
  38.  
  39.   The interface makes special device handling possible from user level
  40.   applications (i.e. outside the kernel). Thus, kernel driver
  41.   development, which is more risky and difficult to debug, is not
  42.   necessary.
  43.  
  44.   However, if you don't program the driver properly it is possible to
  45.   hang the SCSI bus, the driver, or the kernel. Therefore, it is
  46.   important to properly program the generic driver and to first back up
  47.   all files to avoid losing data. Another useful thing to do before
  48.   running your programs is to issue a sync command to ensure that any
  49.   buffers are flushed to disk, minimizing data loss if the system hangs.
  50.  
  51.   Another advantage of the generic driver is that as long as the
  52.   interface itself does not change, all applications are independent of
  53.   new kernel development. In comparison, other low-level kernel drivers
  54.   have to be synchronized with other internal kernel changes.
  55.  
  56.   Typically, the generic driver is used to communicate with new SCSI
  57.   hardware devices that require special user applications to be written
  58.   to take advantage of their features (e.g. scanners, printers, CD-ROM
  59.   jukeboxes). The generic interface allows these to be written quickly.
  60.  
  61.   4.  What Are The Requirements To Use It?
  62.  
  63.   4.1.  Kernel Configuration
  64.  
  65.   You must have a supported SCSI controller, obviously. Furthermore,
  66.   your kernel must have controller support as well as generic support
  67.   compiled in. Configuring the Linux kernel (via make config under
  68.   /usr/src/linux) typically looks like the following:
  69.  
  70.         ...
  71.        *
  72.        * SCSI support
  73.        *
  74.        SCSI support? (CONFIG_SCSI) [n] y
  75.        *
  76.        * SCSI support type (disk, tape, CDrom)
  77.        *
  78.         ...
  79.        Scsi generic support (CONFIG_CHR_DEV_SG) [n] y
  80.        *
  81.        * SCSI low-level drivers
  82.        *
  83.         ...
  84.  
  85.   If available, modules can of course be build instead.
  86.  
  87.   4.2.  Device Files
  88.  
  89.   The generic SCSI driver uses its own device files, separate from those
  90.   used by the other SCSI device drivers. They can be generated using the
  91.   MAKEDEV script, typically found in the /dev directory. Running MAKEDEV
  92.   sg produces these files:
  93.  
  94.        crw-------   1 root     system    21,   0 Aug 20 20:09 /dev/sga
  95.        crw-------   1 root     system    21,   1 Aug 20 20:09 /dev/sgb
  96.        crw-------   1 root     system    21,   2 Aug 20 20:09 /dev/sgc
  97.        crw-------   1 root     system    21,   3 Aug 20 20:09 /dev/sgd
  98.        crw-------   1 root     system    21,   4 Aug 20 20:09 /dev/sge
  99.        crw-------   1 root     system    21,   5 Aug 20 20:09 /dev/sgf
  100.        crw-------   1 root     system    21,   6 Aug 20 20:09 /dev/sgg
  101.        crw-------   1 root     system    21,   7 Aug 20 20:09 /dev/sgh
  102.                                           |    |
  103.                                       major,   minor device numbers
  104.  
  105.   Note that these are character devices for raw access. On some systems
  106.   these devices may be called /dev/{sg0,sg1,...}, depending on your
  107.   installation, so adjust the following examples accordingly.
  108.  
  109.   4.3.  Device Mapping
  110.  
  111.   These device files are dynamically mapped to SCSI id/LUNs on your SCSI
  112.   bus (LUN = logical unit). The mapping allocates devices consecutively
  113.   for each LUN of each device on each SCSI bus found at time of the SCSI
  114.   scan, beginning at the lower LUNs/ids/buses. It starts with the first
  115.   SCSI controller and continues without interruption with all following
  116.   controllers. This is currently done in the initialisation of the SCSI
  117.   driver.
  118.  
  119.   For example, assuming you had three SCSI devices hooked up with ids 1,
  120.   3, and 5 on the first SCSI bus (each having one LUN), then the
  121.   following mapping would be in effect:
  122.  
  123.        /dev/sga -> SCSI id 1
  124.        /dev/sgb -> SCSI id 3
  125.        /dev/sgc -> SCSI id 5
  126.  
  127.   If you now add a new device with id 4, then the mapping (after the
  128.   next rescan) will be:
  129.  
  130.        /dev/sga -> SCSI id 1
  131.        /dev/sgb -> SCSI id 3
  132.        /dev/sgc -> SCSI id 4
  133.        /dev/sgd -> SCSI id 5
  134.  
  135.   Notice the change for id 5 -- the corresponding device is no longer
  136.   mapped to /dev/sgc but is now under /dev/sgd.
  137.  
  138.   Luckily newer kernels allow for changing this order.
  139.  
  140.   4.3.1.  Dynamically insert and remove SCSI devices
  141.  
  142.   If a newer kernel and the /proc file system is running, a non-busy
  143.   device can be removed and installed 'on the fly'.
  144.  
  145.   To remove a SCSI device:
  146.  
  147.        echo "scsi remove-single-device a b c d" > /proc/scsi/scsi
  148.  
  149.   and similar, to add a SCSI device, do
  150.  
  151.        echo "scsi add-single-device a b c d" > /proc/scsi/scsi
  152.  
  153.   where
  154.  
  155.              a == hostadapter id (first one being 0)
  156.              b == SCSI channel on hostadapter (first one being 0)
  157.              c == ID
  158.              d == LUN (first one being 0)
  159.  
  160.   So in order to swap the /dev/sgc and /dev/sgd mappings from the
  161.   previous example, we could do
  162.  
  163.        echo "scsi remove-single-device 0 0 4 0" > /proc/scsi/scsi
  164.        echo "scsi remove-single-device 0 0 5 0" > /proc/scsi/scsi
  165.        echo "scsi add-single-device 0 0 5 0" > /proc/scsi/scsi
  166.        echo "scsi add-single-device 0 0 4 0" > /proc/scsi/scsi
  167.  
  168.   since generic devices are mapped in the order of their insertion.
  169.  
  170.   When adding more devices to the scsi bus keep in mind there are
  171.   limited spare entries for new devices. The memory has been allocated
  172.   at boot time and has room for 2 more devices.
  173.  
  174.   5.  Programmers Guide
  175.  
  176.   The following sections are for programmers who want to use the generic
  177.   SCSI interface in their own applications. An example will be given
  178.   showing how to access a SCSI device with the INQUIRY and the
  179.   TESTUNITREADY commands.
  180.  
  181.   When using these code examples, note the following:
  182.  
  183.   ╖  the location of the header files sg.h and scsi.h has changed in
  184.      kernel version 1.3.98. Now these files are located at
  185.      /usr/src/linux/include/scsi, which is hopefully linked to
  186.      /usr/include/scsi. Previously they were in
  187.      /usr/src/linux/drivers/scsi. We assume a newer kernel in the
  188.      following text.
  189.  
  190.   ╖  the generic SCSI interface was extended in kernel version 1.1.68;
  191.      the examples require at least this version. But please avoid kernel
  192.      version 1.1.77 up to 1.1.89 and 1.3.52 upto 1.3.56 since they had a
  193.      broken generic scsi interface.
  194.  
  195.   ╖  the constant DEVICE in the header section describing the accessed
  196.      device should be set according to your available devices (see
  197.      section ``''.
  198.  
  199.   6.  Overview Of Device Programming
  200.  
  201.   The header file include/scsi/sg.h contains a description of the
  202.   interface (this is based on kernel version 1.3.98):
  203.  
  204.   struct sg_header
  205.    {
  206.     int pack_len;
  207.                      /* length of incoming packet (including header) */
  208.     int reply_len;   /* maximum length of expected reply */
  209.     int pack_id;     /* id number of packet */
  210.     int result;      /* 0==ok, otherwise refer to errno codes */
  211.     unsigned int twelve_byte:1;
  212.                  /* Force 12 byte command length for group 6 & 7 commands  */
  213.     unsigned int other_flags:31;                  /* for future use */
  214.     unsigned char sense_buffer[16]; /* used only by reads */
  215.     /* command follows then data for command */
  216.    };
  217.  
  218.   This structure describes how a SCSI command is to be processed and has
  219.   room to hold the results of the execution of the command.  The
  220.   individual structure components will be discussed later in section
  221.   ``''.
  222.  
  223.   The general way of exchanging data with the generic driver is as
  224.   follows: to send a command to an opened generic device, write() a
  225.   block containing these three parts to it:
  226.  
  227.        struct sg_header
  228.        SCSI command
  229.        data to be sent with the command
  230.  
  231.   To obtain the result of a command, read() a block with this (similar)
  232.   block structure:
  233.  
  234.        struct sg_header
  235.        data coming from the device
  236.  
  237.   This is a general overview of the process. The following sections
  238.   describe each of the steps in more detail.
  239.  
  240.   NOTE: Up to recent kernel versions, it is necessary to block the
  241.   SIGINT signal between the write() and the corresponding read() call
  242.   (i.e. via sigprocmask()). A return after the write() part without any
  243.   read() to fetch the results will block on subsequent accesses. This
  244.   signal blocking has not yet been included in the example code. So
  245.   better do not issue SIGINT (a la ^C) when running these examples.
  246.  
  247.   7.  Opening The Device
  248.  
  249.   A generic device has to be opened for read and write access:
  250.  
  251.                int fd = open (device_name, O_RDWR);
  252.  
  253.   (This is the case even for a read-only hardware device such as a cdrom
  254.   drive).
  255.  
  256.   We have to perform a write to send the command and a read to get back
  257.   any results. In the case of an error the return code is negative (see
  258.   section ``'' for a complete list).
  259.  
  260.   8.  The Header Structure
  261.  
  262.   The header structure struct sg_header serves as a controlling layer
  263.   between the application and the kernel driver.  We now discuss its
  264.   components in detail.
  265.  
  266.      int pack_len
  267.         defines the size of the block written to the driver.  This is
  268.         defined within the kernel for internal use.
  269.  
  270.      int reply_len
  271.         defines the size of the block to be accepted at reply.  This is
  272.         defined from the application side.
  273.  
  274.      int pack_id
  275.         This field helps to assign replies to requests. The application
  276.         can supply a unique id for each request. Suppose you have
  277.         written several commands (say 4) to one device. They may work in
  278.         parallel, one being the fastest. When getting replies via 4
  279.         reads, the replies do not have to have the order of the
  280.         requests. To identify the correct reply for a given request one
  281.         can use the pack_id field. Typically its value is incremented
  282.         after each request (and wraps eventually). The maximum amount of
  283.         outstanding requests is limited by the kernel to SG_MAX_QUEUE
  284.         (eg 4).
  285.  
  286.      int result
  287.         the result code of a read or write call.  This is (sometimes)
  288.         defined from the generic driver (kernel) side.  It is safe to
  289.         set it to null before the write call.  These codes are defined
  290.         in errno.h (0 meaning no error).
  291.  
  292.      unsigned int twelve_byte:1
  293.         This field is necessary only when using non-standard vendor
  294.         specific commands (in the range 0xc0 - 0xff).  When these
  295.         commands have a command length of 12 bytes instead of 10, this
  296.         field has to be set to one before the write call. Other command
  297.         lengths are not supported. This is defined from the application
  298.         side.
  299.  
  300.      unsigned char sense_buffer[16]
  301.         This buffer is set after a command is completed (after a read()
  302.         call) and contains the SCSI sense code. Some command results
  303.         have to be read from here (e.g. for TESTUNITREADY). Usually it
  304.         contains just zero bytes.  The value in this field is set by the
  305.         generic driver (kernel) side.
  306.  
  307.   The following example function interfaces directly with the generic
  308.   kernel driver. It defines the header structure, sends the command via
  309.   write, gets the result via read and does some (limited) error
  310.   checking.  The sense buffer data is available in the output buffer
  311.   (unless a NULL pointer has been given, in which case it's in the input
  312.   buffer). We will use it in the examples which follow.
  313.  
  314.   Note: Set the value of DEVICE to your device descriptor.
  315.  
  316.   #define DEVICE "/dev/sgc"
  317.  
  318.   /* Example program to demonstrate the generic SCSI interface */
  319.   #include <stdio.h>
  320.   #include <unistd.h>
  321.   #include <string.h>
  322.   #include <fcntl.h>
  323.   #include <errno.h>
  324.   #include <scsi/sg.h>
  325.  
  326.   #define SCSI_OFF sizeof(struct sg_header)
  327.   static unsigned char cmd[SCSI_OFF + 18];      /* SCSI command buffer */
  328.   int fd;                               /* SCSI device/file descriptor */
  329.  
  330.   /* process a complete SCSI cmd. Use the generic SCSI interface. */
  331.   static int handle_SCSI_cmd(unsigned cmd_len,         /* command length */
  332.                              unsigned in_size,         /* input data size */
  333.                              unsigned char *i_buff,    /* input buffer */
  334.                              unsigned out_size,        /* output data size */
  335.                              unsigned char *o_buff     /* output buffer */
  336.                              )
  337.   {
  338.       int status = 0;
  339.       struct sg_header *sg_hd;
  340.  
  341.       /* safety checks */
  342.       if (!cmd_len) return -1;            /* need a cmd_len != 0 */
  343.       if (!i_buff) return -1;             /* need an input buffer != NULL */
  344.   #ifdef SG_BIG_BUFF
  345.       if (SCSI_OFF + cmd_len + in_size > SG_BIG_BUFF) return -1;
  346.       if (SCSI_OFF + out_size > SG_BIG_BUFF) return -1;
  347.   #else
  348.       if (SCSI_OFF + cmd_len + in_size > 4096) return -1;
  349.       if (SCSI_OFF + out_size > 4096) return -1;
  350.   #endif
  351.  
  352.       if (!o_buff) out_size = 0;      /* no output buffer, no output size */
  353.  
  354.       /* generic SCSI device header construction */
  355.       sg_hd = (struct sg_header *) i_buff;
  356.       sg_hd->reply_len   = SCSI_OFF + out_size;
  357.       sg_hd->twelve_byte = cmd_len == 12;
  358.       sg_hd->result = 0;
  359.   #if     0
  360.       sg_hd->pack_len    = SCSI_OFF + cmd_len + in_size; /* not necessary */
  361.       sg_hd->pack_id;     /* not used */
  362.       sg_hd->other_flags; /* not used */
  363.   #endif
  364.  
  365.       /* send command */
  366.       status = write( fd, i_buff, SCSI_OFF + cmd_len + in_size );
  367.       if ( status < 0 || status != SCSI_OFF + cmd_len + in_size ||
  368.                          sg_hd->result ) {
  369.           /* some error happened */
  370.           fprintf( stderr, "write(generic) result = 0x%x cmd = 0x%x\n",
  371.                       sg_hd->result, i_buff[SCSI_OFF] );
  372.           perror("");
  373.           return status;
  374.       }
  375.  
  376.       if (!o_buff) o_buff = i_buff;       /* buffer pointer check */
  377.  
  378.       /* retrieve result */
  379.       status = read( fd, o_buff, SCSI_OFF + out_size);
  380.       if ( status < 0 || status != SCSI_OFF + out_size || sg_hd->result ) {
  381.           /* some error happened */
  382.           fprintf( stderr, "read(generic) status = 0x%x, result = 0x%x, "
  383.                            "cmd = 0x%x\n",
  384.                            status, sg_hd->result, o_buff[SCSI_OFF] );
  385.           fprintf( stderr, "read(generic) sense "
  386.                   "%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\n",
  387.                   sg_hd->sense_buffer[0],         sg_hd->sense_buffer[1],
  388.                   sg_hd->sense_buffer[2],         sg_hd->sense_buffer[3],
  389.                   sg_hd->sense_buffer[4],         sg_hd->sense_buffer[5],
  390.                   sg_hd->sense_buffer[6],         sg_hd->sense_buffer[7],
  391.                   sg_hd->sense_buffer[8],         sg_hd->sense_buffer[9],
  392.                   sg_hd->sense_buffer[10],        sg_hd->sense_buffer[11],
  393.                   sg_hd->sense_buffer[12],        sg_hd->sense_buffer[13],
  394.                   sg_hd->sense_buffer[14],        sg_hd->sense_buffer[15]);
  395.           if (status < 0)
  396.               perror("");
  397.       }
  398.       /* Look if we got what we expected to get */
  399.       if (status == SCSI_OFF + out_size) status = 0; /* got them all */
  400.  
  401.       return status;  /* 0 means no error */
  402.   }
  403.  
  404.   While this may look somewhat complex at first appearance, most of the
  405.   code is for error checking and reporting (which is useful even after
  406.   the code is working).
  407.  
  408.   Handle_SCSI_cmd has a generalized form for all SCSI commands types,
  409.   falling into each of these categories:
  410.  
  411.               Data Mode              | Example Command
  412.        ===============================================
  413.        neither input nor output data | test unit ready
  414.         no input data, output data   | inquiry, read
  415.         input data, no output data   | mode select, write
  416.           input data, output data    | mode sense
  417.  
  418.   9.  Inquiry Command Example
  419.  
  420.   One of the most basic SCSI commands is the INQUIRY command, used to
  421.   identify the type and make of the device. Here is the definition from
  422.   the SCSI-2 specification (for details refer to the SCSI-2 standard).
  423.  
  424.                               Table 44: INQUIRY Command
  425.   +=====-========-========-========-========-========-========-========-========+
  426.   |  Bit|   7    |   6    |   5    |   4    |   3    |   2    |   1    |   0    |
  427.   |Byte |        |        |        |        |        |        |        |        |
  428.   |=====+=======================================================================|
  429.   | 0   |                           Operation Code (12h)                        |
  430.   |-----+-----------------------------------------------------------------------|
  431.   | 1   | Logical Unit Number      |                  Reserved         |  EVPD  |
  432.   |-----+-----------------------------------------------------------------------|
  433.   | 2   |                           Page Code                                   |
  434.   |-----+-----------------------------------------------------------------------|
  435.   | 3   |                           Reserved                                    |
  436.   |-----+-----------------------------------------------------------------------|
  437.   | 4   |                           Allocation Length                           |
  438.   |-----+-----------------------------------------------------------------------|
  439.   | 5   |                           Control                                     |
  440.   +=============================================================================+
  441.  
  442.   The output data are as follows:
  443.  
  444.                        Table 45: Standard INQUIRY Data Format
  445.   +=====-========-========-========-========-========-========-========-========+
  446.   |  Bit|   7    |   6    |   5    |   4    |   3    |   2    |   1    |   0    |
  447.   |Byte |        |        |        |        |        |        |        |        |
  448.   |=====+==========================+============================================|
  449.   | 0   | Peripheral Qualifier     |           Peripheral Device Type           |
  450.   |-----+-----------------------------------------------------------------------|
  451.   | 1   |  RMB   |                  Device-Type Modifier                        |
  452.   |-----+-----------------------------------------------------------------------|
  453.   | 2   |   ISO Version   |       ECMA Version       |  ANSI-Approved Version   |
  454.   |-----+-----------------+-----------------------------------------------------|
  455.   | 3   |  AENC  | TrmIOP |     Reserved    |         Response Data Format      |
  456.   |-----+-----------------------------------------------------------------------|
  457.   | 4   |                           Additional Length (n-4)                     |
  458.   |-----+-----------------------------------------------------------------------|
  459.   | 5   |                           Reserved                                    |
  460.   |-----+-----------------------------------------------------------------------|
  461.   | 6   |                           Reserved                                    |
  462.   |-----+-----------------------------------------------------------------------|
  463.   | 7   | RelAdr | WBus32 | WBus16 |  Sync  | Linked |Reserved| CmdQue | SftRe  |
  464.   |-----+-----------------------------------------------------------------------|
  465.   | 8   | (MSB)                                                                 |
  466.   |- - -+---                        Vendor Identification                    ---|
  467.   | 15  |                                                                 (LSB) |
  468.   |-----+-----------------------------------------------------------------------|
  469.   | 16  | (MSB)                                                                 |
  470.   |- - -+---                        Product Identification                   ---|
  471.   | 31  |                                                                 (LSB) |
  472.   |-----+-----------------------------------------------------------------------|
  473.   | 32  | (MSB)                                                                 |
  474.   |- - -+---                        Product Revision Level                   ---|
  475.   | 35  |                                                                 (LSB) |
  476.   |-----+-----------------------------------------------------------------------|
  477.   | 36  |                                                                       |
  478.   |- - -+---                        Vendor Specific                          ---|
  479.   | 55  |                                                                       |
  480.   |-----+-----------------------------------------------------------------------|
  481.   | 56  |                                                                       |
  482.   |- - -+---                        Reserved                                 ---|
  483.   | 95  |                                                                       |
  484.   |=====+=======================================================================|
  485.   |     |                       Vendor-Specific Parameters                      |
  486.   |=====+=======================================================================|
  487.   | 96  |                                                                       |
  488.   |- - -+---                        Vendor Specific                          ---|
  489.   | n   |                                                                       |
  490.   +=============================================================================+
  491.  
  492.   The next example uses the low-level function handle_SCSI_cmd to
  493.   perform the Inquiry SCSI command.
  494.  
  495.   We first append the command block to the generic header, then call
  496.   handle_SCSI_cmd.  Note that the output buffer size argument for the
  497.   handle_SCSI_cmd call excludes the generic header size.  After command
  498.   completion the output buffer contains the requested data, unless an
  499.   error occurred.
  500.  
  501.   #define INQUIRY_CMD     0x12
  502.   #define INQUIRY_CMDLEN  6
  503.   #define INQUIRY_REPLY_LEN 96
  504.   #define INQUIRY_VENDOR  8       /* Offset in reply data to vendor name */
  505.  
  506.   /* request vendor brand and model */
  507.   static unsigned char *Inquiry ( void )
  508.   {
  509.     unsigned char Inqbuffer[ SCSI_OFF + INQUIRY_REPLY_LEN ];
  510.     unsigned char cmdblk [ INQUIRY_CMDLEN ] =
  511.         { INQUIRY_CMD,  /* command */
  512.                     0,  /* lun/reserved */
  513.                     0,  /* page code */
  514.                     0,  /* reserved */
  515.     INQUIRY_REPLY_LEN,  /* allocation length */
  516.                     0 };/* reserved/flag/link */
  517.  
  518.     memcpy( cmd + SCSI_OFF, cmdblk, sizeof(cmdblk) );
  519.  
  520.     /*
  521.      * +------------------+
  522.      * | struct sg_header | <- cmd
  523.      * +------------------+
  524.      * | copy of cmdblk   | <- cmd + SCSI_OFF
  525.      * +------------------+
  526.      */
  527.  
  528.     if (handle_SCSI_cmd(sizeof(cmdblk), 0, cmd,
  529.                         sizeof(Inqbuffer) - SCSI_OFF, Inqbuffer )) {
  530.         fprintf( stderr, "Inquiry failed\n" );
  531.         exit(2);
  532.     }
  533.     return (Inqbuffer + SCSI_OFF);
  534.   }
  535.  
  536.   The example above follows this structure. The Inquiry function copies
  537.   its command block behind the generic header (given by SCSI_OFF). Input
  538.   data is not present for this command.  Handle_SCSI_cmd will define the
  539.   header structure. We can now implement the function main to complete
  540.   this working example program.
  541.  
  542.        void main( void )
  543.        {
  544.          fd = open(DEVICE, O_RDWR);
  545.          if (fd < 0) {
  546.            fprintf( stderr, "Need read/write permissions for "DEVICE".\n" );
  547.            exit(1);
  548.          }
  549.  
  550.          /* print some fields of the Inquiry result */
  551.          printf( "%s\n", Inquiry() + INQUIRY_VENDOR );
  552.        }
  553.  
  554.   We first open the device, check for errors, and then call the higher
  555.   level subroutine. Then we print the results in human readable format
  556.   including the vendor, product, and revision.
  557.  
  558.   Note: There is more information in the Inquiry result than this little
  559.   program gives. You may want to extend the program to give device type,
  560.   ANSI version etc. The device type is of special importance, since it
  561.   determines the mandatory and optional command sets for this device.
  562.   If you don't want to program it yourself, you may want to use the
  563.   scsiinfo program from Eric Youngdale, which requests nearly all
  564.   information about an SCSI device. Look at tsx-11.mit.edu in
  565.   pub/Linux/ALPHA/scsi.
  566.  
  567.   10.  The Sense Buffer
  568.  
  569.   Commands with no output data can give status information via the sense
  570.   buffer (which is part of the header structure).  Sense data is
  571.   available when the previous command has terminated with a CHECK
  572.   CONDITION status. In this case the kernel automatically retrieves the
  573.   sense data via a REQUEST SENSE command. Its structure is:
  574.  
  575.        +=====-========-========-========-========-========-========-========-========+
  576.        |  Bit|   7    |   6    |   5    |   4    |   3    |   2    |   1    |   0    |
  577.        |Byte |        |        |        |        |        |        |        |        |
  578.        |=====+========+==============================================================|
  579.        | 0   | Valid  |                  Error Code (70h or 71h)                     |
  580.        |-----+-----------------------------------------------------------------------|
  581.        | 1   |                           Segment Number                              |
  582.        |-----+-----------------------------------------------------------------------|
  583.        | 2   |Filemark|  EOM   |  ILI   |Reserved|         Sense Key                 |
  584.        |-----+-----------------------------------------------------------------------|
  585.        | 3   | (MSB)                                                                 |
  586.        |- - -+---                        Information                              ---|
  587.        | 6   |                                                                 (LSB) |
  588.        |-----+-----------------------------------------------------------------------|
  589.        | 7   |                           Additional Sense Length (n-7)               |
  590.        |-----+-----------------------------------------------------------------------|
  591.        | 8   | (MSB)                                                                 |
  592.        |- - -+---                        Command-Specific Information             ---|
  593.        | 11  |                                                                 (LSB) |
  594.        |-----+-----------------------------------------------------------------------|
  595.        | 12  |                           Additional Sense Code                       |
  596.        |-----+-----------------------------------------------------------------------|
  597.        | 13  |                           Additional Sense Code Qualifier             |
  598.        |-----+-----------------------------------------------------------------------|
  599.        | 14  |                           Field Replaceable Unit Code                 |
  600.        |-----+-----------------------------------------------------------------------|
  601.        | 15  |  SKSV  |                                                              |
  602.        |- - -+------------               Sense-Key Specific                       ---|
  603.        | 17  |                                                                       |
  604.        |-----+-----------------------------------------------------------------------|
  605.        | 18  |                                                                       |
  606.        |- - -+---                        Additional Sense Bytes                   ---|
  607.        | n   |                                                                       |
  608.        +=============================================================================+
  609.  
  610.   Note: The most useful fields are Sense Key (see section ``''),
  611.   Additional Sense Code and Additional Sense Code Qualifier (see section
  612.   ``''). The latter two are used combined as a pair.
  613.  
  614.   11.  Example Using Sense Buffer
  615.  
  616.   Here we will use the TEST UNIT READY command to check whether media is
  617.   loaded into our device. The header declarations and function
  618.   handle_SCSI_cmd from the inquiry example will be needed as well.
  619.  
  620.                                Table 73: TEST UNIT READY Command
  621.        +=====-========-========-========-========-========-========-========-========+
  622.        |  Bit|   7    |   6    |   5    |   4    |   3    |   2    |   1    |   0    |
  623.        |Byte |        |        |        |        |        |        |        |        |
  624.        |=====+=======================================================================|
  625.        | 0   |                           Operation Code (00h)                        |
  626.        |-----+-----------------------------------------------------------------------|
  627.        | 1   | Logical Unit Number      |                  Reserved                  |
  628.        |-----+-----------------------------------------------------------------------|
  629.        | 2   |                           Reserved                                    |
  630.        |-----+-----------------------------------------------------------------------|
  631.        | 3   |                           Reserved                                    |
  632.        |-----+-----------------------------------------------------------------------|
  633.        | 4   |                           Reserved                                    |
  634.        |-----+-----------------------------------------------------------------------|
  635.        | 5   |                           Control                                     |
  636.        +=============================================================================+
  637.  
  638.   Here is the function which implements it:
  639.  
  640.   #define TESTUNITREADY_CMD 0
  641.   #define TESTUNITREADY_CMDLEN 6
  642.  
  643.   #define ADD_SENSECODE 12
  644.   #define ADD_SC_QUALIFIER 13
  645.   #define NO_MEDIA_SC 0x3a
  646.   #define NO_MEDIA_SCQ 0x00
  647.  
  648.   int TestForMedium ( void )
  649.   {
  650.     /* request READY status */
  651.     static unsigned char cmdblk [TESTUNITREADY_CMDLEN] = {
  652.         TESTUNITREADY_CMD, /* command */
  653.                         0, /* lun/reserved */
  654.                         0, /* reserved */
  655.                         0, /* reserved */
  656.                         0, /* reserved */
  657.                         0};/* control */
  658.  
  659.     memcpy( cmd + SCSI_OFF, cmdblk, sizeof(cmdblk) );
  660.  
  661.     /*
  662.      * +------------------+
  663.      * | struct sg_header | <- cmd
  664.      * +------------------+
  665.      * | copy of cmdblk   | <- cmd + SCSI_OFF
  666.      * +------------------+
  667.      */
  668.  
  669.     if (handle_SCSI_cmd(sizeof(cmdblk), 0, cmd,
  670.                               0, NULL)) {
  671.         fprintf (stderr, "Test unit ready failed\n");
  672.         exit(2);
  673.     }
  674.  
  675.     return
  676.      *(((struct sg_header*)cmd)->sense_buffer +ADD_SENSECODE) !=
  677.                                                           NO_MEDIA_SC ||
  678.      *(((struct sg_header*)cmd)->sense_buffer +ADD_SC_QUALIFIER) !=
  679.                                                           NO_MEDIA_SCQ;
  680.   }
  681.  
  682.   Combined with this main function we can do the check.
  683.  
  684.        void main( void )
  685.        {
  686.          fd = open(DEVICE, O_RDWR);
  687.          if (fd < 0) {
  688.            fprintf( stderr, "Need read/write permissions for "DEVICE".\n" );
  689.            exit(1);
  690.          }
  691.  
  692.          /* look if medium is loaded */
  693.  
  694.          if (!TestForMedium()) {
  695.            printf("device is unloaded\n");
  696.          } else {
  697.            printf("device is loaded\n");
  698.          }
  699.        }
  700.  
  701.   The file generic_demo.c from the appendix contains both examples.
  702.  
  703.   12.  Ioctl Functions
  704.  
  705.   There are two ioctl functions available:
  706.  
  707.   ╖  ioctl(fd, SG_SET_TIMEOUT, &Timeout); sets the timeout value to
  708.      Timeout * 10 milliseconds. Timeout has to be declared as int.
  709.  
  710.   ╖  ioctl(fd, SG_GET_TIMEOUT, &Timeout); gets the current timeout
  711.      value.  Timeout has to be declared as int.
  712.  
  713.   13.  Driver Defaults
  714.  
  715.   13.1.  Transfer Lengths
  716.  
  717.   Currently (at least up to kernel version 1.1.68) input and output
  718.   sizes have to be less than or equal than 4096 bytes unless the kernel
  719.   has been compiled with SG_BIG_BUFF defined, if which case it is
  720.   limited to SG_BIG_BUFF (e.g. 32768) bytes.  These sizes include the
  721.   generic header as well as the command block on input.  SG_BIG_BUFF can
  722.   be safely increased upto (131072 - 512). To take advantage of this, a
  723.   new kernel has to be compiled and booted, of course.
  724.  
  725.   13.2.  Timeout And Retry Values
  726.  
  727.   The default timeout value is set to one minute (Timeout = 6000).  It
  728.   can be changed through an ioctl call (see section ``'').  The default
  729.   number of retries is one.
  730.  
  731.   14.  Obtaining The Scsi Specifications
  732.  
  733.   There are standards entitled SCSI-1 and SCSI-2 (and possibly soon
  734.   SCSI-3). The standards are mostly upward compatible.
  735.  
  736.   The SCSI-1 standard is (in the author's opinion) mostly obsolete, and
  737.   SCSI-2 is the most widely used. SCSI-3 is very new and very expensive.
  738.   These standardized command sets specify mandatory and optional
  739.   commands for SCSI manufacturers and should be preferred over the
  740.   vendor specific command extensions which are not standardized and for
  741.   which programming information is seldom available. Of course sometimes
  742.   there is no alternative to these extensions.
  743.  
  744.   Electronic copies of the latest drafts are available via anonymous ftp
  745.   from:
  746.  
  747.   ╖  ftp.cs.tulane.edu:pub/scsi
  748.  
  749.   ╖  ftp.symbios.com:/pub/standards
  750.  
  751.   ╖  ftp.cs.uni-sb.de:/pub/misc/doc/scsi
  752.  
  753.   (I got my SCSI specification from the Yggdrasil Linux CD-ROM in the
  754.   directory /usr/doc/scsi-2 and /usr/doc/scsi-1).
  755.  
  756.   The SCSI FAQ also lists the following sources of printed information:
  757.  
  758.   The SCSI specification: Available from:
  759.  
  760.              Global Engineering Documents
  761.              15 Inverness Way East
  762.              Englewood Co  80112-5704
  763.              (800) 854-7179
  764.                SCSI-1: X3.131-1986
  765.                SCSI-2: X3.131-199x
  766.                SCSI-3 X3T9.2/91-010R4 Working Draft
  767.  
  768.        (Global Engineering Documentation in Irvine, CA (714)261-1455??)
  769.  
  770.        SCSI-1: Doc \# X3.131-1986 from ANSI, 1430 Broadway, NY, NY 10018
  771.  
  772.        IN-DEPTH EXPLORATION OF SCSI can be obtained from
  773.        Solution Technology, Attn: SCSI Publications, POB 104, Boulder Creek,
  774.        CA 95006, (408)338-4285, FAX (408)338-4374
  775.  
  776.        THE SCSI ENCYLOPEDIA and the SCSI BENCH REFERENCE can be obtained from
  777.        ENDL Publishing, 14426 Black Walnut Ct., Saratoga, CA 95090,
  778.        (408)867-6642, FAX (408)867-2115
  779.  
  780.        SCSI: UNDERSTANDING THE SMALL COMPUTER SYSTEM INTERFACE was published
  781.        by Prentice-Hall, ISBN 0-13-796855-8
  782.  
  783.   15.  Related Information Sources
  784.  
  785.   15.1.  HOWTOs and FAQs
  786.  
  787.   The Linux SCSI-HOWTO by Drew Eckhardt covers all supported SCSI
  788.   controllers as well as device specific questions. A lot of
  789.   troubleshooting hints are given. It is available from sunsite.unc.edu
  790.   in /pub/Linux/docs/LDP and its mirror sites.
  791.  
  792.   General questions about SCSI are answered in the SCSI-FAQ from the
  793.   newsgroup Comp.Periphs.Scsi (available on tsx-11 in
  794.   pub/linux/ALPHA/scsi and mirror sites).
  795.  
  796.   15.2.  Mailing list
  797.  
  798.   There is a mailing list for bug reports and questions regarding SCSI
  799.   development under Linux.  To join, send email to
  800.   majordomo@vger.rutgers.edu with the line subscribe linux-scsi in the
  801.   body of the message.  Messages should be posted to linux-
  802.   scsi@vger.rutgers.edu.  Help text can be requested by sending the
  803.   message line "help" to majordomo@vger.rutgers.edu.
  804.  
  805.   15.3.  Example code
  806.  
  807.      sunsite.unc.edu: apps/graphics/hpscanpbm-0.3a.tar.gz
  808.         This package handles a HP scanjet scanner through the generic
  809.         interface.
  810.  
  811.      tsx-11.mit.edu: BETA/cdrom/private/mkisofs/cdwrite-1.3.tar.gz
  812.         The cdwrite package uses the generic interface to write a cd
  813.         image to a cd writer.
  814.      sunsite.unc.edu: apps/sound/cds/cdda2wav*.src.tar.gz
  815.         A shameless plug for my own application, which copies audio cd
  816.         tracks into wav files.
  817.  
  818.   16.  Other useful stuff
  819.  
  820.   Things that may come in handy. I don't have no idea if there are newer
  821.   or better versions around. Feedback is welcome.
  822.  
  823.   16.1.  Device driver writer helpers
  824.  
  825.   These documents can be found at the sunsite.unc.edu ftp server and its
  826.   mirrors.
  827.  
  828.      /pub/Linux/docs/kernel/kernel-hackers-guide
  829.         The LDP kernel hackers guide. May be a bit outdated, but covers
  830.         the most fundamental things.
  831.  
  832.      /pub/Linux/docs/kernel/drivers.doc.z
  833.         This document covers writing character drivers.
  834.  
  835.      /pub/Linux/docs/kernel/tutorial.doc.z
  836.         Tutorial on writing a character device driver with code.
  837.  
  838.      /pub/Linux/docs/kernel/scsi.paper.tar.gz
  839.         A Latex document describing howto write a SCSI driver.
  840.  
  841.      /pub/Linux/docs/hardware/DEVICES
  842.         A list of device majors and minors used by Linux.
  843.  
  844.   16.2.  Utilities
  845.  
  846.      tsx-11.mit.edu: ALPHA/scsi/scsiinfo*.tar.gz
  847.         Program to query a scsi device for operating parameters, defect
  848.         lists, etc.  An X-based interface is available which requires
  849.         you have Tk/Tcl/wish installed.  With the X-based interface you
  850.         can easily alter the settings on the drive.
  851.  
  852.      tsx-11.mit.edu: ALPHA/kdebug
  853.         A gdb extension for kernel debugging.
  854.  
  855.   17.  Other SCSI Access Interfaces
  856.  
  857.   In Linux there is also another SCSI access method via
  858.   SCSI_IOCTL_SEND_COMMAND ioctl calls, which is deprecated.  Special
  859.   tools like 'scsiinfo' utilize it.
  860.  
  861.   There are some other similar interfaces in use in the un*x world, but
  862.   not available for Linux:
  863.  
  864.   1. CAM (Common Access Method) developed by Future Domain and other
  865.      SCSI vendors. Linux has little support for a SCSI CAM system yet
  866.      (mainly for booting from hard disk).  CAM even supports target
  867.      mode, so one could disguise ones computer as a peripheral hardware
  868.      device (e.g. for a small SCSI net).
  869.  
  870.   2. ASPI (Advanced SCSI Programming Interface) developed by Adaptec.
  871.      This is the de facto standard for MS-DOS machines.
  872.  
  873.   There are other application interfaces from SCO(TM), NeXT(TM), Silicon
  874.   Graphics(TM) and SUN(TM) as well.
  875.  
  876.   18.  Final Comments
  877.  
  878.   The generic SCSI interface bridges the gap between user applications
  879.   and specific devices. But rather than bloating a lot of programs with
  880.   similar sets of low-level functions, it would be more desirable to
  881.   have a shared library with a generalized set of low-level functions
  882.   for a particular purpose.  The main goal should be to have independent
  883.   layers of interfaces.  A good design would separate an application
  884.   into low-level and hardware independent routines. The low-level
  885.   routines could be put into a shared library and made available for all
  886.   applications. Here, standardized interfaces should be followed as much
  887.   as possible before making new ones.
  888.  
  889.   By now you should know more than I do about the Linux generic SCSI
  890.   interface. So you can start developing powerful applications for the
  891.   benefit of the global Linux community now...
  892.  
  893.   19.  Acknowledgments
  894.  
  895.   Special thanks go to Jeff Tranter for proofreading and enhancing the
  896.   text considerably as well as to Carlos Puchol for useful comments.
  897.   Drew Eckhardt's and Eric Youngdale's help on my first (dumb) questions
  898.   about the use of this interface has been appreciated.
  899.  
  900.   T.  Appendix
  901.  
  902.   U.  Error handling
  903.  
  904.   The functions open, ioctl, write and read can report errors. In this
  905.   case their return value is -1 and the global variable errno is set to
  906.   the error number.  The errno values are defined in
  907.   /usr/include/errno.h.  Possible values are:
  908.  
  909.   Function | Error        | Description
  910.   =========|==============|=============================================
  911.   open     | ENXIO        | not a valid device
  912.            | EACCES       | access mode is not read/write (O_RDWR)
  913.            | EBUSY        | device was requested for nonblocking access,
  914.            |              | but is busy now.
  915.            | ERESTARTSYS  | this indicates an internal error. Try to
  916.            |              | make it reproducible and inform the SCSI
  917.            |              | channel (for details on bug reporting
  918.            |              | see Drew Eckhardts SCSI-HOWTO).
  919.   ioctl    | ENXIO        | not a valid device
  920.   read     | EAGAIN       | the device would block. Try again later.
  921.            | ERESTARTSYS  | this indicates an internal error. Try to
  922.            |              | make it reproducible and inform the SCSI
  923.            |              | channel (for details on bug reporting
  924.            |              | see Drew Eckhardts SCSI-HOWTO).
  925.   write    | EIO          | the length is too small (smaller than the
  926.            |              | generic header struct). Caution: Currently
  927.            |              | there is no overlength checking.
  928.            | EAGAIN       | the device would block. Try again later.
  929.            | ENOMEM       | memory required for this request could not be
  930.            |              | allocated. Try later again unless you
  931.            |              | exceeded the maximum transfer size (see above)
  932.   select   |              | none
  933.   close    |              | none
  934.  
  935.   For read/write positive return values indicate as usual the amount of
  936.   bytes that have been successfully transferred. This should equal the
  937.   amount you requested.
  938.  
  939.   U.1.  Error status decoding
  940.  
  941.   Furthermore a detailed reporting is done via the kernels hd_status and
  942.   the devices sense_buffer (see section ``'') both from the generic
  943.   header structure.
  944.  
  945.   The meaning of hd_status can be found in drivers/scsi/scsi.h: This
  946.   unsigned int is composed out of different parts:
  947.  
  948.          lsb  |    ...    |    ...    | msb
  949.        =======|===========|===========|============
  950.        status | sense key | host code | driver byte
  951.  
  952.   These macros from drivers/scsi/scsi.h are available, but unfortunately
  953.   cannot be easily used due to weird header file interdependencies. This
  954.   has to be cleaned.
  955.  
  956.           Macro          | Description
  957.   =======================|=================================================
  958.   status_byte(hd_status) | The SCSI device status. See section Status codes
  959.   msg_byte(hd_status)    | From the device. See section SCSI sense keys
  960.   host_byte(hd_status)   | From the kernel. See section Hostcodes
  961.   driver_byte(hd_status) | From the kernel. See section midlevel codes
  962.  
  963.   U.2.  Status codes
  964.  
  965.   The following status codes from the SCSI device (defined in
  966.   scsi/scsi.h) are available.
  967.  
  968.        Value | Symbol
  969.        ======|=====================
  970.        0x00  | GOOD
  971.        0x01  | CHECK_CONDITION
  972.        0x02  | CONDITION_GOOD
  973.        0x04  | BUSY
  974.        0x08  | INTERMEDIATE_GOOD
  975.        0x0a  | INTERMEDIATE_C_GOOD
  976.        0x0c  | RESERVATION_CONFLICT
  977.  
  978.   Note that these symbol values have been shifted right once.  When the
  979.   status is CHECK_CONDITION, the sense data in the sense buffer is valid
  980.   (check especially the additional sense code and additional sense code
  981.   qualifier).
  982.  
  983.   These values carry the meaning from the SCSI-2 specification:
  984.  
  985.                              Table 27: Status Byte Code
  986.   +=================================-==============================+
  987.   |       Bits of Status Byte       |  Status                      |
  988.   |  7   6   5   4   3   2   1   0  |                              |
  989.   |---------------------------------+------------------------------|
  990.   |  R   R   0   0   0   0   0   R  |  GOOD                        |
  991.   |  R   R   0   0   0   0   1   R  |  CHECK CONDITION             |
  992.   |  R   R   0   0   0   1   0   R  |  CONDITION MET               |
  993.   |  R   R   0   0   1   0   0   R  |  BUSY                        |
  994.   |  R   R   0   1   0   0   0   R  |  INTERMEDIATE                |
  995.   |  R   R   0   1   0   1   0   R  |  INTERMEDIATE-CONDITION MET  |
  996.   |  R   R   0   1   1   0   0   R  |  RESERVATION CONFLICT        |
  997.   |  R   R   1   0   0   0   1   R  |  COMMAND TERMINATED          |
  998.   |  R   R   1   0   1   0   0   R  |  QUEUE FULL                  |
  999.   |                                 |                              |
  1000.   |       All Other Codes           |  Reserved                    |
  1001.   |----------------------------------------------------------------|
  1002.   |  Key: R = Reserved bit                                         |
  1003.   +================================================================+
  1004.  
  1005.   A definition of the status byte codes is given below.
  1006.  
  1007.   GOOD.  This status indicates that the target has successfully completed the
  1008.   command.
  1009.  
  1010.   CHECK CONDITION.  This status indicates that a contingent allegiance condition
  1011.   has occurred (see 6.6).
  1012.  
  1013.   CONDITION MET.  This status or INTERMEDIATE-CONDITION MET is returned whenever
  1014.   the requested operation is satisfied (see the SEARCH DATA and PRE-FETCH
  1015.   commands).
  1016.  
  1017.   BUSY.  This status indicates that the target is busy.  This status shall be
  1018.   returned whenever a target is unable to accept a command from an otherwise
  1019.   acceptable initiator (i.e., no reservation conflicts).  The recommended
  1020.   initiator recovery action is to issue the command again at a later time.
  1021.  
  1022.   INTERMEDIATE.  This status or INTERMEDIATE-CONDITION MET shall be returned for
  1023.   every successfully completed command in a series of linked commands (except
  1024.   the last command), unless the command is terminated with CHECK CONDITION,
  1025.   RESERVATION CONFLICT, or COMMAND TERMINATED status.  If INTERMEDIATE or
  1026.   INTERMEDIATE-CONDITION MET status is not returned, the series of linked
  1027.   commands is terminated and the I/O process is ended.
  1028.  
  1029.   INTERMEDIATE-CONDITION MET.  This status is the combination of the CONDITION
  1030.   MET and INTERMEDIATE statuses.
  1031.  
  1032.   RESERVATION CONFLICT.  This status shall be returned whenever an initiator
  1033.   attempts to access a logical unit or an extent within a logical unit that is
  1034.   reserved with a conflicting reservation type for another SCSI device (see the
  1035.   RESERVE and RESERVE UNIT commands).  The recommended initiator recovery action
  1036.   is to issue the command again at a later time.
  1037.  
  1038.   COMMAND TERMINATED.  This status shall be returned whenever the target
  1039.   terminates the current I/O process after receiving a TERMINATE I/O PROCESS
  1040.   message (see 5.6.22).  This status also indicates that a contingent allegiance
  1041.   condition has occurred (see 6.6).
  1042.  
  1043.   QUEUE FULL.  This status shall be implemented if tagged queuing is
  1044.   implemented.  This status is returned when a SIMPLE QUEUE TAG, ORDERED QUEUE
  1045.   TAG, or HEAD OF QUEUE TAG message is received and the command queue is full.
  1046.   The I/O process is not placed in the command queue.
  1047.  
  1048.   U.3.  SCSI Sense Keys
  1049.  
  1050.   These kernel symbols (from scsi/scsi.h) are predefined:
  1051.  
  1052.        Value | Symbol
  1053.        ======|================
  1054.        0x00  | NO_SENSE
  1055.        0x01  | RECOVERED_ERROR
  1056.        0x02  | NOT_READY
  1057.        0x03  | MEDIUM_ERROR
  1058.        0x04  | HARDWARE_ERROR
  1059.        0x05  | ILLEGAL_REQUEST
  1060.        0x06  | UNIT_ATTENTION
  1061.        0x07  | DATA_PROTECT
  1062.        0x08  | BLANK_CHECK
  1063.        0x0a  | COPY_ABORTED
  1064.        0x0b  | ABORTED_COMMAND
  1065.        0x0d  | VOLUME_OVERFLOW
  1066.        0x0e  | MISCOMPARE
  1067.  
  1068.   A verbatim list from the SCSI-2 doc follows (from section 7.2.14.3):
  1069.  
  1070.                       Table 69: Sense Key (0h-7h) Descriptions
  1071.   +========-====================================================================+
  1072.   | Sense  |  Description                                                       |
  1073.   |  Key   |                                                                    |
  1074.   |--------+--------------------------------------------------------------------|
  1075.   |   0h   |  NO SENSE.  Indicates that there is no specific sense key          |
  1076.   |        |  information to be reported for the designated logical unit.  This |
  1077.   |        |  would be the case for a successful command or a command that      |
  1078.   |        |  received CHECK CONDITION or COMMAND TERMINATED status because one |
  1079.   |        |  of the filemark, EOM, or ILI bits is set to one.                  |
  1080.   |--------+--------------------------------------------------------------------|
  1081.   |   1h   |  RECOVERED ERROR.  Indicates that the last command completed       |
  1082.   |        |  successfully with some recovery action performed by the target.   |
  1083.   |        |  Details may be determinable by examining the additional sense     |
  1084.   |        |  bytes and the information field.  When multiple recovered errors  |
  1085.   |        |  occur during one command, the choice of which error to report     |
  1086.   |        |  (first, last, most severe, etc.) is device specific.              |
  1087.   |--------+--------------------------------------------------------------------|
  1088.   |   2h   |  NOT READY.  Indicates that the logical unit addressed cannot be   |
  1089.   |        |  accessed.  Operator intervention may be required to correct this  |
  1090.   |        |  condition.                                                        |
  1091.   |--------+--------------------------------------------------------------------|
  1092.   |   3h   |  MEDIUM ERROR.  Indicates that the command terminated with a non-  |
  1093.   |        |  recovered error condition that was probably caused by a flaw in   |
  1094.   |        |  the medium or an error in the recorded data.  This sense key may  |
  1095.   |        |  also be returned if the target is unable to distinguish between a |
  1096.   |        |  flaw in the medium and a specific hardware failure (sense key 4h).|
  1097.   |--------+--------------------------------------------------------------------|
  1098.   |   4h   |  HARDWARE ERROR.  Indicates that the target detected a non-        |
  1099.   |        |  recoverable hardware failure (for example, controller failure,    |
  1100.   |        |  device failure, parity error, etc.) while performing the command  |
  1101.   |        |  or during a self test.                                            |
  1102.   |--------+--------------------------------------------------------------------|
  1103.   |   5h   |  ILLEGAL REQUEST.  Indicates that there was an illegal parameter in|
  1104.   |        |  the command descriptor block or in the additional parameters      |
  1105.   |        |  supplied as data for some commands (FORMAT UNIT, SEARCH DATA,     |
  1106.   |        |  etc.).  If the target detects an invalid parameter in the command |
  1107.   |        |  descriptor block, then it shall terminate the command without     |
  1108.   |        |  altering the medium.  If the target detects an invalid parameter  |
  1109.   |        |  in the additional parameters supplied as data, then the target may|
  1110.   |        |  have already altered the medium.  This sense key may also indicate|
  1111.   |        |  that an invalid IDENTIFY message was received (5.6.7).            |
  1112.   |--------+--------------------------------------------------------------------|
  1113.   |   6h   |  UNIT ATTENTION.  Indicates that the removable medium may have been|
  1114.   |        |  changed or the target has been reset.  See 6.9 for more detailed  |
  1115.   |        |  information about the unit attention condition.                   |
  1116.   |--------+--------------------------------------------------------------------|
  1117.   |   7h   |  DATA PROTECT.  Indicates that a command that reads or writes the  |
  1118.   |        |  medium was attempted on a block that is protected from this       |
  1119.   |        |  operation.  The read or write operation is not performed.         |
  1120.   +=============================================================================+
  1121.  
  1122.                       Table 70: Sense Key (8h-Fh) Descriptions
  1123.   +========-====================================================================+
  1124.   | Sense  |  Description                                                       |
  1125.   |  Key   |                                                                    |
  1126.   |--------+--------------------------------------------------------------------|
  1127.   |   8h   |  BLANK CHECK.  Indicates that a write-once device or a sequential- |
  1128.   |        |  access device encountered blank medium or format-defined end-of-  |
  1129.   |        |  data indication while reading or a write-once device encountered a|
  1130.   |        |  non-blank medium while writing.                                   |
  1131.   |--------+--------------------------------------------------------------------|
  1132.   |   9h   |  Vendor Specific.  This sense key is available for reporting vendor|
  1133.   |        |  specific conditions.                                              |
  1134.   |--------+--------------------------------------------------------------------|
  1135.   |   Ah   |  COPY ABORTED.  Indicates a COPY, COMPARE, or COPY AND VERIFY      |
  1136.   |        |  command was aborted due to an error condition on the source       |
  1137.   |        |  device, the destination device, or both.  (See 7.2.3.2 for        |
  1138.   |        |  additional information about this sense key.)                     |
  1139.   |--------+--------------------------------------------------------------------|
  1140.   |   Bh   |  ABORTED COMMAND.  Indicates that the target aborted the command.  |
  1141.   |        |  The initiator may be able to recover by trying the command again. |
  1142.   |--------+--------------------------------------------------------------------|
  1143.   |   Ch   |  EQUAL.  Indicates a SEARCH DATA command has satisfied an equal    |
  1144.   |        |  comparison.                                                       |
  1145.   |--------+--------------------------------------------------------------------|
  1146.   |   Dh   |  VOLUME OVERFLOW.  Indicates that a buffered peripheral device has |
  1147.   |        |  reached the end-of-partition and data may remain in the buffer    |
  1148.   |        |  that has not been written to the medium.  A RECOVER BUFFERED DATA |
  1149.   |        |  command(s) may be issued to read the unwritten data from the      |
  1150.   |        |  buffer.                                                           |
  1151.   |--------+--------------------------------------------------------------------|
  1152.   |   Eh   |  MISCOMPARE.  Indicates that the source data did not match the data|
  1153.   |        |  read from the medium.                                             |
  1154.   |--------+--------------------------------------------------------------------|
  1155.   |   Fh   |  RESERVED.                                                         |
  1156.   +=============================================================================+
  1157.  
  1158.   U.4.  Host codes
  1159.  
  1160.   The following host codes are defined in drivers/scsi/scsi.h. They are
  1161.   set by the kernel driver.
  1162.  
  1163.        Value | Symbol         | Description
  1164.        ======|================|========================================
  1165.        0x00  | DID_OK         | No error
  1166.        0x01  | DID_NO_CONNECT | Couldn't connect before timeout period
  1167.        0x02  | DID_BUS_BUSY   | BUS stayed busy through time out period
  1168.        0x03  | DID_TIME_OUT   | TIMED OUT for other reason
  1169.        0x04  | DID_BAD_TARGET | BAD target
  1170.        0x05  | DID_ABORT      | Told to abort for some other reason
  1171.        0x06  | DID_PARITY     | Parity error
  1172.        0x07  | DID_ERROR      | internal error
  1173.        0x08  | DID_RESET      | Reset by somebody
  1174.        0x09  | DID_BAD_INTR   | Got an interrupt we weren't expecting
  1175.  
  1176.   U.5.  Driver codes
  1177.  
  1178.   The midlevel driver categorizes the returned status from the lowlevel
  1179.   driver based on the sense key from the device. It suggests some
  1180.   actions to be taken such as retry, abort or remap. The routine
  1181.   scsi_done from scsi.c does a very differentiated handling based on
  1182.   host_byte(), status_byte(), msg_byte() and the suggestion. It then
  1183.   sets the driver byte to show what it has done. The driver byte is
  1184.   composed out of two nibbles: the driver status and the suggestion.
  1185.   Each half is composed from the below values being 'or'ed together
  1186.   (found in scsi.h).
  1187.  
  1188.        Value | Symbol         | Description of Driver status
  1189.        ======|================|========================================
  1190.        0x00  | DRIVER_OK      | No error
  1191.        0x01  | DRIVER_BUSY    | not used
  1192.        0x02  | DRIVER_SOFT    | not used
  1193.        0x03  | DRIVER_MEDIA   | not used
  1194.        0x04  | DRIVER_ERROR   | internal driver error
  1195.        0x05  | DRIVER_INVALID | finished (DID_BAD_TARGET or DID_ABORT)
  1196.        0x06  | DRIVER_TIMEOUT | finished with timeout
  1197.        0x07  | DRIVER_HARD    | finished with fatal error
  1198.        0x08  | DRIVER_SENSE   | had sense information available
  1199.  
  1200.        Value | Symbol         | Description of suggestion
  1201.        ======|================|========================================
  1202.        0x10  | SUGGEST_RETRY  | retry the SCSI request
  1203.        0x20  | SUGGEST_ABORT  | abort the request
  1204.        0x30  | SUGGEST_REMAP  | remap the block (not yet implemented)
  1205.        0x40  | SUGGEST_DIE    | let the kernel panic
  1206.        0x80  | SUGGEST_SENSE  | get sense information from the device
  1207.        0xff  | SUGGEST_IS_OK  | nothing to be done
  1208.  
  1209.   V.  Additional sense codes and additional sense code qualifiers
  1210.  
  1211.   When the status of the executed SCSI command is CHECK_CONDITION, sense
  1212.   data is available in the sense buffer. The additional sense code and
  1213.   additional sense code qualifier are contained in that buffer.
  1214.  
  1215.   From the SCSI-2 specification I include two tables. The first is in
  1216.   lexical, the second in numerical order.
  1217.  
  1218.   V.1.  ASC and ASCQ in lexical order
  1219.  
  1220.   The following table list gives a list of descriptions and device types
  1221.   they apply to.
  1222.  
  1223.   +=============================================================================+
  1224.   |           D - DIRECT ACCESS DEVICE                                          |
  1225.   |           .T - SEQUENTIAL ACCESS DEVICE                                     |
  1226.   |           . L - PRINTER DEVICE                                              |
  1227.   |           .  P - PROCESSOR DEVICE                                           |
  1228.   |           .  .W - WRITE ONCE READ MULTIPLE DEVICE                           |
  1229.   |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  1230.   |           .  .  S - SCANNER DEVICE                                          |
  1231.   |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  1232.   |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  1233.   |           .  .  .  C - COMMUNICATION DEVICE                                 |
  1234.   |           .  .  .  .                                                        |
  1235.   | ASC ASCQ  DTLPWRSOMC  DESCRIPTION                                           |
  1236.   | --- ----              ----------------------------------------------------- |
  1237.   | 13h  00h  D   W  O    ADDRESS MARK NOT FOUND FOR DATA FIELD                 |
  1238.   | 12h  00h  D   W  O    ADDRESS MARK NOT FOUND FOR ID FIELD                   |
  1239.   | 00h  11h       R      AUDIO PLAY OPERATION IN PROGRESS                      |
  1240.   | 00h  12h       R      AUDIO PLAY OPERATION PAUSED                           |
  1241.   | 00h  14h       R      AUDIO PLAY OPERATION STOPPED DUE TO ERROR             |
  1242.   | 00h  13h       R      AUDIO PLAY OPERATION SUCCESSFULLY COMPLETED           |
  1243.   | 00h  04h   T    S     BEGINNING-OF-PARTITION/MEDIUM DETECTED                |
  1244.   | 14h  04h   T          BLOCK SEQUENCE ERROR                                  |
  1245.   | 30h  02h  DT  WR O    CANNOT READ MEDIUM - INCOMPATIBLE FORMAT              |
  1246.   | 30h  01h  DT  WR O    CANNOT READ MEDIUM - UNKNOWN FORMAT                   |
  1247.   | 52h  00h   T          CARTRIDGE FAULT                                       |
  1248.   | 3Fh  02h  DTLPWRSOMC  CHANGED OPERATING DEFINITION                          |
  1249.   | 11h  06h      WR O    CIRC UNRECOVERED ERROR                                |
  1250.   | 30h  03h  DT          CLEANING CARTRIDGE INSTALLED                          |
  1251.   | 4Ah  00h  DTLPWRSOMC  COMMAND PHASE ERROR                                   |
  1252.   | 2Ch  00h  DTLPWRSOMC  COMMAND SEQUENCE ERROR                                |
  1253.   | 2Fh  00h  DTLPWRSOMC  COMMANDS CLEARED BY ANOTHER INITIATOR                 |
  1254.   | 2Bh  00h  DTLPWRSO C  COPY CANNOT EXECUTE SINCE HOST CANNOT DISCONNECT      |
  1255.   | 41h  00h  D           DATA PATH FAILURE (SHOULD USE 40 NN)                  |
  1256.   | 4Bh  00h  DTLPWRSOMC  DATA PHASE ERROR                                      |
  1257.   | 11h  07h      W  O    DATA RESYCHRONIZATION ERROR                           |
  1258.   | 16h  00h  D   W  O    DATA SYNCHRONIZATION MARK ERROR                       |
  1259.   | 19h  00h  D      O    DEFECT LIST ERROR                                     |
  1260.   | 19h  03h  D      O    DEFECT LIST ERROR IN GROWN LIST                       |
  1261.   | 19h  02h  D      O    DEFECT LIST ERROR IN PRIMARY LIST                     |
  1262.   | 19h  01h  D      O    DEFECT LIST NOT AVAILABLE                             |
  1263.   | 1Ch  00h  D      O    DEFECT LIST NOT FOUND                                 |
  1264.   | 32h  01h  D   W  O    DEFECT LIST UPDATE FAILURE                            |
  1265.   | 40h  NNh  DTLPWRSOMC  DIAGNOSTIC FAILURE ON COMPONENT NN (80H-FFH)          |
  1266.   | 63h  00h       R      END OF USER AREA ENCOUNTERED ON THIS TRACK            |
  1267.   | 00h  05h   T    S     END-OF-DATA DETECTED                                  |
  1268.   | 14h  03h   T          END-OF-DATA NOT FOUND                                 |
  1269.   | 00h  02h   T    S     END-OF-PARTITION/MEDIUM DETECTED                      |
  1270.   | 51h  00h   T     O    ERASE FAILURE                                         |
  1271.   | 0Ah  00h  DTLPWRSOMC  ERROR LOG OVERFLOW                                    |
  1272.   | 11h  02h  DT  W SO    ERROR TOO LONG TO CORRECT                             |
  1273.   | 03h  02h   T          EXCESSIVE WRITE ERRORS                                |
  1274.   | 3Bh  07h    L         FAILED TO SENSE BOTTOM-OF-FORM                        |
  1275.   | 3Bh  06h    L         FAILED TO SENSE TOP-OF-FORM                           |
  1276.   | 00h  01h   T          FILEMARK DETECTED                                     |
  1277.   | 14h  02h   T          FILEMARK OR SETMARK NOT FOUND                         |
  1278.   | 09h  02h      WR O    FOCUS SERVO FAILURE                                   |
  1279.   | 31h  01h  D L    O    FORMAT COMMAND FAILED                                 |
  1280.   | 58h  00h         O    GENERATION DOES NOT EXIST                             |
  1281.   +=============================================================================+
  1282.  
  1283.   Table 71: (continued)
  1284.   +=============================================================================+
  1285.   | ASC ASCQ  DTLPWRSOMC  DESCRIPTION                                           |
  1286.   | --- ----              ----------------------------------------------------- |
  1287.   | 1Ch  02h  D      O    GROWN DEFECT LIST NOT FOUND                           |
  1288.   | 00h  06h  DTLPWRSOMC  I/O PROCESS TERMINATED                                |
  1289.   | 10h  00h  D   W  O    ID CRC OR ECC ERROR                                   |
  1290.   | 22h  00h  D           ILLEGAL FUNCTION (SHOULD USE 20 00, 24 00, OR 26 00)  |
  1291.   | 64h  00h       R      ILLEGAL MODE FOR THIS TRACK                           |
  1292.   | 28h  01h          M   IMPORT OR EXPORT ELEMENT ACCESSED                     |
  1293.   | 30h  00h  DT  WR OM   INCOMPATIBLE MEDIUM INSTALLED                         |
  1294.   | 11h  08h   T          INCOMPLETE BLOCK READ                                 |
  1295.   | 48h  00h  DTLPWRSOMC  INITIATOR DETECTED ERROR MESSAGE RECEIVED             |
  1296.   | 3Fh  03h  DTLPWRSOMC  INQUIRY DATA HAS CHANGED                              |
  1297.   | 44h  00h  DTLPWRSOMC  INTERNAL TARGET FAILURE                               |
  1298.   | 3Dh  00h  DTLPWRSOMC  INVALID BITS IN IDENTIFY MESSAGE                      |
  1299.   | 2Ch  02h        S     INVALID COMBINATION OF WINDOWS SPECIFIED              |
  1300.   | 20h  00h  DTLPWRSOMC  INVALID COMMAND OPERATION CODE                        |
  1301.   | 21h  01h          M   INVALID ELEMENT ADDRESS                               |
  1302.   | 24h  00h  DTLPWRSOMC  INVALID FIELD IN CDB                                  |
  1303.   | 26h  00h  DTLPWRSOMC  INVALID FIELD IN PARAMETER LIST                       |
  1304.   | 49h  00h  DTLPWRSOMC  INVALID MESSAGE ERROR                                 |
  1305.   | 11h  05h      WR O    L-EC UNCORRECTABLE ERROR                              |
  1306.   | 60h  00h        S     LAMP FAILURE                                          |
  1307.   | 5Bh  02h  DTLPWRSOM   LOG COUNTER AT MAXIMUM                                |
  1308.   | 5Bh  00h  DTLPWRSOM   LOG EXCEPTION                                         |
  1309.   | 5Bh  03h  DTLPWRSOM   LOG LIST CODES EXHAUSTED                              |
  1310.   | 2Ah  02h  DTL WRSOMC  LOG PARAMETERS CHANGED                                |
  1311.   | 21h  00h  DT  WR OM   LOGICAL BLOCK ADDRESS OUT OF RANGE                    |
  1312.   | 08h  00h  DTL WRSOMC  LOGICAL UNIT COMMUNICATION FAILURE                    |
  1313.   | 08h  02h  DTL WRSOMC  LOGICAL UNIT COMMUNICATION PARITY ERROR               |
  1314.   | 08h  01h  DTL WRSOMC  LOGICAL UNIT COMMUNICATION TIME-OUT                   |
  1315.   | 4Ch  00h  DTLPWRSOMC  LOGICAL UNIT FAILED SELF-CONFIGURATION                |
  1316.   | 3Eh  00h  DTLPWRSOMC  LOGICAL UNIT HAS NOT SELF-CONFIGURED YET              |
  1317.   | 04h  01h  DTLPWRSOMC  LOGICAL UNIT IS IN PROCESS OF BECOMING READY          |
  1318.   | 04h  00h  DTLPWRSOMC  LOGICAL UNIT NOT READY, CAUSE NOT REPORTABLE          |
  1319.   | 04h  04h  DTL    O    LOGICAL UNIT NOT READY, FORMAT IN PROGRESS            |
  1320.   | 04h  02h  DTLPWRSOMC  LOGICAL UNIT NOT READY, INITIALIZING COMMAND REQUIRED |
  1321.   | 04h  03h  DTLPWRSOMC  LOGICAL UNIT NOT READY, MANUAL INTERVENTION REQUIRED  |
  1322.   | 25h  00h  DTLPWRSOMC  LOGICAL UNIT NOT SUPPORTED                            |
  1323.   | 15h  01h  DTL WRSOM   MECHANICAL POSITIONING ERROR                          |
  1324.   | 53h  00h  DTL WRSOM   MEDIA LOAD OR EJECT FAILED                            |
  1325.   | 3Bh  0Dh          M   MEDIUM DESTINATION ELEMENT FULL                       |
  1326.   | 31h  00h  DT  W  O    MEDIUM FORMAT CORRUPTED                               |
  1327.   | 3Ah  00h  DTL WRSOM   MEDIUM NOT PRESENT                                    |
  1328.   | 53h  02h  DT  WR OM   MEDIUM REMOVAL PREVENTED                              |
  1329.   | 3Bh  0Eh          M   MEDIUM SOURCE ELEMENT EMPTY                           |
  1330.   | 43h  00h  DTLPWRSOMC  MESSAGE ERROR                                         |
  1331.   | 3Fh  01h  DTLPWRSOMC  MICROCODE HAS BEEN CHANGED                            |
  1332.   | 1Dh  00h  D   W  O    MISCOMPARE DURING VERIFY OPERATION                    |
  1333.   | 11h  0Ah  DT     O    MISCORRECTED ERROR                                    |
  1334.   | 2Ah  01h  DTL WRSOMC  MODE PARAMETERS CHANGED                               |
  1335.   | 07h  00h  DTL WRSOM   MULTIPLE PERIPHERAL DEVICES SELECTED                  |
  1336.   | 11h  03h  DT  W SO    MULTIPLE READ ERRORS                                  |
  1337.   | 00h  00h  DTLPWRSOMC  NO ADDITIONAL SENSE INFORMATION                       |
  1338.   | 00h  15h       R      NO CURRENT AUDIO STATUS TO RETURN                     |
  1339.   | 32h  00h  D   W  O    NO DEFECT SPARE LOCATION AVAILABLE                    |
  1340.   | 11h  09h   T          NO GAP FOUND                                          |
  1341.   | 01h  00h  D   W  O    NO INDEX/SECTOR SIGNAL                                |
  1342.   | 06h  00h  D   WR OM   NO REFERENCE POSITION FOUND                           |
  1343.   +=============================================================================+
  1344.  
  1345.        Table 71: (continued)
  1346.        +=============================================================================+
  1347.        | ASC ASCQ  DTLPWRSOMC  DESCRIPTION                                           |
  1348.        | --- ----              ----------------------------------------------------- |
  1349.        | 02h  00h  D   WR OM   NO SEEK COMPLETE                                      |
  1350.        | 03h  01h   T          NO WRITE CURRENT                                      |
  1351.        | 28h  00h  DTLPWRSOMC  NOT READY TO READY TRANSITION, MEDIUM MAY HAVE CHANGED|
  1352.        | 5Ah  01h  DT  WR OM   OPERATOR MEDIUM REMOVAL REQUEST                       |
  1353.        | 5Ah  00h  DTLPWRSOM   OPERATOR REQUEST OR STATE CHANGE INPUT (UNSPECIFIED)  |
  1354.        | 5Ah  03h  DT  W  O    OPERATOR SELECTED WRITE PERMIT                        |
  1355.        | 5Ah  02h  DT  W  O    OPERATOR SELECTED WRITE PROTECT                       |
  1356.        | 61h  02h        S     OUT OF FOCUS                                          |
  1357.        | 4Eh  00h  DTLPWRSOMC  OVERLAPPED COMMANDS ATTEMPTED                         |
  1358.        | 2Dh  00h   T          OVERWRITE ERROR ON UPDATE IN PLACE                    |
  1359.        | 3Bh  05h    L         PAPER JAM                                             |
  1360.        | 1Ah  00h  DTLPWRSOMC  PARAMETER LIST LENGTH ERROR                           |
  1361.        | 26h  01h  DTLPWRSOMC  PARAMETER NOT SUPPORTED                               |
  1362.        | 26h  02h  DTLPWRSOMC  PARAMETER VALUE INVALID                               |
  1363.        | 2Ah  00h  DTL WRSOMC  PARAMETERS CHANGED                                    |
  1364.        | 03h  00h  DTL W SO    PERIPHERAL DEVICE WRITE FAULT                         |
  1365.        | 50h  02h   T          POSITION ERROR RELATED TO TIMING                      |
  1366.        | 3Bh  0Ch        S     POSITION PAST BEGINNING OF MEDIUM                     |
  1367.        | 3Bh  0Bh        S     POSITION PAST END OF MEDIUM                           |
  1368.        | 15h  02h  DT  WR O    POSITIONING ERROR DETECTED BY READ OF MEDIUM          |
  1369.        | 29h  00h  DTLPWRSOMC  POWER ON, RESET, OR BUS DEVICE RESET OCCURRED         |
  1370.        | 42h  00h  D           POWER-ON OR SELF-TEST FAILURE (SHOULD USE 40 NN)      |
  1371.        | 1Ch  01h  D      O    PRIMARY DEFECT LIST NOT FOUND                         |
  1372.        | 40h  00h  D           RAM FAILURE (SHOULD USE 40 NN)                        |
  1373.        | 15h  00h  DTL WRSOM   RANDOM POSITIONING ERROR                              |
  1374.        | 3Bh  0Ah        S     READ PAST BEGINNING OF MEDIUM                         |
  1375.        | 3Bh  09h        S     READ PAST END OF MEDIUM                               |
  1376.        | 11h  01h  DT  W SO    READ RETRIES EXHAUSTED                                |
  1377.        | 14h  01h  DT  WR O    RECORD NOT FOUND                                      |
  1378.        | 14h  00h  DTL WRSO    RECORDED ENTITY NOT FOUND                             |
  1379.        | 18h  02h  D   WR O    RECOVERED DATA - DATA AUTO-REALLOCATED                |
  1380.        | 18h  05h  D   WR O    RECOVERED DATA - RECOMMEND REASSIGNMENT               |
  1381.        | 18h  06h  D   WR O    RECOVERED DATA - RECOMMEND REWRITE                    |
  1382.        | 17h  05h  D   WR O    RECOVERED DATA USING PREVIOUS SECTOR ID               |
  1383.        | 18h  03h       R      RECOVERED DATA WITH CIRC                              |
  1384.        | 18h  01h  D   WR O    RECOVERED DATA WITH ERROR CORRECTION & RETRIES APPLIED|
  1385.        | 18h  00h  DT  WR O    RECOVERED DATA WITH ERROR CORRECTION APPLIED          |
  1386.        | 18h  04h       R      RECOVERED DATA WITH L-EC                              |
  1387.        | 17h  03h  DT  WR O    RECOVERED DATA WITH NEGATIVE HEAD OFFSET              |
  1388.        | 17h  00h  DT  WRSO    RECOVERED DATA WITH NO ERROR CORRECTION APPLIED       |
  1389.        | 17h  02h  DT  WR O    RECOVERED DATA WITH POSITIVE HEAD OFFSET              |
  1390.        | 17h  01h  DT  WRSO    RECOVERED DATA WITH RETRIES                           |
  1391.        | 17h  04h      WR O    RECOVERED DATA WITH RETRIES AND/OR CIRC APPLIED       |
  1392.        | 17h  06h  D   W  O    RECOVERED DATA WITHOUT ECC - DATA AUTO-REALLOCATED    |
  1393.        | 17h  07h  D   W  O    RECOVERED DATA WITHOUT ECC - RECOMMEND REASSIGNMENT   |
  1394.        | 17h  08h  D   W  O    RECOVERED DATA WITHOUT ECC - RECOMMEND REWRITE        |
  1395.        | 1Eh  00h  D   W  O    RECOVERED ID WITH ECC CORRECTION                      |
  1396.        | 3Bh  08h   T          REPOSITION ERROR                                      |
  1397.        | 36h  00h    L         RIBBON, INK, OR TONER FAILURE                         |
  1398.        | 37h  00h  DTL WRSOMC  ROUNDED PARAMETER                                     |
  1399.        | 5Ch  00h  D      O    RPL STATUS CHANGE                                     |
  1400.        | 39h  00h  DTL WRSOMC  SAVING PARAMETERS NOT SUPPORTED                       |
  1401.        | 62h  00h        S     SCAN HEAD POSITIONING ERROR                           |
  1402.        | 47h  00h  DTLPWRSOMC  SCSI PARITY ERROR                                     |
  1403.        | 54h  00h     P        SCSI TO HOST SYSTEM INTERFACE FAILURE                 |
  1404.        | 45h  00h  DTLPWRSOMC  SELECT OR RESELECT FAILURE                            |
  1405.        +=============================================================================+
  1406.  
  1407.        Table 71: (concluded)
  1408.        +=============================================================================+
  1409.        | ASC ASCQ  DTLPWRSOMC  DESCRIPTION                                           |
  1410.        | --- ----              ----------------------------------------------------- |
  1411.        | 3Bh  00h   TL         SEQUENTIAL POSITIONING ERROR                          |
  1412.        | 00h  03h   T          SETMARK DETECTED                                      |
  1413.        | 3Bh  04h    L         SLEW FAILURE                                          |
  1414.        | 09h  03h      WR O    SPINDLE SERVO FAILURE                                 |
  1415.        | 5Ch  02h  D      O    SPINDLES NOT SYNCHRONIZED                             |
  1416.        | 5Ch  01h  D      O    SPINDLES SYNCHRONIZED                                 |
  1417.        | 1Bh  00h  DTLPWRSOMC  SYNCHRONOUS DATA TRANSFER ERROR                       |
  1418.        | 55h  00h     P        SYSTEM RESOURCE FAILURE                               |
  1419.        | 33h  00h   T          TAPE LENGTH ERROR                                     |
  1420.        | 3Bh  03h    L         TAPE OR ELECTRONIC VERTICAL FORMS UNIT NOT READY      |
  1421.        | 3Bh  01h   T          TAPE POSITION ERROR AT BEGINNING-OF-MEDIUM            |
  1422.        | 3Bh  02h   T          TAPE POSITION ERROR AT END-OF-MEDIUM                  |
  1423.        | 3Fh  00h  DTLPWRSOMC  TARGET OPERATING CONDITIONS HAVE CHANGED              |
  1424.        | 5Bh  01h  DTLPWRSOM   THRESHOLD CONDITION MET                               |
  1425.        | 26h  03h  DTLPWRSOMC  THRESHOLD PARAMETERS NOT SUPPORTED                    |
  1426.        | 2Ch  01h        S     TOO MANY WINDOWS SPECIFIED                            |
  1427.        | 09h  00h  DT  WR O    TRACK FOLLOWING ERROR                                 |
  1428.        | 09h  01h      WR O    TRACKING SERVO FAILURE                                |
  1429.        | 61h  01h        S     UNABLE TO ACQUIRE VIDEO                               |
  1430.        | 57h  00h       R      UNABLE TO RECOVER TABLE-OF-CONTENTS                   |
  1431.        | 53h  01h   T          UNLOAD TAPE FAILURE                                   |
  1432.        | 11h  00h  DT  WRSO    UNRECOVERED READ ERROR                                |
  1433.        | 11h  04h  D   W  O    UNRECOVERED READ ERROR - AUTO REALLOCATE FAILED       |
  1434.        | 11h  0Bh  D   W  O    UNRECOVERED READ ERROR - RECOMMEND REASSIGNMENT       |
  1435.        | 11h  0Ch  D   W  O    UNRECOVERED READ ERROR - RECOMMEND REWRITE THE DATA   |
  1436.        | 46h  00h  DTLPWRSOMC  UNSUCCESSFUL SOFT RESET                               |
  1437.        | 59h  00h         O    UPDATED BLOCK READ                                    |
  1438.        | 61h  00h        S     VIDEO ACQUISITION ERROR                               |
  1439.        | 50h  00h   T          WRITE APPEND ERROR                                    |
  1440.        | 50h  01h   T          WRITE APPEND POSITION ERROR                           |
  1441.        | 0Ch  00h   T    S     WRITE ERROR                                           |
  1442.        | 0Ch  02h  D   W  O    WRITE ERROR - AUTO REALLOCATION FAILED                |
  1443.        | 0Ch  01h  D   W  O    WRITE ERROR RECOVERED WITH AUTO REALLOCATION          |
  1444.        | 27h  00h  DT  W  O    WRITE PROTECTED                                       |
  1445.        |                                                                             |
  1446.        | 80h  XXh     \                                                              |
  1447.        | THROUGH       >       VENDOR SPECIFIC.                                      |
  1448.        | FFh  XX      /                                                              |
  1449.        |                                                                             |
  1450.        | XXh  80h     \                                                              |
  1451.        | THROUGH       >       VENDOR SPECIFIC QUALIFICATION OF STANDARD ASC.        |
  1452.        | XXh  FFh     /                                                              |
  1453.        |                       ALL CODES NOT SHOWN ARE RESERVED.                     |
  1454.        |-----------------------------------------------------------------------------|
  1455.  
  1456.   V.2.  ASC and ASCQ in numerical order
  1457.  
  1458.                          Table 364: ASC and ASCQ Assignments
  1459.  
  1460.   +=============================================================================+
  1461.   |           D - DIRECT ACCESS DEVICE                                          |
  1462.   |           .T - SEQUENTIAL ACCESS DEVICE                                     |
  1463.   |           . L - PRINTER DEVICE                                              |
  1464.   |           .  P - PROCESSOR DEVICE                                           |
  1465.   |           .  .W - WRITE ONCE READ MULTIPLE DEVICE                           |
  1466.   |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  1467.   |           .  .  S - SCANNER DEVICE                                          |
  1468.   |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  1469.   |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  1470.   |           .  .  .  C - COMMUNICATION DEVICE                                 |
  1471.   |           .  .  .  .                                                        |
  1472.   | ASC ASCQ  DTLPWRSOMC  DESCRIPTION                                           |
  1473.   | --- ----              ----------------------------------------------------- |
  1474.   |  00  00   DTLPWRSOMC  NO ADDITIONAL SENSE INFORMATION                       |
  1475.   |  00  01    T          FILEMARK DETECTED                                     |
  1476.   |  00  02    T    S     END-OF-PARTITION/MEDIUM DETECTED                      |
  1477.   |  00  03    T          SETMARK DETECTED                                      |
  1478.   |  00  04    T    S     BEGINNING-OF-PARTITION/MEDIUM DETECTED                |
  1479.   |  00  05    T    S     END-OF-DATA DETECTED                                  |
  1480.   |  00  06   DTLPWRSOMC  I/O PROCESS TERMINATED                                |
  1481.   |  00  11   R           AUDIO PLAY OPERATION IN PROGRESS                      |
  1482.   |  00  12   R           AUDIO PLAY OPERATION PAUSED                           |
  1483.   |  00  13   R           AUDIO PLAY OPERATION SUCCESSFULLY COMPLETED           |
  1484.   |  00  14   R           AUDIO PLAY OPERATION STOPPED DUE TO ERROR             |
  1485.   |  00  15   R           NO CURRENT AUDIO STATUS TO RETURN                     |
  1486.   |  01  00   DW  O       NO INDEX/SECTOR SIGNAL                                |
  1487.   |  02  00   DWR OM      NO SEEK COMPLETE                                      |
  1488.   |  03  00   DTL W SO    PERIPHERAL DEVICE WRITE FAULT                         |
  1489.   |  03  01    T          NO WRITE CURRENT                                      |
  1490.   |  03  02    T          EXCESSIVE WRITE ERRORS                                |
  1491.   |  04  00   DTLPWRSOMC  LOGICAL UNIT NOT READY, CAUSE NOT REPORTABLE          |
  1492.   |  04  01   DTLPWRSOMC  LOGICAL UNIT IS IN PROCESS OF BECOMING READY          |
  1493.   |  04  02   DTLPWRSOMC  LOGICAL UNIT NOT READY, INITIALIZING COMMAND REQUIRED |
  1494.   |  04  03   DTLPWRSOMC  LOGICAL UNIT NOT READY, MANUAL INTERVENTION REQUIRED  |
  1495.   |  04  04   DTL    O    LOGICAL UNIT NOT READY, FORMAT IN PROGRESS            |
  1496.   |  05  00   DTL WRSOMC  LOGICAL UNIT DOES NOT RESPOND TO SELECTION            |
  1497.   |  06  00   DWR OM  NO  REFERENCE POSITION FOUND                              |
  1498.   |  07  00   DTL WRSOM   MULTIPLE PERIPHERAL DEVICES SELECTED                  |
  1499.   |  08  00   DTL WRSOMC  LOGICAL UNIT COMMUNICATION FAILURE                    |
  1500.   |  08  01   DTL WRSOMC  LOGICAL UNIT COMMUNICATION TIME-OUT                   |
  1501.   |  08  02   DTL WRSOMC  LOGICAL UNIT COMMUNICATION PARITY ERROR               |
  1502.   |  09  00   DT  WR O    TRACK FOLLOWING ERROR                                 |
  1503.   |  09  01       WR O    TRA CKING SERVO FAILURE                               |
  1504.   |  09  02       WR O    FOC US SERVO FAILURE                                  |
  1505.   |  09  03       WR O    SPI NDLE SERVO FAILURE                                |
  1506.   +=============================================================================+
  1507.  
  1508.   Table 364: (continued)
  1509.   +=============================================================================+
  1510.   |           D - DIRECT ACCESS DEVICE                                          |
  1511.   |           .T - SEQUENTIAL ACCESS DEVICE                                     |
  1512.   |           . L - PRINTER DEVICE                                              |
  1513.   |           .  P - PROCESSOR DEVICE                                           |
  1514.   |           .  .W - WRITE ONCE READ MULTIPLE DEVICE                           |
  1515.   |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  1516.   |           .  .  S - SCANNER DEVICE                                          |
  1517.   |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  1518.   |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  1519.   |           .  .  .  C - COMMUNICATION DEVICE                                 |
  1520.   |           .  .  .  .                                                        |
  1521.   | ASC ASCQ  DTLPWRSOMC  DESCRIPTION                                           |
  1522.   | --- ----              ----------------------------------------------------- |
  1523.   |  0A  00   DTLPWRSOMC  ERROR LOG OVERFLOW                                    |
  1524.   |  0B  00                                                                     |
  1525.   |  0C  00    T     S    WRITE ERROR                                           |
  1526.   |  0C  01   D   W  O    WRITE ERROR RECOVERED WITH AUTO REALLOCATION          |
  1527.   |  0C  02   D   W  O    WRITE ERROR - AUTO REALLOCATION FAILED                |
  1528.   |  0D  00                                                                     |
  1529.   |  0E  00                                                                     |
  1530.   |  0F  00                                                                     |
  1531.   |  10  00   D   W  O    ID CRC OR ECC ERROR                                   |
  1532.   |  11  00   DT  WRSO    UNRECOVERED READ ERROR                                |
  1533.   |  11  01   DT  W SO    READ RETRIES EXHAUSTED                                |
  1534.   |  11  02   DT  W SO    ERROR TOO LONG TO CORRECT                             |
  1535.   |  11  03   DT  W SO    MULTIPLE READ ERRORS                                  |
  1536.   |  11  04   D   W  O    UNRECOVERED READ ERROR - AUTO REALLOCATE FAILED       |
  1537.   |  11  05       WR O    L-EC UNCORRECTABLE ERROR                              |
  1538.   |  11  06       WR O    CIRC UNRECOVERED ERROR                                |
  1539.   |  11  07       W  O    DATA RESYCHRONIZATION ERROR                           |
  1540.   |  11  08    T          INCOMPLETE BLOCK READ                                 |
  1541.   |  11  09    T          NO GAP FOUND                                          |
  1542.   |  11  0A   DT     O    MISCORRECTED ERROR                                    |
  1543.   |  11  0B   D   W  O    UNRECOVERED READ ERROR - RECOMMEND REASSIGNMENT       |
  1544.   |  11  0C   D   W  O    UNRECOVERED READ ERROR - RECOMMEND REWRITE THE DATA   |
  1545.   |  12  00   D   W  O    ADDRESS MARK NOT FOUND FOR ID FIELD                   |
  1546.   |  13  00   D   W  O    ADDRESS MARK NOT FOUND FOR DATA FIELD                 |
  1547.   |  14  00   DTL WRSO    RECORDED ENTITY NOT FOUND                             |
  1548.   |  14  01   DT  WR O    RECORD NOT FOUND                                      |
  1549.   |  14  02    T          FILEMARK OR SETMARK NOT FOUND                         |
  1550.   |  14  03    T          END-OF-DATA NOT FOUND                                 |
  1551.   |  14  04    T          BLOCK SEQUENCE ERROR                                  |
  1552.   |  15  00   DTL WRSOM   RANDOM POSITIONING ERROR                              |
  1553.   |  15  01   DTL WRSOM   MECHANICAL POSITIONING ERROR                          |
  1554.   |  15  02   DT  WR O    POSITIONING ERROR DETECTED BY READ OF MEDIUM          |
  1555.   |  16  00   DW     O    DATA SYNCHRONIZATION MARK ERROR                       |
  1556.   |  17  00   DT  WRSO    RECOVERED DATA WITH NO ERROR CORRECTION APPLIED       |
  1557.   |  17  01   DT  WRSO    RECOVERED DATA WITH RETRIES                           |
  1558.   |  17  02   DT  WR O    RECOVERED DATA WITH POSITIVE HEAD OFFSET              |
  1559.   |  17  03   DT  WR O    RECOVERED DATA WITH NEGATIVE HEAD OFFSET              |
  1560.   |  17  04       WR O    RECOVERED DATA WITH RETRIES AND/OR CIRC APPLIED       |
  1561.   |  17  05   D   WR O    RECOVERED DATA USING PREVIOUS SECTOR ID               |
  1562.   |  17  06   D   W  O    RECOVERED DATA WITHOUT ECC - DATA AUTO-REALLOCATED    |
  1563.   |  17  07   D   W  O    RECOVERED DATA WITHOUT ECC - RECOMMEND REASSIGNMENT   |
  1564.   |  17  08   D   W  O    RECOVERED DATA WITHOUT ECC - RECOMMEND REWRITE        |
  1565.   |  18  00   DT  WR O    RECOVERED DATA WITH ERROR CORRECTION APPLIED          |
  1566.   |  18  01   D   WR O    RECOVERED DATA WITH ERROR CORRECTION & RETRIES APPLIED|
  1567.   |  18  02   D   WR O    RECOVERED DATA - DATA AUTO-REALLOCATED                |
  1568.   |  18  03        R      RECOVERED DATA WITH CIRC                              |
  1569.   |  18  04        R      RECOVERED DATA WITH LEC                               |
  1570.   |  18  05   D   WR O    RECOVERED DATA - RECOMMEND REASSIGNMENT               |
  1571.   |  18  06   D   WR O    RECOVERED DATA - RECOMMEND REWRITE                    |
  1572.   +=============================================================================+
  1573.  
  1574.        Table 364: (continued)
  1575.        +=============================================================================+
  1576.        |           D - DIRECT ACCESS DEVICE                                          |
  1577.        |           .T - SEQUENTIAL ACCESS DEVICE                                     |
  1578.        |           . L - PRINTER DEVICE                                              |
  1579.        |           .  P - PROCESSOR DEVICE                                           |
  1580.        |           .  .W - WRITE ONCE READ MULTIPLE DEVICE                           |
  1581.        |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  1582.        |           .  .  S - SCANNER DEVICE                                          |
  1583.        |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  1584.        |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  1585.        |           .  .  .  C - COMMUNICATION DEVICE                                 |
  1586.        |           .  .  .  .                                                        |
  1587.        | ASC ASCQ  DTLPWRSOMC  DESCRIPTION                                           |
  1588.        | --- ----              ----------------------------------------------------- |
  1589.        |  19  00   D      O    DEFECT LIST ERROR                                     |
  1590.        |  19  01   D      O    DEFECT LIST NOT AVAILABLE                             |
  1591.        |  19  02   D      O    DEFECT LIST ERROR IN PRIMARY LIST                     |
  1592.        |  19  03   D      O    DEFECT LIST ERROR IN GROWN LIST                       |
  1593.        |  1A  00   DTLPWRSOMC  PARAMETER LIST LENGTH ERROR                           |
  1594.        |  1B  00   DTLPWRSOMC  SYNCHRONOUS DATA TRANSFER ERROR                       |
  1595.        |  1C  00   D      O    DEFECT LIST NOT FOUND                                 |
  1596.        |  1C  01   D      O    PRIMARY DEFECT LIST NOT FOUND                         |
  1597.        |  1C  02   D      O    GROWN DEFECT LIST NOT FOUND                           |
  1598.        |  1D  00   D   W  O    MISCOMPARE DURING VERIFY OPERATION                    |
  1599.        |  1E  00   D   W  O    RECOVERED ID WITH ECC                                 |
  1600.        |  1F  00                                                                     |
  1601.        |  20  00   DTLPWRSOMC  INVALID COMMAND OPERATION CODE                        |
  1602.        |  21  00   DT  WR OM   LOGICAL BLOCK ADDRESS OUT OF RANGE                    |
  1603.        |  21  01           M   INVALID ELEMENT ADDRESS                               |
  1604.        |  22  00   D           ILLEGAL FUNCTION (SHOULD USE 20 00, 24 00, OR 26 00)  |
  1605.        |  23  00                                                                     |
  1606.        |  24  00   DTLPWRSOMC  INVALID FIELD IN CDB                                  |
  1607.        |  25  00   DTLPWRSOMC  LOGICAL UNIT NOT SUPPORTED                            |
  1608.        |  26  00   DTLPWRSOMC  INVALID FIELD IN PARAMETER LIST                       |
  1609.        |  26  01   DTLPWRSOMC  PARAMETER NOT SUPPORTED                               |
  1610.        |  26  02   DTLPWRSOMC  PARAMETER VALUE INVALID                               |
  1611.        |  26  03   DTLPWRSOMC  THRESHOLD PARAMETERS NOT SUPPORTED                    |
  1612.        |  27  00   DT  W  O    WRITE PROTECTED                                       |
  1613.        |  28  00   DTLPWRSOMC  NOT READY TO READY TRANSITION(MEDIUM MAY HAVE CHANGED)|
  1614.        |  28  01           M   IMPORT OR EXPORT ELEMENT ACCESSED                     |
  1615.        |  29  00   DTLPWRSOMC  POWER ON, RESET, OR BUS DEVICE RESET OCCURRED         |
  1616.        |  2A  00   DTL WRSOMC  PARAMETERS CHANGED                                    |
  1617.        |  2A  01   DTL WRSOMC  MODE PARAMETERS CHANGED                               |
  1618.        |  2A  02   DTL WRSOMC  LOG PARAMETERS CHANGED                                |
  1619.        |  2B  00   DTLPWRSO C  COPY CANNOT EXECUTE SINCE HOST CANNOT DISCONNECT      |
  1620.        |  2C  00   DTLPWRSOMC  COMMAND SEQUENCE ERROR                                |
  1621.        |  2C  01         S     TOO MANY WINDOWS SPECIFIED                            |
  1622.        |  2C  02         S     INVALID COMBINATION OF WINDOWS SPECIFIED              |
  1623.        |  2D  00    T          OVERWRITE ERROR ON UPDATE IN PLACE                    |
  1624.        |  2E  00                                                                     |
  1625.        |  2F  00   DTLPWRSOMC  COMMANDS CLEARED BY ANOTHER INITIATOR                 |
  1626.        |  30  00   DT  WR OM   INCOMPATIBLE MEDIUM INSTALLED                         |
  1627.        |  30  01   DT  WR O    CANNOT READ MEDIUM - UNKNOWN FORMAT                   |
  1628.        |  30  02   DT  WR O    CANNOT READ MEDIUM - INCOMPATIBLE FORMAT              |
  1629.        |  30  03   DT          CLEANING CARTRIDGE INSTALLED                          |
  1630.        |  31  00   DT  W  O    MEDIUM FORMAT CORRUPTED                               |
  1631.        |  31  01   D L    O    FORMAT COMMAND FAILED                                 |
  1632.        |  32  00   D   W  O    NO DEFECT SPARE LOCATION AVAILABLE                    |
  1633.        |  32  01   D   W  O    DEFECT LIST UPDATE FAILURE                            |
  1634.        |  33  00    T          TAPE LENGTH ERROR                                     |
  1635.        |  34  00                                                                     |
  1636.        |  35  00                                                                     |
  1637.        |  36  00     L         RIBBON, INK, OR TONER FAILURE                         |
  1638.        +=============================================================================+
  1639.  
  1640.        Table 364: (continued)
  1641.        +=============================================================================+
  1642.        |           D - DIRECT ACCESS DEVICE                                          |
  1643.        |           .T - SEQUENTIAL ACCESS DEVICE                                     |
  1644.        |           . L - PRINTER DEVICE                                              |
  1645.        |           .  P - PROCESSOR DEVICE                                           |
  1646.        |           .  .W - WRITE ONCE READ MULTIPLE DEVICE                           |
  1647.        |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  1648.        |           .  .  S - SCANNER DEVICE                                          |
  1649.        |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  1650.        |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  1651.        |           .  .  .  C - COMMUNICATION DEVICE                                 |
  1652.        |           .  .  .  .                                                        |
  1653.        | ASC ASCQ  DTLPWRSOMC  DESCRIPTION                                           |
  1654.        | --- ----              ----------------------------------------------------- |
  1655.        |  37  00   DTL WRSOMC  ROUNDED PARAMETER                                     |
  1656.        |  38  00                                                                     |
  1657.        |  39  00   DTL WRSOMC  SAVING PARAMETERS NOT SUPPORTED                       |
  1658.        |  3A  00   DTL WRSOM   MEDIUM NOT PRESENT                                    |
  1659.        |  3B  00    TL         SEQUENTIAL POSITIONING ERROR                          |
  1660.        |  3B  01    T          TAPE POSITION ERROR AT BEGINNING-OF-MEDIUM            |
  1661.        |  3B  02    T          TAPE POSITION ERROR AT END-OF-MEDIUM                  |
  1662.        |  3B  03     L         TAPE OR ELECTRONIC VERTICAL FORMS UNIT NOT READY      |
  1663.        |  3B  04     L         SLEW FAILURE                                          |
  1664.        |  3B  05     L         PAPER JAM                                             |
  1665.        |  3B  06     L         FAILED TO SENSE TOP-OF-FORM                           |
  1666.        |  3B  07     L         FAILED TO SENSE BOTTOM-OF-FORM                        |
  1667.        |  3B  08    T          REPOSITION ERROR                                      |
  1668.        |  3B  09         S     READ PAST END OF MEDIUM                               |
  1669.        |  3B  0A         S     READ PAST BEGINNING OF MEDIUM                         |
  1670.        |  3B  0B         S     POSITION PAST END OF MEDIUM                           |
  1671.        |  3B  0C         S     POSITION PAST BEGINNING OF MEDIUM                     |
  1672.        |  3B  0D           M   MEDIUM DESTINATION ELEMENT FULL                       |
  1673.        |  3B  0E           M   MEDIUM SOURCE ELEMENT EMPTY                           |
  1674.        |  3C  00                                                                     |
  1675.        |  3D  00   DTLPWRSOMC  INVALID BITS IN IDENTIFY MESSAGE                      |
  1676.        |  3E  00   DTLPWRSOMC  LOGICAL UNIT HAS NOT SELF-CONFIGURED YET              |
  1677.        |  3F  00   DTLPWRSOMC  TARGET OPERATING CONDITIONS HAVE CHANGED              |
  1678.        |  3F  01   DTLPWRSOMC  MICROCODE HAS BEEN CHANGED                            |
  1679.        |  3F  02   DTLPWRSOMC  CHANGED OPERATING DEFINITION                          |
  1680.        |  3F  03   DTLPWRSOMC  INQUIRY DATA HAS CHANGED                              |
  1681.        |  40  00   D           RAM FAILURE (SHOULD USE 40 NN)                        |
  1682.        |  40  NN   DTLPWRSOMC  DIAGNOSTIC FAILURE ON COMPONENT NN (80H-FFH)          |
  1683.        |  41  00   D           DATA PATH FAILURE (SHOULD USE 40 NN)                  |
  1684.        |  42  00   D           POWER-ON OR SELF-TEST FAILURE (SHOULD USE 40 NN)      |
  1685.        |  43  00   DTLPWRSOMC  MESSAGE ERROR                                         |
  1686.        |  44  00   DTLPWRSOMC  INTERNAL TARGET FAILURE                               |
  1687.        |  45  00   DTLPWRSOMC  SELECT OR RESELECT FAILURE                            |
  1688.        |  46  00   DTLPWRSOMC  UNSUCCESSFUL SOFT RESET                               |
  1689.        |  47  00   DTLPWRSOMC  SCSI PARITY ERROR                                     |
  1690.        |  48  00   DTLPWRSOMC  INITIATOR DETECTED ERROR MESSAGE RECEIVED             |
  1691.        |  49  00   DTLPWRSOMC  INVALID MESSAGE ERROR                                 |
  1692.        |  4A  00   DTLPWRSOMC  COMMAND PHASE ERROR                                   |
  1693.        |  4B  00   DTLPWRSOMC  DATA PHASE ERROR                                      |
  1694.        |  4C  00   DTLPWRSOMC  LOGICAL UNIT FAILED SELF-CONFIGURATION                |
  1695.        |  4D  00                                                                     |
  1696.        |  4E  00   DTLPWRSOMC  OVERLAPPED COMMANDS ATTEMPTED                         |
  1697.        |  4F  00                                                                     |
  1698.        |  50  00    T          WRITE APPEND ERROR                                    |
  1699.        |  50  01    T          WRITE APPEND POSITION ERROR                           |
  1700.        |  50  02    T          POSITION ERROR RELATED TO TIMING                      |
  1701.        |  51  00    T     O    ERASE FAILURE                                         |
  1702.        |  52  00    T          CARTRIDGE FAULT                                       |
  1703.        +=============================================================================+
  1704.  
  1705.        Table 364: (continued)
  1706.        +=============================================================================+
  1707.        |           D - DIRECT ACCESS DEVICE                                          |
  1708.        |           .T - SEQUENTIAL ACCESS DEVICE                                     |
  1709.        |           . L - PRINTER DEVICE                                              |
  1710.        |           .  P - PROCESSOR DEVICE                                           |
  1711.        |           .  .W - WRITE ONCE READ MULTIPLE DEVICE                           |
  1712.        |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  1713.        |           .  .  S - SCANNER DEVICE                                          |
  1714.        |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  1715.        |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  1716.        |           .  .  .  C - COMMUNICATION DEVICE                                 |
  1717.        |           .  .  .  .                                                        |
  1718.        | ASC ASCQ  DTLPWRSOMC  DESCRIPTION                                           |
  1719.        | --- ----              ----------------------------------------------------- |
  1720.        |  53  00   DTL WRSOM   MEDIA LOAD OR EJECT FAILED                            |
  1721.        |  53  01    T          UNLOAD TAPE FAILURE                                   |
  1722.        |  53  02   DT  WR OM   MEDIUM REMOVAL PREVENTED                              |
  1723.        |  54  00      P        SCSI TO HOST SYSTEM INTERFACE FAILURE                 |
  1724.        |  55  00      P        SYSTEM RESOURCE FAILURE                               |
  1725.        |  56  00                                                                     |
  1726.        |  57  00        R      UNABLE TO RECOVER TABLE-OF-CONTENTS                   |
  1727.        |  58  00     O         GENERATION DOES NOT EXIST                             |
  1728.        |  59  00     O         UPDATED BLOCK READ                                    |
  1729.        |  5A  00   DTLPWRSOM   OPERATOR REQUEST OR STATE CHANGE INPUT (UNSPECIFIED)  |
  1730.        |  5A  01   DT  WR OM   OPERATOR MEDIUM REMOVAL REQUEST                       |
  1731.        |  5A  02   DT  W  O    OPERATOR SELECTED WRITE PROTECT                       |
  1732.        |  5A  03   DT  W  O    OPERATOR SELECTED WRITE PERMIT                        |
  1733.        |  5B  00   DTLPWRSOM   LOG EXCEPTION                                         |
  1734.        |  5B  01   DTLPWRSOM   THRESHOLD CONDITION MET                               |
  1735.        |  5B  02   DTLPWRSOM   LOG COUNTER AT MAXIMUM                                |
  1736.        |  5B  03   DTLPWRSOM   LOG LIST CODES EXHAUSTED                              |
  1737.        |  5C  00   D   O       RPL STATUS CHANGE                                     |
  1738.        |  5C  01   D   O       SPINDLES SYNCHRONIZED                                 |
  1739.        |  5C  02   D   O       SPINDLES NOT SYNCHRONIZED                             |
  1740.        |  5D  00                                                                     |
  1741.        |  5E  00                                                                     |
  1742.        |  5F  00                                                                     |
  1743.        |  60  00         S     LAMP FAILURE                                          |
  1744.        |  61  00         S     VIDEO ACQUISITION ERROR                               |
  1745.        |  61  01         S     UNABLE TO ACQUIRE VIDEO                               |
  1746.        |  61  02         S     OUT OF FOCUS                                          |
  1747.        |  62  00         S     SCAN HEAD POSITIONING ERROR                           |
  1748.        |  63  00        R      END OF USER AREA ENCOUNTERED ON THIS TRACK            |
  1749.        |  64  00        R      ILLEGAL MODE FOR THIS TRACK                           |
  1750.        |  65  00                                                                     |
  1751.        |  66  00                                                                     |
  1752.        |  67  00                                                                     |
  1753.        |  68  00                                                                     |
  1754.        |  69  00                                                                     |
  1755.        |  6A  00                                                                     |
  1756.        |  6B  00                                                                     |
  1757.        |  6C  00                                                                     |
  1758.        |  6D  00                                                                     |
  1759.        |  6E  00                                                                     |
  1760.        |  6F  00                                                                     |
  1761.        +=============================================================================+
  1762.  
  1763.   Table 364: (concluded)
  1764.   +=============================================================================+
  1765.   |           D - DIRECT ACCESS DEVICE                                          |
  1766.   |           .T - SEQUENTIAL ACCESS DEVICE                                     |
  1767.   |           . L - PRINTER DEVICE                                              |
  1768.   |           .  P - PROCESSOR DEVICE                                           |
  1769.   |           .  .W - WRITE ONCE READ MULTIPLE DEVICE                           |
  1770.   |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  1771.   |           .  .  S - SCANNER DEVICE                                          |
  1772.   |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  1773.   |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  1774.   |           .  .  .  C - COMMUNICATION DEVICE                                 |
  1775.   |           .  .  .  .                                                        |
  1776.   | ASC ASCQ  DTLPWRSOMC  DESCRIPTION                                           |
  1777.   | --- ----              ----------------------------------------------------- |
  1778.   |  70  00                                                                     |
  1779.   |  71  00                                                                     |
  1780.   |  72  00                                                                     |
  1781.   |  73  00                                                                     |
  1782.   |  74  00                                                                     |
  1783.   |  75  00                                                                     |
  1784.   |  76  00                                                                     |
  1785.   |  77  00                                                                     |
  1786.   |  78  00                                                                     |
  1787.   |  79  00                                                                     |
  1788.   |  7A  00                                                                     |
  1789.   |  7B  00                                                                     |
  1790.   |  7C  00                                                                     |
  1791.   |  7D  00                                                                     |
  1792.   |  7E  00                                                                     |
  1793.   |  7F  00                                                                     |
  1794.   |                                                                             |
  1795.   |  80  xxh \                                                                  |
  1796.   |   THROUGH >  VENDOR SPECIFIC.                                               |
  1797.   |  FF  xxh /                                                                  |
  1798.   |                                                                             |
  1799.   |  xxh 80 \                                                                   |
  1800.   |  THROUGH >  VENDOR SPECIFIC QUALIFICATION OF STANDARD ASC.                  |
  1801.   |  xxh FF /                                                                   |
  1802.   |               ALL CODES NOT SHOWN OR BLANK ARE RESERVED.                    |
  1803.   +=============================================================================+
  1804.  
  1805.   W.  A SCSI command code quick reference
  1806.  
  1807.   Table 365 is a numerical order listing of the command operation codes.
  1808.  
  1809.                           Table 365: SCSI-2 Operation Codes
  1810.  
  1811.   +=============================================================================+
  1812.   |           D - DIRECT ACCESS DEVICE                       Device Column Key  |
  1813.   |           .T - SEQUENTIAL ACCESS DEVICE                  M = Mandatory      |
  1814.   |           . L - PRINTER DEVICE                           O = Optional       |
  1815.   |           .  P - PROCESSOR DEVICE                        V = Vendor Specific|
  1816.   |           .  .W - WRITE ONCE READ MULTIPLE DEVICE        R = Reserved       |
  1817.   |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  1818.   |           .  .  S - SCANNER DEVICE                                          |
  1819.   |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  1820.   |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  1821.   |           .  .  .  C - COMMUNICATION DEVICE                                 |
  1822.   |           .  .  .  .                                                        |
  1823.   |        OP DTLPWRSOMC Description                                            |
  1824.   |----------+----------+-------------------------------------------------------|
  1825.   |        00 MMMMMMMMMM TEST UNIT READY                                        |
  1826.   |        01  M         REWIND                                                 |
  1827.   |        01 O V OO OO  REZERO UNIT                                            |
  1828.   |        02 VVVVVV  V                                                         |
  1829.   |        03 MMMMMMMMMM REQUEST SENSE                                          |
  1830.   |        04   O        FORMAT                                                 |
  1831.   |        04 M      O   FORMAT UNIT                                            |
  1832.   |        05 VMVVVV  V  READ BLOCK LIMITS                                      |
  1833.   |        06 VVVVVV  V                                                         |
  1834.   |        07         O  INITIALIZE ELEMENT STATUS                              |
  1835.   |        07 OVV O  OV  REASSIGN BLOCKS                                        |
  1836.   |        08          M GET MESSAGE(06)                                        |
  1837.   |        08 OMV OO OV  READ(06)                                               |
  1838.   |        08    O       RECEIVE                                                |
  1839.   |        09 VVVVVV  V                                                         |
  1840.   |        0A   M        PRINT                                                  |
  1841.   |        0A          M SEND MESSAGE(06)                                       |
  1842.   |        0A    M       SEND(06)                                               |
  1843.   |        0A OM  O  OV  WRITE(06)                                              |
  1844.   |        0B O   OO OV  SEEK(06)                                               |
  1845.   |        0B   O        SLEW AND PRINT                                         |
  1846.   |        0C VVVVVV  V                                                         |
  1847.   |        0D VVVVVV  V                                                         |
  1848.   |        0E VVVVVV  V                                                         |
  1849.   |        0F VOVVVV  V  READ REVERSE                                           |
  1850.   |        10   O O      SYNCHRONIZE BUFFER                                     |
  1851.   |        10 VM VVV     WRITE FILEMARKS                                        |
  1852.   |        11 VMVVVV     SPACE                                                  |
  1853.   |        12 MMMMMMMMMM INQUIRY                                                |
  1854.   |        13 VOVVVV     VERIFY(06)                                             |
  1855.   |        14 VOOVVV     RECOVER BUFFERED DATA                                  |
  1856.   |        15 OMO OOOOOO MODE SELECT(06)                                        |
  1857.   |        16 M   MM MO  RESERVE                                                |
  1858.   |        16  MM   M    RESERVE UNIT                                           |
  1859.   |        17 M   MM MO  RELEASE                                                |
  1860.   |        17  MM   M    RELEASE UNIT                                           |
  1861.   |        18 OOOOOOOO   COPY                                                   |
  1862.   |        19 VMVVVV     ERASE                                                  |
  1863.   |        1A OMO OOOOOO MODE SENSE(06)                                         |
  1864.   |        1B  O         LOAD UNLOAD                                            |
  1865.   |        1B       O    SCAN                                                   |
  1866.   |        1B   O        STOP PRINT                                             |
  1867.   |        1B O   OO O   STOP START UNIT                                        |
  1868.   +=============================================================================+
  1869.  
  1870.        Table 365: (continued)
  1871.        +=============================================================================+
  1872.        |           D - DIRECT ACCESS DEVICE                       Device Column Key  |
  1873.        |           .T - SEQUENTIAL ACCESS DEVICE                  M = Mandatory      |
  1874.        |           . L - PRINTER DEVICE                           O = Optional       |
  1875.        |           .  P - PROCESSOR DEVICE                        V = Vendor Specific|
  1876.        |           .  .W - WRITE ONCE READ MULTIPLE DEVICE        R = Reserved       |
  1877.        |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  1878.        |           .  .  S - SCANNER DEVICE                                          |
  1879.        |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  1880.        |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  1881.        |           .  .  .  C - COMMUNICATION DEVICE                                 |
  1882.        |           .  .  .  .                                                        |
  1883.        |        OP DTLPWRSOMC Description                                            |
  1884.        |----------+----------+-------------------------------------------------------|
  1885.        |        1C OOOOOOOOOO RECEIVE DIAGNOSTIC RESULTS                             |
  1886.        |        1D MMMMMMMMMM SEND DIAGNOSTIC                                        |
  1887.        |        1E OO  OO OO  PREVENT ALLOW MEDIUM REMOVAL                           |
  1888.        |        1F                                                                   |
  1889.        |        20 V   VV V                                                          |
  1890.        |        21 V   VV V                                                          |
  1891.        |        22 V   VV V                                                          |
  1892.        |        23 V   VV V                                                          |
  1893.        |        24 V   VVM    SET WINDOW                                             |
  1894.        |        25       O    GET WINDOW                                             |
  1895.        |        25 M   M  M   READ CAPACITY                                          |
  1896.        |        25      M     READ CD-ROM CAPACITY                                   |
  1897.        |        26 V   VV                                                            |
  1898.        |        27 V   VV                                                            |
  1899.        |        28          O GET MESSAGE(10)                                        |
  1900.        |        28 M   MMMM   READ(10)                                               |
  1901.        |        29 V   VV O   READ GENERATION                                        |
  1902.        |        2A          O SEND MESSAGE(10)                                       |
  1903.        |        2A       O    SEND(10)                                               |
  1904.        |        2A M   M  M   WRITE(10)                                              |
  1905.        |        2B  O         LOCATE                                                 |
  1906.        |        2B         O  POSITION TO ELEMENT                                    |
  1907.        |        2B O   OO O   SEEK(10)                                               |
  1908.        |        2C V      O   ERASE(10)                                              |
  1909.        |        2D V   O  O   READ UPDATED BLOCK                                     |
  1910.        |        2E O   O  O   WRITE AND VERIFY(10)                                   |
  1911.        |        2F O   OO O   VERIFY(10)                                             |
  1912.        |        30 O   OO O   SEARCH DATA HIGH(10)                                   |
  1913.        |        31       O    OBJECT POSITION                                        |
  1914.        |        31 O   OO O   SEARCH DATA EQUAL(10)                                  |
  1915.        |        32 O   OO O   SEARCH DATA LOW(10)                                    |
  1916.        |        33 O   OO O   SET LIMITS(10)                                         |
  1917.        |        34       O    GET DATA BUFFER STATUS                                 |
  1918.        |        34 O   OO O   PRE-FETCH                                              |
  1919.        |        34  O         READ POSITION                                          |
  1920.        |        35 O   OO O   SYNCHRONIZE CACHE                                      |
  1921.        |        36 O   OO O   LOCK UNLOCK CACHE                                      |
  1922.        |        37 O      O   READ DEFECT DATA(10)                                   |
  1923.        |        38     O  O   MEDIUM SCAN                                            |
  1924.        |        39 OOOOOOOO   COMPARE                                                |
  1925.        |        3A OOOOOOOO   COPY AND VERIFY                                        |
  1926.        |        3B OOOOOOOOOO WRITE BUFFER                                           |
  1927.        |        3C OOOOOOOOOO READ BUFFER                                            |
  1928.        |        3D     O  O   UPDATE BLOCK                                           |
  1929.        |        3E O   OO O   READ LONG                                              |
  1930.        |        3F O   O  O   WRITE LONG                                             |
  1931.        +=============================================================================+
  1932.  
  1933.        Table 365: (continued)
  1934.        +=============================================================================+
  1935.        |           D - DIRECT ACCESS DEVICE                       Device Column Key  |
  1936.        |           .T - SEQUENTIAL ACCESS DEVICE                  M = Mandatory      |
  1937.        |           . L - PRINTER DEVICE                           O = Optional       |
  1938.        |           .  P - PROCESSOR DEVICE                        V = Vendor Specific|
  1939.        |           .  .W - WRITE ONCE READ MULTIPLE DEVICE        R = Reserved       |
  1940.        |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  1941.        |           .  .  S - SCANNER DEVICE                                          |
  1942.        |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  1943.        |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  1944.        |           .  .  .  C - COMMUNICATION DEVICE                                 |
  1945.        |           .  .  .  .                                                        |
  1946.        |        OP DTLPWRSOMC Description                                            |
  1947.        |----------+----------+-------------------------------------------------------|
  1948.        |        40 OOOOOOOOOO CHANGE DEFINITION                                      |
  1949.        |        41 O          WRITE SAME                                             |
  1950.        |        42      O     READ SUB-CHANNEL                                       |
  1951.        |        43      O     READ TOC                                               |
  1952.        |        44      O     READ HEADER                                            |
  1953.        |        45      O     PLAY AUDIO(10)                                         |
  1954.        |        46                                                                   |
  1955.        |        47      O     PLAY AUDIO MSF                                         |
  1956.        |        48      O     PLAY AUDIO TRACK INDEX                                 |
  1957.        |        49      O     PLAY TRACK RELATIVE(10)                                |
  1958.        |        4A                                                                   |
  1959.        |        4B      O     PAUSE RESUME                                           |
  1960.        |        4C OOOOOOOOOO LOG SELECT                                             |
  1961.        |        4D OOOOOOOOOO LOG SENSE                                              |
  1962.        |        4E                                                                   |
  1963.        |        4F                                                                   |
  1964.        |        50                                                                   |
  1965.        |        51                                                                   |
  1966.        |        52                                                                   |
  1967.        |        53                                                                   |
  1968.        |        54                                                                   |
  1969.        |        55 OOO OOOOOO MODE SELECT(10)                                        |
  1970.        |        56                                                                   |
  1971.        |        57                                                                   |
  1972.        |        58                                                                   |
  1973.        |        59                                                                   |
  1974.        |        5A OOO OOOOOO MODE SENSE(10)                                         |
  1975.        |        5B                                                                   |
  1976.        |        5C                                                                   |
  1977.        |        5D                                                                   |
  1978.        |        5E                                                                   |
  1979.        |        5F                                                                   |
  1980.        +=============================================================================+
  1981.  
  1982.   Table 365: (concluded)
  1983.   +=============================================================================+
  1984.   |           D - DIRECT ACCESS DEVICE                       Device Column Key  |
  1985.   |           .T - SEQUENTIAL ACCESS DEVICE                  M = Mandatory      |
  1986.   |           . L - PRINTER DEVICE                           O = Optional       |
  1987.   |           .  P - PROCESSOR DEVICE                        V = Vendor Specific|
  1988.   |           .  .W - WRITE ONCE READ MULTIPLE DEVICE        R = Reserved       |
  1989.   |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  1990.   |           .  .  S - SCANNER DEVICE                                          |
  1991.   |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  1992.   |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  1993.   |           .  .  .  C - COMMUNICATION DEVICE                                 |
  1994.   |           .  .  .  .                                                        |
  1995.   |        OP DTLPWRSOMC Description                                            |
  1996.   |----------+----------+-------------------------------------------------------|
  1997.   |        A0                                                                   |
  1998.   |        A1                                                                   |
  1999.   |        A2                                                                   |
  2000.   |        A3                                                                   |
  2001.   |        A4                                                                   |
  2002.   |        A5         M  MOVE MEDIUM                                            |
  2003.   |        A5      O     PLAY AUDIO(12)                                         |
  2004.   |        A6         O  EXCHANGE MEDIUM                                        |
  2005.   |        A7                                                                   |
  2006.   |        A8          O GET MESSAGE(12)                                        |
  2007.   |        A8     OO O   READ(12)                                               |
  2008.   |        A9      O     PLAY TRACK RELATIVE(12)                                |
  2009.   |        AA          O SEND MESSAGE(12)                                       |
  2010.   |        AA     O  O   WRITE(12)                                              |
  2011.   |        AB                                                                   |
  2012.   |        AC        O   ERASE(12)                                              |
  2013.   |        AD                                                                   |
  2014.   |        AE     O  O   WRITE AND VERIFY(12)                                   |
  2015.   |        AF     OO O   VERIFY(12)                                             |
  2016.   |        B0     OO O   SEARCH DATA HIGH(12)                                   |
  2017.   |        B1     OO O   SEARCH DATA EQUAL(12)                                  |
  2018.   |        B2     OO O   SEARCH DATA LOW(12)                                    |
  2019.   |        B3     OO O   SET LIMITS(12)                                         |
  2020.   |        B4                                                                   |
  2021.   |        B5                                                                   |
  2022.   |        B5         O  REQUEST VOLUME ELEMENT ADDRESS                         |
  2023.   |        B6                                                                   |
  2024.   |        B6         O  SEND VOLUME TAG                                        |
  2025.   |        B7        O   READ DEFECT DATA(12)                                   |
  2026.   |        B8                                                                   |
  2027.   |        B8         O  READ ELEMENT STATUS                                    |
  2028.   |        B9                                                                   |
  2029.   |        BA                                                                   |
  2030.   |        BB                                                                   |
  2031.   |        BC                                                                   |
  2032.   |        BD                                                                   |
  2033.   |        BE                                                                   |
  2034.   |        BF                                                                   |
  2035.   +=============================================================================+
  2036.  
  2037.   X.  Example programs
  2038.  
  2039.   Here is the C example program, which requests manufacturer/model and
  2040.   reports if a medium is loaded in the device.
  2041.  
  2042.   #define DEVICE "/dev/sgc"
  2043.   /* Example program to demonstrate the generic SCSI interface */
  2044.   #include <stdio.h>
  2045.   #include <unistd.h>
  2046.   #include <string.h>
  2047.   #include <fcntl.h>
  2048.   #include <errno.h>
  2049.   #include <scsi/sg.h>
  2050.  
  2051.   #define SCSI_OFF sizeof(struct sg_header)
  2052.   static unsigned char cmd[SCSI_OFF + 18];      /* SCSI command buffer */
  2053.   int fd;                               /* SCSI device/file descriptor */
  2054.  
  2055.   /* process a complete scsi cmd. Use the generic scsi interface. */
  2056.   static int handle_scsi_cmd(unsigned cmd_len,         /* command length */
  2057.                              unsigned in_size,         /* input data size */
  2058.                              unsigned char *i_buff,    /* input buffer */
  2059.                              unsigned out_size,        /* output data size */
  2060.                              unsigned char *o_buff     /* output buffer */
  2061.                              )
  2062.   {
  2063.       int status = 0;
  2064.       struct sg_header *sg_hd;
  2065.  
  2066.       /* safety checks */
  2067.       if (!cmd_len) return -1;            /* need a cmd_len != 0 */
  2068.       if (!i_buff) return -1;             /* need an input buffer != NULL */
  2069.   #ifdef SG_BIG_BUFF
  2070.       if (SCSI_OFF + cmd_len + in_size > SG_BIG_BUFF) return -1;
  2071.       if (SCSI_OFF + out_size > SG_BIG_BUFF) return -1;
  2072.   #else
  2073.       if (SCSI_OFF + cmd_len + in_size > 4096) return -1;
  2074.       if (SCSI_OFF + out_size > 4096) return -1;
  2075.   #endif
  2076.  
  2077.       if (!o_buff) out_size = 0;
  2078.  
  2079.       /* generic scsi device header construction */
  2080.       sg_hd = (struct sg_header *) i_buff;
  2081.       sg_hd->reply_len   = SCSI_OFF + out_size;
  2082.       sg_hd->twelve_byte = cmd_len == 12;
  2083.       sg_hd->result = 0;
  2084.   #if     0
  2085.       sg_hd->pack_len    = SCSI_OFF + cmd_len + in_size; /* not necessary */
  2086.       sg_hd->pack_id;     /* not used */
  2087.       sg_hd->other_flags; /* not used */
  2088.   #endif
  2089.  
  2090.       /* send command */
  2091.       status = write( fd, i_buff, SCSI_OFF + cmd_len + in_size );
  2092.       if ( status < 0 || status != SCSI_OFF + cmd_len + in_size ||
  2093.                          sg_hd->result ) {
  2094.           /* some error happened */
  2095.           fprintf( stderr, "write(generic) result = 0x%x cmd = 0x%x\n",
  2096.                       sg_hd->result, i_buff[SCSI_OFF] );
  2097.           perror("");
  2098.           return status;
  2099.       }
  2100.  
  2101.       if (!o_buff) o_buff = i_buff;       /* buffer pointer check */
  2102.  
  2103.       /* retrieve result */
  2104.       status = read( fd, o_buff, SCSI_OFF + out_size);
  2105.       if ( status < 0 || status != SCSI_OFF + out_size || sg_hd->result ) {
  2106.           /* some error happened */
  2107.           fprintf( stderr, "read(generic) result = 0x%x cmd = 0x%x\n",
  2108.                   sg_hd->result, o_buff[SCSI_OFF] );
  2109.           fprintf( stderr, "read(generic) sense "
  2110.                   "%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\n",
  2111.                   sg_hd->sense_buffer[0],         sg_hd->sense_buffer[1],
  2112.                   sg_hd->sense_buffer[2],         sg_hd->sense_buffer[3],
  2113.                   sg_hd->sense_buffer[4],         sg_hd->sense_buffer[5],
  2114.                   sg_hd->sense_buffer[6],         sg_hd->sense_buffer[7],
  2115.                   sg_hd->sense_buffer[8],         sg_hd->sense_buffer[9],
  2116.                   sg_hd->sense_buffer[10],        sg_hd->sense_buffer[11],
  2117.                   sg_hd->sense_buffer[12],        sg_hd->sense_buffer[13],
  2118.                   sg_hd->sense_buffer[14],        sg_hd->sense_buffer[15]);
  2119.           if (status < 0)
  2120.               perror("");
  2121.       }
  2122.       /* Look if we got what we expected to get */
  2123.       if (status == SCSI_OFF + out_size) status = 0; /* got them all */
  2124.  
  2125.       return status;  /* 0 means no error */
  2126.   }
  2127.  
  2128.   #define INQUIRY_CMD     0x12
  2129.   #define INQUIRY_CMDLEN  6
  2130.   #define INQUIRY_REPLY_LEN 96
  2131.   #define INQUIRY_VENDOR  8       /* Offset in reply data to vendor name */
  2132.  
  2133.   /* request vendor brand and model */
  2134.   static unsigned char *Inquiry ( void )
  2135.   {
  2136.     unsigned char Inqbuffer[ SCSI_OFF + INQUIRY_REPLY_LEN ];
  2137.     unsigned char cmdblk [ INQUIRY_CMDLEN ] =
  2138.         { INQUIRY_CMD,  /* command */
  2139.                     0,  /* lun/reserved */
  2140.                     0,  /* page code */
  2141.                     0,  /* reserved */
  2142.     INQUIRY_REPLY_LEN,  /* allocation length */
  2143.                     0 };/* reserved/flag/link */
  2144.  
  2145.     memcpy( cmd + SCSI_OFF, cmdblk, sizeof(cmdblk) );
  2146.  
  2147.     /*
  2148.      * +------------------+
  2149.      * | struct sg_header | <- cmd
  2150.      * +------------------+
  2151.      * | copy of cmdblk   | <- cmd + SCSI_OFF
  2152.      * +------------------+
  2153.      */
  2154.  
  2155.     if (handle_scsi_cmd(sizeof(cmdblk), 0, cmd,
  2156.                         sizeof(Inqbuffer) - SCSI_OFF, Inqbuffer )) {
  2157.         fprintf( stderr, "Inquiry failed\n" );
  2158.         exit(2);
  2159.     }
  2160.     return (Inqbuffer + SCSI_OFF);
  2161.   }
  2162.  
  2163.   #define TESTUNITREADY_CMD 0
  2164.   #define TESTUNITREADY_CMDLEN 6
  2165.  
  2166.   #define ADD_SENSECODE 12
  2167.   #define ADD_SC_QUALIFIER 13
  2168.   #define NO_MEDIA_SC 0x3a
  2169.   #define NO_MEDIA_SCQ 0x00
  2170.   int TestForMedium ( void )
  2171.   {
  2172.     /* request READY status */
  2173.     static unsigned char cmdblk [TESTUNITREADY_CMDLEN] = {
  2174.         TESTUNITREADY_CMD, /* command */
  2175.                         0, /* lun/reserved */
  2176.                         0, /* reserved */
  2177.                         0, /* reserved */
  2178.                         0, /* reserved */
  2179.                         0};/* reserved */
  2180.  
  2181.     memcpy( cmd + SCSI_OFF, cmdblk, sizeof(cmdblk) );
  2182.  
  2183.     /*
  2184.      * +------------------+
  2185.      * | struct sg_header | <- cmd
  2186.      * +------------------+
  2187.      * | copy of cmdblk   | <- cmd + SCSI_OFF
  2188.      * +------------------+
  2189.      */
  2190.  
  2191.     if (handle_scsi_cmd(sizeof(cmdblk), 0, cmd,
  2192.                               0, NULL)) {
  2193.         fprintf (stderr, "Test unit ready failed\n");
  2194.         exit(2);
  2195.     }
  2196.  
  2197.     return
  2198.      *(((struct sg_header*)cmd)->sense_buffer +ADD_SENSECODE) !=
  2199.                                                           NO_MEDIA_SC ||
  2200.      *(((struct sg_header*)cmd)->sense_buffer +ADD_SC_QUALIFIER) !=
  2201.                                                           NO_MEDIA_SCQ;
  2202.   }
  2203.  
  2204.   void main( void )
  2205.   {
  2206.     fd = open(DEVICE, O_RDWR);
  2207.     if (fd < 0) {
  2208.       fprintf( stderr, "Need read/write permissions for "DEVICE".\n" );
  2209.       exit(1);
  2210.     }
  2211.  
  2212.     /* print some fields of the Inquiry result */
  2213.     printf( "%s\n", Inquiry() + INQUIRY_VENDOR );
  2214.  
  2215.     /* look if medium is loaded */
  2216.     if (!TestForMedium()) {
  2217.       printf("device is unloaded\n");
  2218.     } else {
  2219.       printf("device is loaded\n");
  2220.     }
  2221.   }
  2222.  
  2223.