Commit | Line | Data |
---|---|---|
f406ae69 KB |
1 | /*- |
2 | * Copyright (c) 1982, 1986, 1991 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * %sccs.include.redist.c% | |
da7c5cc6 | 6 | * |
f2293c35 | 7 | * @(#)tty_tty.c 7.19 (Berkeley) %G% |
da7c5cc6 | 8 | */ |
63c57592 BJ |
9 | |
10 | /* | |
964bcfb1 | 11 | * Indirect driver for controlling tty. |
63c57592 | 12 | */ |
94368568 JB |
13 | #include "param.h" |
14 | #include "systm.h" | |
15 | #include "conf.h" | |
94368568 | 16 | #include "ioctl.h" |
94368568 | 17 | #include "proc.h" |
063b2136 | 18 | #include "tty.h" |
232c0273 MT |
19 | #include "vnode.h" |
20 | #include "file.h" | |
63c57592 | 21 | |
232c0273 MT |
22 | #define cttyvp(p) ((p)->p_flag&SCTTY ? (p)->p_session->s_ttyvp : NULL) |
23 | ||
63c57592 | 24 | /*ARGSUSED*/ |
431fd894 | 25 | cttyopen(dev, flag, mode, p) |
830bbc16 | 26 | dev_t dev; |
431fd894 MK |
27 | int flag, mode; |
28 | struct proc *p; | |
63c57592 | 29 | { |
3789a403 | 30 | struct vnode *ttyvp = cttyvp(p); |
232c0273 | 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, | |
f254ddb7 | 37 | (flag&FREAD ? VREAD : 0) | (flag&FWRITE ? VWRITE : 0), p->p_ucred, p); |
f21184ce KM |
38 | if (!error) |
39 | error = VOP_OPEN(ttyvp, flag, NOCRED, p); | |
29e3ce7f | 40 | VOP_UNLOCK(ttyvp); |
f21184ce | 41 | return (error); |
63c57592 BJ |
42 | } |
43 | ||
44 | /*ARGSUSED*/ | |
758b32dd | 45 | cttyread(dev, uio, flag) |
be3a1208 BJ |
46 | dev_t dev; |
47 | struct uio *uio; | |
3e2a6ec5 | 48 | int flag; |
63c57592 | 49 | { |
758b32dd | 50 | register struct vnode *ttyvp = cttyvp(uio->uio_procp); |
18b87772 | 51 | int error; |
63c57592 | 52 | |
232c0273 | 53 | if (ttyvp == NULL) |
431fd894 | 54 | return (EIO); |
18b87772 KM |
55 | VOP_LOCK(ttyvp); |
56 | error = VOP_READ(ttyvp, uio, flag, NOCRED); | |
57 | VOP_UNLOCK(ttyvp); | |
58 | return (error); | |
63c57592 BJ |
59 | } |
60 | ||
61 | /*ARGSUSED*/ | |
758b32dd | 62 | cttywrite(dev, uio, flag) |
be3a1208 BJ |
63 | dev_t dev; |
64 | struct uio *uio; | |
3e2a6ec5 | 65 | int flag; |
63c57592 | 66 | { |
758b32dd | 67 | register struct vnode *ttyvp = cttyvp(uio->uio_procp); |
18b87772 | 68 | int error; |
63c57592 | 69 | |
232c0273 | 70 | if (ttyvp == NULL) |
431fd894 | 71 | return (EIO); |
18b87772 KM |
72 | VOP_LOCK(ttyvp); |
73 | error = VOP_WRITE(ttyvp, uio, flag, NOCRED); | |
74 | VOP_UNLOCK(ttyvp); | |
75 | return (error); | |
63c57592 BJ |
76 | } |
77 | ||
78 | /*ARGSUSED*/ | |
431fd894 | 79 | cttyioctl(dev, cmd, addr, flag, p) |
35c1dcdb BJ |
80 | dev_t dev; |
81 | int cmd; | |
82 | caddr_t addr; | |
83 | int flag; | |
431fd894 | 84 | struct proc *p; |
63c57592 | 85 | { |
431fd894 | 86 | struct vnode *ttyvp = cttyvp(p); |
63c57592 | 87 | |
232c0273 | 88 | if (ttyvp == NULL) |
431fd894 | 89 | return (EIO); |
9060c89c | 90 | if (cmd == TIOCNOTTY) { |
431fd894 MK |
91 | if (!SESS_LEADER(p)) { |
92 | p->p_flag &= ~SCTTY; | |
232c0273 MT |
93 | return (0); |
94 | } else | |
95 | return (EINVAL); | |
4460d508 | 96 | } |
f254ddb7 | 97 | return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED, p)); |
63c57592 | 98 | } |
231ed58b | 99 | |
a8d3bf7f | 100 | /*ARGSUSED*/ |
431fd894 | 101 | cttyselect(dev, flag, p) |
a8d3bf7f BJ |
102 | dev_t dev; |
103 | int flag; | |
431fd894 | 104 | struct proc *p; |
231ed58b | 105 | { |
431fd894 | 106 | struct vnode *ttyvp = cttyvp(p); |
231ed58b | 107 | |
232c0273 | 108 | if (ttyvp == NULL) |
620eb66b | 109 | return (1); /* try operation to get EOF/failure */ |
f254ddb7 | 110 | return (VOP_SELECT(ttyvp, flag, FREAD|FWRITE, NOCRED, p)); |
231ed58b | 111 | } |