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 | * |
ea67b335 | 7 | * @(#)tty_tty.c 7.18 (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 | { |
9342689a JH |
30 | USES_VOP_ACCESS; |
31 | USES_VOP_LOCK; | |
32 | USES_VOP_OPEN; | |
33 | USES_VOP_UNLOCK; | |
3789a403 | 34 | struct vnode *ttyvp = cttyvp(p); |
232c0273 | 35 | int error; |
63c57592 | 36 | |
232c0273 | 37 | if (ttyvp == NULL) |
830bbc16 | 38 | return (ENXIO); |
29e3ce7f KM |
39 | VOP_LOCK(ttyvp); |
40 | error = VOP_ACCESS(ttyvp, | |
f254ddb7 | 41 | (flag&FREAD ? VREAD : 0) | (flag&FWRITE ? VWRITE : 0), p->p_ucred, p); |
f21184ce KM |
42 | if (!error) |
43 | error = VOP_OPEN(ttyvp, flag, NOCRED, p); | |
29e3ce7f | 44 | VOP_UNLOCK(ttyvp); |
f21184ce | 45 | return (error); |
63c57592 BJ |
46 | } |
47 | ||
48 | /*ARGSUSED*/ | |
758b32dd | 49 | cttyread(dev, uio, flag) |
be3a1208 BJ |
50 | dev_t dev; |
51 | struct uio *uio; | |
3e2a6ec5 | 52 | int flag; |
63c57592 | 53 | { |
9342689a JH |
54 | USES_VOP_LOCK; |
55 | USES_VOP_READ; | |
56 | USES_VOP_UNLOCK; | |
758b32dd | 57 | register struct vnode *ttyvp = cttyvp(uio->uio_procp); |
18b87772 | 58 | int error; |
63c57592 | 59 | |
232c0273 | 60 | if (ttyvp == NULL) |
431fd894 | 61 | return (EIO); |
18b87772 KM |
62 | VOP_LOCK(ttyvp); |
63 | error = VOP_READ(ttyvp, uio, flag, NOCRED); | |
64 | VOP_UNLOCK(ttyvp); | |
65 | return (error); | |
63c57592 BJ |
66 | } |
67 | ||
68 | /*ARGSUSED*/ | |
758b32dd | 69 | cttywrite(dev, uio, flag) |
be3a1208 BJ |
70 | dev_t dev; |
71 | struct uio *uio; | |
3e2a6ec5 | 72 | int flag; |
63c57592 | 73 | { |
9342689a JH |
74 | USES_VOP_LOCK; |
75 | USES_VOP_UNLOCK; | |
76 | USES_VOP_WRITE; | |
758b32dd | 77 | register struct vnode *ttyvp = cttyvp(uio->uio_procp); |
18b87772 | 78 | int error; |
63c57592 | 79 | |
232c0273 | 80 | if (ttyvp == NULL) |
431fd894 | 81 | return (EIO); |
18b87772 KM |
82 | VOP_LOCK(ttyvp); |
83 | error = VOP_WRITE(ttyvp, uio, flag, NOCRED); | |
84 | VOP_UNLOCK(ttyvp); | |
85 | return (error); | |
63c57592 BJ |
86 | } |
87 | ||
88 | /*ARGSUSED*/ | |
431fd894 | 89 | cttyioctl(dev, cmd, addr, flag, p) |
35c1dcdb BJ |
90 | dev_t dev; |
91 | int cmd; | |
92 | caddr_t addr; | |
93 | int flag; | |
431fd894 | 94 | struct proc *p; |
63c57592 | 95 | { |
9342689a | 96 | USES_VOP_IOCTL; |
431fd894 | 97 | struct vnode *ttyvp = cttyvp(p); |
63c57592 | 98 | |
232c0273 | 99 | if (ttyvp == NULL) |
431fd894 | 100 | return (EIO); |
9060c89c | 101 | if (cmd == TIOCNOTTY) { |
431fd894 MK |
102 | if (!SESS_LEADER(p)) { |
103 | p->p_flag &= ~SCTTY; | |
232c0273 MT |
104 | return (0); |
105 | } else | |
106 | return (EINVAL); | |
4460d508 | 107 | } |
f254ddb7 | 108 | return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED, p)); |
63c57592 | 109 | } |
231ed58b | 110 | |
a8d3bf7f | 111 | /*ARGSUSED*/ |
431fd894 | 112 | cttyselect(dev, flag, p) |
a8d3bf7f BJ |
113 | dev_t dev; |
114 | int flag; | |
431fd894 | 115 | struct proc *p; |
231ed58b | 116 | { |
9342689a | 117 | USES_VOP_SELECT; |
431fd894 | 118 | struct vnode *ttyvp = cttyvp(p); |
231ed58b | 119 | |
232c0273 | 120 | if (ttyvp == NULL) |
620eb66b | 121 | return (1); /* try operation to get EOF/failure */ |
f254ddb7 | 122 | return (VOP_SELECT(ttyvp, flag, FREAD|FWRITE, NOCRED, p)); |
231ed58b | 123 | } |