Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/gentty.c
+++ new/usr/src/uts/common/io/gentty.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 28 /* All Rights Reserved */
29 29
30 30
31 31 /* from S5R4 1.22 */
32 32
33 33 /*
34 34 * Indirect driver for controlling tty.
35 35 */
36 36 #include <sys/types.h>
37 37 #include <sys/errno.h>
38 38 #include <sys/conf.h>
39 39 #include <sys/proc.h>
40 40 #include <sys/tty.h>
41 41 #include <sys/stream.h>
42 42 #include <sys/strsubr.h>
43 43 #include <sys/cred.h>
44 44 #include <sys/uio.h>
45 45 #include <sys/session.h>
46 46 #include <sys/ddi.h>
47 47 #include <sys/debug.h>
48 48 #include <sys/stat.h>
49 49 #include <sys/sunddi.h>
50 50 #include <sys/param.h>
51 51 #include <sys/systm.h>
52 52 #include <sys/modctl.h>
53 53 #include <sys/fs/snode.h>
54 54 #include <sys/file.h>
55 55
56 56 #define IS_STREAM(dev) (devopsp[getmajor(dev)]->devo_cb_ops->cb_str != NULL)
57 57
58 58 int syopen(dev_t *, int, int, cred_t *);
59 59 int syclose(dev_t, int, int, cred_t *);
60 60 int syread(dev_t, struct uio *, cred_t *);
61 61 int sywrite(dev_t, struct uio *, cred_t *);
62 62 int sypoll(dev_t, short, int, short *, struct pollhead **);
63 63 int syioctl(dev_t, int, intptr_t, int, cred_t *, int *);
64 64
65 65 static int sy_info(dev_info_t *, ddi_info_cmd_t, void *, void **);
66 66 static int sy_attach(dev_info_t *, ddi_attach_cmd_t);
67 67 static dev_info_t *sy_dip; /* private copy of devinfo pointer */
68 68
69 69 struct cb_ops sy_cb_ops = {
70 70
71 71 syopen, /* open */
72 72 syclose, /* close */
73 73 nodev, /* strategy */
74 74 nodev, /* print */
75 75 nodev, /* dump */
76 76 syread, /* read */
77 77 sywrite, /* write */
78 78 syioctl, /* ioctl */
79 79 nodev, /* devmap */
80 80 nodev, /* mmap */
81 81 nodev, /* segmap */
82 82 sypoll, /* poll */
83 83 ddi_prop_op, /* cb_prop_op */
84 84 0, /* streamtab */
85 85 D_NEW | D_MP /* Driver compatibility flag */
86 86
87 87 };
88 88
89 89 struct dev_ops sy_ops = {
90 90
91 91 DEVO_REV, /* devo_rev, */
92 92 0, /* refcnt */
93 93 sy_info, /* info */
94 94 nulldev, /* identify */
95 95 nulldev, /* probe */
96 96 sy_attach, /* attach */
97 97 nodev, /* detach */
98 98 nodev, /* reset */
99 99 &sy_cb_ops, /* driver operations */
100 100 (struct bus_ops *)0, /* bus operations */
101 101 NULL, /* power */
102 102 ddi_quiesce_not_needed, /* quiesce */
103 103 };
104 104
105 105
106 106 extern int nodev(void);
107 107 extern int nulldev(void);
108 108 extern int dseekneg_flag;
109 109 extern struct mod_ops mod_driverops;
110 110 extern struct dev_ops sy_ops;
111 111
112 112 /*
113 113 * Module linkage information for the kernel.
↓ open down ↓ |
113 lines elided |
↑ open up ↑ |
114 114 */
115 115
116 116 static struct modldrv modldrv = {
117 117 &mod_driverops, /* Type of module. This one is a pseudo driver */
118 118 "Indirect driver for tty 'sy'",
119 119 &sy_ops, /* driver ops */
120 120 };
121 121
122 122 static struct modlinkage modlinkage = {
123 123 MODREV_1,
124 - &modldrv,
125 - NULL
124 + { &modldrv, NULL }
126 125 };
127 126
128 127
129 128 int
130 129 _init(void)
131 130 {
132 131 return (mod_install(&modlinkage));
133 132 }
134 133
135 134
136 135 int
137 136 _fini(void)
138 137 {
139 138 return (mod_remove(&modlinkage));
140 139 }
141 140
142 141 int
143 142 _info(struct modinfo *modinfop)
144 143 {
145 144 return (mod_info(&modlinkage, modinfop));
146 145 }
147 146
148 147 /* ARGSUSED */
149 148 static int
150 149 sy_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
151 150 {
152 151 if (ddi_create_minor_node(devi, "tty", S_IFCHR,
153 152 0, DDI_PSEUDO, NULL) == DDI_FAILURE) {
154 153 ddi_remove_minor_node(devi, NULL);
155 154 return (-1);
156 155 }
157 156 sy_dip = devi;
158 157 return (DDI_SUCCESS);
159 158 }
160 159
161 160 /* ARGSUSED */
162 161 static int
163 162 sy_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
164 163 {
165 164 dev_t dev = (dev_t)arg;
166 165 int error;
167 166
168 167 switch (infocmd) {
169 168 case DDI_INFO_DEVT2DEVINFO:
170 169 if (sy_dip == NULL) {
171 170 *result = (void *)NULL;
172 171 error = DDI_FAILURE;
173 172 } else {
174 173 *result = (void *) sy_dip;
175 174 error = DDI_SUCCESS;
176 175 }
177 176 break;
178 177 case DDI_INFO_DEVT2INSTANCE:
179 178 if (getminor(dev) != 0) {
180 179 *result = (void *)-1;
181 180 error = DDI_FAILURE;
182 181 } else {
183 182 *result = (void *)0;
184 183 error = DDI_SUCCESS;
185 184 }
186 185 break;
187 186 default:
188 187 error = DDI_FAILURE;
189 188 }
190 189 return (error);
191 190 }
192 191
193 192
194 193 /* ARGSUSED */
195 194 int
196 195 syopen(dev_t *devp, int flag, int otyp, struct cred *cr)
197 196 {
198 197 dev_t ttyd;
199 198 vnode_t *ttyvp;
200 199 sess_t *sp;
201 200 int error;
202 201
203 202 if ((sp = tty_hold()) == NULL)
204 203 return (EINTR);
205 204
206 205 if (sp->s_dev == NODEV) {
207 206 tty_rele(sp);
208 207 return (ENXIO);
209 208 }
210 209
211 210 ttyd = sp->s_dev;
212 211 ttyvp = sp->s_vp;
213 212
214 213 /*
215 214 * Open the control terminal. The control terminal may be
216 215 * opened multiple times and it is closed in freectty().
217 216 * The multi-open, single-clone means that no cloning
218 217 * can happen via this open, hence the assertion.
219 218 */
220 219 error = VOP_OPEN(&ttyvp, FNOCTTY | flag, cr, NULL);
221 220 if (error == 0) {
222 221 struct snode *csp;
223 222
224 223 /*
225 224 * XXX: This driver binds a single minor number to the
226 225 * current controlling tty of the process issueing the
227 226 * open / close. If we implement a traditional close
228 227 * for this driver then specfs will only invoke this driver
229 228 * on the last close of our one minor number - which is not
230 229 * what we want. Since we already get the open / close
231 230 * semantic that we want from makectty and freectty, we reach
232 231 * back into the common snode and decrease the open count so
233 232 * that the specfs filtering of all but the last close
234 233 * does not get in our way. To clean this up, a new cb_flag
235 234 * that causes specfs to call the driver on each close
236 235 * should be considered.
237 236 */
238 237 ASSERT(ttyd == ttyvp->v_rdev);
239 238 ASSERT(vn_matchops(ttyvp, spec_getvnodeops()));
240 239 csp = VTOS(VTOS(ttyvp)->s_commonvp);
241 240 mutex_enter(&csp->s_lock);
242 241 ASSERT(csp->s_count > 1);
243 242 csp->s_count--;
244 243 mutex_exit(&csp->s_lock);
245 244 }
246 245
247 246 tty_rele(sp);
248 247 return (error);
249 248 }
250 249
251 250 /* ARGSUSED */
252 251 int
253 252 syclose(dev_t dev, int flag, int otyp, struct cred *cr)
254 253 {
255 254 return (0);
256 255 }
257 256
258 257 /* ARGSUSED */
259 258 int
260 259 syread(dev_t dev, struct uio *uiop, struct cred *cr)
261 260 {
262 261 sess_t *sp;
263 262 int error;
264 263
265 264 if ((sp = tty_hold()) == NULL)
266 265 return (EINTR);
267 266
268 267 if (sp->s_dev == NODEV) {
269 268 tty_rele(sp);
270 269 return (ENXIO);
271 270 }
272 271
273 272 error = VOP_READ(sp->s_vp, uiop, 0, cr, NULL);
274 273
275 274 tty_rele(sp);
276 275 return (error);
277 276 }
278 277
279 278 /* ARGSUSED */
280 279 int
281 280 sywrite(dev_t dev, struct uio *uiop, struct cred *cr)
282 281 {
283 282 sess_t *sp;
284 283 int error;
285 284
286 285 if ((sp = tty_hold()) == NULL)
287 286 return (EINTR);
288 287
289 288 if (sp->s_dev == NODEV) {
290 289 tty_rele(sp);
291 290 return (ENXIO);
292 291 }
293 292
294 293 error = VOP_WRITE(sp->s_vp, uiop, 0, cr, NULL);
295 294
296 295 tty_rele(sp);
297 296 return (error);
298 297 }
299 298
300 299
301 300 /* ARGSUSED */
302 301 int
303 302 syioctl(dev_t dev, int cmd, intptr_t arg, int mode, struct cred *cr,
304 303 int *rvalp)
305 304 {
306 305 sess_t *sp;
307 306 int error;
308 307
309 308 if (cmd == TIOCNOTTY) {
310 309 /*
311 310 * we can't allow this ioctl. the reason is that it
312 311 * attempts to remove the ctty for a session. to do
313 312 * this the ctty can't be in use but we grab a hold on
314 313 * the current ctty (via tty_hold) to perform this ioctl.
315 314 * if we were to allow this ioctl to pass through we
316 315 * would deadlock with ourselves.
317 316 */
318 317 return (EINVAL);
319 318 }
320 319
321 320 if ((sp = tty_hold()) == NULL)
322 321 return (EINTR);
323 322
324 323 if (sp->s_dev == NODEV) {
325 324 tty_rele(sp);
326 325 return (ENXIO);
327 326 }
328 327
329 328 error = VOP_IOCTL(sp->s_vp, cmd, arg, mode, cr, rvalp, NULL);
330 329
331 330 tty_rele(sp);
332 331 return (error);
333 332 }
334 333
335 334
336 335
337 336 /* ARGSUSED */
338 337 int
339 338 sypoll(dev_t dev, short events, int anyyet, short *reventsp,
340 339 struct pollhead **phpp)
341 340 {
342 341 sess_t *sp;
343 342 int error;
344 343
345 344 if ((sp = tty_hold()) == NULL)
346 345 return (EINTR);
347 346
348 347 if (sp->s_dev == NODEV) {
349 348 tty_rele(sp);
350 349 return (ENXIO);
351 350 }
352 351
353 352 error = VOP_POLL(sp->s_vp, events, anyyet, reventsp, phpp, NULL);
354 353
355 354 tty_rele(sp);
356 355 return (error);
357 356 }
↓ open down ↓ |
222 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX