xref: /onnv-gate/usr/src/uts/common/sys/sad.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 1997-1999, 2002 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*0Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate #ifndef _SYS_SAD_H
32*0Sstevel@tonic-gate #define	_SYS_SAD_H
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.5 */
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate #include <sys/types.h>
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate #ifdef	__cplusplus
39*0Sstevel@tonic-gate extern "C" {
40*0Sstevel@tonic-gate #endif
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate /*
43*0Sstevel@tonic-gate  * Streams Administrative Driver
44*0Sstevel@tonic-gate  */
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate /*
47*0Sstevel@tonic-gate  * As time has passed, it has become necessary to add members to some
48*0Sstevel@tonic-gate  * of the structures passed downstream with these ioctls.  Currently,
49*0Sstevel@tonic-gate  * only the SAD_GAP/SAD_SAP ioctls are versioned, (which use the
50*0Sstevel@tonic-gate  * strapush structure), but the versioning mechanism is general enough
51*0Sstevel@tonic-gate  * to be applied to any SAD ioctls.  This is done by repartitioning
52*0Sstevel@tonic-gate  * the SAD ioctl namespace to include a version number in addition to
53*0Sstevel@tonic-gate  * the command (see below).
54*0Sstevel@tonic-gate  *
55*0Sstevel@tonic-gate  * In the case of the SAD_GAP/SAD_SAP ioctls, an application can
56*0Sstevel@tonic-gate  * choose which "version" of the ioctl to use by #defining AP_VERSION
57*0Sstevel@tonic-gate  * before including this file. Old code implicitly has AP_VERSION set
58*0Sstevel@tonic-gate  * to 0, and even newly compiled code defaults to an AP_VERSION of 0,
59*0Sstevel@tonic-gate  * since it may not be aware of the new structure members and
60*0Sstevel@tonic-gate  * therefore not know to set them to reasonable values.  In order for
61*0Sstevel@tonic-gate  * programs to make use of a newer version, they must explicitly
62*0Sstevel@tonic-gate  * #define AP_VERSION to the appropriate value. Note that the kernel
63*0Sstevel@tonic-gate  * always defaults to the latest version, since it is internally
64*0Sstevel@tonic-gate  * self-consistent.
65*0Sstevel@tonic-gate  */
66*0Sstevel@tonic-gate #ifndef	AP_VERSION
67*0Sstevel@tonic-gate #ifdef	_KERNEL
68*0Sstevel@tonic-gate #define	AP_VERSION		1		/* latest version */
69*0Sstevel@tonic-gate #else
70*0Sstevel@tonic-gate #define	AP_VERSION		0		/* SVR4 version */
71*0Sstevel@tonic-gate #endif
72*0Sstevel@tonic-gate #endif
73*0Sstevel@tonic-gate 
74*0Sstevel@tonic-gate /*
75*0Sstevel@tonic-gate  * ioctl defines
76*0Sstevel@tonic-gate  *
77*0Sstevel@tonic-gate  * The layout for the low 16 bits is 01000101VVVVCCCC, where the
78*0Sstevel@tonic-gate  * first bitpattern is `D' in binary, followed by a 4 bit version
79*0Sstevel@tonic-gate  * field (limiting the number of versions to 16), followed by a
80*0Sstevel@tonic-gate  * 4 bit command field (limiting the number of commands to 16).
81*0Sstevel@tonic-gate  */
82*0Sstevel@tonic-gate #define	SADIOC		('D' << 8)
83*0Sstevel@tonic-gate #define	SAD_SAP		(SADIOC|AP_VERSION << 4|01)
84*0Sstevel@tonic-gate #define	SAD_GAP		(SADIOC|AP_VERSION << 4|02)
85*0Sstevel@tonic-gate #define	SAD_VML		(SADIOC|03)		/* validate module list */
86*0Sstevel@tonic-gate 
87*0Sstevel@tonic-gate /*
88*0Sstevel@tonic-gate  * Device naming and numbering conventions.
89*0Sstevel@tonic-gate  */
90*0Sstevel@tonic-gate #define	USERDEV		"/dev/sad/user"
91*0Sstevel@tonic-gate #define	ADMINDEV	"/dev/sad/admin"
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate #define	USRMIN		0
94*0Sstevel@tonic-gate #define	ADMMIN		1
95*0Sstevel@tonic-gate 
96*0Sstevel@tonic-gate /*
97*0Sstevel@tonic-gate  * The maximum modules you can push on a stream using the autopush
98*0Sstevel@tonic-gate  * feature.  This should be less than NSTRPUSH.
99*0Sstevel@tonic-gate  */
100*0Sstevel@tonic-gate #define	MAXAPUSH	8
101*0Sstevel@tonic-gate 
102*0Sstevel@tonic-gate /*
103*0Sstevel@tonic-gate  * autopush info common to user and kernel
104*0Sstevel@tonic-gate  */
105*0Sstevel@tonic-gate struct apcommon {
106*0Sstevel@tonic-gate 	uint_t	apc_cmd;		/* command (see below) */
107*0Sstevel@tonic-gate 	major_t	apc_major;		/* major # of device */
108*0Sstevel@tonic-gate 	minor_t	apc_minor;		/* minor # of device */
109*0Sstevel@tonic-gate 	minor_t	apc_lastminor;		/* last minor for range */
110*0Sstevel@tonic-gate 	uint_t	apc_npush;		/* number of modules to push */
111*0Sstevel@tonic-gate };
112*0Sstevel@tonic-gate 
113*0Sstevel@tonic-gate /*
114*0Sstevel@tonic-gate  * New autopush information structure.  This wouldn't be necessary
115*0Sstevel@tonic-gate  * except `struct apcommon' wasn't defined last in the `strapush'
116*0Sstevel@tonic-gate  * structure, making it difficult to grow the structure without
117*0Sstevel@tonic-gate  * breaking binary compatibility.  Note that new members can be added
118*0Sstevel@tonic-gate  * to this structure in the future, at which point AP_VERSION should
119*0Sstevel@tonic-gate  * be incremented (of course, a new STRAPUSH_Vx_LEN macro should be
120*0Sstevel@tonic-gate  * added and sad.c should be changed to handle the new member).
121*0Sstevel@tonic-gate  */
122*0Sstevel@tonic-gate struct apdata {
123*0Sstevel@tonic-gate 	uint_t		apd_anchor;	/* position of anchor in stream */
124*0Sstevel@tonic-gate };
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate /*
127*0Sstevel@tonic-gate  * ap_cmd: various flavors of autopush
128*0Sstevel@tonic-gate  */
129*0Sstevel@tonic-gate #define	SAP_CLEAR	0		/* remove configuration list */
130*0Sstevel@tonic-gate #define	SAP_ONE		1		/* configure one minor device */
131*0Sstevel@tonic-gate #define	SAP_RANGE	2		/* configure range of minor devices */
132*0Sstevel@tonic-gate #define	SAP_ALL		3		/* configure all minor devices */
133*0Sstevel@tonic-gate 
134*0Sstevel@tonic-gate /*
135*0Sstevel@tonic-gate  * format for autopush ioctls
136*0Sstevel@tonic-gate  */
137*0Sstevel@tonic-gate struct strapush {
138*0Sstevel@tonic-gate 	struct apcommon	sap_common;			  /* see above */
139*0Sstevel@tonic-gate 	char		sap_list[MAXAPUSH][FMNAMESZ + 1]; /* module list */
140*0Sstevel@tonic-gate #if AP_VERSION > 0
141*0Sstevel@tonic-gate 	struct apdata	sap_data;			  /* see above */
142*0Sstevel@tonic-gate #endif
143*0Sstevel@tonic-gate };
144*0Sstevel@tonic-gate 
145*0Sstevel@tonic-gate #define	sap_cmd		sap_common.apc_cmd
146*0Sstevel@tonic-gate #define	sap_major	sap_common.apc_major
147*0Sstevel@tonic-gate #define	sap_minor	sap_common.apc_minor
148*0Sstevel@tonic-gate #define	sap_lastminor	sap_common.apc_lastminor
149*0Sstevel@tonic-gate #define	sap_npush	sap_common.apc_npush
150*0Sstevel@tonic-gate #define	sap_anchor	sap_data.apd_anchor
151*0Sstevel@tonic-gate 
152*0Sstevel@tonic-gate #ifdef _KERNEL
153*0Sstevel@tonic-gate 
154*0Sstevel@tonic-gate /*
155*0Sstevel@tonic-gate  * state values for ioctls
156*0Sstevel@tonic-gate  */
157*0Sstevel@tonic-gate #define	GETSTRUCT	1
158*0Sstevel@tonic-gate #define	GETRESULT	2
159*0Sstevel@tonic-gate #define	GETLIST		3
160*0Sstevel@tonic-gate 
161*0Sstevel@tonic-gate #define	SAD_VER(ioccmd)	(((ioccmd) >> 4) & 0x0f)
162*0Sstevel@tonic-gate #define	SAD_CMD(ioccmd)	((ioccmd) & ~0xf0)
163*0Sstevel@tonic-gate 
164*0Sstevel@tonic-gate #define	STRAPUSH_V0_LEN	(size_t)(&((struct strapush *)0)->sap_data)
165*0Sstevel@tonic-gate #define	STRAPUSH_V1_LEN	(size_t)(STRAPUSH_V0_LEN + sizeof (uint_t))
166*0Sstevel@tonic-gate 
167*0Sstevel@tonic-gate struct saddev {
168*0Sstevel@tonic-gate 	queue_t	*sa_qp;		/* pointer to read queue */
169*0Sstevel@tonic-gate 	caddr_t	 sa_addr;	/* saved address for copyout */
170*0Sstevel@tonic-gate 	int	 sa_flags;	/* see below */
171*0Sstevel@tonic-gate };
172*0Sstevel@tonic-gate 
173*0Sstevel@tonic-gate /*
174*0Sstevel@tonic-gate  * values for saddev flags field.
175*0Sstevel@tonic-gate  */
176*0Sstevel@tonic-gate #define	SADPRIV		0x01
177*0Sstevel@tonic-gate 
178*0Sstevel@tonic-gate /*
179*0Sstevel@tonic-gate  * Module Autopush Cache
180*0Sstevel@tonic-gate  */
181*0Sstevel@tonic-gate struct autopush {
182*0Sstevel@tonic-gate 	struct autopush	*ap_nextp;		/* next on list */
183*0Sstevel@tonic-gate 	int		 ap_flags;		/* see below */
184*0Sstevel@tonic-gate 	struct apcommon  ap_common;		/* see above */
185*0Sstevel@tonic-gate 	char		 ap_list[MAXAPUSH][FMNAMESZ + 1];
186*0Sstevel@tonic-gate 						/* list of modules to push */
187*0Sstevel@tonic-gate 	int		 ap_cnt;		/* in use count */
188*0Sstevel@tonic-gate 	struct apdata	 ap_data;		/* see above */
189*0Sstevel@tonic-gate };
190*0Sstevel@tonic-gate 
191*0Sstevel@tonic-gate /*
192*0Sstevel@tonic-gate  * The command issued by the user ultimately becomes
193*0Sstevel@tonic-gate  * the type of the autopush entry.  Therefore, occurrences of
194*0Sstevel@tonic-gate  * "type" in the code refer to an existing autopush entry.
195*0Sstevel@tonic-gate  * Occurrences of "cmd" in the code refer to the command the
196*0Sstevel@tonic-gate  * user is currently trying to complete.  types and cmds take
197*0Sstevel@tonic-gate  * on the same values.
198*0Sstevel@tonic-gate  */
199*0Sstevel@tonic-gate #define	ap_type		ap_common.apc_cmd
200*0Sstevel@tonic-gate #define	ap_major	ap_common.apc_major
201*0Sstevel@tonic-gate #define	ap_minor	ap_common.apc_minor
202*0Sstevel@tonic-gate #define	ap_lastminor	ap_common.apc_lastminor
203*0Sstevel@tonic-gate #define	ap_npush	ap_common.apc_npush
204*0Sstevel@tonic-gate #define	ap_anchor	ap_data.apd_anchor
205*0Sstevel@tonic-gate 
206*0Sstevel@tonic-gate /*
207*0Sstevel@tonic-gate  * autopush flag values
208*0Sstevel@tonic-gate  */
209*0Sstevel@tonic-gate #define	APFREE	0x00	/* free */
210*0Sstevel@tonic-gate #define	APUSED	0x01	/* used */
211*0Sstevel@tonic-gate #define	APHASH	0x02	/* on hash list */
212*0Sstevel@tonic-gate 
213*0Sstevel@tonic-gate /*
214*0Sstevel@tonic-gate  * hash function for cache
215*0Sstevel@tonic-gate  */
216*0Sstevel@tonic-gate #define	strphash(maj)	strpcache[(((int)maj)&strpmask)]
217*0Sstevel@tonic-gate 
218*0Sstevel@tonic-gate extern struct saddev	*saddev;	/* sad device array */
219*0Sstevel@tonic-gate extern int		sadcnt;		/* number of elements in saddev */
220*0Sstevel@tonic-gate extern struct autopush	*autopush;	/* autopush data array */
221*0Sstevel@tonic-gate extern int		nautopush;	/* number of elements in autopush */
222*0Sstevel@tonic-gate extern struct autopush **strpcache;	/* autopush hash list */
223*0Sstevel@tonic-gate extern int		strpmask;	/* used in hash function */
224*0Sstevel@tonic-gate 
225*0Sstevel@tonic-gate /*
226*0Sstevel@tonic-gate  * function prototypes
227*0Sstevel@tonic-gate  */
228*0Sstevel@tonic-gate #ifdef C2_AUDIT
229*0Sstevel@tonic-gate void audit_stropen(struct vnode *, dev_t *, int, cred_t *);
230*0Sstevel@tonic-gate void audit_strclose(struct vnode *, int, cred_t *);
231*0Sstevel@tonic-gate void audit_strioctl(struct vnode *, int, intptr_t, int, int, cred_t *, int *);
232*0Sstevel@tonic-gate struct strbuf;
233*0Sstevel@tonic-gate void audit_strputmsg(struct vnode *, struct strbuf *, struct strbuf *,
234*0Sstevel@tonic-gate 						unsigned char, int, int);
235*0Sstevel@tonic-gate void audit_fdsend(int, struct file *, int);
236*0Sstevel@tonic-gate void audit_fdrecv(int, struct file *);
237*0Sstevel@tonic-gate #endif
238*0Sstevel@tonic-gate 
239*0Sstevel@tonic-gate extern void ap_free(struct autopush *);
240*0Sstevel@tonic-gate extern void sad_initspace(void);
241*0Sstevel@tonic-gate 
242*0Sstevel@tonic-gate #endif /* _KERNEL */
243*0Sstevel@tonic-gate 
244*0Sstevel@tonic-gate #ifdef	__cplusplus
245*0Sstevel@tonic-gate }
246*0Sstevel@tonic-gate #endif
247*0Sstevel@tonic-gate 
248*0Sstevel@tonic-gate #endif	/* _SYS_SAD_H */
249