old-www/HOWTO/SCSI-Generic-HOWTO/what.html

231 lines
5.3 KiB
HTML

<HTML
><HEAD
><TITLE
>What the sg driver does</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
"><LINK
REL="HOME"
TITLE="The Linux SCSI Generic (sg) HOWTO"
HREF="index.html"><LINK
REL="PREVIOUS"
TITLE="Introduction"
HREF="intro.html"><LINK
REL="NEXT"
TITLE="Identifying the version of the SG driver"
HREF="iddriver.html"></HEAD
><BODY
CLASS="CHAPTER"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>The Linux SCSI Generic (sg) HOWTO</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="intro.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="iddriver.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="CHAPTER"
><H1
><A
NAME="WHAT">Chapter 2. What the sg driver does</H1
><P
>The sg driver permits user applications to send SCSI commands to devices
that understand them. SCSI commands are 6, 10, 12 or 16 bytes long
<A
NAME="AEN70"
HREF="#FTN.AEN70"
>[1]</A
>.
The SCSI disk driver (sd), once device initialization is complete, only
sends SCSI READ and WRITE commands. There a several other interesting
things one might want to do, for example, perform a low level format or turn
on write caching.</P
><P
>Associated with some SCSI commands there is data to be written to the device.
A SCSI WRITE command is one obvious example. When instructed, the sg driver
arranges for data to be transferred to the device along with the SCSI
command. It is possible that the lower level driver (often known as
the "Host Bus Adapter" [HBA] or simply "adapter" driver) is unable to
send the command to the device. An example of this occurs when the device does
not respond in which case a 'host_status' or 'driver-status' error will
be conveyed back to the user application.</P
><P
>All going well the SCSI command (and optionally some data) are conveyed
to the device. The device will respond with a single byte value called
the 'scsi_status'. GOOD is the scsi status indicating everything has
gone well. The most common other status is CHECK CONDITION. In this
latter case, the SCSI mid level issues a REQUEST SENSE SCSI command
The response of the REQUEST SENSE is 18 bytes or more in length and is
called the "sense buffer". It will indicate why the original command
may not have been executed. It is important to realize that a CHECK
CONDITION may vary in severity from informative (e.g. command needed to
be retried before succeeding) to fatal (e.g. "medium error" which often
indicates it is time to replace the disk).</P
><P
>So in all cases a user application should check the various status values.
If necessary the "sense buffer" will be copied back to the user
application. SCSI commands like READ convey data back to the user application
(if they succeed). The sg driver arranges for this data transfer from the
device to the user space, if necessary.</P
><P
>The description so far has concentrated on a disk device, but in reality
the sg driver is not needed very often for disks because there already
is a purpose built device driver for that: sd. The same is true of reading
audio and data CDs (sr [scd]) and tapes (st). However scanners that
understand the SCSI command set and CDR "burning" programs tend to use
the sg driver. Other applications include tape "robots" and music
CD "ripping".</P
><P
>To find out more about SCSI (draft) standards and resources visit
<A
HREF="http://www.t10.org"
TARGET="_top"
><TT
CLASS="LITERAL"
>www.t10.org</TT
></A
>.
To use the sg device driver you should be familiar with the
SCSI commands supported by the device that you wish to control.
Getting hold of such information for devices like scanners can be
quite challenging (if the vendor does not provide it).</P
><P
>The first SCSI command sent to a SCSI device when it is initialized
is an INQUIRY. All SCSI devices should respond promptly to an INQUIRY
supplying information such as the vendor, product designation and revision.
<A
HREF="pexample.html"
>Appendix C</A
> shows the sg driver being used
to send an INQUIRY and print out some of the information in the response.</P
></DIV
><H3
CLASS="FOOTNOTES"
>Notes</H3
><TABLE
BORDER="0"
CLASS="FOOTNOTES"
WIDTH="100%"
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="5%"
><A
NAME="FTN.AEN70"
HREF="what.html#AEN70"
>[1]</A
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="95%"
><P
>SCSI command opcode 0x7f does allow for variable length commands but
that is not supported in Linux currently.</P
></TD
></TR
></TABLE
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="intro.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="iddriver.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Introduction</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Identifying the version of the SG driver</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>