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