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