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
--- 17 unchanged lines hidden (view full) ---
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)tty_pty.c 8.2 (Berkeley) 9/23/93
34 * $Id: tty_pty.c,v 1.15 1995/07/22 16:45:08 bde Exp $
35 */
36
37/*
38 * Pseudo-teletype Driver
39 * (Actually two drivers, requiring two entries in 'cdevsw')
40 */
41#include "pty.h" /* XXX */
42
--- 84 unchanged lines hidden (view full) ---
127 tp->t_oflag = TTYDEF_OFLAG;
128 tp->t_lflag = TTYDEF_LFLAG;
129 tp->t_cflag = TTYDEF_CFLAG;
130 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
131 ttsetwater(tp); /* would be done in xxparam() */
132 } else if (tp->t_state&TS_XCLUDE && p->p_ucred->cr_uid != 0)
133 return (EBUSY);
134 if (tp->t_oproc) /* Ctrlr still around. */
135 (void)(*linesw[tp->t_line].l_modem)(tp, 1);
136 while ((tp->t_state & TS_CARR_ON) == 0) {
137 if (flag&FNONBLOCK)
138 break;
139 error = ttysleep(tp, TSA_CARR_ON(tp), TTIPRI | PCATCH,
140 "ptsopn", 0);
141 if (error)
142 return (error);
143 }
--- 119 unchanged lines hidden (view full) ---
263 wakeup(TSA_PTC_READ(tp));
264 }
265 if (flag & FWRITE) {
266 selwakeup(&pti->pt_selw);
267 wakeup(TSA_PTC_WRITE(tp));
268 }
269}
270
271int
272ptcopen(dev, flag, devtype, p)
273 dev_t dev;
274 int flag, devtype;
275 struct proc *p;
276{
277 register struct tty *tp;
278 struct pt_ioctl *pti;
279
280 if (minor(dev) >= npty)
281 return (ENXIO);
282 tp = &pt_tty[minor(dev)];
283 if (tp->t_oproc)
--- 14 unchanged lines hidden (view full) ---
298int
299ptcclose(dev)
300 dev_t dev;
301{
302 register struct tty *tp;
303
304 tp = &pt_tty[minor(dev)];
305 (void)(*linesw[tp->t_line].l_modem)(tp, 0);
306
307 /*
308 * XXX MDMBUF makes no sense for ptys but would inhibit the above
309 * l_modem(). CLOCAL makes sense but isn't supported. Special
310 * l_modem()s that ignore carrier drop make no sense for ptys but
311 * may be in use because other parts of the line discipline make
312 * sense for ptys. Recover by doing everything that a normal
313 * ttymodem() would have done except for sending a SIGHUP.
314 */
315 tp->t_state &= ~(TS_CARR_ON | TS_CONNECTED);
316 tp->t_state |= TS_ZOMBIE;
317 ttyflush(tp, FREAD | FWRITE);
318
319 tp->t_oproc = 0; /* mark closed */
320 tp->t_session = 0;
321 return (0);
322}
323
324int
325ptcread(dev, uio, flag)
326 dev_t dev;
--- 31 unchanged lines hidden (view full) ---
358 if (error)
359 return (error);
360 pti->pt_ucntl = 0;
361 return (0);
362 }
363 if (tp->t_outq.c_cc && (tp->t_state&TS_TTSTOP) == 0)
364 break;
365 }
366 if ((tp->t_state & TS_CONNECTED) == 0)
367 return (0); /* EOF */
368 if (flag & IO_NDELAY)
369 return (EWOULDBLOCK);
370 error = tsleep(TSA_PTC_READ(tp), TTIPRI | PCATCH, "ptcin", 0);
371 if (error)
372 return (error);
373 }
374 if (pti->pt_flags & (PF_PKT|PF_UCNTL))
--- 37 unchanged lines hidden (view full) ---
412 dev_t dev;
413 int rw;
414 struct proc *p;
415{
416 register struct tty *tp = &pt_tty[minor(dev)];
417 struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
418 int s;
419
420 if ((tp->t_state & TS_CONNECTED) == 0)
421 return (1);
422 switch (rw) {
423
424 case FREAD:
425 /*
426 * Need to block timeouts (ttrstart).
427 */
428 s = spltty();
--- 83 unchanged lines hidden (view full) ---
512 return (error);
513 /* check again for safety */
514 if ((tp->t_state&TS_ISOPEN) == 0)
515 return (EIO);
516 }
517 while (cc > 0) {
518 if ((tp->t_rawq.c_cc + tp->t_canq.c_cc) >= TTYHOG - 2 &&
519 (tp->t_canq.c_cc > 0 || !(tp->t_iflag&ICANON))) {
520 wakeup(TSA_HUP_OR_INPUT(tp));
521 goto block;
522 }
523 (*linesw[tp->t_line].l_rint)(*cp++, tp);
524 cnt++;
525 cc--;
526 }
527 cc = 0;
528 }
529 return (0);
530block:
531 /*
532 * Come here to wait for slave to open, for space
533 * in outq, or space in rawq.
534 */
535 if ((tp->t_state & TS_CONNECTED) == 0)
536 return (EIO);
537 if (flag & IO_NDELAY) {
538 /* adjust for data copied in but not written */
539 uio->uio_resid += cc;
540 if (cnt == 0)
541 return (EWOULDBLOCK);
542 return (0);
543 }
--- 176 unchanged lines hidden ---
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
--- 17 unchanged lines hidden (view full) ---
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)tty_pty.c 8.2 (Berkeley) 9/23/93
34 * $Id: tty_pty.c,v 1.15 1995/07/22 16:45:08 bde Exp $
35 */
36
37/*
38 * Pseudo-teletype Driver
39 * (Actually two drivers, requiring two entries in 'cdevsw')
40 */
41#include "pty.h" /* XXX */
42
--- 84 unchanged lines hidden (view full) ---
127 tp->t_oflag = TTYDEF_OFLAG;
128 tp->t_lflag = TTYDEF_LFLAG;
129 tp->t_cflag = TTYDEF_CFLAG;
130 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
131 ttsetwater(tp); /* would be done in xxparam() */
132 } else if (tp->t_state&TS_XCLUDE && p->p_ucred->cr_uid != 0)
133 return (EBUSY);
134 if (tp->t_oproc) /* Ctrlr still around. */
135 (void)(*linesw[tp->t_line].l_modem)(tp, 1);
136 while ((tp->t_state & TS_CARR_ON) == 0) {
137 if (flag&FNONBLOCK)
138 break;
139 error = ttysleep(tp, TSA_CARR_ON(tp), TTIPRI | PCATCH,
140 "ptsopn", 0);
141 if (error)
142 return (error);
143 }
--- 119 unchanged lines hidden (view full) ---
263 wakeup(TSA_PTC_READ(tp));
264 }
265 if (flag & FWRITE) {
266 selwakeup(&pti->pt_selw);
267 wakeup(TSA_PTC_WRITE(tp));
268 }
269}
270
271int
272ptcopen(dev, flag, devtype, p)
273 dev_t dev;
274 int flag, devtype;
275 struct proc *p;
276{
277 register struct tty *tp;
278 struct pt_ioctl *pti;
279
280 if (minor(dev) >= npty)
281 return (ENXIO);
282 tp = &pt_tty[minor(dev)];
283 if (tp->t_oproc)
--- 14 unchanged lines hidden (view full) ---
298int
299ptcclose(dev)
300 dev_t dev;
301{
302 register struct tty *tp;
303
304 tp = &pt_tty[minor(dev)];
305 (void)(*linesw[tp->t_line].l_modem)(tp, 0);
306
307 /*
308 * XXX MDMBUF makes no sense for ptys but would inhibit the above
309 * l_modem(). CLOCAL makes sense but isn't supported. Special
310 * l_modem()s that ignore carrier drop make no sense for ptys but
311 * may be in use because other parts of the line discipline make
312 * sense for ptys. Recover by doing everything that a normal
313 * ttymodem() would have done except for sending a SIGHUP.
314 */
315 tp->t_state &= ~(TS_CARR_ON | TS_CONNECTED);
316 tp->t_state |= TS_ZOMBIE;
317 ttyflush(tp, FREAD | FWRITE);
318
319 tp->t_oproc = 0; /* mark closed */
320 tp->t_session = 0;
321 return (0);
322}
323
324int
325ptcread(dev, uio, flag)
326 dev_t dev;
--- 31 unchanged lines hidden (view full) ---
358 if (error)
359 return (error);
360 pti->pt_ucntl = 0;
361 return (0);
362 }
363 if (tp->t_outq.c_cc && (tp->t_state&TS_TTSTOP) == 0)
364 break;
365 }
366 if ((tp->t_state & TS_CONNECTED) == 0)
367 return (0); /* EOF */
368 if (flag & IO_NDELAY)
369 return (EWOULDBLOCK);
370 error = tsleep(TSA_PTC_READ(tp), TTIPRI | PCATCH, "ptcin", 0);
371 if (error)
372 return (error);
373 }
374 if (pti->pt_flags & (PF_PKT|PF_UCNTL))
--- 37 unchanged lines hidden (view full) ---
412 dev_t dev;
413 int rw;
414 struct proc *p;
415{
416 register struct tty *tp = &pt_tty[minor(dev)];
417 struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
418 int s;
419
420 if ((tp->t_state & TS_CONNECTED) == 0)
421 return (1);
422 switch (rw) {
423
424 case FREAD:
425 /*
426 * Need to block timeouts (ttrstart).
427 */
428 s = spltty();
--- 83 unchanged lines hidden (view full) ---
512 return (error);
513 /* check again for safety */
514 if ((tp->t_state&TS_ISOPEN) == 0)
515 return (EIO);
516 }
517 while (cc > 0) {
518 if ((tp->t_rawq.c_cc + tp->t_canq.c_cc) >= TTYHOG - 2 &&
519 (tp->t_canq.c_cc > 0 || !(tp->t_iflag&ICANON))) {
520 wakeup(TSA_HUP_OR_INPUT(tp));
521 goto block;
522 }
523 (*linesw[tp->t_line].l_rint)(*cp++, tp);
524 cnt++;
525 cc--;
526 }
527 cc = 0;
528 }
529 return (0);
530block:
531 /*
532 * Come here to wait for slave to open, for space
533 * in outq, or space in rawq.
534 */
535 if ((tp->t_state & TS_CONNECTED) == 0)
536 return (EIO);
537 if (flag & IO_NDELAY) {
538 /* adjust for data copied in but not written */
539 uio->uio_resid += cc;
540 if (cnt == 0)
541 return (EWOULDBLOCK);
542 return (0);
543 }
--- 176 unchanged lines hidden ---