2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* Copyright (c) 1997 Apple Computer, Inc. All Rights Reserved */
27 * Copyright (c) 1982, 1986, 1989, 1993
28 * The Regents of the University of California. All rights reserved.
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. All advertising materials mentioning features or use of this software
39 * must display the following acknowledgement:
40 * This product includes software developed by the University of
41 * California, Berkeley and its contributors.
42 * 4. Neither the name of the University nor the names of its contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
46 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * @(#)tty_pty.c 8.4 (Berkeley) 2/20/95
62 * Pseudo-teletype Driver
63 * (Actually two drivers, requiring two entries in 'cdevsw')
65 #include "pty.h" /* XXX */
67 #include <sys/param.h>
68 #include <sys/systm.h>
69 #include <sys/ioctl.h>
75 #include <sys/kernel.h>
76 #include <sys/vnode.h>
78 #include <sys/signalvar.h>
82 #define FREE_BSDSTATIC static
84 #include <machine/spl.h>
86 #define FREE_BSDSTATIC __private_extern__
87 #define d_open_t open_close_fcn_t
88 #define d_close_t open_close_fcn_t
89 #define d_devtotty_t struct tty **
90 #define d_ioctl_t ioctl_fcn_t
91 #define d_read_t read_write_fcn_t
92 #define d_write_t read_write_fcn_t
93 #define d_select_t select_fcn_t
94 typedef void d_stop_t
__P((struct tty
*tp
, int rw
));
98 static void ptyattach
__P((int n
));
100 static void ptsstart
__P((struct tty
*tp
));
101 static void ptcwakeup
__P((struct tty
*tp
, int flag
));
103 FREE_BSDSTATIC d_open_t ptsopen
;
104 FREE_BSDSTATIC d_close_t ptsclose
;
105 FREE_BSDSTATIC d_read_t ptsread
;
106 FREE_BSDSTATIC d_write_t ptswrite
;
107 FREE_BSDSTATIC d_ioctl_t ptyioctl
;
108 FREE_BSDSTATIC d_stop_t ptsstop
;
109 FREE_BSDSTATIC d_devtotty_t ptydevtotty
;
110 FREE_BSDSTATIC d_open_t ptcopen
;
111 FREE_BSDSTATIC d_close_t ptcclose
;
112 FREE_BSDSTATIC d_read_t ptcread
;
113 FREE_BSDSTATIC d_write_t ptcwrite
;
114 FREE_BSDSTATIC d_select_t ptcselect
;
117 #define CDEV_MAJOR_S 5
118 #define CDEV_MAJOR_C 6
119 static struct cdevsw pts_cdevsw
=
120 { ptsopen
, ptsclose
, ptsread
, ptswrite
, /*5*/
121 ptyioctl
, ptsstop
, nullreset
, ptydevtotty
,/* ttyp */
122 ttselect
, nommap
, NULL
, "pts", NULL
, -1 };
124 static struct cdevsw ptc_cdevsw
=
125 { ptcopen
, ptcclose
, ptcread
, ptcwrite
, /*6*/
126 ptyioctl
, nullstop
, nullreset
, ptydevtotty
,/* ptyp */
127 ptcselect
, nommap
, NULL
, "ptc", NULL
, -1 };
133 #define NPTY 32 /* crude XXX */
134 #warning You have only one pty defined, redefining to 32.
139 #define MAXUNITS (8 * 32)
140 static void *devfs_token_pts
[MAXUNITS
];
141 static void *devfs_token_ptc
[MAXUNITS
];
142 static const char jnames
[] = "pqrsPQRS";
145 #define NPTY MAXUNITS
146 #warning Can't have more than 256 pty's with DEVFS defined.
147 #endif /* NPTY > MAXUNITS */
151 #define BUFSIZ 100 /* Chunk size iomoved to/from user */
154 * pts == /dev/tty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
155 * ptc == /dev/pty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
158 FREE_BSDSTATIC
struct tty pt_tty
[NPTY
]; /* XXX */
160 /* NeXT All references to have been changed to indirections in the file */
161 FREE_BSDSTATIC
struct tty
*pt_tty
[NPTY
] = { NULL
};
164 static struct pt_ioctl
{
166 struct selinfo pt_selr
, pt_selw
;
169 } pt_ioctl
[NPTY
]; /* XXX */
170 static int npty
= NPTY
; /* for pstat -t */
172 #define PF_PKT 0x08 /* packet mode */
173 #define PF_STOPPED 0x10 /* user told stopped */
174 #define PF_REMOTE 0x20 /* remote and flow controlled input */
175 #define PF_NOSTOP 0x40
176 #define PF_UCNTL 0x80 /* user control mode */
180 * Establish n (or default if n is 1) ptys in the system.
182 * XXX cdevsw & pstat require the array `pty[]' to be an array
190 #define DEFAULT_NPTY 32
192 /* maybe should allow 0 => none? */
195 ntb
= n
* sizeof(struct tty
);
197 mem
= malloc(ntb
+ ALIGNBYTES
+ n
* sizeof(struct pt_ioctl
),
200 MALLOC(mem
, char *, ntb
+ ALIGNBYTES
+ n
* sizeof(struct pt_ioctl
),
203 pt_tty
= (struct tty
*)mem
;
204 mem
= (char *)ALIGN(mem
+ ntb
);
205 pt_ioctl
= (struct pt_ioctl
*)mem
;
216 #include <miscfs/devfs/devfs.h>
217 #define START_CHAR 'p'
219 int pty_init(int n_ptys
)
224 /* create the pseudo tty device nodes */
225 for (j
= 0; j
< 10; j
++) {
226 for (i
= 0; i
< HEX_BASE
; i
++) {
227 int m
= j
* HEX_BASE
+ i
;
230 (void)devfs_make_node(makedev(4, m
),
231 DEVFS_CHAR
, UID_ROOT
, GID_WHEEL
, 0666,
232 "tty%c%x", j
+ START_CHAR
, i
);
233 (void)devfs_make_node(makedev(5, m
),
234 DEVFS_CHAR
, UID_ROOT
, GID_WHEEL
, 0666,
235 "pty%c%x", j
+ START_CHAR
, i
);
245 ptsopen(dev
, flag
, devtype
, p
)
250 register struct tty
*tp
;
254 tp
= &pt_tty
[minor(dev
)];
257 * You will see this sourt of code coming up in diffs later both
258 * the ttymalloc and the tp indirection.
260 if (minor(dev
) >= npty
)
262 if (!pt_tty
[minor(dev
)]) {
263 tp
= pt_tty
[minor(dev
)] = ttymalloc();
265 tp
= pt_tty
[minor(dev
)];
267 if ((tp
->t_state
& TS_ISOPEN
) == 0) {
268 ttychars(tp
); /* Set up default chars */
269 tp
->t_iflag
= TTYDEF_IFLAG
;
270 tp
->t_oflag
= TTYDEF_OFLAG
;
271 tp
->t_lflag
= TTYDEF_LFLAG
;
272 tp
->t_cflag
= TTYDEF_CFLAG
;
273 tp
->t_ispeed
= tp
->t_ospeed
= TTYDEF_SPEED
;
274 ttsetwater(tp
); /* would be done in xxparam() */
275 } else if (tp
->t_state
&TS_XCLUDE
&& p
->p_ucred
->cr_uid
!= 0)
277 if (tp
->t_oproc
) /* Ctrlr still around. */
278 (void)(*linesw
[tp
->t_line
].l_modem
)(tp
, 1);
279 while ((tp
->t_state
& TS_CARR_ON
) == 0) {
282 error
= ttysleep(tp
, TSA_CARR_ON(tp
), TTIPRI
| PCATCH
,
287 error
= (*linesw
[tp
->t_line
].l_open
)(dev
, tp
);
289 ptcwakeup(tp
, FREAD
|FWRITE
);
294 ptsclose(dev
, flag
, mode
, p
)
299 register struct tty
*tp
;
302 tp
= pt_tty
[minor(dev
)];
303 err
= (*linesw
[tp
->t_line
].l_close
)(tp
, flag
);
304 ptsstop(tp
, FREAD
|FWRITE
);
310 ptsread(dev
, uio
, flag
)
316 struct proc
*p
= curproc
;
318 struct proc
*p
= current_proc();
320 register struct tty
*tp
= pt_tty
[minor(dev
)];
321 register struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
325 ut
= (struct uthread
*)get_bsdthread_info(current_act());
327 if (pti
->pt_flags
& PF_REMOTE
) {
328 while (isbackground(p
, tp
)) {
329 if ((p
->p_sigignore
& sigmask(SIGTTIN
)) ||
330 (ut
->uu_sigmask
& sigmask(SIGTTIN
)) ||
331 p
->p_pgrp
->pg_jobc
== 0 ||
332 p
->p_flag
& P_PPWAIT
)
334 pgsignal(p
->p_pgrp
, SIGTTIN
, 1);
335 error
= ttysleep(tp
, &lbolt
, TTIPRI
| PCATCH
| PTTYBLOCK
, "ptsbg",
340 if (tp
->t_canq
.c_cc
== 0) {
341 if (flag
& IO_NDELAY
)
342 return (EWOULDBLOCK
);
343 error
= ttysleep(tp
, TSA_PTS_READ(tp
), TTIPRI
| PCATCH
,
349 while (tp
->t_canq
.c_cc
> 1 && uio
->uio_resid
> 0)
350 if (ureadc(getc(&tp
->t_canq
), uio
) < 0) {
354 if (tp
->t_canq
.c_cc
== 1)
355 (void) getc(&tp
->t_canq
);
360 error
= (*linesw
[tp
->t_line
].l_read
)(tp
, uio
, flag
);
361 ptcwakeup(tp
, FWRITE
);
366 * Write to pseudo-tty.
367 * Wakeups of controlling tty will happen
368 * indirectly, when tty driver calls ptsstart.
371 ptswrite(dev
, uio
, flag
)
376 register struct tty
*tp
;
378 tp
= pt_tty
[minor(dev
)];
379 if (tp
->t_oproc
== 0)
381 return ((*linesw
[tp
->t_line
].l_write
)(tp
, uio
, flag
));
385 * Start output on pseudo-tty.
386 * Wake up process selecting or sleeping for input from controlling tty.
392 register struct pt_ioctl
*pti
= &pt_ioctl
[minor(tp
->t_dev
)];
394 if (tp
->t_state
& TS_TTSTOP
)
396 if (pti
->pt_flags
& PF_STOPPED
) {
397 pti
->pt_flags
&= ~PF_STOPPED
;
398 pti
->pt_send
= TIOCPKT_START
;
400 ptcwakeup(tp
, FREAD
);
408 struct pt_ioctl
*pti
= &pt_ioctl
[minor(tp
->t_dev
)];
411 selwakeup(&pti
->pt_selr
);
412 wakeup(TSA_PTC_READ(tp
));
415 selwakeup(&pti
->pt_selw
);
416 wakeup(TSA_PTC_WRITE(tp
));
421 ptcopen(dev
, flag
, devtype
, p
)
426 register struct tty
*tp
;
427 struct pt_ioctl
*pti
;
429 if (minor(dev
) >= npty
)
431 if(!pt_tty
[minor(dev
)]) {
432 tp
= pt_tty
[minor(dev
)] = ttymalloc();
434 tp
= pt_tty
[minor(dev
)];
437 tp
->t_oproc
= ptsstart
;
439 tp
->t_stop
= ptsstop
;
441 (void)(*linesw
[tp
->t_line
].l_modem
)(tp
, 1);
442 tp
->t_lflag
&= ~EXTPROC
;
443 pti
= &pt_ioctl
[minor(dev
)];
451 ptcclose(dev
, flags
, fmt
, p
)
457 register struct tty
*tp
;
459 tp
= pt_tty
[minor(dev
)];
460 (void)(*linesw
[tp
->t_line
].l_modem
)(tp
, 0);
463 * XXX MDMBUF makes no sense for ptys but would inhibit the above
464 * l_modem(). CLOCAL makes sense but isn't supported. Special
465 * l_modem()s that ignore carrier drop make no sense for ptys but
466 * may be in use because other parts of the line discipline make
467 * sense for ptys. Recover by doing everything that a normal
468 * ttymodem() would have done except for sending a SIGHUP.
470 if (tp
->t_state
& TS_ISOPEN
) {
471 tp
->t_state
&= ~(TS_CARR_ON
| TS_CONNECTED
);
472 tp
->t_state
|= TS_ZOMBIE
;
473 ttyflush(tp
, FREAD
| FWRITE
);
476 tp
->t_oproc
= 0; /* mark closed */
481 ptcread(dev
, uio
, flag
)
486 register struct tty
*tp
= pt_tty
[minor(dev
)];
487 struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
492 * We want to block until the slave
493 * is open, and there's something to read;
494 * but if we lost the slave or we're NBIO,
495 * then return the appropriate error instead.
498 if (tp
->t_state
&TS_ISOPEN
) {
499 if (pti
->pt_flags
&PF_PKT
&& pti
->pt_send
) {
500 error
= ureadc((int)pti
->pt_send
, uio
);
503 if (pti
->pt_send
& TIOCPKT_IOCTL
) {
504 cc
= min(uio
->uio_resid
,
505 sizeof(tp
->t_termios
));
506 uiomove((caddr_t
)&tp
->t_termios
, cc
,
512 if (pti
->pt_flags
&PF_UCNTL
&& pti
->pt_ucntl
) {
513 error
= ureadc((int)pti
->pt_ucntl
, uio
);
519 if (tp
->t_outq
.c_cc
&& (tp
->t_state
&TS_TTSTOP
) == 0)
522 if ((tp
->t_state
& TS_CONNECTED
) == 0)
523 return (0); /* EOF */
524 if (flag
& IO_NDELAY
)
525 return (EWOULDBLOCK
);
526 error
= tsleep(TSA_PTC_READ(tp
), TTIPRI
| PCATCH
, "ptcin", 0);
530 if (pti
->pt_flags
& (PF_PKT
|PF_UCNTL
))
531 error
= ureadc(0, uio
);
532 while (uio
->uio_resid
> 0 && error
== 0) {
533 cc
= q_to_b(&tp
->t_outq
, buf
, min(uio
->uio_resid
, BUFSIZ
));
536 error
= uiomove(buf
, cc
, uio
);
544 register struct tty
*tp
;
547 struct pt_ioctl
*pti
= &pt_ioctl
[minor(tp
->t_dev
)];
550 /* note: FLUSHREAD and FLUSHWRITE already ok */
552 flush
= TIOCPKT_STOP
;
553 pti
->pt_flags
|= PF_STOPPED
;
555 pti
->pt_flags
&= ~PF_STOPPED
;
556 pti
->pt_send
|= flush
;
557 /* change of perspective */
567 ptcselect(dev
, rw
, wql
, p
)
573 register struct tty
*tp
= pt_tty
[minor(dev
)];
574 struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
577 if ((tp
->t_state
& TS_CONNECTED
) == 0)
583 * Need to block timeouts (ttrstart).
586 if ((tp
->t_state
&TS_ISOPEN
) &&
587 tp
->t_outq
.c_cc
&& (tp
->t_state
&TS_TTSTOP
) == 0) {
594 case 0: /* exceptional */
595 if ((tp
->t_state
&TS_ISOPEN
) &&
596 ((pti
->pt_flags
&PF_PKT
&& pti
->pt_send
) ||
597 (pti
->pt_flags
&PF_UCNTL
&& pti
->pt_ucntl
)))
599 selrecord(p
, &pti
->pt_selr
, wql
);
604 if (tp
->t_state
&TS_ISOPEN
) {
605 if (pti
->pt_flags
& PF_REMOTE
) {
606 if (tp
->t_canq
.c_cc
== 0)
609 if (tp
->t_rawq
.c_cc
+ tp
->t_canq
.c_cc
< TTYHOG
-2)
611 if (tp
->t_canq
.c_cc
== 0 && (tp
->t_iflag
&ICANON
))
615 selrecord(p
, &pti
->pt_selw
, wql
);
623 ptcwrite(dev
, uio
, flag
)
625 register struct uio
*uio
;
628 register struct tty
*tp
= pt_tty
[minor(dev
)];
629 register u_char
*cp
= NULL
;
631 u_char locbuf
[BUFSIZ
];
633 struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
637 if ((tp
->t_state
&TS_ISOPEN
) == 0)
639 if (pti
->pt_flags
& PF_REMOTE
) {
642 while ((uio
->uio_resid
> 0 || cc
> 0) &&
643 tp
->t_canq
.c_cc
< TTYHOG
- 1) {
645 cc
= min(uio
->uio_resid
, BUFSIZ
);
646 cc
= min(cc
, TTYHOG
- 1 - tp
->t_canq
.c_cc
);
648 error
= uiomove((caddr_t
)cp
, cc
, uio
);
651 /* check again for safety */
652 if ((tp
->t_state
& TS_ISOPEN
) == 0) {
653 /* adjust as usual */
654 uio
->uio_resid
+= cc
;
659 cc
= b_to_q((char *)cp
, cc
, &tp
->t_canq
);
661 * XXX we don't guarantee that the canq size
662 * is >= TTYHOG, so the above b_to_q() may
663 * leave some bytes uncopied. However, space
664 * is guaranteed for the null terminator if
665 * we don't fail here since (TTYHOG - 1) is
666 * not a multiple of CBSIZE.
672 /* adjust for data copied in but not written */
673 uio
->uio_resid
+= cc
;
674 (void) putc(0, &tp
->t_canq
);
676 wakeup(TSA_PTS_READ(tp
));
679 while (uio
->uio_resid
> 0 || cc
> 0) {
681 cc
= min(uio
->uio_resid
, BUFSIZ
);
683 error
= uiomove((caddr_t
)cp
, cc
, uio
);
686 /* check again for safety */
687 if ((tp
->t_state
& TS_ISOPEN
) == 0) {
688 /* adjust for data copied in but not written */
689 uio
->uio_resid
+= cc
;
694 if ((tp
->t_rawq
.c_cc
+ tp
->t_canq
.c_cc
) >= TTYHOG
- 2 &&
695 (tp
->t_canq
.c_cc
> 0 || !(tp
->t_iflag
&ICANON
))) {
696 wakeup(TSA_HUP_OR_INPUT(tp
));
699 (*linesw
[tp
->t_line
].l_rint
)(*cp
++, tp
);
708 * Come here to wait for slave to open, for space
709 * in outq, or space in rawq, or an empty canq.
711 if ((tp
->t_state
& TS_CONNECTED
) == 0) {
712 /* adjust for data copied in but not written */
713 uio
->uio_resid
+= cc
;
716 if (flag
& IO_NDELAY
) {
717 /* adjust for data copied in but not written */
718 uio
->uio_resid
+= cc
;
720 return (EWOULDBLOCK
);
723 error
= tsleep(TSA_PTC_WRITE(tp
), TTOPRI
| PCATCH
, "ptcout", 0);
725 /* adjust for data copied in but not written */
726 uio
->uio_resid
+= cc
;
733 /* XXX we eventually want to go to this model,
734 * but premier can't change the cdevsw */
739 if (minor(dev
) >= npty
)
742 return &pt_tty
[minor(dev
)];
749 ptyioctl(dev
, cmd
, data
, flag
)
755 ptyioctl(dev
, cmd
, data
, flag
, p
)
763 register struct tty
*tp
= pt_tty
[minor(dev
)];
764 register struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
765 register u_char
*cc
= tp
->t_cc
;
769 * IF CONTROLLER STTY THEN MUST FLUSH TO PREVENT A HANG.
770 * ttywflush(tp) will hang if there are characters in the outq.
772 if (cmd
== TIOCEXT
) {
774 * When the EXTPROC bit is being toggled, we need
775 * to send an TIOCPKT_IOCTL if the packet driver
779 if (pti
->pt_flags
& PF_PKT
) {
780 pti
->pt_send
|= TIOCPKT_IOCTL
;
781 ptcwakeup(tp
, FREAD
);
783 tp
->t_lflag
|= EXTPROC
;
785 if ((tp
->t_lflag
& EXTPROC
) &&
786 (pti
->pt_flags
& PF_PKT
)) {
787 pti
->pt_send
|= TIOCPKT_IOCTL
;
788 ptcwakeup(tp
, FREAD
);
790 tp
->t_lflag
&= ~EXTPROC
;
795 if (cdevsw
[major(dev
)]->d_open
== ptcopen
)
797 if (cdevsw
[major(dev
)].d_open
== ptcopen
)
803 * We aviod calling ttioctl on the controller since,
804 * in that case, tp must be the controlling terminal.
806 *(int *)data
= tp
->t_pgrp
? tp
->t_pgrp
->pg_id
: 0;
811 if (pti
->pt_flags
& PF_UCNTL
)
813 pti
->pt_flags
|= PF_PKT
;
815 pti
->pt_flags
&= ~PF_PKT
;
820 if (pti
->pt_flags
& PF_PKT
)
822 pti
->pt_flags
|= PF_UCNTL
;
824 pti
->pt_flags
&= ~PF_UCNTL
;
829 pti
->pt_flags
|= PF_REMOTE
;
831 pti
->pt_flags
&= ~PF_REMOTE
;
832 ttyflush(tp
, FREAD
|FWRITE
);
843 ndflush(&tp
->t_outq
, tp
->t_outq
.c_cc
);
847 if (*(unsigned int *)data
>= NSIG
||
848 *(unsigned int *)data
== 0)
850 if ((tp
->t_lflag
&NOFLSH
) == 0)
851 ttyflush(tp
, FREAD
|FWRITE
);
852 pgsignal(tp
->t_pgrp
, *(unsigned int *)data
, 1);
853 if ((*(unsigned int *)data
== SIGINFO
) &&
854 ((tp
->t_lflag
&NOKERNINFO
) == 0))
858 error
= (*linesw
[tp
->t_line
].l_ioctl
)(tp
, cmd
, data
, flag
, p
);
860 error
= ttioctl(tp
, cmd
, data
, flag
, p
);
862 if (pti
->pt_flags
& PF_UCNTL
&&
863 (cmd
& ~0xff) == UIOCCMD(0)) {
865 pti
->pt_ucntl
= (u_char
)cmd
;
866 ptcwakeup(tp
, FREAD
);
873 * If external processing and packet mode send ioctl packet.
875 if ((tp
->t_lflag
&EXTPROC
) && (pti
->pt_flags
& PF_PKT
)) {
884 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
891 pti
->pt_send
|= TIOCPKT_IOCTL
;
892 ptcwakeup(tp
, FREAD
);
897 stop
= (tp
->t_iflag
& IXON
) && CCEQ(cc
[VSTOP
], CTRL('s'))
898 && CCEQ(cc
[VSTART
], CTRL('q'));
899 if (pti
->pt_flags
& PF_NOSTOP
) {
901 pti
->pt_send
&= ~TIOCPKT_NOSTOP
;
902 pti
->pt_send
|= TIOCPKT_DOSTOP
;
903 pti
->pt_flags
&= ~PF_NOSTOP
;
904 ptcwakeup(tp
, FREAD
);
908 pti
->pt_send
&= ~TIOCPKT_DOSTOP
;
909 pti
->pt_send
|= TIOCPKT_NOSTOP
;
910 pti
->pt_flags
|= PF_NOSTOP
;
911 ptcwakeup(tp
, FREAD
);
918 static ptc_devsw_installed
= 0;
921 ptc_drvinit(void *unused
)
928 if( ! ptc_devsw_installed
) {
929 dev
= makedev(CDEV_MAJOR_S
, 0);
930 cdevsw_add(&dev
, &pts_cdevsw
, NULL
);
931 dev
= makedev(CDEV_MAJOR_C
, 0);
932 cdevsw_add(&dev
, &ptc_cdevsw
, NULL
);
933 ptc_devsw_installed
= 1;
935 for ( i
= 0 ; i
<NPTY
; i
++ ) {
939 devfs_add_devswf(&pts_cdevsw
,i
,
941 "tty%c%n",jnames
[j
],k
);
943 devfs_add_devswf(&ptc_cdevsw
,i
,
945 "pty%c%n",jnames
[j
],k
);
951 SYSINIT(ptcdev
,SI_SUB_DRIVERS
,SI_ORDER_MIDDLE
+CDEV_MAJOR_C
,ptc_drvinit
,NULL
)