2 .\" Copyright (c) 2006, Sun Microsystems, Inc., All Rights Reserved
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH MKIOCB 9F "Jan 16, 2006"
8 mkiocb \- allocates a STREAMS ioctl block for M_IOCTL messages in the kernel.
12 #include <sys/stream.h>
16 \fBmblk_t *\fR\fBmkiocb\fR(\fBuint_t\fR \fIcommand\fR);
22 Solaris DDI specific (Solaris DDI).
30 ioctl command for the \fBioc_cmd\fR field.
36 STREAMS modules or drivers might need to issue an ioctl to a lower module or
37 driver. The \fBmkiocb()\fR function tries to allocate (using \fBallocb\fR(9F))
38 a STREAMS \fBM_IOCTL\fR message block (\fBiocblk\fR(9S)). Buffer allocation
39 fails only when the system is out of memory. If no buffer is available, the
40 \fBqbufcall\fR(9F) function can help a module recover from an allocation
44 The \fBmkiocb\fR function returns a \fBmblk_t\fR structure which is large
45 enough to hold any of the ioctl messages (\fBiocblk\fR(9S), \fBcopyreq\fR(9S)
46 or \fBcopyresp\fR(9S)), and has the following special properties:
53 Set to \fBb_rptr + sizeof(struct iocblk)\fR.
68 \fB\fBb_datap->db_type\fR\fR
76 The fields in the iocblk structure are initialized as follows:
83 Set to the command value passed in.
92 Set to a unique identifier.
101 Set to point to a credential structure encoding the maximum system privilege
102 and which does not need to be freed in any fashion.
108 \fB\fBioc_count\fR\fR
126 \fB\fBioc_error\fR\fR
135 \fB\fBioc_flags\fR\fR
138 Set to \fBIOC_NATIVE\fR to reflect that this is native to the running kernel.
144 Upon success, the \fBmkiocb()\fR function returns a pointer to the allocated
145 \fBmblk_t\fR of type \fBM_IOCTL\fR.
148 On failure, it returns a null pointer.
152 The \fBmkiocb()\fR function can be called from user, interrupt, or kernel
156 \fBExample 1 \fR\fBM_IOCTL\fR Allocation
159 The first example shows an \fBM_IOCTL\fR allocation with the ioctl command
160 \fBTEST_CMD\fR. If the \fBiocblk\fR(9S) cannot be allocated, \fINULL\fR is
161 returned, indicating an allocation failure (line 5). In line 11, the
162 \fBputnext\fR(9F) function is used to send the message downstream.
167 1 test_function(queue_t *q, test_info_t *testinfo)
171 5 if ((mp = mkiocb(TEST_CMD)) == NULL)
174 8 /* save off ioctl ID value */
175 9 testinfo->xx_iocid = ((struct iocblk *)mp->b_rptr)->ioc_id;
177 11 putnext(q, mp); /* send message downstream */
184 \fBExample 2 \fRThe ioctl \fBID \fRValue
187 During the read service routine, the ioctl \fBID \fRvalue for \fBM_IOCACK\fR or
188 \fBM_IOCNAK\fR should equal the ioctl that was previously sent by this module
195 1 test_lrsrv(queue_t *q)
199 5 switch (DB_TYPE(mp)) {
202 8 /* Does this match the ioctl that this module sent */
203 9 ioc = (struct iocblk*)mp->b_rptr;
204 10 if (ioc->ioc_id == testinfo->xx_iocid) {
205 11 /* matches, so process the message */
217 \fBExample 3 \fRAn iocblk Allocation Which Fails
220 The next example shows an iocblk allocation which fails. Since the open routine
221 is in user context, the caller may block using \fBqbufcall\fR(9F) until memory
227 1 test_open(queue_t *q, dev_t devp, int oflag, int sflag,
230 3 while ((mp = mkiocb(TEST_IOCTL)) == NULL) {
233 6 id = qbufcall(q, sizeof (union ioctypes), BPRI_HI,
234 7 dummy_callback, 0);
235 8 /* Handle interrupts */
236 9 if (!qwait_sig(q)) {
237 10 qunbufcall(q, id);
249 \fBallocb\fR(9F), \fBputnext\fR(9F), \fBqbufcall\fR(9F), \fBqwait_sig\fR(9F),
250 \fBcopyreq\fR(9S), \fBcopyresp\fR(9S), \fBiocblk\fR(9S)
253 \fIWriting Device Drivers\fR
256 \fISTREAMS Programming Guide\fR
260 It is the module's responsibility to remember the \fBID\fR value of the
261 \fBM_IOCTL\fR that was allocated. This will ensure proper cleanup and \fBID\fR
262 matching when the \fBM_IOCACK\fR or \fBM_IOCNAK\fR is received.