xref: /illumos-gate/usr/src/man/man4i/streamio.4i (revision ddb365bfc9e868ad24ccdcb0dc91af18b10df082)
1.\" Copyright (c) 2017, Joyent, Inc.
2.\" Copyright (c) 2009, Sun Microsystems, Inc.  All Rights Reserved.
3.\" Copyright 1989 AT&T
4.\" The contents of this file are subject to the terms of the
5.\" Common Development and Distribution License (the "License").
6.\" You may not use this file except in compliance with the License.
7.\"
8.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9.\" or http://www.opensolaris.org/os/licensing.
10.\" See the License for the specific language governing permissions
11.\" and limitations under the License.
12.\"
13.\" When distributing Covered Code, include this CDDL HEADER in each
14.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15.\" If applicable, add the following below this CDDL HEADER, with the
16.\" fields enclosed by brackets "[]" replaced with your own identifying
17.\" information: Portions Copyright [yyyy] [name of copyright owner]
18.Dd March 13, 2022
19.Dt STREAMIO 4I
20.Os
21.Sh NAME
22.Nm streamio
23.Nd STREAMS ioctl commands
24.Sh SYNOPSIS
25.In sys/types.h
26.In stropts.h
27.In sys/conf.h
28.Ft int
29.Fo ioctl
30.Fa "int fildes"
31.Fa "int command"
32.Fa "\&... /*arg*/"
33.Fc
34.Sh DESCRIPTION
35STREAMS (see
36.Xr Intro 3 )
37.Fn ioctl
38commands are a subset of the
39.Xr ioctl 2
40commands and perform a variety of control functions on streams.
41.Pp
42The
43.Fa fildes
44argument is an open file descriptor that refers to a stream.
45The
46.Fa command
47argument determines the control function to be performed as
48described below.
49The
50.Fa arg
51argument represents additional information that
52is needed by this command.
53The type of
54.Fa arg
55depends upon the command, but
56it is generally an integer or a pointer to a command-specific data structure.
57The
58.Fa command
59and
60.Fa arg
61arguments are interpreted by the STREAM head.
62Certain combinations of these arguments may be passed to a module or driver in
63the stream.
64.Pp
65Since these STREAMS commands are
66.Sy ioctls ,
67they are subject to the errors described in
68.Xr ioctl 2 .
69In addition to those errors, the call will fail
70with
71.Va errno
72set to
73.Er EINVAL ,
74without processing a control function, if the STREAM referenced by
75.Fa fildes
76is linked below a multiplexor, or if
77.Fa command
78is not a valid value for a stream.
79.Pp
80Also, as described in
81.Xr ioctl 2 ,
82STREAMS modules and drivers can detect
83errors.
84In this case, the module or driver sends an error message to the STREAM
85head containing an error value.
86This causes subsequent calls to fail with
87.Va errno
88set to this value.
89.Sh IOCTLS
90The following
91.Fn ioctl
92commands, with error values indicated, are applicable to all STREAMS files:
93.Bl -tag -width I_SETCLTIME
94.It Dv I_PUSH
95Pushes the module whose name is pointed to by
96.Va arg
97onto the top of the current stream, just below the STREAM head.
98If the STREAM is a pipe, the module
99will be inserted between the stream heads of both ends of the pipe.
100It then calls the open routine of the newly-pushed module.
101On failure,
102.Va errno
103is set to one of the following values:
104.Bl -tag -width ENOTSUP
105.It Er EINVAL
106Invalid module name.
107.It Er EFAULT
108.Va arg
109points outside the allocated address space.
110.It Er ENXIO
111Open routine of new module failed.
112.It Er ENXIO
113Hangup received on
114.Va fildes .
115.It Er ENOTSUP
116Pushing a module is not supported on this stream.
117.El
118.It Dv I_POP
119Removes the module just below the STREAM head of the STREAM pointed to by
120.Fa fildes .
121To remove a module from a pipe requires that the module was
122pushed on the side it is being removed from.
123.Fa arg
124should be
125.Sy 0
126in an
127.Dv I_POP
128request.
129On failure,
130.Va errno
131is set to one of the following values:
132.Bl -tag -width ENOTSUP
133.It Er EINVAL
134No module present in the stream.
135.It Er ENXIO
136Hangup received on
137.Fa fildes .
138.It Er EPERM
139Attempt to pop through an anchor by an unprivileged process.
140.It Er ENOTSUP
141Removal is not supported.
142.El
143.It Dv I_ANCHOR
144Positions the stream anchor to be at the stream's module directly below the
145stream head.
146Once this has been done, only a privileged process may pop modules
147below the anchor on the stream.
148.Va arg
149must be
150.Sy 0
151in an
152.Dv I_ANCHOR
153request.
154On failure,
155.Va errno
156is set to the following value:
157.Bl -tag -width EINVAL
158.It Er EINVAL
159Request to put an anchor on a pipe.
160.El
161.It Dv I_LOOK
162Retrieves the name of the module just below the stream head of the stream
163pointed to by
164.Fa fildes ,
165and places it in a null terminated character string
166pointed at by
167.Fa arg .
168The buffer pointed to by
169.Fa arg
170should be at least
171.Dv FMNAMESZ Ns +1
172bytes long.
173This requires the declaration
174.Ql "#include <sys/conf.h>" .
175On failure,
176.Dv errno
177is set to one of the following values:
178.Bl -tag -width EFAULT
179.It Er EFAULT
180.Fa arg
181points outside the allocated address space.
182.It Er EINVAL
183No module present in stream.
184.El
185.It Dv I_FLUSH
186This request flushes all input and/or output queues, depending on the value of
187.Fa arg .
188Legal
189.Fa arg
190values are:
191.Bl -tag -width FLUSHRW
192.It Dv FLUSHR
193Flush read queues.
194.It Dv FLUSHW
195Flush write queues.
196.It Dv FLUSHRW
197Flush read and write queues.
198.El
199.Pp
200If a pipe or FIFO does not have any modules pushed, the read queue of the
201stream head on either end is flushed depending on the value of
202.Fa arg .
203.Pp
204If
205.Dv FLUSHR
206is set and
207.Fa fildes
208is a pipe, the read queue for that end
209of the pipe is flushed and the write queue for the other end is flushed.
210If
211.Fa fildes
212is a FIFO, both queues are flushed.
213.Pp
214If
215.Dv FLUSHW
216is set and
217.Fa fildes
218is a pipe and the other end of the pipe
219exists, the read queue for the other end of the pipe is flushed and the write
220queue for this end is flushed.
221If
222.Fa fildes
223is a FIFO, both queues of the
224FIFO are flushed.
225.Pp
226If
227.Dv FLUSHRW
228is set, all read queues are flushed, that is, the read queue
229for the FIFO and the read queue on both ends of the pipe are flushed.
230.Pp
231Correct flush handling of a pipe or FIFO with modules pushed is achieved via
232the
233.Sy pipemod
234module.
235This module should be the first module pushed onto a
236pipe so that it is at the midpoint of the pipe itself.
237.Pp
238On failure,
239.Va errno
240is set to one of the following values:
241.Bl -tag -width EINVAL
242.It Er ENOSR
243Unable to allocate buffers for flush message due to insufficient stream memory
244resources.
245.It Er EINVAL
246Invalid
247.Va arg
248value.
249.It Er ENXIO
250Hangup received on
251.Fa fildes .
252.El
253.It Dv I_FLUSHBAND
254Flushes a particular band of messages.
255.Fa arg
256points to a
257.Vt bandinfo
258structure that has the following members:
259.Bd -literal -offset 2n
260unsigned char bi_pri;
261int bi_flag;
262.Ed
263.Pp
264The
265.Fa bi_flag
266field may be one of
267.Dv FLUSHR ,
268.Dv FLUSHW ,
269or
270.Dv FLUSHRW
271as described earlier.
272.It Dv I_SETSIG
273Informs the stream head that the user wishes the kernel to issue the
274.Dv SIGPOLL
275signal (see
276.Xr signal 3C )
277when a particular event has occurred on the stream associated with
278.Fa fildes .
279.Dv I_SETSIG
280supports an asynchronous processing capability in streams.
281The value of
282.Fa arg
283is a bitmask that specifies the events for which the user should be signaled.
284It is the bitwise OR of any combination of the following constants:
285.Bl -tag -width S_BANDURG
286.It Dv S_INPUT
287Any message other than an
288.Dv M_PCPROTO
289has arrived on a stream head read queue.
290This event is maintained for compatibility with previous releases.
291This event is triggered even if the message is of zero length.
292.It Dv S_RDNORM
293An ordinary (non-priority) message has arrived on a stream head read queue.
294This event is triggered even if the message is of zero length.
295.It Dv S_RDBAND
296A priority band message (band > 0) has arrived on a stream head read queue.
297This event is triggered even if the message is of zero length.
298.It Dv S_HIPRI
299A high priority message is present on the stream head read queue.
300This event is triggered even if the message is of zero length.
301.It Dv S_OUTPUT
302The write queue just below the stream head is no longer full.
303This notifies the
304user that there is room on the queue for sending (or writing) data downstream.
305.It Dv S_WRNORM
306This event is the same as
307.Dv S_OUTPUT .
308.It Dv S_WRBAND
309A priority band greater than 0 of a queue downstream exists and is writable.
310This notifies the user that there is room on the queue for sending (or writing)
311priority data downstream.
312.It Dv S_MSG
313A STREAMS signal message that contains the
314.Dv SIGPOLL
315signal has reached the
316front of the stream head read queue.
317.It Dv S_ERROR
318An
319.Dv M_ERROR
320message has reached the stream head.
321.It Dv S_HANGUP
322An
323.Dv M_HANGUP
324message has reached the stream head.
325.It Dv S_BANDURG
326When used in conjunction with
327.Dv S_RDBAND ,
328.Dv SIGURG
329is generated instead of
330.Dv SIGPOLL
331when a priority message reaches the front of the stream head
332read queue.
333.El
334.Pp
335A user process may choose to be signaled only of high priority messages by
336setting the
337.Fa arg
338bitmask to the value
339.Dv S_HIPRI .
340.Pp
341Processes that wish to receive
342.Dv SIGPOLL
343signals must explicitly register
344to receive them using
345.Dv I_SETSIG .
346If several processes register to receive
347this signal for the same event on the same stream, each process will be
348signaled when the event occurs.
349.Pp
350If the value of
351.Fa arg
352is zero, the calling process will be unregistered and
353will not receive further
354.Dv SIGPOLL
355signals.
356On failure,
357.Va errno
358is set to one of the following values:
359.Bl -tag -width EINVAL
360.It Er EINVAL
361.Fa arg
362value is invalid or
363.Fa arg
364is zero and process is not registered to receive the
365.Dv SIGPOLL
366signal.
367.It Er EAGAIN
368Allocation of a data structure to store the signal request failed.
369.El
370.It Dv I_GETSIG
371Returns the events for which the calling process is currently registered to be
372sent a
373.Dv SIGPOLL
374signal.
375The events are returned as a bitmask pointed to by
376.Va arg ,
377where the events are those specified in the description of
378.Dv I_SETSIG
379above.
380On failure,
381.Va errno
382is set to one of the following values:
383.Bl -tag -width EINVAL
384.It Er EINVAL
385Process not registered to receive the
386.Dv SIGPOLL
387signal.
388.It Er EFAULT
389.Fa arg
390points outside the allocated address space.
391.El
392.It Dv I_FIND
393Compares the names of all modules currently present in the stream to the name
394pointed to by
395.Fa arg ,
396and returns 1 if the named module is present in the stream.
397It returns 0 if the named module is not present.
398On failure,
399.Va errno
400is set to one of the following values:
401.Bl -tag -width EINVAL
402.It Er EFAULT
403.Fa arg
404points outside the allocated address space.
405.It Er EINVAL
406.Fa arg
407does not contain a valid module name.
408.El
409.It Dv I_PEEK
410Allows a user to retrieve the information in the first message on the stream
411head read queue without taking the message off the queue.
412.Dv I_PEEK
413is analogous to
414.Xr getmsg 2
415except that it does not remove the message from the queue.
416.Fa arg
417points to a
418.Vt strpeek
419structure, which contains the following members:
420.Bd -literal -offset 2n
421struct strbuf ctlbuf;
422struct strbuf databuf;
423long flags;
424.Ed
425.Pp
426The
427.Ft maxlen
428field in the
429.Vt ctlbuf
430and
431.Vt databuf
432.Vt strbuf
433structures (see
434.Xr getmsg 2 )
435must be set to the number of bytes of control
436information and/or data information, respectively, to retrieve.
437.Fa flags
438may be set to
439.Dv RS_HIPRI
440or
441.Sy 0 .
442If
443.Dv RS_HIPRI
444is set,
445.Dv I_PEEK
446will look for a high priority message on the stream head read queue.
447Otherwise,
448.Dv I_PEEK
449will look for the first message on the stream head read queue.
450.Pp
451.Dv I_PEEK
452returns
453.Sy 1
454if a message was retrieved, and returns
455.Sy 0
456if no message was found on the stream head read queue.
457It does not wait for a message to arrive.
458On return,
459.Vt ctlbuf
460specifies information in the control buffer,
461.Vt databuf
462specifies information in the data buffer, and
463.Fa flags
464contains the value
465.Dv RS_HIPRI
466or
467.Sy 0 .
468On failure,
469.Va errno
470is set to the following value:
471.Bl -tag -width EBADMSG
472.It Er EFAULT
473.Fa arg
474points, or the buffer area specified in
475.Vt ctlbuf
476or
477.Vt databuf
478is, outside the allocated address space.
479.It Er EBADMSG
480Queued message to be read is not valid for
481.Dv I_PEEK .
482.It Er EINVAL
483Illegal value for
484.Vt flags .
485.It Er ENOSR
486Unable to allocate buffers to perform the
487.Dv I_PEEK
488due to insufficient STREAMS memory resources.
489.El
490.It Dv I_SRDOPT
491Sets the read mode (see
492.Xr read 2 )
493using the value of the argument
494.Va arg .
495Legal
496.Va arg
497values are:
498.Bl -tag -width RNORM
499.It Dv RNORM
500Byte-stream mode, the default.
501.It Dv RMSGD
502Message-discard mode.
503.It Dv RMSGN
504Message-nondiscard mode.
505.El
506.Pp
507In addition, the stream head's treatment of control messages may be changed by
508setting the following flags in
509.Va arg :
510.Bl -tag -width RPROTNORM
511.It Dv RPROTNORM
512Reject
513.Xr read 2
514with
515.Er EBADMSG
516if a control message is at the front of the stream head read queue.
517.It Dv RPROTDAT
518Deliver the control portion of a message as data when a user issues
519.Xr read 2 .
520This is the default behavior.
521.It Dv RPROTDIS
522Discard the control portion of a message, delivering any data portion, when a
523user issues a
524.Xr read 2 .
525.El
526.Pp
527On failure,
528.Va errno
529is set to the following value:
530.Bl -tag -width EINVAL
531.It Er EINVAL
532.Va arg
533is not one of the above legal values, or
534.Va arg
535is the bitwise
536inclusive
537.Sy OR
538of
539.Dv RMSGD
540and
541.Dv RMSGN .
542.El
543.It Dv I_GRDOPT
544Returns the current read mode setting in an
545.Vt int
546pointed to by the argument
547.Fa arg .
548Read modes are described in
549.Xr read 2 .
550On failure,
551.Va errno
552is set to the following value:
553.Bl -tag -width EFAULT
554.It Er EFAULT
555.Fa arg
556points outside the allocated address space.
557.El
558.It Dv I_NREAD
559Counts the number of data bytes in data blocks in the first message on the
560stream head read queue, and places this value in the location pointed to by
561.Fa arg .
562The return value for the command is the number of messages on the
563stream head read queue.
564For example, if zero is returned in
565.Fa arg ,
566but the
567.Fn ioctl
568return value is greater than zero, this indicates that a
569zero-length message is next on the queue.
570On failure,
571.Va errno
572is set to the following value:
573.Bl -tag -width EFAULT
574.It Er EFAULT
575.Fa arg
576points outside the allocated address space.
577.El
578.It Dv I_FDINSERT
579Creates a message from specified buffer(s), adds information about another
580stream and sends the message downstream.
581The message contains a control part and an optional data part.
582The data and control parts to be sent are
583distinguished by placement in separate buffers, as described below.
584.Pp
585The
586.Fa arg
587argument points to a
588.Vt strfdinsert
589structure, which contains
590the following members:
591.Bd -literal -offset 2n
592struct  strbuf  ctlbuf;
593struct  strbuf	databuf;
594t_uscalar_t	flags;
595int		fildes;
596int		offset;
597.Ed
598.Pp
599The
600.Fa len
601member in the
602.Vt ctlbuf
603.Vt strbuf
604structure (see
605.Xr putmsg 2 )
606must be set to the size of a
607.Vt t_uscalar_t
608plus the number of bytes of
609control information to be sent with the message.
610The
611.Fa fildes
612member specifies the file descriptor of the other stream, and the
613.Fa offset
614member, which must be suitably aligned for use as a
615.Vt t_uscalar_t ,
616specifies the offset from the start of the control buffer where
617.Dv I_FDINSERT
618will store a
619.Vt t_uscalar_t
620whose interpretation is specific to the stream end.
621The
622.Fa len
623member in the
624.Vt databuf
625.Vt strbuf
626structure must be set to the number of bytes of data information to be sent with
627the message, or to 0 if no data part is to be sent.
628.Pp
629The
630.Fa flags
631member specifies the type of message to be created.
632A normal message is created if
633.Fa flags
634is set to 0, and a high-priority message is created if
635.Fa flags
636is set to
637.Dv RS_HIPRI .
638For non-priority messages,
639.Dv I_FDINSERT
640will block if the stream write queue is full due to internal
641flow control conditions.
642For priority messages,
643.Dv I_FDINSERT
644does not block on this condition.
645or non-priority messages,
646.Dv I_FDINSERT
647does not
648block when the write queue is full and
649.Dv O_NDELAY
650or
651.Dv O_NONBLOCK
652is set.
653Instead, it fails and sets
654.Va errno
655to
656.Er EAGAIN .
657.Pp
658.Dv I_FDINSERT
659also blocks, unless prevented by lack of internal resources, waiting for the
660availability of message blocks in the stream, regardless of priority or whether
661.Dv O_NDELAY
662or
663.Dv O_NONBLOCK
664has been specified.
665No partial message is sent.
666.Pp
667The
668.Fn ioctl
669function with the
670.Dv I_FDINSERT
671command will fail if:
672.Bl -tag -width EAGAIN
673.It Er EAGAIN
674A non-priority message is specified, the
675.Dv O_NDELAY
676or
677.Dv O_NONBLOCK
678flag is set, and the stream write queue is full due to internal flow control
679conditions.
680.It Er ENOSR
681Buffers can not be allocated for the message that is to be created.
682.It Er EFAULT
683The
684.Fa arg
685argument points, or the buffer area specified in
686.Vt ctlbuf
687or
688.Vt databuf
689is, outside the allocated address space.
690.It Er EINVAL
691One of the following: The
692.Fa fildes
693member of the
694.Vt strfdinsert
695structure is not a valid, open stream file descriptor; the size of a
696.Vt t_uscalar_t
697plus
698.Fa offset
699is greater than the
700.Fa len
701member for the buffer specified through
702.Fa ctlptr ;
703the
704.Fa offset
705member does not specify a properly-aligned location in the data buffer; or an
706undefined value is stored in
707.Fa flags .
708.It Er ENXIO
709Hangup received on the
710.Fa fildes
711argument of the
712.Fn ioctl
713call or the
714.Fa fildes
715member of the
716.Vt strfdinsert
717structure.
718.It Er ERANGE
719The
720.Fa len
721field for the buffer specified through
722.Vt databuf
723does not fall within the range specified by the maximum and minimum packet
724sizes of the topmost stream module; or the
725.Fa len
726member for the buffer specified through
727.Vt databuf
728is larger than the maximum configured size of the data part of a message; or the
729.Fa len
730member for the buffer specified through
731.Vt ctlbuf
732is larger than the maximum configured size of the control part of a message.
733.El
734.Pp
735.Dv I_FDINSERT
736can also fail if an error message was received by the stream
737head of the stream corresponding to the
738.Fa fildes
739member of the
740.Vt strfdinsert
741structure.
742In this case,
743.Va errno
744will be set to the value in the message.
745.It Dv I_STR
746Constructs an internal
747.Sy STREAMS
748ioctl message from the data pointed to by
749.Fa arg ,
750and sends that message downstream.
751.Pp
752This mechanism is provided to send user
753.Fn ioctl
754requests to downstream modules and drivers.
755It allows information to be sent with the
756.Fn ioctl ,
757and will return to the user any information sent upstream by the downstream
758recipient.
759.Dv I_STR
760blocks until the system responds with either a positive or negative
761acknowledgement message, or until the request times out after some period of
762time.
763If the request times out, it fails with
764.Va errno
765set to
766.Er ETIME .
767.Pp
768To send requests downstream,
769.Fa arg
770must point to a
771.Vt strioctl
772structure which contains the following members:
773.Bd -literal -offset 2n
774int  ic_cmd;
775int  ic_timout;
776int  ic_len;
777char  *ic_dp;
778.Ed
779.Pp
780.Fa ic_cmd
781is the internal
782.Fn ioctl
783command intended for a downstream module or driver and
784.Fa ic_timout
785is the number of seconds (-1 = infinite, 0 = use default, >0 = as specified) an
786.Dv I_STR
787request will wait for acknowledgement before timing out.
788.Fa ic_len
789is the number of bytes in the data argument and
790.Fa ic_dp
791is a pointer to the data argument.
792The
793.Fa ic_len
794field has two uses: on input, it contains the length of the data
795argument passed in, and on return from the command, it contains the number of
796bytes being returned to the user (the buffer pointed to by
797.Fa ic_dp
798should be large enough to contain the maximum amount of data that any module or
799the driver in the stream can return).
800.Pp
801At most one
802.Dv I_STR
803can be active on a stream.
804Further
805.Dv I_STR
806calls
807will block until the active
808.Dv I_STR
809completes via a positive or negative
810acknowledgement, a timeout, or an error condition at the stream head.
811By setting the
812.Fa ic_timout
813field to 0, the user is requesting STREAMS to provide
814the
815.Sy DEFAULT
816timeout.
817The default timeout is specific to the STREAMS
818implementation and may vary depending on which release of Solaris you are
819using.
820For Solaris 8 (and earlier versions), the default timeout is fifteen
821seconds.
822The
823.Dv O_NDELAY
824and
825.Dv O_NONBLOCK
826(see
827.Xr open 2 )
828flags have no effect on this call.
829.Pp
830The stream head will convert the information pointed to by the
831.Vt strioctl
832structure to an internal
833.Fn ioctl
834command message and send it downstream.
835On failure,
836.Va errno
837is set to one of the following values:
838.Bl -tag -width EFAULT
839.It Er ENOSR
840Unable to allocate buffers for the
841.Fn ioctl
842message due to insufficient STREAMS memory resources.
843.It Er EFAULT
844Either
845.Fa arg
846points outside the allocated address space, or the buffer area
847specified by
848.Fa ic_dp
849and
850.Fa ic_len
851(separately for data sent and data returned) is outside the allocated address
852space.
853.It Er EINVAL
854.Fa ic_len
855is less than 0 or
856.Fa ic_len
857is larger than the maximum configured size of the data part of a message or
858.Fa ic_timout
859is less than \(mi1.
860.It Er ENXIO
861Hangup received on
862.Fa fildes .
863.It Er ETIME
864A downstream
865.Fn ioctl
866timed out before acknowledgement was received.
867.El
868.Pp
869An
870.Dv I_STR
871can also fail while waiting for an acknowledgement if a message
872indicating an error or a hangup is received at the stream head.
873In addition, an
874error code can be returned in the positive or negative acknowledgement message,
875in the event the ioctl command sent downstream fails.
876For these cases,
877.Dv I_STR
878will fail with
879.Va errno
880set to the value in the message.
881.It Dv I_SWROPT
882Sets the write mode using the value of the argument
883.Fa arg .
884Legal bit settings for
885.Fa arg
886are:
887.Bl -tag -width SNDZERO
888.It Dv SNDZERO
889Send a zero-length message downstream when a write of 0 bytes occurs.
890.El
891.Pp
892To not send a zero-length message when a write of 0 bytes occurs, this bit must
893not be set in
894.Fa arg .
895.Pp
896On failure,
897.Va errno
898may be set to the following value:
899.Bl -tag -width EINVAL
900.It Er EINVAL
901.Fa arg
902is not the above legal value.
903.El
904.It Dv I_GWROPT
905Returns the current write mode setting, as described above, in the
906.Vt int
907that is pointed to by the argument
908.Fa arg .
909.It Dv I_SENDFD
910Requests the stream associated with
911.Fa fildes
912to send a message, containing
913a file pointer, to the stream head at the other end of a stream pipe.
914The file
915pointer corresponds to
916.Fa arg ,
917which must be an open file descriptor.
918.Pp
919.Dv I_SENDFD
920converts
921.Fa arg
922into the corresponding system file pointer.
923It allocates a message block and inserts the file pointer in the block.
924The user id and group id associated with the sending process are also inserted.
925This message is placed directly on the read queue (see
926.Xr Intro 3 )
927of the stream head at the other end of the stream pipe to which it is connected.
928On failure,
929.Va errno
930is set to one of the following values:
931.Bl -tag -width EAGAIN
932.It Er EAGAIN
933The sending stream is unable to allocate a message block to contain the file
934pointer.
935.It Er EAGAIN
936The read queue of the receiving stream head is full and cannot accept the
937message sent by
938.Dv I_SENDFD .
939.It Er EBADF
940.Fa arg
941is not a valid, open file descriptor.
942.It Er EINVAL
943.Va fildes
944is not connected to a stream pipe.
945.It Er ENXIO
946Hangup received on
947.Fa fildes .
948.El
949.It Dv I_RECVFD
950Retrieves the file descriptor associated with the message sent by an
951.Dv I_SENDFD
952.Fn ioctl
953over a stream pipe.
954.Fa arg
955is a pointer to a data buffer large enough to hold an
956.Vt strrecvfd
957data structure containing the following members:
958.Bd -literal -offset 2n
959int	fd;
960uid_t	uid;
961gid_t	gid;
962.Ed
963.Pp
964.Fa fd
965is an integer file descriptor.
966.Fa uid
967and
968.Fa gid
969are the user id and group id, respectively, of the sending stream.
970.Pp
971If
972.Dv O_NDELAY
973and
974.Dv O_NONBLOCK
975are clear (see
976.Xr open 2 ) ,
977.Dv I_RECVFD
978will block until a message is present at the stream head.
979If
980.Dv O_NDELAY
981or
982.Dv O_NONBLOCK
983is set,
984.Dv I_RECVFD
985will fail with
986.Va errno
987set to
988.Er EAGAIN
989if no message is present at the stream head.
990.Pp
991If the message at the stream head is a message sent by an
992.Dv I_SENDFD ,
993a new
994user file descriptor is allocated for the file pointer contained in the
995message.
996The new file descriptor is placed in the
997.Fa fd
998field of the
999.Vt strrecvfd
1000structure.
1001The structure is copied into the user data buffer pointed to by
1002.Fa arg .
1003On failure,
1004.Va errno
1005is set to one of the following values:
1006.Bl -tag -width EOVERFLOW
1007.It Er EAGAIN
1008A message is not present at the stream head read queue, and the
1009.Dv O_NDELAY
1010or
1011.Dv O_NONBLOCK
1012flag is set.
1013.It Er EBADMSG
1014The message at the stream head read queue is not a message containing a passed
1015file descriptor.
1016.It Er EFAULT
1017.Fa arg
1018points outside the allocated address space.
1019.It Er EMFILE
1020.Dv NOFILES
1021file descriptors are currently open.
1022.It Er ENXIO
1023Hangup received on
1024.Fa fildes .
1025.It Er EOVERFLOW
1026.Fa uid
1027or
1028.Fa gid
1029is too large to be stored in the structure pointed to by
1030.Fa arg .
1031.El
1032.It Dv I_LIST
1033Allows the user to list all the module names on the stream, up to and including
1034the topmost driver name.
1035If
1036.Fa arg
1037is
1038.Dv NULL ,
1039the return value is the number of modules, including the driver, that are on
1040the stream pointed to by
1041.Fa fildes .
1042This allows the user to allocate enough space for the module
1043names.
1044If
1045.Fa arg
1046is non-null, it should point to an
1047.Vt str_list
1048structure that has the following members:
1049.Bd -literal -offset 2n
1050int sl_nmods;
1051struct  str_mlist  *sl_modlist;
1052.Ed
1053.Pp
1054The
1055.Vt str_mlist
1056structure has the following member:
1057.Bd -literal -offset 2n
1058char l_name[FMNAMESZ+1];
1059.Ed
1060.Pp
1061The
1062.Fa sl_nmods
1063member indicates the number of entries the process has allocated in the array.
1064Upon return, the
1065.Fa sl_modlist
1066member of the
1067.Vt str_list
1068structure contains the list of module names, and the number of
1069entries that have been filled into the
1070.Fa sl_modlist
1071array is found in the
1072.Fa sl_nmods
1073member (the number includes the number of modules including the driver).
1074The return value from
1075.Fn ioctl
1076is 0.
1077The entries are filled in
1078starting at the top of the stream and continuing downstream until either the
1079end of the stream is reached, or the number of requested modules
1080.Pq Fa sl_nmods
1081is satisfied.
1082On failure,
1083.Va errno
1084may be set to one of the following values:
1085.Bl -tag -width EINVAL
1086.It Er EINVAL
1087The
1088.Fa sl_nmods
1089member is less than 1.
1090.It Er EAGAIN
1091Unable to allocate buffers
1092.El
1093.It Dv I_ATMARK
1094Allows the user to see if the current message on the stream head read queue is
1095.Dq marked
1096by some module downstream.
1097.Fa arg
1098determines how the checking is
1099done when there may be multiple marked messages on the stream head read queue.
1100It may take the following values:
1101.Bl -tag -width LASTMARK
1102.It Dv ANYMARK
1103Check if the message is marked.
1104.It Dv LASTMARK
1105Check if the message is the last one marked on the queue.
1106.El
1107.Pp
1108The return value is
1109.Sy 1
1110if the mark condition is satisfied and
1111.Sy 0
1112otherwise.
1113On failure,
1114.Va errno
1115is set to the following value:
1116.Bl -tag -width EINVAL
1117.It Er EINVAL
1118Invalid
1119.Fa arg
1120value.
1121.El
1122.It Dv I_CKBAND
1123Check if the message of a given priority band exists on the stream head read
1124queue.
1125This returns
1126.Sy 1
1127if a message of a given priority exists,
1128.Sy 0
1129if not, or
1130.Sy \(mi1
1131on error.
1132.Fa arg
1133should be an integer containing the value of the priority band in question.
1134On failure,
1135.Va errno
1136is set to the following value:
1137.Bl -tag -width EINVAL
1138.It Er EINVAL
1139Invalid
1140.Fa arg
1141value.
1142.El
1143.It Dv I_GETBAND
1144Returns the priority band of the first message on the stream head read queue in
1145the integer referenced by
1146.Fa arg .
1147On failure,
1148.Va errno
1149is set to the following value:
1150.Bl -tag -width ENODATA
1151.It Er ENODATA
1152No message on the stream head read queue.
1153.El
1154.It Dv I_CANPUT
1155Check if a certain band is writable.
1156.Fa arg
1157is set to the priority band in question.
1158The return value is
1159.Sy 0
1160if the priority band
1161.Fa arg
1162is flow controlled,
1163.Sy 1
1164if the band is writable, or
1165.Sy \(mi1
1166on error.
1167On failure,
1168.Va errno
1169is set to the following value:
1170.Bl -tag -width EINVAL
1171.It Er EINVAL
1172Invalid
1173.Va arg
1174value.
1175.El
1176.It Dv I_SETCLTIME
1177Allows the user to set the time the stream head will delay when a stream is
1178closing and there are data on the write queues.
1179Before closing each module and driver, the stream head will delay for the
1180specified amount of time to allow the data to drain.
1181Note, however, that the module or driver may itself delay in its close routine;
1182this delay is independent of the stream head's delay and is not settable.
1183If, after the delay, data are still present, data will be flushed.
1184.Fa arg
1185is a pointer to an integer containing the number of
1186milliseconds to delay, rounded up to the nearest legal value on the system.
1187The default is fifteen seconds.
1188On failure,
1189.Va errno
1190is set to the following value:
1191.Bl -tag -width EINVAL
1192.It Er EINVAL
1193Invalid
1194.Fa arg
1195value.
1196.El
1197.It Dv I_GETCLTIME
1198Returns the close time delay in the integer pointed by
1199.Va arg .
1200.It Dv I_SERROPT
1201Sets the error mode using the value of the argument
1202.Fa arg .
1203.Pp
1204Normally stream head errors are persistent; once they are set due to an
1205.Dv M_ERROR
1206or
1207.Dv M_HANGUP ,
1208the error condition will remain until the stream is closed.
1209This option can be used to set the stream head into
1210non-persistent error mode i\.e\. once the error has been returned in response
1211to a
1212.Xr read 2 ,
1213.Xr getmsg 2 ,
1214.Xr ioctl 2 ,
1215.Xr write 2 ,
1216or
1217.Xr putmsg 2
1218call the error condition will be cleared.
1219The error mode can be controlled independently for read and write side errors.
1220Legal
1221.Fa arg
1222values
1223are either none or one of:
1224.Bl -tag -width RERRNONPERSIST
1225.It Dv RERRNORM
1226Persistent read errors, the default.
1227.It Dv RERRNONPERSIST
1228Non-persistent read errors.
1229.El
1230.Pp
1231.Sy OR Ns 'ed
1232with either none or one of:
1233.Bl -tag -width WERRNONPERSIST
1234.It Dv WERRNORM
1235Persistent write errors, the default.
1236.It Dv WERRNONPERSIST
1237Non-persistent write errors.
1238.El
1239.Pp
1240When no value is specified e\.g\.  for the read side error behavior then the
1241behavior for that side will be left unchanged.
1242.Pp
1243On failure,
1244.Va errno
1245is set to the following value:
1246.Bl -tag -width EINVAL
1247.It Er EINVAL
1248.Va arg
1249is not one of the above legal values.
1250.El
1251.It Dv I_GERROPT
1252Returns the current error mode setting in an
1253.Vt int
1254pointed to by the argument
1255.Fa arg .
1256Error modes are described above for
1257.Dv I_SERROPT .
1258On failure,
1259.Va errno
1260is set to the following value:
1261.Bl -tag -width EFAULT
1262.It Er EFAULT
1263.Fa arg
1264points outside the allocated address space.
1265.El
1266.El
1267.Pp
1268The following four commands are used for connecting and disconnecting
1269multiplexed STREAMS configurations.
1270.Bl -tag -width I_PUNLINK
1271.It Dv I_LINK
1272Connects two streams, where
1273.Fa fildes
1274is the file descriptor of the stream
1275connected to the multiplexing driver, and
1276.Fa arg
1277is the file descriptor of the stream connected to another driver.
1278The stream designated by
1279.Va arg
1280gets
1281connected below the multiplexing driver.
1282.Dv I_LINK
1283requires the multiplexing
1284driver to send an acknowledgement message to the stream head regarding the
1285linking operation.
1286This call returns a multiplexor ID number (an identifier
1287used to disconnect the multiplexor, see
1288.Dv I_UNLINK )
1289on success, and \(mi1 on failure.
1290On failure,
1291.Va errno
1292is set to one of the following values:
1293.Bl -tag -width EAGAIN
1294.It Er ENXIO
1295Hangup received on
1296.Va fildes .
1297.It Er ETIME
1298Time out before acknowledgement message was received at stream head.
1299.It Er EAGAIN
1300Temporarily unable to allocate storage to perform the
1301.Dv I_LINK .
1302.It Er ENOSR
1303Unable to allocate storage to perform the
1304.Dv I_LINK
1305due to insufficient
1306.Sy STREAMS
1307memory resources.
1308.It Er EBADF
1309.Va arg
1310is not a valid, open file descriptor.
1311.It Er EINVAL
1312.Va fildes
1313stream does not support multiplexing.
1314.It Er EINVAL
1315is not a stream, or is already linked under a multiplexor.
1316.It Er EINVAL
1317The specified link operation would cause a
1318.Dq cycle
1319in the resulting configuration; that is, a driver would be linked into the
1320multiplexing configuration in more than one place.
1321.It Er EINVAL
1322.Va fildes
1323is the file descriptor of a pipe or FIFO.
1324.It Er EINVAL
1325Either the upper or lower stream has a major number \(>= the maximum major
1326number on the system.
1327.El
1328.Pp
1329An
1330.Dv I_LINK
1331can also fail while waiting for the multiplexing driver to
1332acknowledge the link request, if a message indicating an error or a hangup is
1333received at the stream head of
1334.Fa fildes .
1335In addition, an error code can be
1336returned in the positive or negative acknowledgement message.
1337For these cases,
1338.Dv I_LINK
1339will fail with
1340.Va errno
1341set to the value in the message.
1342.It Dv I_UNLINK
1343Disconnects the two streams specified by
1344.Fa fildes
1345and
1346.Fa arg .
1347.Fa fildes
1348is the file descriptor of the stream connected to the multiplexing
1349driver.
1350.Fa arg
1351is the multiplexor ID number that was returned by the
1352.Dv I_LINK .
1353If
1354.Fa arg
1355is \(mi1, then all streams that were linked to
1356.Fa fildes
1357are disconnected.
1358As in
1359.Dv I_LINK ,
1360this command requires the multiplexing driver to acknowledge the unlink.
1361On failure,
1362.Va errno
1363is set to one of the following values:
1364.Bl -tag -width EINVAL
1365.It Er ENXIO
1366Hangup received on
1367.Va fildes .
1368.It Er ETIME
1369Time out before acknowledgement message was received at stream head.
1370.It Er ENOSR
1371Unable to allocate storage to perform the
1372.Dv I_UNLINK
1373due to insufficient
1374STREAMS memory resources.
1375.It Er EINVAL
1376.Fa arg
1377is an invalid multiplexor ID number or
1378.Fa fildes
1379is not the stream on which the
1380.Dv I_LINK
1381that returned
1382.Fa arg
1383was performed.
1384.It Er EINVAL
1385.Fa fildes
1386is the file descriptor of a pipe or FIFO.
1387.El
1388.Pp
1389An
1390.Dv I_UNLINK
1391can also fail while waiting for the multiplexing driver to
1392acknowledge the link request, if a message indicating an error or a hangup is
1393received at the stream head of
1394.Fa fildes .
1395In addition, an error code can be
1396returned in the positive or negative acknowledgement message.
1397For these cases,
1398.Dv I_UNLINK
1399will fail with
1400.Va errno
1401set to the value in the message.
1402.It Dv I_PLINK
1403Connects two streams, where
1404.Fa fildes
1405is the file descriptor of the stream
1406connected to the multiplexing driver, and
1407.Fa arg
1408is the file descriptor of
1409the stream connected to another driver.
1410The stream designated by
1411.Fa arg
1412gets
1413connected via a persistent link below the multiplexing driver.
1414.Dv I_PLINK
1415requires the multiplexing driver to send an acknowledgement message to the
1416stream head regarding the linking operation.
1417This call creates a persistent
1418link that continues to exist even if the file descriptor
1419.Fa fildes
1420associated with the upper stream to the multiplexing driver is closed.
1421This
1422call returns a multiplexor ID number (an identifier that may be used to
1423disconnect the multiplexor, see
1424.Dv I_PUNLINK )
1425on success, and \(mi1 on failure.
1426On failure,
1427.Va errno
1428is set to one of the following values:
1429.Bl -tag -width EAGAIN
1430.It Er ENXIO
1431Hangup received on
1432.Fa fildes .
1433.It Er ETIME
1434Time out before acknowledgement message was received at the stream head.
1435.It Er EAGAIN
1436Unable to allocate STREAMS storage to perform the
1437.Dv I_PLINK .
1438.It Er EBADF
1439.Va arg
1440is not a valid, open file descriptor.
1441.It Er EINVAL
1442.Va fildes
1443does not support multiplexing.
1444.It Er EINVAL
1445.Va arg
1446is not a stream or is already linked under a multiplexor.
1447.It Er EINVAL
1448The specified link operation would cause a
1449.Dq cycle
1450in the resulting configuration; that is, if a driver would be linked into the
1451multiplexing configuration in more than one place.
1452.It Er EINVAL
1453.Fa fildes
1454is the file descriptor of a pipe or FIFO.
1455.El
1456.Pp
1457An
1458.Dv I_PLINK
1459can also fail while waiting for the multiplexing driver to
1460acknowledge the link request, if a message indicating an error on a hangup is
1461received at the stream head of
1462.Fa fildes .
1463In addition, an error code can be
1464returned in the positive or negative acknowledgement message.
1465For these cases,
1466.Dv I_PLINK
1467will fail with
1468.Va errno
1469set to the value in the message.
1470.It Dv I_PUNLINK
1471Disconnects the two streams specified by
1472.Fa fildes
1473and
1474.Fa arg
1475that are
1476connected with a persistent link.
1477.Fa fildes
1478is the file descriptor of the
1479stream connected to the multiplexing driver.
1480.Fa arg
1481is the multiplexor ID number that was returned by
1482.Dv I_PLINK
1483when a stream was linked below the multiplexing driver.
1484If
1485.Fa arg
1486is
1487.Dv MUXID_ALL
1488then all streams that are persistent links to
1489.Fa fildes
1490are disconnected.
1491As in
1492.Dv I_PLINK ,
1493this command requires the multiplexing driver to acknowledge the unlink.
1494On failure,
1495.Va errno
1496is set to one of the following values:
1497.Bl -tag -width EAGAIN
1498.It Er ENXIO
1499Hangup received on
1500.Fa fildes .
1501.It Er ETIME
1502Time out before acknowledgement message was received at the stream head.
1503.It Er EAGAIN
1504Unable to allocate buffers for the acknowledgement message.
1505.It Er EINVAL
1506Invalid multiplexor ID number.
1507.It Er EINVAL
1508.Fa fildes
1509is the file descriptor of a pipe or FIFO.
1510.El
1511.Pp
1512An
1513.Dv I_PUNLINK
1514can also fail while waiting for the multiplexing driver to
1515acknowledge the link request if a message indicating an error or a hangup is
1516received at the stream head of
1517.Fa fildes .
1518In addition, an error code can be
1519returned in the positive or negative acknowledgement message.
1520For these cases,
1521.Dv I_PUNLINK
1522will fail with
1523.Va errno
1524set to the value in the message.
1525.El
1526.Sh RETURN VALUES
1527Unless specified otherwise above, the return value from
1528.Xr ioctl 2
1529is
1530.Sy 0
1531upon success and
1532.Sy \(mi1
1533upon failure, with
1534.Va errno
1535set as indicated.
1536.Sh SEE ALSO
1537.Xr close 2 ,
1538.Xr fcntl 2 ,
1539.Xr getmsg 2 ,
1540.Xr ioctl 2 ,
1541.Xr open 2 ,
1542.Xr poll 2 ,
1543.Xr putmsg 2 ,
1544.Xr read 2 ,
1545.Xr write 2 ,
1546.Xr Intro 3 ,
1547.Xr signal 3C ,
1548.Xr signal.h 3HEAD
1549.Pp
1550.%B STREAMS Programming Guide
1551