xref: /titanic_44/usr/src/uts/common/sys/strredir.h (revision ea8dc4b6d2251b437950c0056bc626b311c73c27)
1 /*
2  * CDDL HEADER START
3  *
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
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1990-1998 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef	_SYS_STRREDIR_H
28 #define	_SYS_STRREDIR_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * strredir.h:	Declarations for the redirection driver and its matching
38  *		STREAMS module.
39  */
40 
41 /*
42  * The module's module id.
43  *
44  * XXX:	Since there's no authority responsible for administering this name
45  *	space, there's no guarantee that this value is unique.  That wouldn't
46  *	be so bad except that the DKI now suggests that ioctl cookie values
47  *	should be based on module id to make them unique...
48  */
49 #define	_STRREDIR_MODID	7326
50 
51 /*
52  * Redirection ioctls:
53  */
54 #define	SRIOCSREDIR	((_STRREDIR_MODID<<16) | 1)	/* set redir target */
55 #define	SRIOCISREDIR	((_STRREDIR_MODID<<16) | 2)	/* is redir target? */
56 
57 
58 /*
59  * Everything from here on is of interest only to the kernel.
60  */
61 #ifdef	_KERNEL
62 
63 #include <sys/types.h>
64 #include <sys/cred.h>
65 #include <sys/vnode.h>
66 
67 /*
68  * Per-open instance driver state information.
69  *
70  * The underlying device potentially can be opened through (at least) two
71  * paths:  through this driver and through the underlying device's driver.  To
72  * ensure that reference counts are meaningful and therefore that close
73  * routines are called at the right time, it's important to make sure that the
74  * snode for the underlying device instance never has a contribution of more
75  * than one through this driver, regardless of how many times this driver's
76  * been opened.  The wd_wsconsopen field keeps track of the necessary
77  * information to ensure this property.
78  *
79  * The structure also contains copies of the flag and cred values supplied
80  * when the device instance was first opened, so that it's possible to reopen
81  * the underlying device in srreset.
82  */
83 typedef struct wcd_data {
84 	struct wcd_data	*wd_next;	/* link to next open instance */
85 	minor_t		wd_unit;	/* minor device # for this instance */
86 	struct wcrlist	*wd_list;	/* the head of the redirection list */
87 	vnode_t		*wd_vp;		/* underlying device instance vnode */
88 	int		wd_wsconsopen;	/* see above */
89 	int		wd_flag;	/* see above */
90 	cred_t		*wd_cred;	/* see above */
91 } wcd_data_t;
92 
93 /*
94  * Per-open instance module state information.
95  *
96  * An invariant:  when wm_wd is non-NULL, wm_entry is also non-NULL and is on
97  * the list rooted at wm_wd->wd_list.
98  */
99 typedef struct wcm_data {
100 	struct wcd_data	*wm_wd;		/* Xref to redir driver data */
101 	struct wcrlist	*wm_entry;	/* Redir entry that refers to us */
102 } wcm_data_t;
103 
104 /*
105  * We record the list of redirections as a linked list of wcrlist
106  * structures.
107  *
108  * We need to keep track of:
109  * 1)	The target's vp, so that we can vector reads, writes, etc. off to the
110  *	current designee.
111  * 2)	The per-open instance private data structure of the redirmod module
112  *	instance we push onto the target stream, so that we can clean up there
113  *	when we go away.  (I'm not sure that this is actually necessary.)
114  */
115 typedef struct wcrlist {
116 	struct wcrlist	*wl_next;	/* next entry */
117 	vnode_t		*wl_vp;		/* target's vnode */
118 	struct wcm_data	*wl_data;	/* target's redirmod private data */
119 } wcrlist_t;
120 
121 /*
122  * A given instance of the redirection driver must be able to open the
123  * corresponding instance of the underlying device when the redirection list
124  * empties.  To do so it needs a vnode for the underlying instance.  The
125  * underlying driver is responsible for supplying routines for producing and
126  * disposing of this vnode.  The get routine must return a held vnode, so that
127  * it can't vanish while the redirecting driver is using it.
128  */
129 typedef struct srvnops {
130 	int	(*svn_get)();	/* (minor #, vpp) --> errno value */
131 	void	(*svn_rele)();	/* (minor #, vp) */
132 } srvnops_t;
133 
134 extern void srpop(wcm_data_t *, int, cred_t *);
135 
136 #endif	/* _KERNEL */
137 
138 #ifdef	__cplusplus
139 }
140 #endif
141 
142 #endif	/* _SYS_STRREDIR_H */
143