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 | * | |
758b32dd | 6 | * @(#)tty_tty.c 7.13 (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 "ioctl.h" |
16 | #include "tty.h" | |
17 | #include "proc.h" | |
232c0273 MT |
18 | #include "vnode.h" |
19 | #include "file.h" | |
63c57592 | 20 | |
232c0273 MT |
21 | #define cttyvp(p) ((p)->p_flag&SCTTY ? (p)->p_session->s_ttyvp : NULL) |
22 | ||
63c57592 | 23 | /*ARGSUSED*/ |
431fd894 | 24 | cttyopen(dev, flag, mode, p) |
830bbc16 | 25 | dev_t dev; |
431fd894 MK |
26 | int flag, mode; |
27 | struct proc *p; | |
63c57592 | 28 | { |
3789a403 | 29 | struct vnode *ttyvp = cttyvp(p); |
232c0273 | 30 | int error; |
63c57592 | 31 | |
232c0273 | 32 | if (ttyvp == NULL) |
830bbc16 | 33 | return (ENXIO); |
29e3ce7f KM |
34 | VOP_LOCK(ttyvp); |
35 | error = VOP_ACCESS(ttyvp, | |
f254ddb7 | 36 | (flag&FREAD ? VREAD : 0) | (flag&FWRITE ? VWRITE : 0), p->p_ucred, p); |
29e3ce7f KM |
37 | VOP_UNLOCK(ttyvp); |
38 | if (error) | |
232c0273 | 39 | return (error); |
f254ddb7 | 40 | return (VOP_OPEN(ttyvp, flag, NOCRED, p)); |
63c57592 BJ |
41 | } |
42 | ||
43 | /*ARGSUSED*/ | |
758b32dd | 44 | cttyread(dev, uio, flag) |
be3a1208 BJ |
45 | dev_t dev; |
46 | struct uio *uio; | |
63c57592 | 47 | { |
758b32dd | 48 | register struct vnode *ttyvp = cttyvp(uio->uio_procp); |
18b87772 | 49 | int error; |
63c57592 | 50 | |
232c0273 | 51 | if (ttyvp == NULL) |
431fd894 | 52 | return (EIO); |
18b87772 KM |
53 | VOP_LOCK(ttyvp); |
54 | error = VOP_READ(ttyvp, uio, flag, NOCRED); | |
55 | VOP_UNLOCK(ttyvp); | |
56 | return (error); | |
63c57592 BJ |
57 | } |
58 | ||
59 | /*ARGSUSED*/ | |
758b32dd | 60 | cttywrite(dev, uio, flag) |
be3a1208 BJ |
61 | dev_t dev; |
62 | struct uio *uio; | |
63c57592 | 63 | { |
758b32dd | 64 | register struct vnode *ttyvp = cttyvp(uio->uio_procp); |
18b87772 | 65 | int error; |
63c57592 | 66 | |
232c0273 | 67 | if (ttyvp == NULL) |
431fd894 | 68 | return (EIO); |
18b87772 KM |
69 | VOP_LOCK(ttyvp); |
70 | error = VOP_WRITE(ttyvp, uio, flag, NOCRED); | |
71 | VOP_UNLOCK(ttyvp); | |
72 | return (error); | |
63c57592 BJ |
73 | } |
74 | ||
75 | /*ARGSUSED*/ | |
431fd894 | 76 | cttyioctl(dev, cmd, addr, flag, p) |
35c1dcdb BJ |
77 | dev_t dev; |
78 | int cmd; | |
79 | caddr_t addr; | |
80 | int flag; | |
431fd894 | 81 | struct proc *p; |
63c57592 | 82 | { |
431fd894 | 83 | struct vnode *ttyvp = cttyvp(p); |
63c57592 | 84 | |
232c0273 | 85 | if (ttyvp == NULL) |
431fd894 | 86 | return (EIO); |
9060c89c | 87 | if (cmd == TIOCNOTTY) { |
431fd894 MK |
88 | if (!SESS_LEADER(p)) { |
89 | p->p_flag &= ~SCTTY; | |
232c0273 MT |
90 | return (0); |
91 | } else | |
92 | return (EINVAL); | |
4460d508 | 93 | } |
f254ddb7 | 94 | return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED, p)); |
63c57592 | 95 | } |
231ed58b | 96 | |
a8d3bf7f | 97 | /*ARGSUSED*/ |
431fd894 | 98 | cttyselect(dev, flag, p) |
a8d3bf7f BJ |
99 | dev_t dev; |
100 | int flag; | |
431fd894 | 101 | struct proc *p; |
231ed58b | 102 | { |
431fd894 | 103 | struct vnode *ttyvp = cttyvp(p); |
231ed58b | 104 | |
232c0273 | 105 | if (ttyvp == NULL) |
620eb66b | 106 | return (1); /* try operation to get EOF/failure */ |
f254ddb7 | 107 | return (VOP_SELECT(ttyvp, flag, FREAD|FWRITE, NOCRED, p)); |
231ed58b | 108 | } |