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 135298 2004-09-16 12:07:25Z 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>
--- 22 unchanged lines hidden (view full) ---
64static void ptsstop(struct tty *tp, int rw);
65static void ptcwakeup(struct tty *tp, int flag);
66static struct cdev *ptyinit(struct cdev *cdev);
67
68static d_open_t ptsopen;
69static d_close_t ptsclose;
70static d_read_t ptsread;
71static d_write_t ptswrite;
72static d_ioctl_t ptyioctl;
73static d_open_t ptcopen;
74static d_close_t ptcclose;
75static d_read_t ptcread;
76static d_write_t ptcwrite;
77static d_poll_t ptcpoll;
78
79#define CDEV_MAJOR_S 5
80static struct cdevsw pts_cdevsw = {
81 .d_version = D_VERSION,
82 .d_open = ptsopen,
83 .d_close = ptsclose,
84 .d_read = ptsread,
85 .d_write = ptswrite,
86 .d_ioctl = ptyioctl,
87 .d_name = "pts",
88 .d_maj = CDEV_MAJOR_S,
89 .d_flags = D_TTY | D_NEEDGIANT,
90};
91
92#define CDEV_MAJOR_C 6
93static struct cdevsw ptc_cdevsw = {
94 .d_version = D_VERSION,
95 .d_open = ptcopen,
96 .d_close = ptcclose,
97 .d_read = ptcread,
98 .d_write = ptcwrite,
99 .d_ioctl = ptyioctl,
100 .d_poll = ptcpoll,
101 .d_name = "ptc",
102 .d_maj = CDEV_MAJOR_C,
103 .d_flags = D_TTY | D_NEEDGIANT,
104};
105
106#define BUFSIZ 100 /* Chunk size iomoved to/from user */
107
--- 406 unchanged lines hidden (view full) ---
514 uio->uio_resid += cc;
515 return (error);
516 }
517 goto again;
518}
519
520/*ARGSUSED*/
521static int
522ptyioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
523{
524 struct tty *tp = dev->si_tty;
525 struct ptsc *pt = dev->si_drv1;
526 u_char *cc = tp->t_cc;
527 int stop, error;
528
529 if (devsw(dev)->d_open == ptcopen) {
530 switch (cmd) {
531
532 case TIOCGPGRP:
533 /*
534 * We avoid calling ttioctl on the controller since,
535 * in that case, tp must be the controlling terminal.
536 */
537 *(int *)data = tp->t_pgrp ? tp->t_pgrp->pg_id : 0;
538 return (0);
539
540 case TIOCPKT:
541 if (*(int *)data) {
542 if (pt->pt_flags & PF_UCNTL)
543 return (EINVAL);
544 pt->pt_flags |= PF_PKT;
545 } else
546 pt->pt_flags &= ~PF_PKT;
547 return (0);
548
549 case TIOCUCNTL:
550 if (*(int *)data) {
551 if (pt->pt_flags & PF_PKT)
552 return (EINVAL);
553 pt->pt_flags |= PF_UCNTL;
554 } else
555 pt->pt_flags &= ~PF_UCNTL;
556 return (0);
557 }
558
559 /*
560 * The rest of the ioctls shouldn't be called until
561 * the slave is open.
562 */
563 if ((tp->t_state & TS_ISOPEN) == 0)
564 return (EAGAIN);
565
566 switch (cmd) {
567#ifndef BURN_BRIDGES
568#ifdef COMPAT_43
569 case TIOCSETP:
570 case TIOCSETN:
571#endif
572#endif
573 case TIOCSETD:
574 case TIOCSETA:
575 case TIOCSETAW:
576 case TIOCSETAF:
577 /*
578 * IF CONTROLLER STTY THEN MUST FLUSH TO PREVENT A HANG.
579 * ttywflush(tp) will hang if there are characters in
580 * the outq.
581 */
582 ndflush(&tp->t_outq, tp->t_outq.c_cc);
583 break;
584
585 case TIOCSIG:
586 if (*(unsigned int *)data >= NSIG ||
587 *(unsigned int *)data == 0)
588 return(EINVAL);
589 if ((tp->t_lflag&NOFLSH) == 0)
590 ttyflush(tp, FREAD|FWRITE);
591 if (tp->t_pgrp != NULL) {
592 PGRP_LOCK(tp->t_pgrp);
593 pgsignal(tp->t_pgrp, *(unsigned int *)data, 1);
594 PGRP_UNLOCK(tp->t_pgrp);
595 }
596 if ((*(unsigned int *)data == SIGINFO) &&
597 ((tp->t_lflag&NOKERNINFO) == 0))
598 ttyinfo(tp);
599 return(0);
600 }
601 }
602 if (cmd == TIOCEXT) {
603 /*
604 * When the EXTPROC bit is being toggled, we need
605 * to send an TIOCPKT_IOCTL if the packet driver
606 * is turned on.
607 */
608 if (*(int *)data) {
609 if (pt->pt_flags & PF_PKT) {
--- 114 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
--- 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 135298 2004-09-16 12:07:25Z 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>
--- 22 unchanged lines hidden (view full) ---
64static void ptsstop(struct tty *tp, int rw);
65static void ptcwakeup(struct tty *tp, int flag);
66static struct cdev *ptyinit(struct cdev *cdev);
67
68static d_open_t ptsopen;
69static d_close_t ptsclose;
70static d_read_t ptsread;
71static d_write_t ptswrite;
72static d_ioctl_t ptyioctl;
73static d_open_t ptcopen;
74static d_close_t ptcclose;
75static d_read_t ptcread;
76static d_write_t ptcwrite;
77static d_poll_t ptcpoll;
78
79#define CDEV_MAJOR_S 5
80static struct cdevsw pts_cdevsw = {
81 .d_version = D_VERSION,
82 .d_open = ptsopen,
83 .d_close = ptsclose,
84 .d_read = ptsread,
85 .d_write = ptswrite,
86 .d_ioctl = ptyioctl,
87 .d_name = "pts",
88 .d_maj = CDEV_MAJOR_S,
89 .d_flags = D_TTY | D_NEEDGIANT,
90};
91
92#define CDEV_MAJOR_C 6
93static struct cdevsw ptc_cdevsw = {
94 .d_version = D_VERSION,
95 .d_open = ptcopen,
96 .d_close = ptcclose,
97 .d_read = ptcread,
98 .d_write = ptcwrite,
99 .d_ioctl = ptyioctl,
100 .d_poll = ptcpoll,
101 .d_name = "ptc",
102 .d_maj = CDEV_MAJOR_C,
103 .d_flags = D_TTY | D_NEEDGIANT,
104};
105
106#define BUFSIZ 100 /* Chunk size iomoved to/from user */
107
--- 406 unchanged lines hidden (view full) ---
514 uio->uio_resid += cc;
515 return (error);
516 }
517 goto again;
518}
519
520/*ARGSUSED*/
521static int
522ptyioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
523{
524 struct tty *tp = dev->si_tty;
525 struct ptsc *pt = dev->si_drv1;
526 u_char *cc = tp->t_cc;
527 int stop, error;
528
529 if (devsw(dev)->d_open == ptcopen) {
530 switch (cmd) {
531
532 case TIOCGPGRP:
533 /*
534 * We avoid calling ttioctl on the controller since,
535 * in that case, tp must be the controlling terminal.
536 */
537 *(int *)data = tp->t_pgrp ? tp->t_pgrp->pg_id : 0;
538 return (0);
539
540 case TIOCPKT:
541 if (*(int *)data) {
542 if (pt->pt_flags & PF_UCNTL)
543 return (EINVAL);
544 pt->pt_flags |= PF_PKT;
545 } else
546 pt->pt_flags &= ~PF_PKT;
547 return (0);
548
549 case TIOCUCNTL:
550 if (*(int *)data) {
551 if (pt->pt_flags & PF_PKT)
552 return (EINVAL);
553 pt->pt_flags |= PF_UCNTL;
554 } else
555 pt->pt_flags &= ~PF_UCNTL;
556 return (0);
557 }
558
559 /*
560 * The rest of the ioctls shouldn't be called until
561 * the slave is open.
562 */
563 if ((tp->t_state & TS_ISOPEN) == 0)
564 return (EAGAIN);
565
566 switch (cmd) {
567#ifndef BURN_BRIDGES
568#ifdef COMPAT_43
569 case TIOCSETP:
570 case TIOCSETN:
571#endif
572#endif
573 case TIOCSETD:
574 case TIOCSETA:
575 case TIOCSETAW:
576 case TIOCSETAF:
577 /*
578 * IF CONTROLLER STTY THEN MUST FLUSH TO PREVENT A HANG.
579 * ttywflush(tp) will hang if there are characters in
580 * the outq.
581 */
582 ndflush(&tp->t_outq, tp->t_outq.c_cc);
583 break;
584
585 case TIOCSIG:
586 if (*(unsigned int *)data >= NSIG ||
587 *(unsigned int *)data == 0)
588 return(EINVAL);
589 if ((tp->t_lflag&NOFLSH) == 0)
590 ttyflush(tp, FREAD|FWRITE);
591 if (tp->t_pgrp != NULL) {
592 PGRP_LOCK(tp->t_pgrp);
593 pgsignal(tp->t_pgrp, *(unsigned int *)data, 1);
594 PGRP_UNLOCK(tp->t_pgrp);
595 }
596 if ((*(unsigned int *)data == SIGINFO) &&
597 ((tp->t_lflag&NOKERNINFO) == 0))
598 ttyinfo(tp);
599 return(0);
600 }
601 }
602 if (cmd == TIOCEXT) {
603 /*
604 * When the EXTPROC bit is being toggled, we need
605 * to send an TIOCPKT_IOCTL if the packet driver
606 * is turned on.
607 */
608 if (*(int *)data) {
609 if (pt->pt_flags & PF_PKT) {
--- 114 unchanged lines hidden ---