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 | * |
f21184ce | 7 | * @(#)tty_tty.c 7.15 (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 JB |
16 | #include "ioctl.h" |
17 | #include "tty.h" | |
18 | #include "proc.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; | |
63c57592 | 48 | { |
758b32dd | 49 | register struct vnode *ttyvp = cttyvp(uio->uio_procp); |
18b87772 | 50 | int error; |
63c57592 | 51 | |
232c0273 | 52 | if (ttyvp == NULL) |
431fd894 | 53 | return (EIO); |
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*/ | |
758b32dd | 61 | cttywrite(dev, uio, flag) |
be3a1208 BJ |
62 | dev_t dev; |
63 | struct uio *uio; | |
63c57592 | 64 | { |
758b32dd | 65 | register struct vnode *ttyvp = cttyvp(uio->uio_procp); |
18b87772 | 66 | int error; |
63c57592 | 67 | |
232c0273 | 68 | if (ttyvp == NULL) |
431fd894 | 69 | return (EIO); |
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*/ | |
431fd894 | 77 | cttyioctl(dev, cmd, addr, flag, p) |
35c1dcdb BJ |
78 | dev_t dev; |
79 | int cmd; | |
80 | caddr_t addr; | |
81 | int flag; | |
431fd894 | 82 | struct proc *p; |
63c57592 | 83 | { |
431fd894 | 84 | struct vnode *ttyvp = cttyvp(p); |
63c57592 | 85 | |
232c0273 | 86 | if (ttyvp == NULL) |
431fd894 | 87 | return (EIO); |
9060c89c | 88 | if (cmd == TIOCNOTTY) { |
431fd894 MK |
89 | if (!SESS_LEADER(p)) { |
90 | p->p_flag &= ~SCTTY; | |
232c0273 MT |
91 | return (0); |
92 | } else | |
93 | return (EINVAL); | |
4460d508 | 94 | } |
f254ddb7 | 95 | return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED, p)); |
63c57592 | 96 | } |
231ed58b | 97 | |
a8d3bf7f | 98 | /*ARGSUSED*/ |
431fd894 | 99 | cttyselect(dev, flag, p) |
a8d3bf7f BJ |
100 | dev_t dev; |
101 | int flag; | |
431fd894 | 102 | struct proc *p; |
231ed58b | 103 | { |
431fd894 | 104 | struct vnode *ttyvp = cttyvp(p); |
231ed58b | 105 | |
232c0273 | 106 | if (ttyvp == NULL) |
620eb66b | 107 | return (1); /* try operation to get EOF/failure */ |
f254ddb7 | 108 | return (VOP_SELECT(ttyvp, flag, FREAD|FWRITE, NOCRED, p)); |
231ed58b | 109 | } |