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 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; |
72static d_ioctl_t ptsioctl; |
73static d_open_t ptcopen; 74static d_close_t ptcclose; 75static d_read_t ptcread; |
76static d_ioctl_t ptcioctl; |
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, |
87 .d_ioctl = ptsioctl, |
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, |
100 .d_ioctl = ptcioctl, |
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 |
523ptcioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td) |
524{ 525 struct tty *tp = dev->si_tty; 526 struct ptsc *pt = dev->si_drv1; |
527 |
528 switch (cmd) { |
529 |
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); |
537 |
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); |
546 |
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 } |
556 |
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); |
563 |
564 switch (cmd) { |
565#ifndef BURN_BRIDGES 566#ifdef COMPAT_43 |
567 case TIOCSETP: 568 case TIOCSETN: |
569#endif 570#endif |
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; |
582 |
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); |
593 } |
594 if ((*(unsigned int *)data == SIGINFO) && 595 ((tp->t_lflag&NOKERNINFO) == 0)) 596 ttyinfo(tp); 597 return(0); |
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 |
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 --- |