📄 ioctl.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>ioctl</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="ioctl"></a> <a name="tag_03_282"></a><!-- ioctl --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_282_01"></a>NAME</h4><blockquote>ioctl - control a STREAMS device (<b>STREAMS</b>)</blockquote><h4><a name="tag_03_282_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('XSR')">XSR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include <<a href="../basedefs/stropts.h.html">stropts.h</a>><br><br> int ioctl(int</tt> <i>fildes</i><tt>, int</tt> <i>request</i><tt>, ... /* arg */); <img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div><tt><br></tt></blockquote><h4><a name="tag_03_282_03"></a>DESCRIPTION</h4><blockquote><p>The <i>ioctl</i>() function shall perform a variety of control functions on STREAMS devices. For non-STREAMS devices, thefunctions performed by this call are unspecified. The <i>request</i> argument and an optional third argument (with varying type)shall be passed to and interpreted by the appropriate part of the STREAM associated with <i>fildes</i>.</p><p>The <i>fildes</i> argument is an open file descriptor that refers to a device.</p><p>The <i>request</i> argument selects the control function to be performed and shall depend on the STREAMS device beingaddressed.</p><p>The <i>arg</i> argument represents additional information that is needed by this specific STREAMS device to perform therequested function. The type of <i>arg</i> depends upon the particular control request, but it shall be either an integer or apointer to a device-specific data structure.</p><p>The <i>ioctl</i>() commands applicable to STREAMS, their arguments, and error conditions that apply to each individual commandare described below.</p><p>The following <i>ioctl</i>() commands, with error values indicated, are applicable to all STREAMS files:</p><dl compact><dt>I_PUSH</dt><dd>Pushes the module whose name is pointed to by <i>arg</i> onto the top of the current STREAM, just below the STREAM head. Itthen calls the <a href="../functions/open.html"><i>open</i>()</a> function of the newly-pushed module. <p>The <i>ioctl</i>() function with the I_PUSH command shall fail if:</p><dl compact><dt>[EINVAL]</dt><dd>Invalid module name.</dd><dt>[ENXIO]</dt><dd>Open function of new module failed.</dd><dt>[ENXIO]</dt><dd>Hangup received on <i>fildes</i>.</dd></dl></dd><dt>I_POP</dt><dd>Removes the module just below the STREAM head of the STREAM pointed to by <i>fildes</i>. The <i>arg</i> argument should be 0 inan I_POP request. <p>The <i>ioctl</i>() function with the I_POP command shall fail if:</p><dl compact><dt>[EINVAL]</dt><dd>No module present in the STREAM.</dd><dt>[ENXIO]</dt><dd>Hangup received on <i>fildes</i>.</dd></dl></dd><dt>I_LOOK</dt><dd>Retrieves the name of the module just below the STREAM head of the STREAM pointed to by <i>fildes</i>, and places it in acharacter string pointed to by <i>arg</i>. The buffer pointed to by <i>arg</i> should be at least FMNAMESZ+1 bytes long, whereFMNAMESZ is defined in <a href="../basedefs/stropts.h.html"><i><stropts.h></i></a>. <p>The <i>ioctl</i>() function with the I_LOOK command shall fail if:</p><dl compact><dt>[EINVAL]</dt><dd>No module present in the STREAM.</dd></dl></dd><dt>I_FLUSH</dt><dd>Flushes read and/or write queues, depending on the value of <i>arg</i>. Valid <i>arg</i> values are: <dl compact><dt>FLUSHR</dt><dd>Flush all read queues.</dd><dt>FLUSHW</dt><dd>Flush all write queues.</dd><dt>FLUSHRW</dt><dd>Flush all read and all write queues.</dd></dl><p>The <i>ioctl</i>() function with the I_FLUSH command shall fail if:</p><dl compact><dt>[EINVAL]</dt><dd>Invalid <i>arg</i> value.</dd><dt>[EAGAIN] or [ENOSR]</dt><dd><br>Unable to allocate buffers for flush message.</dd><dt>[ENXIO]</dt><dd>Hangup received on <i>fildes</i>.</dd></dl></dd><dt>I_FLUSHBAND</dt><dd>Flushes a particular band of messages. The <i>arg</i> argument points to a <b>bandinfo</b> structure. The <i>bi_flag</i> membermay be one of FLUSHR, FLUSHW, or FLUSHRW as described above. The <i>bi_pri</i> member determines the priority band to beflushed.</dd><dt>I_SETSIG</dt><dd>Requests that the STREAMS implementation send the SIGPOLL signal to the calling process when a particular event has occurred onthe STREAM associated with <i>fildes</i>. I_SETSIG supports an asynchronous processing capability in STREAMS. The value of<i>arg</i> is a bitmask that specifies the events for which the process should be signaled. It is the bitwise-inclusive OR of anycombination of the following constants: <dl compact><dt>S_RDNORM</dt><dd>A normal (priority band set to 0) message has arrived at the head of a STREAM head read queue. A signal shall be generated evenif the message is of zero length.</dd><dt>S_RDBAND</dt><dd>A message with a non-zero priority band has arrived at the head of a STREAM head read queue. A signal shall be generated evenif the message is of zero length.</dd><dt>S_INPUT</dt><dd>A message, other than a high-priority message, has arrived at the head of a STREAM head read queue. A signal shall be generatedeven if the message is of zero length.</dd><dt>S_HIPRI</dt><dd>A high-priority message is present on a STREAM head read queue. A signal shall be generated even if the message is of zerolength.</dd><dt>S_OUTPUT</dt><dd>The write queue for normal data (priority band 0) just below the STREAM head is no longer full. This notifies the process thatthere is room on the queue for sending (or writing) normal data downstream.</dd><dt>S_WRNORM</dt><dd>Equivalent to S_OUTPUT.</dd><dt>S_WRBAND</dt><dd>The write queue for a non-zero priority band just below the STREAM head is no longer full. This notifies the process that thereis room on the queue for sending (or writing) priority data downstream.</dd><dt>S_MSG</dt><dd>A STREAMS signal message that contains the SIGPOLL signal has reached the front of the STREAM head read queue.</dd><dt>S_ERROR</dt><dd>Notification of an error condition has reached the STREAM head.</dd><dt>S_HANGUP</dt><dd>Notification of a hangup has reached the STREAM head.</dd><dt>S_BANDURG</dt><dd>When used in conjunction with S_RDBAND, SIGURG is generated instead of SIGPOLL when a priority message reaches the front of theSTREAM head read queue.</dd></dl><p>If <i>arg</i> is 0, the calling process shall be unregistered and shall not receive further SIGPOLL signals for the streamassociated with <i>fildes</i>.</p><p>Processes that wish to receive SIGPOLL signals shall ensure that they explicitly register to receive them using I_SETSIG. Ifseveral processes register to receive this signal for the same event on the same STREAM, each process shall be signaled when theevent occurs.</p><p>The <i>ioctl</i>() function with the I_SETSIG command shall fail if:</p><dl compact><dt>[EINVAL]</dt><dd>The value of <i>arg</i> is invalid.</dd><dt>[EINVAL]</dt><dd>The value of <i>arg</i> is 0 and the calling process is not registered to receive the SIGPOLL signal.</dd><dt>[EAGAIN]</dt><dd>There were insufficient resources to store the signal request.</dd></dl></dd><dt>I_GETSIG</dt><dd>Returns the events for which the calling process is currently registered to be sent a SIGPOLL signal. The events are returnedas a bitmask in an <b>int</b> pointed to by <i>arg</i>, where the events are those specified in the description of I_SETSIG above. <p>The <i>ioctl</i>() function with the I_GETSIG command shall fail if:</p><dl compact><dt>[EINVAL]</dt><dd>Process is not registered to receive the SIGPOLL signal.</dd></dl></dd><dt>I_FIND</dt><dd>Compares the names of all modules currently present in the STREAM to the name pointed to by <i>arg</i>, and returns 1 if thenamed module is present in the STREAM, or returns 0 if the named module is not present. <p>The <i>ioctl</i>() function with the I_FIND command shall fail if:</p><dl compact><dt>[EINVAL]</dt><dd><i>arg</i> does not contain a valid module name.</dd></dl></dd><dt>I_PEEK</dt><dd>Retrieves the information in the first message on the STREAM head read queue without taking the message off the queue. It isanalogous to <a href="../functions/getmsg.html"><i>getmsg</i>()</a> except that this command does not remove the message from thequeue. The <i>arg</i> argument points to a <b>strpeek</b> structure. <p>The application shall ensure that the <i>maxlen</i> member in the <b>ctlbuf</b> and <b>databuf strbuf</b> structures is set tothe number of bytes of control information and/or data information, respectively, to retrieve. The <i>flags</i> member may bemarked RS_HIPRI or 0, as described by <a href="../functions/getmsg.html"><i>getmsg</i>()</a>. If the process sets <i>flags</i> toRS_HIPRI, for example, I_PEEK shall only look for a high-priority message on the STREAM head read queue.</p><p>I_PEEK returns 1 if a message was retrieved, and returns 0 if no message was found on the STREAM head read queue, or if theRS_HIPRI flag was set in <i>flags</i> and a high-priority message was not present on the STREAM head read queue. It does not waitfor a message to arrive. On return, <b>ctlbuf</b> specifies information in the control buffer, <b>databuf</b> specifies informationin the data buffer, and <i>flags</i> contains the value RS_HIPRI or 0.</p></dd><dt>I_SRDOPT</dt><dd>Sets the read mode using the value of the argument <i>arg</i>. Read modes are described in <a href="read.html"><i>read</i>()</a> . Valid <i>arg</i> flags are: <dl compact><dt>RNORM</dt><dd>Byte-stream mode, the default.</dd><dt>RMSGD</dt><dd>Message-discard mode.</dd><dt>RMSGN</dt><dd>Message-nondiscard mode.</dd></dl><p>The bitwise-inclusive OR of RMSGD and RMSGN shall return [EINVAL]. The bitwise-inclusive OR of RNORM and either RMSGD or RMSGNshall result in the other flag overriding RNORM which is the default.</p><p>In addition, treatment of control messages by the STREAM head may be changed by setting any of the following flags in<i>arg</i>:</p><dl compact><dt>RPROTNORM</dt><dd>Fail <a href="../functions/read.html"><i>read</i>()</a> with [EBADMSG] if a message containing a control part is at the frontof the STREAM head read queue.</dd><dt>RPROTDAT</dt><dd>Deliver the control part of a message as data when a process issues a <a href="../functions/read.html"><i>read</i>()</a>.</dd><dt>RPROTDIS</dt><dd>Discard the control part of a message, delivering any data portion, when a process issues a <a href="../functions/read.html"><i>read</i>()</a>.</dd>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -