Deleted Added
sdiff udiff text old ( 154170 ) new ( 154833 )
full compact
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 16 unchanged lines hidden (view full) ---

25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)tty_pty.c 8.4 (Berkeley) 2/20/95
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD: head/sys/kern/tty_pty.c 154170 2006-01-10 09:19:10Z phk $");
34
35/*
36 * Pseudo-teletype Driver
37 * (Actually two drivers, requiring two entries in 'cdevsw')
38 */
39#include "opt_compat.h"
40#include "opt_tty.h"
41#include <sys/param.h>

--- 60 unchanged lines hidden (view full) ---

102
103struct ptsc {
104 int pt_flags;
105 struct selinfo pt_selr, pt_selw;
106 u_char pt_send;
107 u_char pt_ucntl;
108 struct tty *pt_tty;
109 struct cdev *devs, *devc;
110 struct prison *pt_prison;
111};
112
113#define PF_PKT 0x08 /* packet mode */
114#define PF_STOPPED 0x10 /* user told stopped */
115#define PF_NOSTOP 0x40
116#define PF_UCNTL 0x80 /* user control mode */
117

--- 9 unchanged lines hidden (view full) ---

127 * ptc == /dev/pty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
128 *
129 * XXX: define and add mapping of upper minor bits to allow more
130 * than 256 ptys.
131 */
132static struct cdev *
133ptyinit(struct cdev *devc, struct thread *td)
134{
135 struct cdev *devs;
136 struct ptsc *pt;
137 int n;
138
139 n = minor(devc);
140 /* For now we only map the lower 8 bits of the minor */
141 if (n & ~0xff)
142 return (NULL);
143
144 devc->si_flags &= ~SI_CHEAPCLONE;
145
146 pt = malloc(sizeof(*pt), M_PTY, M_WAITOK | M_ZERO);
147 pt->devs = devs = make_dev_cred(&pts_cdevsw, n, td->td_ucred,
148 UID_ROOT, GID_WHEEL, 0666, "tty%c%r", names[n / 32], n % 32);
149 pt->devc = devc;
150
151 pt->pt_tty = ttyalloc();
152 pt->pt_tty->t_sc = pt;
153 devs->si_drv1 = devc->si_drv1 = pt;
154 devs->si_tty = devc->si_tty = pt->pt_tty;
155 pt->pt_tty->t_dev = devs;
156 return (devc);
157}
158
159/*ARGSUSED*/
160static int
161ptsopen(struct cdev *dev, int flag, int devtype, struct thread *td)
162{
163 struct tty *tp;
164 int error;
165 struct ptsc *pt;
166

--- 13 unchanged lines hidden (view full) ---

180 if (flag&FNONBLOCK)
181 break;
182 error = ttysleep(tp, TSA_CARR_ON(tp), TTIPRI | PCATCH,
183 "ptsopn", 0);
184 if (error)
185 return (error);
186 }
187 error = ttyld_open(tp, dev);
188 if (error == 0)
189 ptcwakeup(tp, FREAD|FWRITE);
190 return (error);
191}
192
193static int
194ptsclose(struct cdev *dev, int flag, int mode, struct thread *td)
195{
196 struct tty *tp;
197 int err;
198
199 tp = dev->si_tty;
200 err = ttyld_close(tp, flag);
201 (void) tty_close(tp);
202 return (err);
203}
204
205static int
206ptsread(struct cdev *dev, struct uio *uio, int flag)
207{
208 struct tty *tp = dev->si_tty;
209 int error = 0;

--- 71 unchanged lines hidden (view full) ---

281 tp->t_stop = ptsstop;
282 (void)ttyld_modem(tp, 1);
283 tp->t_lflag &= ~EXTPROC;
284 pt = dev->si_drv1;
285 pt->pt_prison = td->td_ucred->cr_prison;
286 pt->pt_flags = 0;
287 pt->pt_send = 0;
288 pt->pt_ucntl = 0;
289 return (0);
290}
291
292static int
293ptcclose(struct cdev *dev, int flags, int fmt, struct thread *td)
294{
295 struct tty *tp;
296
297 tp = dev->si_tty;
298 (void)ttyld_modem(tp, 0);
299
300 /*
301 * XXX MDMBUF makes no sense for ptys but would inhibit the above
302 * l_modem(). CLOCAL makes sense but isn't supported. Special

--- 4 unchanged lines hidden (view full) ---

307 */
308 if (tp->t_state & TS_ISOPEN) {
309 tp->t_state &= ~(TS_CARR_ON | TS_CONNECTED);
310 tp->t_state |= TS_ZOMBIE;
311 ttyflush(tp, FREAD | FWRITE);
312 }
313
314 tp->t_oproc = 0; /* mark closed */
315 return (0);
316}
317
318static int
319ptcread(struct cdev *dev, struct uio *uio, int flag)
320{
321 struct tty *tp = dev->si_tty;
322 struct ptsc *pt = dev->si_drv1;

--- 398 unchanged lines hidden ---