This source file includes following definitions.
- cttyopen
- cttyread
- cttywrite
- cttyioctl
- cttypoll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/ioctl.h>
41 #include <sys/proc.h>
42 #include <sys/tty.h>
43 #include <sys/vnode.h>
44 #include <sys/file.h>
45 #include <sys/conf.h>
46
47
48 #define cttyvp(p) ((p)->p_flag & P_CONTROLT ? (p)->p_session->s_ttyvp : NULL)
49
50
51 int
52 cttyopen(dev_t dev, int flag, int mode, struct proc *p)
53 {
54 struct vnode *ttyvp = cttyvp(p);
55 int error;
56
57 if (ttyvp == NULL)
58 return (ENXIO);
59 vn_lock(ttyvp, LK_EXCLUSIVE | LK_RETRY, p);
60 #ifdef PARANOID
61
62
63
64
65
66
67
68
69 error = VOP_ACCESS(ttyvp,
70 (flag&FREAD ? VREAD : 0) | (flag&FWRITE ? VWRITE : 0), p->p_ucred, p);
71 if (!error)
72 #endif
73 error = VOP_OPEN(ttyvp, flag, NOCRED, p);
74 VOP_UNLOCK(ttyvp, 0, p);
75 return (error);
76 }
77
78
79 int
80 cttyread(dev_t dev, struct uio *uio, int flag)
81 {
82 struct proc *p = uio->uio_procp;
83 struct vnode *ttyvp = cttyvp(uio->uio_procp);
84 int error;
85
86 if (ttyvp == NULL)
87 return (EIO);
88 vn_lock(ttyvp, LK_EXCLUSIVE | LK_RETRY, p);
89 error = VOP_READ(ttyvp, uio, flag, NOCRED);
90 VOP_UNLOCK(ttyvp, 0, p);
91 return (error);
92 }
93
94
95 int
96 cttywrite(dev_t dev, struct uio *uio, int flag)
97 {
98 struct proc *p = uio->uio_procp;
99 struct vnode *ttyvp = cttyvp(uio->uio_procp);
100 int error;
101
102 if (ttyvp == NULL)
103 return (EIO);
104 vn_lock(ttyvp, LK_EXCLUSIVE | LK_RETRY, p);
105 error = VOP_WRITE(ttyvp, uio, flag, NOCRED);
106 VOP_UNLOCK(ttyvp, 0, p);
107 return (error);
108 }
109
110
111 int
112 cttyioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
113 {
114 struct vnode *ttyvp = cttyvp(p);
115
116 if (ttyvp == NULL)
117 return (EIO);
118 if (cmd == TIOCSCTTY)
119 return (EINVAL);
120 if (cmd == TIOCNOTTY) {
121 if (!SESS_LEADER(p)) {
122 atomic_clearbits_int(&p->p_flag, P_CONTROLT);
123 return (0);
124 } else
125 return (EINVAL);
126 }
127 return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED, p));
128 }
129
130
131 int
132 cttypoll(dev_t dev, int events, struct proc *p)
133 {
134 struct vnode *ttyvp = cttyvp(p);
135
136 if (ttyvp == NULL)
137 return (seltrue(dev, events, p));
138 return (VOP_POLL(ttyvp, events, p));
139 }