]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * Copyright (c) 1987, 1988 NeXT, Inc. | |
30 | * | |
31 | * HISTORY | |
32 | * 7-Jan-93 Mac Gillon (mgillon) at NeXT | |
33 | * Integrated POSIX support | |
34 | * | |
35 | * 12-Aug-87 John Seamons (jks) at NeXT | |
36 | * Ported to NeXT. | |
37 | */ | |
38 | ||
39 | /* | |
40 | * Indirect driver for console. | |
41 | */ | |
42 | #include <sys/param.h> | |
43 | #include <sys/systm.h> | |
44 | #include <sys/conf.h> | |
45 | #include <sys/ioctl.h> | |
46 | #include <sys/tty.h> | |
47 | #include <sys/proc.h> | |
48 | #include <sys/uio.h> | |
b0d623f7 | 49 | #include <machine/cons.h> |
1c79356b | 50 | |
b0d623f7 A |
51 | struct tty *constty; /* current console device */ |
52 | ||
53 | /* | |
54 | * The km driver supplied the default console device for the systems | |
55 | * (usually a raw frame buffer driver, but potentially a serial driver). | |
56 | */ | |
57 | extern struct tty *km_tty[1]; | |
58 | ||
59 | static dev_t | |
60 | cndev(void) | |
61 | { | |
62 | if (constty) | |
63 | return constty->t_dev; | |
64 | else | |
65 | return km_tty[0]->t_dev; | |
66 | } | |
1c79356b A |
67 | |
68 | /*ARGSUSED*/ | |
69 | int | |
2d21ac55 | 70 | consopen(__unused dev_t dev, int flag, int devtype, struct proc *pp) |
1c79356b | 71 | { |
b0d623f7 A |
72 | dev = cndev(); |
73 | return ((*cdevsw[major(dev)].d_open)(dev, flag, devtype, pp)); | |
1c79356b A |
74 | } |
75 | ||
b0d623f7 | 76 | |
1c79356b A |
77 | /*ARGSUSED*/ |
78 | int | |
2d21ac55 | 79 | consclose(__unused dev_t dev, int flag, int mode, struct proc *pp) |
1c79356b | 80 | { |
b0d623f7 A |
81 | dev = cndev(); |
82 | return ((*cdevsw[major(dev)].d_close)(dev, flag, mode, pp)); | |
1c79356b A |
83 | } |
84 | ||
b0d623f7 | 85 | |
1c79356b A |
86 | /*ARGSUSED*/ |
87 | int | |
2d21ac55 | 88 | consread(__unused dev_t dev, struct uio *uio, int ioflag) |
1c79356b | 89 | { |
b0d623f7 A |
90 | dev = cndev(); |
91 | return ((*cdevsw[major(dev)].d_read)(dev, uio, ioflag)); | |
1c79356b A |
92 | } |
93 | ||
b0d623f7 | 94 | |
1c79356b A |
95 | /*ARGSUSED*/ |
96 | int | |
2d21ac55 | 97 | conswrite(__unused dev_t dev, struct uio *uio, int ioflag) |
1c79356b | 98 | { |
b0d623f7 A |
99 | dev = cndev(); |
100 | return ((*cdevsw[major(dev)].d_write)(dev, uio, ioflag)); | |
1c79356b A |
101 | } |
102 | ||
b0d623f7 | 103 | |
1c79356b A |
104 | /*ARGSUSED*/ |
105 | int | |
2d21ac55 | 106 | consioctl(__unused dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p) |
1c79356b | 107 | { |
b0d623f7 A |
108 | dev = cndev(); |
109 | #if 0 | |
1c79356b A |
110 | /* |
111 | * Superuser can always use this to wrest control of console | |
112 | * output from the "virtual" console. | |
b0d623f7 A |
113 | * |
114 | * XXX Unfortunately, this code doesn't do what the author thougt | |
115 | * XXX it did; use of the console device, a TIOCCONS would always | |
116 | * XXX disassociate the console from a virtual terminal and send | |
117 | * XXX it back to the fake tty. | |
1c79356b | 118 | */ |
b0d623f7 A |
119 | if ((unsigned) cmd == TIOCCONS && constty) { |
120 | int error = proc_suser(p); | |
121 | if (!error) { | |
122 | constty = NULL; | |
91447636 | 123 | } |
b0d623f7 | 124 | return(error); |
1c79356b | 125 | } |
b0d623f7 | 126 | #endif /* 0 */ |
91447636 | 127 | |
b0d623f7 | 128 | return ((*cdevsw[major(dev)].d_ioctl)(dev, cmd, addr, flag, p)); |
1c79356b A |
129 | } |
130 | ||
b0d623f7 | 131 | |
1c79356b | 132 | /*ARGSUSED*/ |
91447636 | 133 | /* called with funnel held */ |
1c79356b | 134 | int |
2d21ac55 | 135 | consselect(__unused dev_t dev, int flag, void *wql, struct proc *p) |
1c79356b | 136 | { |
b0d623f7 A |
137 | dev = cndev(); |
138 | return ((*cdevsw[major(dev)].d_select)(dev, flag, wql, p)); | |
1c79356b | 139 | } |