ioctl() — Control device

Standards

Standards / Extensions C or C++ Dependencies

XPG4.2
Single UNIX Specification, Version 3

both  

Format

Terminals:
#include <sys/ioctl.h>

int ioctl(int fildes int cmd, ... /* arg */);
Sockets:
#define _XOPEN_SOURCE_EXTENDED 1

/**     OR      **/

#define _OE_SOCKETS

#include <sys/ioctl.h>
#include <net/rtrouteh.h>
#include <net/if.h>
int ioctl(int fildes, int cmd, ... /* arg */);
STREAMS:
#define _XOPEN_SOURCE_EXTENDED 1
#include <stropts.h>
int ioctl(int fildes int cmd, ... /* arg */);

General description

ioctl() performs a variety of control functions on devices. The cmd argument and an optional third argument (with varying type) are passed to and interpreted by the device associated with fildes.

The cmd argument selects the control function to be performed and will depend on the device being addressed.

The arg argument represents additional information that is needed by this specific device to perform the requested function. The type of arg depends upon the particular control request, but it is either an integer or a pointer to a device-specific data structure.

ioctl() information is divided into the following topics:
  • Terminals
  • Sockets
  • STREAMS
  • ACLs

Terminals

The following ioctl() commands are used with terminals:
Command
Description
TIOCSWINSZ
Set window size. Used as the second operand in an ioctl() against a terminal. The window size information pointed to by the third operand is copied into an area in the kernel associated with the terminal, and a SIGWINCH signal is generated against the foreground process group.
TIOCGWINSZ
Get window size. Used as the second operand in an ioctl() against a terminal. The current window size is returned in the area pointed to by the third operand - a winsize structure.
The winsize structure is the third operand in an ioctl() call when you use TIOCSWINSZ or TIOCGWINSZ. The structure contains four unsigned short integers:
Field
Description
ws_row
Number of rows in the window, in characters.
ws_col
Number of columns in the window, in characters. This assumes single-byte characters. Multibyte characters may take more room.
ws_xpixel
Horizontal size of the window, in pixels.
ws_ypixel
Vertical size of the window, in pixels.

Sockets

The following ioctl() commands are used with sockets:
Command
Description
FIONBIO
Sets or clears nonblocking I/O for a socket. arg is a pointer to an integer. If the integer is 0, nonblocking I/O on the socket is cleared. Otherwise, the socket is set for nonblocking I/O.
FIONREAD
Gets the number of immediately readable bytes for the socket. arg is a pointer to an integer. Sets the value of the integer to the number of immediately readable characters for the socket.
FIONWRITE
Returns the number of bytes that can be written to the connected peer AF_UNIX stream socket before the socket blocks or returns EWOULDBLOCK. The number of bytes returned is not guaranteed unless there is serialization by the using applications.
FIOGETOWN
Returns the PID that has been set that designates the recipient of signals.
FIOSETOWN
Sets the PID to be used when sending signals

FIOGETOWN and FIOSETOWN are equivalent to the F_GETOWN and F_SETOWN commands of fctl(). For information on the values for pid, refer to that function. This function is only valid for AF_INET stream sockets.

SECIGET
Gets the peer socket's security identity values for an AF_UNIX connected stream socket. The MVS™ user ID, effective UID, and effective GID of the peer process are returned in the seci structure, which is mapped by BPXYSECI. This option is valid only for the AF_UNIX domain.
SECIGET_T
Returns both the process and, if available, the task level security information of the peer for an AF_UNIX stream connected to the socket. The task level security information is from the task that issued the connect() or accept(). The security information is returned in a struct __sect_s as defined in <sys/ioctl.h>. The security information is not available until accept() completes. The availability of the peer's task level security data is determined by the task level userid length field. If zero, the peer does not have task level security data.
SIOCADDRT
Adds a routing table entry. arg is a pointer to a rtentry structure, as defined in <net/rtrouteh.h>. The routing table entry, passed as an argument, is added to the routing tables. This option is valid only for the AF_INET domain.
SIOCATMARK
Queries whether the current location in the data input is pointing to out-of-band data. arg is a pointer to an integer. SIOCATMARK sets the argument to 1 if the socket points to a mark in the data stream for out-of-band data; otherwise, it sets the argument to 0. Refer to recv(), recvfrom() and recvmsg() for more information on receiving out-of-band data.
SIOCDELRT
Deletes a routing table entry. arg is a pointer to a rtentry structure, as defined in <net/rtrouteh.h>. If it exists, the routing table entry passed as an argument is deleted from the routing tables. This option is valid only for the AF_INET domain.
SIOCGIFADDR

Gets the network interface address. arg is a pointer to an ifreq structure, as defined in <net/if.h>. The interface address is returned in the argument. This option is valid only for the AF_INET domain.

This macro is protected by the _OPEN_SYS_IF_EXT feature.

SIOCGIFBRDADDR

Gets the network interface broadcast address. arg is a pointer to an ifreq structure, as defined in <net/if.h>. The interface broadcast address is returned in the argument. This option is valid only for the AF_INET domain.

This macro is protected by the _OPEN_SYS_IF_EXT feature.

SIOCGIFCONF

Gets the network interface configuration. arg is a pointer to an ifconf structure, as defined in <net/if.h>. The interface configuration is returned in the buffer pointed to by the ifconf structure. The returned data's length is returned in the field that had originally contained the length of the buffer. This option is valid only for the AF_INET domain.

This macro is protected by the _OPEN_SYS_IF_EXT feature.

SIOCGIFCONF6
Gets the name, address, and other information about the IPv6 network interfaces that are configured. This is similar to the SIOCGIFCONF command for IPv4.

To request OSM interfaces, the application must have READ authorization to the EZB.OSM.sysname.tcpname resource.

A struct __net_ifconf6header_s is passed as the argument of the ioctl. This structure specifies the buffer where the configuration information is to be written and is returned with the number of entries and entry length of each struct, and __net_ifconf6entry_s that was written to the output buffer. These structures are defined in <sys/ioctl.h>.

If __nif6h_buflen and __nif6h_buffer are both zero, a query function is performed and the header is returned with:

__nif6h_version
The maximum supported version.
Note: If the version number is supplied (not zero), the entry length returned will be for the specified version. (If it is supported)
__nif6h_entries
The total number of entries that will be output.
__nif6h_entrylen
The length of each individual entry.
If a call to get information fails with either
errno = ERANGE, or
errno = EINVAL and __nif6h_version has changed
The call was converted into a query function and the header has been filled in as described above. In these cases, the content of the output buffer is undefined.

If Common INET is configured and multiple TCP/IP stacks are attached to the socket, the output from each stack that is enabled for IPv6 will be concatenated in the output buffer and the header will contain the total number of entries returned from all the stacks. The version returned with the query function will be the highest version supported by all the stacks.

This ioctl can be issued on an AF_INET or AF_INET6 socket.

Error Code
Description
EAFNOSUPPORT
No IPv6 enabled TCP/IP stacks are active.
EINVAL
The input version number is not supported.
ERANGE
The buffer is too small to contain all of the IPv6 network interface entries.
SIOCGIFDSTADDR

Gets the network interface destination address. arg is a pointer to an ifreq structure, as defined in <net/if.h>. The interface destination (point-to-point) address is returned in the argument. This option is valid only for the AF_INET domain.

This macro is protected by the _OPEN_SYS_IF_EXT feature.

SIOCGIFFLAGS

Gets the network interface flags. arg is a pointer to an ifreq structure, as defined in <net/if.h>. The interface flags are returned in the argument. This option is valid only for the AF_INET domain.

This macro is protected by the _OPEN_SYS_IF_EXT feature.

SIOCGIFMETRIC

Gets the network interface routing metric. arg is a pointer to an ifreq structure, as defined in <net/if.h>. The interface routing metric is returned in the argument. This option is valid only for the AF_INET domain.

This macro is protected by the _OPEN_SYS_IF_EXT feature.

SIOCGIFMTU

Gets the network interface MTU (maximum transmission unit). arg is a pointer to an ifreq structure, as defined in <net/if.h>. The interface MTU is returned in the argument, arg->ifr_mtu. This option is only valid for the AF_INET domain.

This macro is protected by the _OPEN_SYS_IF_EXT feature.

SIOCGIFNETMASK

Gets the network interface network mask. arg is a pointer to an ifreq structure, as defined in <net/if.h>. The interface network mask is returned in the argument. This option is valid only for the AF_INET domain.

This macro is protected by the _OPEN_SYS_IF_EXT feature.

SIOCGSPLXFQDN
Gets the fully qualified domain name for a given server and domain name in a sysplex. This is an special purpose command to support applications that have registered with WorkLoad Manager (WLM) for connection optimization services using the Domain Name System (DNS). 'arg' is a pointer to sysplexFqDn structure, as defined in <ezbzsdnc.h>. sysplexFqDn contains pointer to sysplexFqDnData structure, as defined in <ezbzsdnc.h>.

sysplexFqDnData structure contains server name(input), group name(input) and fully qualified domain name(output).

ioctl() with the SIOCGSPLXFQDN command will fail if:
Error Code
Description
EFAULT
Write user storage failed
EINVAL
One of the following:
  • Group name required
  • Buffer length not valid
  • Socket call parameter error
ENXIO
One of the following:
  • Sysplex address not found
  • Res not found In DNS
  • Time out
  • Time Unexpected Error
Example: The following is an example of the ioctl() call used with SIOCGSPLXFQDN.
  #include <ezbzsdnc.h>
      sysplexFqDn        splxFqDn;
      sysplexFqDnData    splxData;
      int                rc;

      splxFqDn.splxVersion = splxDataVersion;
      splxFqDn.splxBufLen  = sizeof(sysplexFqDnData);
      splxFqDn.splxBufAddr = &splxData;

      /*  Assign values to splxData.groupName, */
      /*  splxData.serverName if required      */
          .
          .

      /* Get the fully qualified domain name   */
      rc = ioctl(s,SIOCGSPLXFQDN, (char *) &splxFqDn);

      /* splxData.domainName contains the fully*/
      /* qualified domain name.                */
SIOCSECENVR

Used to SET or GET the security environment for a server socket. arg points to a struct __seco_s where element __seco_argument is set to 1 for a SET and 2 for a GET request.

When used with the SET argument, the AF_UNIX stream socket server will designate the server socket as one that requires the full security environment of the connecting client to be available before the connect will complete successfully. During connect processing, connect obtains the security environment of the connector and anchors it off the connector's socket for use by the server. If the security environment cannot be obtained during connect processing, the connect will fail. This command has no effect on sockets that do not become server sockets.

When used with the GET argument, the AF_UNIX stream socket server will copy the previously SET security environment from the connector's address space to the server's address space so it can be used as input on calls to the security product. This command has meaning only for server sockets that previously issued SIOCSECENVR with the SET argument.

SIOCSIFMETRIC

Sets the network interface routing metric. arg is a pointer to an ifreq structure, as defined in <net/if.h>. SIOCSIFMETRIC sets the interface routing metric to the value passed in the argument. This option is valid only for the AF_INET domain.

This macro is protected by the _OPEN_SYS_IF_EXT feature.

SIOCSPARTNERINFO
Sets an indicator to retrieve the partner security credentials during connection setup and saves the information, enabling an application to issue a SIOCGPARTNERINFO ioctl without suspending the application, or at least minimizing the time to retrieve the information. The SIOCSPARTNERINFO ioctl must be issued prior to the SIOCGPARTNERINFO ioctl. For more information, see z/OS Communications Server: IP Programmer's Guide and Reference.
SIOCSVIPA
Defines or deletes an IPv4 dynamic VIPA. arg is a pointer to a dvreq structure as defined in <ezbzdvpc.h>. This option is valid only for the AF_INET domain.
SIOCSVIPA6
Defines or deletes an IPv6 dynamic VIPA. arg is a pointer to a dvreq6 structure as defined in <ezbzdvpc.h>. This option is valid only for the AF_INET6 domain.
SIOCTIEDESTHRD
Associates (ties) or disassociates (unties) a descriptor with a thread. arg is a pointer to an int. When *arg is 1, the descriptor is tied to the calling thread. When *arg is 0, the descriptor is untied from the calling thread. If the task should terminate before the descriptor is closed or untied from the task, z/OS UNIX file system thread termination processing will close the descriptor. This command can be used on both heavy weight and medium weight threads.

Special behavior for C++: To use this function with C++, you must use the _XOPEN_SOURCE_EXTENDED 1 feature test macro.

Terminal and sockets returned value

If successful, ioctl() returns 0.

If unsuccessful, ioctl() returns -1 and sets errno to one of the following values:
Error Code
Description
EBADF
The fildes parameter is not a valid socket descriptor.
EINVAL
The request is not valid or not supported.
EIO
The process group of the process issuing the function is an orphaned, background process group, and the process issuing the function is not ignoring or blocking SIGTTOU.
EMVSPARM
Incorrect parameters were passed to the service.
ENODEV
The device is incorrect. The function is not supported by the device driver.
ENOTTY
An incorrect file descriptor was specified. The file type was not character special.

Example

The following is an example of the ioctl() call.
int s;
int dontblock;
int rc;
⋮
/* Place the socket into nonblocking mode */
dontblock = 1;
rc = ioctl(s, FIONBIO, (
char *) &dontblock);
⋮

STREAMS

The following ioctl() commands are used with STREAMS:
L_PUSH
Pushes the module whose name is pointed to by arg onto the top of the current STREAM, just below the STREAM head. It then calls the open() function of the newly-pushed module.
ioctl() with the I_PUSH command will fail if:
Error Code
Description
EINVAL
Non-valid module name.
ENXIO
Open function of new module failed.
ENXIO
Hang-up received on fildes
L_POP
Removes the module just below the STREAM pointed to by fildes. The arg argument should be 0 in an I_POP request.
ioctl() with the I_POP command will fail if:
Error Code
Description
EINVAL
No module present in the STREAM.
ENXIO
Hang-up received on fildes.
L_LOOK
Retrieves the name of the module just below the STREAM head of the STREAM pointed to by fildes and places it in a character string pointed to by arg. The buffer pointed to by arg should be at least FMNAMESZ+1 bytes long, where FMNAMESZ is defined in <stropts.h>.
ioctl() with the I_LOOK command will fail if:
Error Code
Description
EINVAL
No module present in the STREAM.
L_FLUSH
This request flushes read and/or write queues, depending on the value of arg. Valid arg values are:
FLUSHR
Flush all read queues.
FLUSHW
Flush all write queues.
FLUSHRW
Flush all read and all write queues.
ioctl() with the I_FLUSH command will fail if:
Error Code
Description
EAGAIN or ENOSR
Unable to allocate buffers for flush message.
EINVAL
Non-valid arg value.
ENXIO
Hang-up received on fildes.
I_FLUSHBAND
Flushes a particular band of messages. The arg argument points to a bandinfo structure. The bi_flag member may be one of FLUSHER, FLUSHW, or FLUSHRW as described above. The bi_pri member determines the priority band to be flushed.
I_SETSIG
Requests that the STREAMS implementation send the SIGPOLL signal to the calling process when a particular event has occurred on the STREAM associated with fildes. I_SETIG supports an asynchronous processing capability in STREAMS. The value of arg is a bitmask that specifies the events for which the process should be signaled. It is the bitwise OR of any combination of the following constants:
S_RDNORM
A normal (priority band set to 0) message has arrived at the head of a STREAM head read queue. A signal will be generated even if the message is of zero length.
S_RDBAND
A message with a nonzero priority band has arrived at the head of a STREAM head read queue. A signal will be generated even if the message is of zero length.
S_INPUT
A message, other than a high-priority message, has arrived at the head of a STREAM head read queue. A signal will be generated even if the message is of zero length.
S_HIPRI
A high-priority message is present on a STREAM head read queue. A signal will be generated even if the message is of zero length.
S_OUTPUT
The write queue for normal data (priority band 0) just below the STREAM head is no longer full. This notifies the process that there is room on the queue for sending (or writing) normal data downstream.
S_WRNORM
Same as S_OUTPUT.
S_WRBAND
The write queue for a nonzero priority band just below the STREAM head is no longer full. This notifies the process that there is no room on the queue for sending (or writing) priority data downstream.
S_MSG
A STREAMS signal message that contains the SIGPOLL signal has reached the front of the STREAM head read queue.
S_ERROR
Notification of an error condition has reached the STREAM head.
S_HANGUP
When used in conjunction with S_RDBAND, SIGURG is generated instead of SIGPOLL when a priority message reaches the front of the STREAM head read queue.

If arg is 0, the calling process will be unregistered and will not receive further SIGPOLL signals for the STREAM associated with fildes.

Processes that wish to receive SIGPOLL signals must explicitly register to receive them using I_SETSIG. If several processes register to receive this signal for the same event on the same STREAM, each process will be signaled when the event occurs.

ioctl() with the I_SETSIG command will fail if:
Error Code
Description
EAGAIN
There were insufficient resources to store the signal request.
EINVAL
The value of arg is not valid.
EINVAL
The value of arg is 0 and the calling process is not registered to receive the SIGPOLL signal.
I_GETSIG
Returns the events for which the calling process is currently registered to be sent a SIGPOLL signal. The events are returned as a bitmask in an int pointed to by arg, where the events are those specified in the description of I_SETSIG above.
ioctl() with the I_GETSIG command will fail if:
Error Code
Description
EINVAL
Process is not registered to receive the SIGPOLL signal.
I_FIND
This request compares the names of all modules currently present in the STREAM to the name pointed to by arg, and returns 1 if the name module is present in the STREAM, or returns 0 if the named module is not present.
ioctl() with the I_FIND command will fail if:
Error Code
Description
EINVAL
arg does not contain a valid module name.
I_PEEK
This request allows a process to retrieve the information in the first message on the STREAM head read queue without taking the message off the queue. It is analogous to getmsg() except that this command does not remove the message from the queue. The arg argument points to a strpeek structure.

The maxlen member in the ctlbuf and databuf strbuf structure must be set to the number of bytes of control information and/or data information, respectively, to retrieve. The flags member may be marked RS_HIPRI or 0, as described by getmsg() - getpmsg(). If the process sets flags to RS_HIPRI, for example, I_PEEK will only look for a high-priority message on the STREAM head read queue.

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 the RS_HIPFI flag was set in flags and a high-priority message was not present on the STREAM head read queue. It does not wait for a message to arrive. On return, ctlbuf specifies information in the control buffer, databuf specifies information in the data buffer, and flags contains the value RS_HIPRI or 0.

I_SRDOPT
Sets the read mode using the value of the argument arg. Read modes are described in read(). Valid arg flags are:
RNORM
Byte-stream mode, the default.
RMSGD
Message-discard mode.
RMSGN
Message-nondiscarded mode.

The bitwise inclusive-OR of RMSGD and RMSGN will return EINVAL. The bitwise inclusive-OR of RNORM and either RMSGD or RMSGN will result in the other flag overriding RNORM which is the default.

In addition, treatment of control messages by the STREAM head may be changed by setting any of the following flag in arg:
RPROTNORM
Fail read() with EBADMSG if a message containing a control part is at the front of the STREAM head read queue.
RPROTDAT
Deliver the control part of a message as data when a process issues a read().
RPROTDIS
Discard the control part of a message, delivery any data portion, when a process issues a read().
ioctl() with the I_SRDOPT command will fail if:
Error Code
Description
EINVAL
The arg argument is not valid.
I_GRDOPT
Returns the current read mode setting, as described above, in an int pointed to by the argument arg. Read modes are described in read().
I_NREAD
Counts the number of data bytes in the data part of the first message on the STREAM head read queue and places this value in the init pointed to by arg. The return value for the command is the number of messages on the STREAM head read queue. For example, if 0 is returned in arg, but the ioctl() return value is greater than 0, this indicates that a zero-length message is next on the queue.
I_FDINSERT
Creates a message from specified buffer(s), adds information about another STREAM, and sends the message downstream. The message contains a control part and an optional data part. The data and control parts to be sent are distinguished by placement in separate buffers, as described below. The arg argument points to a strfdinsert structure.

The len member in the ctlbuf strbuf structure must be set to the size of a pointer plus the number of bytes of control information to be sent with the message. The fildes member specifies the file descriptor of the other STREAM, and the offset member, which must be suitably aligned for use as a pointer, specifies the offset from the start of the control buffer where I_FDINSERT will store a pointer whose interpretation is specific to the STREAM end. The len member in the databuf strbuf structure must be set to the number of bytes of data information to be sent with the message, or 0 if no data part is to be sent.

The flags member specifies the type of message to be created. A normal message is created if flags is set to 0, and a high-priority message is created if flags is set to RS_HIPRI. For non-priority messages, I_FDINSERT will block if the STREAM write queue is full due to internal flow control conditions. For priority messages, I_FDINSERT does not block on this condition. For non-priority messages, I_FDINSERT does not block when the write queue is full and O_NONBLOCK is set. Instead, it fails and sets errno to EAGAIN.

I_FDINSERT also blocks, unless prevented by lack of internal resources, waiting for the availability of message blocks in the STREAM, regardless of priority or whether O_NONBLOCK has been specified. No partial message is sent.

ioctl() with the I_FDINSERT command will fail if:
Error Code
Description
EAGAIN
A non-priority message is specified, the O_NONBLOCK flag is set, and the STREAM write queue is full due to internal flow control conditions.
EAGAIN or ENOSR
Buffers can not be allocated for the message that is to be created.
EINVAL
One of the following:
  • The fd member of the strfdinsert structure is not a valid, open STREAM file descriptor.
  • The size of a pointer plus offset is greater than the len member for the buffer specified through ctlptr
  • the offset member does not specify a properly-aligned location in the data buffer.
  • An undefined value is stored in flags
ENXIO
Hang-up received for fd or fildes.
ERANGE
The len member for the buffer specified through databuf does not fall within the range specified by the maximum and minimum packet sizes of the topmost STREAM module or the len member for the buffer specified through databuf is larger than the maximum configured size of the data part of a message; or the len member for the buffer specified through ctlbuf is larger than the maximum configured size of the control part of a message.
I_STR
Constructs an internal STREAMS ioctl() message from the data pointed to by arg, and sends that message downstream.

This mechanism is provided to send ioctl() requests to downstream modules and drivers. It allows information to be sent with ioctl(), and returns to the process any information sent upstream by the downstream recipient. I_STR blocks until the system responds with either a positive or negative acknowledgement message, or until the request "times out" after some period of time. If the request times out, it fails with errno set to ETIME.

At most, one I_STR can be active on a STREAM. Further I_STR calls will block until the active I_STR completes at the STREAM head. The default timeout interval for these requests is 15 seconds. The O_NONBLOCK flag has no effect on this call.

To send requests downstream, arg must point to a strioctl structure.

The ic_cmd member is the internal ioctl() command intended for a downstream module or driver and ic_timeout is the number of seconds (-1 = infinite, 0 = use implementation-dependent timeout interval, >0 = as specified) an I_STR request will wait for acknowledgement before timing out. ic_len member has two uses: on input, it contains the length of the data argument passed in, and on return from the command, it contains the number of bytes being returned to the process (the buffer pointed to by ic_dp should be large enough to contain the maximum amount of data that any module or the driver in the STREAM can return.)

The STREAM head will convert the information pointed to by the strioctl structure to an internal ioctl() command message and send it downstream.

ioctl() with the I_STR command will fail if:
Error Code
Description
EAGAIN or ENOSR
Unable to allocate buffers for the ioctl() message.
EINVAL
This ic_len member is less than 0 or larger than the maximum configured size of the data part of a message, or ic_timeout is less than -1.
ENXIO
Hang-up received on fildes.
ETIME
A downstream ioctl() timed out before acknowledgement was received.

An I_STR can also fail while waiting for an acknowledgement if a message indicating an error or a hang-up is received at the STREAM head. In addition, an error code can be returned in the positive or negative acknowledgement message, in the event the ioctl() command sent downstream fails. For these cases, I_STR fails with errno set to the value in the message.

I_SWROPT
Sets the write mode using the value of the argument arg. Valid bit settings for arg are:
SNDZERO
Send a zero-length message downstream when a write() if 0 bytes occurs. To not send a zero-length message when a write() of 0 bytes occurs, this bit must not be set in arg (for example, arg would be set to 0).
ioctl() with the I_SWROPT command will fail if:
Error Code
Description
EINVAL
arg is not the above value.
I_GWROPT
Returns the current write mode setting as described above, in the int that is pointed to by the argument arg.
I_SENDFD
I_SENDFD creates a new reference to the open file description associated with the file descriptor arg and writes a message on the STREAMS-based pipes fildes containing the reference, together with the user ID and group ID of the calling process.
ioctl() with the I_SENDFD command will fail if:
Error Code
Description
EAGAIN
The sending STREAM is unable to allocate a message block to contain the file pointer; or the read queues of the receiving STREAM head is full and cannot accept the message sent by I_SENDFD.
EBADF
The arg argument is not a valid, open file descriptor.
EINVAL
The fildes argument is not connected to a STREAM pipe.
ENXIO
Hang-up received on fildes.
I_RECVFD
Retrieves the reference to an open file description from a message within a STREAMS-based pipe using the I_SENDFD command, and allocates a new file descriptor in the calling process that refers to this open file description. The arg argument is a pointer to an strrecvfd data structure as defined in <stropts.h>.

The fd member is a file descriptor. The uid and gid members are the effective user ID and effective group ID, respectively, of the sending process.

If O_NONBLOCK is not set I_RECVFD blocks until a message is present at the STREAM head. If O_NONBLOCK is set, I_RECVFD fails with errno set to EAGAIN if no message is present at the STREAM head.

If the message at the STREAM head is a message sent by an I_SENDFD, a new file descriptor is allocated for the open file descriptor referenced in the message. The new file descriptor is placed in the fd member of the strrecvfd structure pointed to by arg.

ioctl() with the I_RECVFD command will fail if:
Error Code
Description
EAGAIN
A message is not present at the STREAM head read queue and the O_NONBLOCK flag is set.
EBADMSG
The message at the STREAM head read queue is not a message containing a passed file descriptor.
EMFILE
The process has the maximum number of file descriptors currently open that is allowed.
ENXIO
Hang-up received on fildes.
I_LIST
This request allows the process to list all the module names on the STREAM, up to and including the topmost driver names. If arg is a NULL pointer, the return value is the number of modules, including the driver, that are on the STREAM pointed to by fildes. This lets the process allocate enough space for the module names. Otherwise, it should point to an str_list structure.

The sl_nmods member indicates the number of entries the process has allocated in the array. Upon return, the sl_modlist member of the str_list structure contains the list of module names. The number of entries that have been filled into the sl_modlist array is found in the sl_nmode member (the number includes the number of module including the driver). The return value from ioctl() is 0. The entries are filled in starting at the top of the STREAM and continuing downstream until either the end of the STREAM is reached, or the number of requested modules (sl_nmods) is satisfied.

ioctl() with the I_LIST command will fail if:
Error Code
Description
EAGAIN or ENOSR
Unable to allocate buffers.
EINVAL
The sl_nmods member is less than 1.
I_ATMARK
This request allows the process to see if the message at the head of the STREAM head read queue is marked by some module downstream. The arg argument determines how the checking is done when there may be multiple marked messages on the STREAM head read queue. It may take on the following values:

ANYMARK Check if the message is marked.

LASTMARK Check if the message is the last one marked on the queue.

The bitwise inclusive-OR of the flags ANYMARK and LASTMARK is permitted.

The return value is 1 if the mark condition is satisfied and 0 otherwise.

ioctl() with the I_ATMARK command will fail if:

EINVAL Non-valid arg value.

I_CKBAND
Check if he message of a given priority band exists on the STREAM head read queue. This returns 1 if a message of the given priority exists, 0 if no message exists, or -1 on error. arg should be of type int.

ioctl() with the I_CKBAND command will fail if :

EINVAL Non-valid arg value.

I_GETBAND
Return the priority band of the first message on the STREAM head read queue in the integer referenced by arg.

ioctl() with the I_GETBAND command will fail if:

ENODATA No message on the STREAM head read queue.

I_CANPUT
Check if a certain band is writable. arg is set to the priority band in question. The return value is 0 if the band is flow-controlled, 1 if the band is writable, or -1 on error.

ioctl() with the I_CANPUT command will fail if:

EINVAL Non-valid arg value.

I_SETCLTIME
This request allows the process to set the time the STREAM head will delay when a STREAM is closing and there is data on the write queues. Before closing each module or driver, if there is a data on its write queue, the STREAM head will delay for the specified amount of time to allow the data to drain. If, after the delay, data is still present, it will be flushed. The arg argument is a pointer to an integer specifying the number of milliseconds to delay, rounded up to the nearest valid value. If I_SETCLTIME is not performed on a STREAM, an implementation-dependent default timeout interval is used.

ioctl() with the I_SETCLTIME command will fail if:

EINVAL Non-valid arg value.

I_GETCLTIME
This request returns the close time delay in the integer pointed to by arg
Multiplexed STREAMS configurations: The following four commands are used for connecting and disconnecting multiplexed STREAMS configurations. These commands use an implementation-dependent default timeout interval.
I_LINK
Connects two STREAMS, where fildes is the file descriptor of the STREAM connected to the multiplexing driver, and arg is the file descriptor of the STREAM connected to another driver. The STREAM designated by arg gets connected below the multiplexing driver. I_LINK requires the multiplexing driver to the send an acknowledgement message to the STREAM head regarding the connection. This call returns a multiplexer ID number (an identifier used to disconnect the multiplexer; see (I_UNLINK) on success, and -1 on failure.
ioctl() with the I_LINK command will fail if:
Error Code
Description
EAGAIN or ENOSR
Unable to allocate STREAMS storage to perform the I_LINK.
EBADF
The arg argument is not a valid, open file descriptor.
EINVAL
The fildes does not support multiplexing; or arg is not a STREAM or is already connected downstream from a multiplexer, or the specified I_LINK operation would connect the STREAM head in more than one place in the multiplexed STREAM.
ENXIO
Hang-up received on fildes.
ETIME
Time out before acknowledgement message was received at STREAM head.

An I_LINK can also fail while waiting for the multiplexing driver to acknowledge the request, if a message indicating an error or a hang-up is received at the STREAM head of fildes. In addition, an error code can be returned in the positive or negative acknowledgement message. For these cases, I_LINK fails with errno set to the value in the message.

I_UNLINK
Disconnects the two STREAMs specified by fildes and arg. fildes is the file descriptor of the STREAM connected to the multiplexing driver. The arg argument is the multiplexer ID number that was returned by the I_LINK ioctl() command when a STREAM was connected downstream from the multiplexing driver. If arg is MUXID_ALL, then all STREAMs that were connected to fildes are disconnected. As in I_LINK, this command requires acknowledgement.
ioctl() with the I_UNLINK command will fail if:
Error Code
Description
EAGAIN or ENOSR
Unable to allocate buffers for the acknowledgement message.
EINVAL
Non-valid multiplexer ID number.
ENXIO
Hang-up received on fildes.
ETIME
Time out before acknowledgement message was received at STREAM head.

An I_UNLINK can also fail while waiting for the multiplexing driver to acknowledge the request if a message indicating an error or a hang-up is received at the STREAM head of fildes In addition, an error code can be returned in the positive or negative acknowledgement message. For these cases, I_UNLINK fails with errno set to the value in the message.

I_PLINK
Creates a persistent connection between two STREAMs, where fildes is the file descriptor of the STREAM connected to another driver. This call creates a persistent connection which can exist even if the file descriptor fildes associated with the upper STREAM to the multiplexing driver is closed. The STREAM designated by arg gets connected using a persistent connection below the multiplexing driver. I_PLINK requires the multiplexing driver to send an acknowledgement message to the STREAM head. This call returns a multiplexer ID number (an identifier that may be used to disconnect the multiplexer, see I_PUNLINK) on success, and -1 on failure.
ioctl() with the I_PLINK command will fail if:
Error Code
Description
EAGAIN or ENOSR
Unable to allocate STREAMS storage to perform the I_PLINK.
EBADF
The arg argument is not valid, open file descriptor.
EINVAL
The fildes argument does not support multiplexing; or arg is not a STREAM or is already connected downstream from a multiplexer; or the specified I_PLINK operation would connect the STREAM head in more than one place in the multiplexed STREAM.
ENXIO
Hang-up received on fildes.
ETIME
Time out before acknowledgement message was received at STREAM head.

An I_PLINK can also fail while waiting for the multiplexing driver to acknowledge the request, if a message indicating an error or a hang-up is received at the STREAM head of fildes In addition, an error code can be returned in the positive or negative acknowledgement message. For these cases, I_PLINK fails with errno set to the value in the message.

I_PUNLINK
Disconnects the two STREAMs specified by fildes and arg from a persistent connection. The fildes argument is the file descriptor of the STREAM connected to the multiplexing driver. The arg argument is the multiplexer ID number that was returned by the I_PLINK ioctl() command when a STREAM was connected downstream from the multiplexing driver. If arg is MUXID_ALL then all STREAMs which are persistent connections to fildes are disconnected. As in I_PLINK, this command requires the multiplexing driver to the acknowledge the request.
ioctl() with the I_PUNLINK command will fail if:
Error Code
Description
EAGAIN or ENOSR
Unable to allocate buffers for the acknowledgement message.
EINVAL
Non-valid multiplexer ID number.
ENXIO
Hang-up received on fildes.
ETIME
Time out before acknowledgement message was received at STREAM head.

An I_PUNLINK can also fail while waiting for the multiplexing driver to acknowledge the request if a message indicating an error or a hang-up is received at the STREAM head of fildes. In addition, an error code can be returned in the positive or negative acknowledgement message. For these cases, I_PUNLINK fails with errno set to the value in the message.

STREAMS returned value

If successful, ioctl() returns a value other than -1 that depends upon the STREAMS device control function.

If unsuccessful, ioctl() returns -1 and sets errno to one of the following values.

Note: It is impossible for ioctl() to perform any STREAMS type commands successfully, since z/OS® UNIX services do not provide any STREAMS-based files. The function will always return -1 with errno set to indicate the failure. See open() — Open a file for more information.

Under the following general conditions, ioctl() will fail if:

Error Code
Description
EBADF
The fildes argument is not a valid open file descriptor.
EINTR
A signal was caught during the ioctl() operation.
EINVAL
The STREAM or multiplexer referenced by fildes is linked (directly or indirectly) downstream from a multiplexer.
If an underlying device driver detects an error, ioctl() will fail if:
Error Code
Description
EINVAL
The cmd or arg argument is not valid for this device.
EIO
Some physical I/O error has occurred.
ENODEV
The fildes argument refers to a valid STREAMS device, but the corresponding device driver does not support ioctl().
ENOTTY
The fildes argument is not associated with a STREAMS device that accepts control functions.
ENXIO
The cmd or arg argument is not valid for this device driver, but the service requested can not be performed on this particular sub-device.

If a STREAM is connected downstream from a multiplexer, any ioctl() command except I_UNLINK and I_PUNLINK will set errno to EINVAL.

ACLs

The following ioctl() commands are used with ACLs:
Command
Description
SETFACL
Set ACL. Used to set information into an Access Control List. arg specifies the user buffer containing the input ACL which is mapped by struct ACL_buf followed immediately by an array of struct ACL_entrys. arglen specifies the combined length of the struct ACL_buf and the array of struct ACL_entrys. See z/OS UNIX System Services Programming: Assembler Callable Services Reference for more information about ACL_buf and the ACL_entrys.
GETFACL
Get ACL. Used to retrieve information from an Access Control List. arg specifies the user buffer into which the requested ACL will be returned. The data is mapped by struct ACL_BUF followed immediately by an array of struct ACL_entrys. See z/OS UNIX System Services Programming: Assembler Callable Services Reference for more information about ACL_buf and the ACL_entrys. Arglen specifies the combined length of the struct ACL and the array of struct ACL_entrys in the user buffer.

ACLs returned value

If successful, ioctl() returns 0.

If unsuccessful, ioctl() returns -1 and sets errno to one of the following values:
Error Code
Description
EBADF
The fildes parameter is not a valid file descriptor.
EINVAL
The request is not valid or not supported.
EMVSPARM
Incorrect parameters were passed to the service.
ENODEV
The device is incorrect. The function is not supported by the device driver.

Example

The following is an example of the ioctl() call.
int s;
int rc;
int acllen;
ext_acl_t aclbufp;
s = open("datafile", O_RDWR);
acllen = sizeof struct ACL_buf + (1024 * sizeof ACL_entry);
aclbufp = (ext_acl_t) malloc(acllen);
rc  =  ioctl(s, GETFACL, acllen, aclbufp)

Related information