Commit | Line | Data |
---|---|---|
b688fc87 WJ |
1 | /*- |
2 | * Copyright (c) 1982, 1986, 1991 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
32 | * | |
33 | * @(#)tty_tty.c 7.15 (Berkeley) 5/28/91 | |
34 | */ | |
35 | ||
36 | /* | |
37 | * Indirect driver for controlling tty. | |
38 | */ | |
39 | #include "param.h" | |
40 | #include "systm.h" | |
41 | #include "conf.h" | |
42 | #include "ioctl.h" | |
43 | #include "tty.h" | |
44 | #include "proc.h" | |
45 | #include "vnode.h" | |
46 | #include "file.h" | |
47 | ||
48 | #define cttyvp(p) ((p)->p_flag&SCTTY ? (p)->p_session->s_ttyvp : NULL) | |
49 | ||
50 | /*ARGSUSED*/ | |
51 | cttyopen(dev, flag, mode, p) | |
52 | dev_t dev; | |
53 | int flag, mode; | |
54 | struct proc *p; | |
55 | { | |
56 | struct vnode *ttyvp = cttyvp(p); | |
57 | int error; | |
58 | ||
59 | if (ttyvp == NULL) | |
60 | return (ENXIO); | |
61 | VOP_LOCK(ttyvp); | |
62 | error = VOP_ACCESS(ttyvp, | |
63 | (flag&FREAD ? VREAD : 0) | (flag&FWRITE ? VWRITE : 0), p->p_ucred, p); | |
64 | if (!error) | |
65 | error = VOP_OPEN(ttyvp, flag, NOCRED, p); | |
66 | VOP_UNLOCK(ttyvp); | |
67 | return (error); | |
68 | } | |
69 | ||
70 | /*ARGSUSED*/ | |
71 | cttyread(dev, uio, flag) | |
72 | dev_t dev; | |
73 | struct uio *uio; | |
74 | { | |
75 | register struct vnode *ttyvp = cttyvp(uio->uio_procp); | |
76 | int error; | |
77 | ||
78 | if (ttyvp == NULL) | |
79 | return (EIO); | |
80 | VOP_LOCK(ttyvp); | |
81 | error = VOP_READ(ttyvp, uio, flag, NOCRED); | |
82 | VOP_UNLOCK(ttyvp); | |
83 | return (error); | |
84 | } | |
85 | ||
86 | /*ARGSUSED*/ | |
87 | cttywrite(dev, uio, flag) | |
88 | dev_t dev; | |
89 | struct uio *uio; | |
90 | { | |
91 | register struct vnode *ttyvp = cttyvp(uio->uio_procp); | |
92 | int error; | |
93 | ||
94 | if (ttyvp == NULL) | |
95 | return (EIO); | |
96 | VOP_LOCK(ttyvp); | |
97 | error = VOP_WRITE(ttyvp, uio, flag, NOCRED); | |
98 | VOP_UNLOCK(ttyvp); | |
99 | return (error); | |
100 | } | |
101 | ||
102 | /*ARGSUSED*/ | |
103 | cttyioctl(dev, cmd, addr, flag, p) | |
104 | dev_t dev; | |
105 | int cmd; | |
106 | caddr_t addr; | |
107 | int flag; | |
108 | struct proc *p; | |
109 | { | |
110 | struct vnode *ttyvp = cttyvp(p); | |
111 | ||
112 | if (ttyvp == NULL) | |
113 | return (EIO); | |
114 | if (cmd == TIOCNOTTY) { | |
115 | if (!SESS_LEADER(p)) { | |
116 | p->p_flag &= ~SCTTY; | |
117 | return (0); | |
118 | } else | |
119 | return (EINVAL); | |
120 | } | |
121 | return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED, p)); | |
122 | } | |
123 | ||
124 | /*ARGSUSED*/ | |
125 | cttyselect(dev, flag, p) | |
126 | dev_t dev; | |
127 | int flag; | |
128 | struct proc *p; | |
129 | { | |
130 | struct vnode *ttyvp = cttyvp(p); | |
131 | ||
132 | if (ttyvp == NULL) | |
133 | return (1); /* try operation to get EOF/failure */ | |
134 | return (VOP_SELECT(ttyvp, flag, FREAD|FWRITE, NOCRED, p)); | |
135 | } |