4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4 1.8 */
34 * This module establishes a unique connection on
35 * a STREAMS-based pipe.
37 #include <sys/types.h>
38 #include <sys/sysmacros.h>
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/errno.h>
42 #include <sys/signal.h>
44 #include <sys/fstyp.h>
45 #include <sys/stropts.h>
46 #include <sys/stream.h>
47 #include <sys/strsubr.h>
48 #include <sys/vnode.h>
50 #include <sys/fs/fifonode.h>
51 #include <sys/debug.h>
55 * This is the loadable module wrapper.
58 #include <sys/modctl.h>
60 extern struct streamtab conninfo
;
62 static struct fmodsw fsw
= {
69 * Module linkage information for the kernel.
72 static struct modlstrmod modlstrmod
= {
73 &mod_strmodops
, "Streams-based pipes", &fsw
76 static struct modlinkage modlinkage
= {
77 MODREV_1
, (void *)&modlstrmod
, NULL
83 return (mod_install(&modlinkage
));
89 return (mod_remove(&modlinkage
));
93 _info(struct modinfo
*modinfop
)
95 return (mod_info(&modlinkage
, modinfop
));
99 * Define local and external routines.
101 int connopen(queue_t
*, dev_t
*, int, int, cred_t
*);
102 int connclose(queue_t
*, int, cred_t
*);
103 int connput(queue_t
*, mblk_t
*);
106 * Define STREAMS header information.
108 static struct module_info conn_info
= {
116 static struct qinit connrinit
= {
125 static struct qinit connwinit
= {
134 struct streamtab conninfo
= {
140 * For each invocation of connopen(), create a new pipe. One end of the pipe
141 * is sent to the process on the other end of this STREAM. The vnode for
142 * the other end is returned to the open() system call as the vnode for
145 * On the first invocation of connopen(), a flag is set and the routine
146 * returns 0, since the first open corresponds to the pushing of the module.
150 connopen(queue_t
*rqp
, dev_t
*devp
, int flag
, int sflag
, cred_t
*crp
)
154 fifonode_t
*streamfnp
;
156 if ((streamvp
= strq2vp(rqp
)) == NULL
) {
161 * CONNLD is only allowed to be pushed onto a "pipe" that has both
164 if (streamvp
->v_type
!= VFIFO
) {
169 streamfnp
= VTOF(streamvp
);
171 if (!(streamfnp
->fn_flag
& ISPIPE
) ||
172 streamfnp
->fn_dest
->fn_open
== 0) {
178 * If this is the first time CONNLD was opened while on this stream,
179 * it is being pushed. Therefore, set a flag and return 0.
181 if (rqp
->q_ptr
== 0) {
182 if (streamfnp
->fn_flag
& FIFOCONNLD
) {
186 rqp
->q_ptr
= (caddr_t
)1;
187 streamfnp
->fn_flag
|= FIFOCONNLD
;
197 connclose(queue_t
*q
, int cflag
, cred_t
*crp
)
200 fifonode_t
*streamfnp
;
203 streamvp
= strq2vp(q
);
205 ASSERT(streamvp
!= NULL
);
206 ASSERT(streamvp
->v_type
== VFIFO
);
208 streamfnp
= VTOF(streamvp
);
209 streamfnp
->fn_flag
&= ~FIFOCONNLD
;
215 * Use same put procedure for write and read queues.
218 connput(queue_t
*q
, mblk_t
*bp
)