]>
Commit | Line | Data |
---|---|---|
5ba3f43e A |
1 | /* |
2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. | |
3 | */ | |
4 | /* | |
5 | * Copyright (c) 1987, 1988 NeXT, Inc. | |
6 | * | |
7 | * HISTORY 7-Jan-93 Mac Gillon (mgillon) at NeXT Integrated POSIX support | |
8 | * | |
9 | * 12-Aug-87 John Seamons (jks) at NeXT Ported to NeXT. | |
10 | */ | |
11 | ||
12 | /* | |
13 | * Indirect driver for console. | |
14 | */ | |
15 | #include <sys/param.h> | |
16 | #include <sys/systm.h> | |
17 | #include <sys/conf.h> | |
18 | #include <sys/ioctl.h> | |
19 | #include <sys/tty.h> | |
20 | #include <sys/proc.h> | |
21 | #include <sys/uio.h> | |
22 | ||
23 | struct tty *constty; /* current console device */ | |
24 | ||
25 | /* | |
26 | * The km driver supplied the default console device for the systems | |
27 | * (usually a raw frame buffer driver, but potentially a serial driver). | |
28 | */ | |
29 | extern struct tty *km_tty[1]; | |
30 | ||
31 | /* | |
32 | * cdevsw[] entries for the console device driver | |
33 | */ | |
34 | int cnopen(__unused dev_t dev, int flag, int devtype, proc_t pp); | |
35 | int cnclose(__unused dev_t dev, int flag, int mode, proc_t pp); | |
36 | int cnread(__unused dev_t dev, struct uio *uio, int ioflag); | |
37 | int cnwrite(__unused dev_t dev, struct uio *uio, int ioflag); | |
38 | int cnioctl(__unused dev_t dev, u_long cmd, caddr_t addr, int flg, proc_t p); | |
39 | int cnselect(__unused dev_t dev, int flag, void * wql, proc_t p); | |
40 | ||
41 | static dev_t | |
42 | cndev(void) | |
43 | { | |
44 | if (constty) | |
45 | return constty->t_dev; | |
46 | else | |
47 | return km_tty[0]->t_dev; | |
48 | } | |
49 | ||
50 | int | |
51 | cnopen(__unused dev_t dev, int flag, int devtype, struct proc *pp) | |
52 | { | |
53 | dev = cndev(); | |
54 | return ((*cdevsw[major(dev)].d_open)(dev, flag, devtype, pp)); | |
55 | } | |
56 | ||
57 | ||
58 | int | |
59 | cnclose(__unused dev_t dev, int flag, int mode, struct proc *pp) | |
60 | { | |
61 | dev = cndev(); | |
62 | return ((*cdevsw[major(dev)].d_close)(dev, flag, mode, pp)); | |
63 | } | |
64 | ||
65 | ||
66 | int | |
67 | cnread(__unused dev_t dev, struct uio *uio, int ioflag) | |
68 | { | |
69 | dev = cndev(); | |
70 | return ((*cdevsw[major(dev)].d_read)(dev, uio, ioflag)); | |
71 | } | |
72 | ||
73 | ||
74 | int | |
75 | cnwrite(__unused dev_t dev, struct uio *uio, int ioflag) | |
76 | { | |
77 | dev = cndev(); | |
78 | return ((*cdevsw[major(dev)].d_write)(dev, uio, ioflag)); | |
79 | } | |
80 | ||
81 | ||
82 | int | |
83 | cnioctl(__unused dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p) | |
84 | { | |
85 | dev = cndev(); | |
86 | ||
87 | /* | |
88 | * XXX This check prevents the cons.c code from being shared between | |
89 | * XXX all architectures; it is probably not needed on ARM, either, | |
90 | * XXX but I have no test platforms or ability to run a kernel. | |
91 | * | |
92 | * Superuser can always use this to wrest control of console | |
93 | * output from the "virtual" console. | |
94 | */ | |
95 | if ((unsigned) cmd == TIOCCONS && constty) { | |
96 | int error = proc_suser(p); | |
97 | if (error) | |
98 | return (error); | |
99 | constty = NULL; | |
100 | return (0); | |
101 | } | |
102 | return ((*cdevsw[major(dev)].d_ioctl)(dev, cmd, addr, flag, p)); | |
103 | } | |
104 | ||
105 | ||
106 | int | |
107 | cnselect(__unused dev_t dev, int flag, void *wql, struct proc *p) | |
108 | { | |
109 | dev = cndev(); | |
110 | return ((*cdevsw[major(dev)].d_select)(dev, flag, wql, p)); | |
111 | } |