215 lines
3.8 KiB
HTML
215 lines
3.8 KiB
HTML
<HTML
|
|
><HEAD
|
|
><TITLE
|
|
>SG_IO</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="UP"
|
|
TITLE="Ioctl()s"
|
|
HREF="ioctl.html"><LINK
|
|
REL="PREVIOUS"
|
|
TITLE="Ioctl()s"
|
|
HREF="ioctl.html"><LINK
|
|
REL="NEXT"
|
|
TITLE="SG_GET_ACCESS_COUNT"
|
|
HREF="g_access.html"></HEAD
|
|
><BODY
|
|
CLASS="SECT1"
|
|
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="ioctl.html"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="80%"
|
|
ALIGN="center"
|
|
VALIGN="bottom"
|
|
>Chapter 8. Ioctl()s</TD
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="right"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="g_access.html"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"></DIV
|
|
><DIV
|
|
CLASS="SECT1"
|
|
><H1
|
|
CLASS="SECT1"
|
|
><A
|
|
NAME="SG_IO">8.1. SG_IO</H1
|
|
><DIV
|
|
CLASS="FORMALPARA"
|
|
><P
|
|
><B
|
|
>SG_IO 0x2285. </B
|
|
>The idea is deceptively simple: just hand a sg_io_hdr_t object to an
|
|
ioctl() and it will return when the SCSI command is finished. It is
|
|
logically equivalent to doing a write() followed by a blocking read().
|
|
The word "blocking" here implies the read() will wait until the SCSI
|
|
command is complete.</P
|
|
></DIV
|
|
><P
|
|
>The same file descriptor can be used both for SG_IO synchronous calls and
|
|
the write() read() sequences at the same time. The sg driver makes sure that
|
|
the response to a SG_IO call will never accidentally be fetched by a read().
|
|
Even though a single file descriptor can be shared in this manner, it is
|
|
probably more sensible (and results in cleaner code) if separate file
|
|
descriptors to the same SCSI device are used in this case.</P
|
|
><P
|
|
>It is possible that the wait for the command completion is
|
|
interrupted by a signal. In this case the SG_IO call will yield an
|
|
EINTR error. This is reasonably complex to handle and is discussed
|
|
in the ioctl(SG_SET_KEEP_ORPHAN) description below.
|
|
The following SCSI commands will be permitted by SG_IO when the sg
|
|
file descriptor was opened O_RDONLY:
|
|
<P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
>TEST UNIT READY</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>REQUEST SENSE</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>INQUIRY</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>READ CAPACITY</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>READ BUFFER</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>READ(6) (10) and (12)</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>MODE SENSE(6) and (10)</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>LOG SENSE</P
|
|
></LI
|
|
></UL
|
|
>
|
|
All commands to SCSI device type SCANNER are accepted. Other cases
|
|
yield an EPERM error. Note
|
|
that the write() read() interface must have the sg file descriptor
|
|
open()-ed with O_RDWR as write permission is required by Linux to execute
|
|
a write() system call.</P
|
|
><P
|
|
>The ability of the SG_IO ioctl() to issue certain SCSI commands has led
|
|
to some relaxation on file descriptors open()ed "read-only" compared with
|
|
the version 2 sg driver. The open() call will now attempt to allocate a
|
|
reserved buffer for all newly opened file descriptors. The
|
|
ioctl(SG_SET_RESERVED_SIZE) will now work on "read-only" file descriptors.</P
|
|
></DIV
|
|
><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="ioctl.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="g_access.html"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
>Ioctl()s</TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="ioctl.html"
|
|
ACCESSKEY="U"
|
|
>Up</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
>SG_GET_ACCESS_COUNT</TD
|
|
></TR
|
|
></TABLE
|
|
></DIV
|
|
></BODY
|
|
></HTML
|
|
> |