183 lines
3.5 KiB
HTML
183 lines
3.5 KiB
HTML
|
<HTML
|
||
|
><HEAD
|
||
|
><TITLE
|
||
|
>read()</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="System calls"
|
||
|
HREF="syscalls.html"><LINK
|
||
|
REL="PREVIOUS"
|
||
|
TITLE="write()"
|
||
|
HREF="write.html"><LINK
|
||
|
REL="NEXT"
|
||
|
TITLE="poll()"
|
||
|
HREF="poll.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="write.html"
|
||
|
ACCESSKEY="P"
|
||
|
>Prev</A
|
||
|
></TD
|
||
|
><TD
|
||
|
WIDTH="80%"
|
||
|
ALIGN="center"
|
||
|
VALIGN="bottom"
|
||
|
>Chapter 7. System calls</TD
|
||
|
><TD
|
||
|
WIDTH="10%"
|
||
|
ALIGN="right"
|
||
|
VALIGN="bottom"
|
||
|
><A
|
||
|
HREF="poll.html"
|
||
|
ACCESSKEY="N"
|
||
|
>Next</A
|
||
|
></TD
|
||
|
></TR
|
||
|
></TABLE
|
||
|
><HR
|
||
|
ALIGN="LEFT"
|
||
|
WIDTH="100%"></DIV
|
||
|
><DIV
|
||
|
CLASS="SECT1"
|
||
|
><H1
|
||
|
CLASS="SECT1"
|
||
|
><A
|
||
|
NAME="READ">7.3. read()</H1
|
||
|
><DIV
|
||
|
CLASS="FORMALPARA"
|
||
|
><P
|
||
|
><B
|
||
|
>read(int sg_fd, void * buffer, size_t count). </B
|
||
|
>The action of read() with a control block based on struct sg_header is
|
||
|
discussed in the earlier document:
|
||
|
<A
|
||
|
HREF="http://www.torque.net/sg/p/scsi-generic.txt"
|
||
|
TARGET="_top"
|
||
|
><TT
|
||
|
CLASS="LITERAL"
|
||
|
>www.torque.net/sg/p/scsi-generic.txt</TT
|
||
|
></A
|
||
|
>
|
||
|
(i.e. the sg version 2 documentation). This section describes the action of
|
||
|
read() when it is given a control block based on struct sg_io_hdr.</P
|
||
|
></DIV
|
||
|
><P
|
||
|
>The 'buffer' should point to an object of type sg_io_hdr_t and 'count'
|
||
|
should be sizeof(sg_io_hdr_t) [it can be larger but the excess is ignored].
|
||
|
If the read() call succeeds then the 'count' is returned as the result.</P
|
||
|
><P
|
||
|
>By default, read() will return the oldest completed request that is
|
||
|
queued up. A read() will not interfere with any request associated
|
||
|
with the SG_IO ioctl() on this file descriptor except in a special
|
||
|
case when a SG_IO ioctl() is interrupted by a signal.</P
|
||
|
><P
|
||
|
>If the SG_SET_FORCE_PACK_ID,1 ioctl() is active then read() will attempt
|
||
|
to fetch the packet whose pack_id (given earlier to write()) matches the
|
||
|
sg_io_hdr_t::pack_id given to this read(). If not available it will either
|
||
|
wait or yield EAGAIN. As a special case, -1 in sg_io_hdr_t::pack_id given
|
||
|
to read() will match the request whose response has been waiting for
|
||
|
the longest time. Take care to also set 'dxfer_direction' to any valid
|
||
|
value (e.g. SG_DXFER_NONE) when in this mode. The 'interface_id' member
|
||
|
should also be set appropriately.</P
|
||
|
><P
|
||
|
>Apart from the SG_SET_FORCE_PACK_ID case (and then only for the 3 indicated
|
||
|
fields), the sg_io_hdr_t object given to read() can be uninitialized. Note
|
||
|
that the 'sbp' pointer value for optionally outputting a sense buffer was
|
||
|
recorded from the earlier, corresponding write().</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="write.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="poll.html"
|
||
|
ACCESSKEY="N"
|
||
|
>Next</A
|
||
|
></TD
|
||
|
></TR
|
||
|
><TR
|
||
|
><TD
|
||
|
WIDTH="33%"
|
||
|
ALIGN="left"
|
||
|
VALIGN="top"
|
||
|
>write()</TD
|
||
|
><TD
|
||
|
WIDTH="34%"
|
||
|
ALIGN="center"
|
||
|
VALIGN="top"
|
||
|
><A
|
||
|
HREF="syscalls.html"
|
||
|
ACCESSKEY="U"
|
||
|
>Up</A
|
||
|
></TD
|
||
|
><TD
|
||
|
WIDTH="33%"
|
||
|
ALIGN="right"
|
||
|
VALIGN="top"
|
||
|
>poll()</TD
|
||
|
></TR
|
||
|
></TABLE
|
||
|
></DIV
|
||
|
></BODY
|
||
|
></HTML
|
||
|
>
|