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 (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 27 /* All Rights Reserved */ 28 29 30 #ifndef _SYS_SAD_H 31 #define _SYS_SAD_H 32 33 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.5 */ 34 35 #include <sys/types.h> 36 #include <sys/modhash.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 apcommon ap_common; /* see above */ 183 char ap_list[MAXAPUSH][FMNAMESZ + 1]; 184 /* list of modules to push */ 185 int ap_cnt; /* in use count */ 186 struct apdata ap_data; /* see above */ 187 }; 188 189 /* 190 * The command issued by the user ultimately becomes 191 * the type of the autopush entry. Therefore, occurrences of 192 * "type" in the code refer to an existing autopush entry. 193 * Occurrences of "cmd" in the code refer to the command the 194 * user is currently trying to complete. types and cmds take 195 * on the same values. 196 */ 197 #define ap_type ap_common.apc_cmd 198 #define ap_major ap_common.apc_major 199 #define ap_minor ap_common.apc_minor 200 #define ap_lastminor ap_common.apc_lastminor 201 #define ap_npush ap_common.apc_npush 202 #define ap_anchor ap_data.apd_anchor 203 204 extern struct saddev *saddev; /* sad device array */ 205 extern int sadcnt; /* number of elements in saddev */ 206 207 extern kmutex_t sad_lock; /* protects sad ap data store */ 208 209 /* 210 * function prototypes 211 */ 212 #ifdef C2_AUDIT 213 void audit_stropen(struct vnode *, dev_t *, int, cred_t *); 214 void audit_strclose(struct vnode *, int, cred_t *); 215 void audit_strioctl(struct vnode *, int, intptr_t, int, int, cred_t *, int *); 216 struct strbuf; 217 void audit_strputmsg(struct vnode *, struct strbuf *, struct strbuf *, 218 unsigned char, int, int); 219 void audit_fdsend(int, struct file *, int); 220 void audit_fdrecv(int, struct file *); 221 #endif 222 223 extern void sad_initspace(void); 224 225 /* 226 * The following interfaces do not care about sad_lock. 227 */ 228 extern struct autopush *sad_ap_alloc(void); 229 extern int sad_apc_verify(struct apcommon *); 230 extern int sad_ap_verify(struct autopush *); 231 232 /* 233 * The following interfaces attempt to acquire sad_lock. 234 */ 235 extern void sad_ap_rele(struct autopush *); 236 extern struct autopush *sad_ap_find_by_dev(dev_t); 237 238 /* 239 * The following interfaces require sad_lock to be held when invoked. 240 */ 241 extern void sad_ap_insert(struct autopush *); 242 extern void sad_ap_remove(struct autopush *); 243 extern struct autopush *sad_ap_find(struct apcommon *); 244 245 #endif /* _KERNEL */ 246 247 #ifdef __cplusplus 248 } 249 #endif 250 251 #endif /* _SYS_SAD_H */ 252