Commit | Line | Data |
---|---|---|
da7c5cc6 | 1 | /* |
0880b18e | 2 | * Copyright (c) 1982, 1986 Regents of the University of California. |
da7c5cc6 KM |
3 | * All rights reserved. The Berkeley software License Agreement |
4 | * specifies the terms and conditions for redistribution. | |
5 | * | |
620eb66b | 6 | * @(#)tty_tty.c 7.9 (Berkeley) %G% |
da7c5cc6 | 7 | */ |
63c57592 BJ |
8 | |
9 | /* | |
964bcfb1 | 10 | * Indirect driver for controlling tty. |
63c57592 | 11 | */ |
94368568 JB |
12 | #include "param.h" |
13 | #include "systm.h" | |
14 | #include "conf.h" | |
94368568 JB |
15 | #include "user.h" |
16 | #include "ioctl.h" | |
17 | #include "tty.h" | |
18 | #include "proc.h" | |
232c0273 MT |
19 | #include "vnode.h" |
20 | #include "file.h" | |
94368568 | 21 | #include "uio.h" |
63c57592 | 22 | |
232c0273 MT |
23 | #define cttyvp(p) ((p)->p_flag&SCTTY ? (p)->p_session->s_ttyvp : NULL) |
24 | ||
63c57592 BJ |
25 | /*ARGSUSED*/ |
26 | syopen(dev, flag) | |
830bbc16 BJ |
27 | dev_t dev; |
28 | int flag; | |
63c57592 | 29 | { |
232c0273 MT |
30 | struct vnode *ttyvp = cttyvp(u.u_procp); |
31 | int error; | |
63c57592 | 32 | |
232c0273 | 33 | if (ttyvp == NULL) |
830bbc16 | 34 | return (ENXIO); |
29e3ce7f KM |
35 | VOP_LOCK(ttyvp); |
36 | error = VOP_ACCESS(ttyvp, | |
37 | (flag&FREAD ? VREAD : 0) | (flag&FWRITE ? VWRITE : 0), u.u_cred); | |
38 | VOP_UNLOCK(ttyvp); | |
39 | if (error) | |
232c0273 MT |
40 | return (error); |
41 | return (VOP_OPEN(ttyvp, flag, NOCRED)); | |
63c57592 BJ |
42 | } |
43 | ||
44 | /*ARGSUSED*/ | |
76e0e3c3 | 45 | syread(dev, uio, flag) |
be3a1208 BJ |
46 | dev_t dev; |
47 | struct uio *uio; | |
63c57592 | 48 | { |
18b87772 KM |
49 | register struct vnode *ttyvp = cttyvp(u.u_procp); |
50 | int error; | |
63c57592 | 51 | |
232c0273 | 52 | if (ttyvp == NULL) |
840510a3 | 53 | return (ENXIO); |
18b87772 KM |
54 | VOP_LOCK(ttyvp); |
55 | error = VOP_READ(ttyvp, uio, flag, NOCRED); | |
56 | VOP_UNLOCK(ttyvp); | |
57 | return (error); | |
63c57592 BJ |
58 | } |
59 | ||
60 | /*ARGSUSED*/ | |
76e0e3c3 | 61 | sywrite(dev, uio, flag) |
be3a1208 BJ |
62 | dev_t dev; |
63 | struct uio *uio; | |
63c57592 | 64 | { |
18b87772 KM |
65 | register struct vnode *ttyvp = cttyvp(u.u_procp); |
66 | int error; | |
63c57592 | 67 | |
232c0273 | 68 | if (ttyvp == NULL) |
840510a3 | 69 | return (ENXIO); |
18b87772 KM |
70 | VOP_LOCK(ttyvp); |
71 | error = VOP_WRITE(ttyvp, uio, flag, NOCRED); | |
72 | VOP_UNLOCK(ttyvp); | |
73 | return (error); | |
63c57592 BJ |
74 | } |
75 | ||
76 | /*ARGSUSED*/ | |
77 | syioctl(dev, cmd, addr, flag) | |
35c1dcdb BJ |
78 | dev_t dev; |
79 | int cmd; | |
80 | caddr_t addr; | |
81 | int flag; | |
63c57592 | 82 | { |
232c0273 | 83 | struct vnode *ttyvp = cttyvp(u.u_procp); |
63c57592 | 84 | |
232c0273 MT |
85 | if (ttyvp == NULL) |
86 | return (ENXIO); | |
9060c89c | 87 | if (cmd == TIOCNOTTY) { |
232c0273 MT |
88 | if (!SESS_LEADER(u.u_procp)) { |
89 | u.u_procp->p_flag &= ~SCTTY; | |
90 | return (0); | |
91 | } else | |
92 | return (EINVAL); | |
4460d508 | 93 | } |
232c0273 | 94 | return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED)); |
63c57592 | 95 | } |
231ed58b | 96 | |
a8d3bf7f | 97 | /*ARGSUSED*/ |
231ed58b | 98 | syselect(dev, flag) |
a8d3bf7f BJ |
99 | dev_t dev; |
100 | int flag; | |
231ed58b | 101 | { |
232c0273 | 102 | struct vnode *ttyvp = cttyvp(u.u_procp); |
231ed58b | 103 | |
232c0273 | 104 | if (ttyvp == NULL) |
620eb66b | 105 | return (1); /* try operation to get EOF/failure */ |
6df51f9c | 106 | return (VOP_SELECT(ttyvp, flag, FREAD|FWRITE, NOCRED)); |
231ed58b | 107 | } |