221 lines
4.2 KiB
HTML
221 lines
4.2 KiB
HTML
<HTML
|
|
><HEAD
|
|
><TITLE
|
|
>open()</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="System calls"
|
|
HREF="syscalls.html"><LINK
|
|
REL="NEXT"
|
|
TITLE="write()"
|
|
HREF="write.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="syscalls.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="write.html"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"></DIV
|
|
><DIV
|
|
CLASS="SECT1"
|
|
><H1
|
|
CLASS="SECT1"
|
|
><A
|
|
NAME="OPEN">7.1. open()</H1
|
|
><DIV
|
|
CLASS="FORMALPARA"
|
|
><P
|
|
><B
|
|
>open(const char * filename, int flags). </B
|
|
>The filename should be a sg device file name as discussed in the
|
|
<A
|
|
HREF="interface.html"
|
|
>Chapter 4</A
|
|
>.
|
|
Flags can be a number of the following or-ed together:
|
|
<P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
>O_RDONLY restricts operations to read()s and ioctl()s
|
|
(i.e. can't use write() ).</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>O_RDWR permits all system calls to be executed. </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>O_EXCL waits for other opens on the associated SCSI device to be closed
|
|
before proceeding. If O_NONBLOCK is set then yields EBUSY when someone
|
|
else has the SCSI device open. The combination of O_RDONLY and O_EXCL is
|
|
disallowed.</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>O_NONBLOCK Sets non-blocking mode. Calls that would otherwise block
|
|
yield EAGAIN (e.g. read() ) or EBUSY (e.g. open() ). This flag is ignored by
|
|
ioctl(SG_IO) .</P
|
|
></LI
|
|
></UL
|
|
>
|
|
Either O_RDONLY or O_RDWR must be set in flag. Either of the other 2
|
|
flags (but not both) can be or-ed in.</P
|
|
></DIV
|
|
><P
|
|
>Note that multiple file descriptors may be open to the same SCSI device.
|
|
[This is a way of side stepping the SG_MAX_QUEUE limit.] At the sg level
|
|
separate state information is maintained. This means that even if
|
|
multiple file descriptors are open to a single SCSI device their
|
|
write() read() sequences are essentially independent.</P
|
|
><P
|
|
>Open() calls may be blocked due to exclusive locks (i.e. O_EXCL). An
|
|
exclusive lock applies to a single SCSI device and only to sg's
|
|
use of that device (i.e. it has no effect on access via sd, sr or st
|
|
to that device). If the O_NONBLOCK flag is used then open() calls
|
|
that would have otherwise blocked, yield EBUSY. Applications that
|
|
scan sg devices trying to determine their identity (e.g. whether
|
|
one is a scanner) should use the O_NONBLOCK flag otherwise they
|
|
run the risk of blocking.</P
|
|
><P
|
|
>The driver will attempt to reserve SG_DEF_RESERVED_SIZE bytes (32KBytes in
|
|
the current sg.h) on open(). The size of this reserved buffer can
|
|
subsequently be modified with the SG_SET_RESERVED_SIZE ioctl(). In both
|
|
cases these are requests subject to various dynamic constraints. The actual
|
|
amount of memory obtained can be found by the SG_GET_RESERVED_SIZE ioctl().
|
|
The reserved buffer will be used if:
|
|
<P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
>it is not already in use (e.g. when command queuing is in use)</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>a write() or ioctl(SG_IO) requests a data transfer size that is less
|
|
than or equal to the reserved buffer size.</P
|
|
></LI
|
|
></UL
|
|
></P
|
|
><P
|
|
>Returns a file descriptor if >= 0 , otherwise -1 implies an error.</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="syscalls.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="write.html"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
>System calls</TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="syscalls.html"
|
|
ACCESSKEY="U"
|
|
>Up</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
>write()</TD
|
|
></TR
|
|
></TABLE
|
|
></DIV
|
|
></BODY
|
|
></HTML
|
|
> |