2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1997 Apple Computer, Inc. All Rights Reserved */
24 * Copyright (c) 1982, 1986, 1989, 1993
25 * The Regents of the University of California. All rights reserved.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * @(#)tty_pty.c 8.4 (Berkeley) 2/20/95
59 * Pseudo-teletype Driver
60 * (Actually two drivers, requiring two entries in 'cdevsw')
62 #include "pty.h" /* XXX */
64 #include <sys/param.h>
65 #include <sys/systm.h>
66 #include <sys/ioctl.h>
72 #include <sys/kernel.h>
73 #include <sys/vnode.h>
74 #include <sys/signalvar.h>
78 #define FREE_BSDSTATIC static
80 #include <machine/spl.h>
82 #define FREE_BSDSTATIC __private_extern__
83 #define d_open_t open_close_fcn_t
84 #define d_close_t open_close_fcn_t
85 #define d_devtotty_t struct tty **
86 #define d_ioctl_t ioctl_fcn_t
87 #define d_read_t read_write_fcn_t
88 #define d_write_t read_write_fcn_t
89 #define d_select_t select_fcn_t
90 typedef void d_stop_t
__P((struct tty
*tp
, int rw
));
94 static void ptyattach
__P((int n
));
96 static void ptsstart
__P((struct tty
*tp
));
97 static void ptcwakeup
__P((struct tty
*tp
, int flag
));
99 FREE_BSDSTATIC d_open_t ptsopen
;
100 FREE_BSDSTATIC d_close_t ptsclose
;
101 FREE_BSDSTATIC d_read_t ptsread
;
102 FREE_BSDSTATIC d_write_t ptswrite
;
103 FREE_BSDSTATIC d_ioctl_t ptyioctl
;
104 FREE_BSDSTATIC d_stop_t ptsstop
;
105 FREE_BSDSTATIC d_devtotty_t ptydevtotty
;
106 FREE_BSDSTATIC d_open_t ptcopen
;
107 FREE_BSDSTATIC d_close_t ptcclose
;
108 FREE_BSDSTATIC d_read_t ptcread
;
109 FREE_BSDSTATIC d_write_t ptcwrite
;
110 FREE_BSDSTATIC d_select_t ptcselect
;
113 #define CDEV_MAJOR_S 5
114 #define CDEV_MAJOR_C 6
115 static struct cdevsw pts_cdevsw
=
116 { ptsopen
, ptsclose
, ptsread
, ptswrite
, /*5*/
117 ptyioctl
, ptsstop
, nullreset
, ptydevtotty
,/* ttyp */
118 ttselect
, nommap
, NULL
, "pts", NULL
, -1 };
120 static struct cdevsw ptc_cdevsw
=
121 { ptcopen
, ptcclose
, ptcread
, ptcwrite
, /*6*/
122 ptyioctl
, nullstop
, nullreset
, ptydevtotty
,/* ptyp */
123 ptcselect
, nommap
, NULL
, "ptc", NULL
, -1 };
129 #define NPTY 32 /* crude XXX */
130 #warning You have only one pty defined, redefining to 32.
135 #define MAXUNITS (8 * 32)
136 static void *devfs_token_pts
[MAXUNITS
];
137 static void *devfs_token_ptc
[MAXUNITS
];
138 static const char jnames
[] = "pqrsPQRS";
141 #define NPTY MAXUNITS
142 #warning Can't have more than 256 pty's with DEVFS defined.
143 #endif /* NPTY > MAXUNITS */
147 #define BUFSIZ 100 /* Chunk size iomoved to/from user */
150 * pts == /dev/tty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
151 * ptc == /dev/pty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
154 FREE_BSDSTATIC
struct tty pt_tty
[NPTY
]; /* XXX */
156 /* NeXT All references to have been changed to indirections in the file */
157 FREE_BSDSTATIC
struct tty
*pt_tty
[NPTY
] = { NULL
};
160 static struct pt_ioctl
{
162 struct selinfo pt_selr
, pt_selw
;
165 } pt_ioctl
[NPTY
]; /* XXX */
166 static int npty
= NPTY
; /* for pstat -t */
168 #define PF_PKT 0x08 /* packet mode */
169 #define PF_STOPPED 0x10 /* user told stopped */
170 #define PF_REMOTE 0x20 /* remote and flow controlled input */
171 #define PF_NOSTOP 0x40
172 #define PF_UCNTL 0x80 /* user control mode */
176 * Establish n (or default if n is 1) ptys in the system.
178 * XXX cdevsw & pstat require the array `pty[]' to be an array
186 #define DEFAULT_NPTY 32
188 /* maybe should allow 0 => none? */
191 ntb
= n
* sizeof(struct tty
);
193 mem
= malloc(ntb
+ ALIGNBYTES
+ n
* sizeof(struct pt_ioctl
),
196 MALLOC(mem
, char *, ntb
+ ALIGNBYTES
+ n
* sizeof(struct pt_ioctl
),
199 pt_tty
= (struct tty
*)mem
;
200 mem
= (char *)ALIGN(mem
+ ntb
);
201 pt_ioctl
= (struct pt_ioctl
*)mem
;
212 #include <miscfs/devfs/devfs.h>
213 #define START_CHAR 'p'
215 int pty_init(int n_ptys
)
220 /* create the pseudo tty device nodes */
221 for (j
= 0; j
< 10; j
++) {
222 for (i
= 0; i
< HEX_BASE
; i
++) {
223 int m
= j
* HEX_BASE
+ i
;
226 (void)devfs_make_node(makedev(4, m
),
227 DEVFS_CHAR
, UID_ROOT
, GID_WHEEL
, 0666,
228 "tty%c%x", j
+ START_CHAR
, i
);
229 (void)devfs_make_node(makedev(5, m
),
230 DEVFS_CHAR
, UID_ROOT
, GID_WHEEL
, 0666,
231 "pty%c%x", j
+ START_CHAR
, i
);
241 ptsopen(dev
, flag
, devtype
, p
)
246 register struct tty
*tp
;
250 tp
= &pt_tty
[minor(dev
)];
253 * You will see this sourt of code coming up in diffs later both
254 * the ttymalloc and the tp indirection.
256 if (minor(dev
) >= npty
)
258 if (!pt_tty
[minor(dev
)]) {
259 tp
= pt_tty
[minor(dev
)] = ttymalloc();
261 tp
= pt_tty
[minor(dev
)];
263 if ((tp
->t_state
& TS_ISOPEN
) == 0) {
264 ttychars(tp
); /* Set up default chars */
265 tp
->t_iflag
= TTYDEF_IFLAG
;
266 tp
->t_oflag
= TTYDEF_OFLAG
;
267 tp
->t_lflag
= TTYDEF_LFLAG
;
268 tp
->t_cflag
= TTYDEF_CFLAG
;
269 tp
->t_ispeed
= tp
->t_ospeed
= TTYDEF_SPEED
;
270 ttsetwater(tp
); /* would be done in xxparam() */
271 } else if (tp
->t_state
&TS_XCLUDE
&& p
->p_ucred
->cr_uid
!= 0)
273 if (tp
->t_oproc
) /* Ctrlr still around. */
274 (void)(*linesw
[tp
->t_line
].l_modem
)(tp
, 1);
275 while ((tp
->t_state
& TS_CARR_ON
) == 0) {
278 error
= ttysleep(tp
, TSA_CARR_ON(tp
), TTIPRI
| PCATCH
,
283 error
= (*linesw
[tp
->t_line
].l_open
)(dev
, tp
);
285 ptcwakeup(tp
, FREAD
|FWRITE
);
290 ptsclose(dev
, flag
, mode
, p
)
295 register struct tty
*tp
;
298 tp
= pt_tty
[minor(dev
)];
299 err
= (*linesw
[tp
->t_line
].l_close
)(tp
, flag
);
300 ptsstop(tp
, FREAD
|FWRITE
);
306 ptsread(dev
, uio
, flag
)
312 struct proc
*p
= curproc
;
314 struct proc
*p
= current_proc();
316 register struct tty
*tp
= pt_tty
[minor(dev
)];
317 register struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
321 if (pti
->pt_flags
& PF_REMOTE
) {
322 while (isbackground(p
, tp
)) {
323 if ((p
->p_sigignore
& sigmask(SIGTTIN
)) ||
324 (p
->p_sigmask
& sigmask(SIGTTIN
)) ||
325 p
->p_pgrp
->pg_jobc
== 0 ||
326 p
->p_flag
& P_PPWAIT
)
328 pgsignal(p
->p_pgrp
, SIGTTIN
, 1);
329 error
= ttysleep(tp
, &lbolt
, TTIPRI
| PCATCH
| PTTYBLOCK
, "ptsbg",
334 if (tp
->t_canq
.c_cc
== 0) {
335 if (flag
& IO_NDELAY
)
336 return (EWOULDBLOCK
);
337 error
= ttysleep(tp
, TSA_PTS_READ(tp
), TTIPRI
| PCATCH
,
343 while (tp
->t_canq
.c_cc
> 1 && uio
->uio_resid
> 0)
344 if (ureadc(getc(&tp
->t_canq
), uio
) < 0) {
348 if (tp
->t_canq
.c_cc
== 1)
349 (void) getc(&tp
->t_canq
);
354 error
= (*linesw
[tp
->t_line
].l_read
)(tp
, uio
, flag
);
355 ptcwakeup(tp
, FWRITE
);
360 * Write to pseudo-tty.
361 * Wakeups of controlling tty will happen
362 * indirectly, when tty driver calls ptsstart.
365 ptswrite(dev
, uio
, flag
)
370 register struct tty
*tp
;
372 tp
= pt_tty
[minor(dev
)];
373 if (tp
->t_oproc
== 0)
375 return ((*linesw
[tp
->t_line
].l_write
)(tp
, uio
, flag
));
379 * Start output on pseudo-tty.
380 * Wake up process selecting or sleeping for input from controlling tty.
386 register struct pt_ioctl
*pti
= &pt_ioctl
[minor(tp
->t_dev
)];
388 if (tp
->t_state
& TS_TTSTOP
)
390 if (pti
->pt_flags
& PF_STOPPED
) {
391 pti
->pt_flags
&= ~PF_STOPPED
;
392 pti
->pt_send
= TIOCPKT_START
;
394 ptcwakeup(tp
, FREAD
);
402 struct pt_ioctl
*pti
= &pt_ioctl
[minor(tp
->t_dev
)];
405 selwakeup(&pti
->pt_selr
);
406 wakeup(TSA_PTC_READ(tp
));
409 selwakeup(&pti
->pt_selw
);
410 wakeup(TSA_PTC_WRITE(tp
));
415 ptcopen(dev
, flag
, devtype
, p
)
420 register struct tty
*tp
;
421 struct pt_ioctl
*pti
;
423 if (minor(dev
) >= npty
)
425 if(!pt_tty
[minor(dev
)]) {
426 tp
= pt_tty
[minor(dev
)] = ttymalloc();
428 tp
= pt_tty
[minor(dev
)];
431 tp
->t_oproc
= ptsstart
;
433 tp
->t_stop
= ptsstop
;
435 (void)(*linesw
[tp
->t_line
].l_modem
)(tp
, 1);
436 tp
->t_lflag
&= ~EXTPROC
;
437 pti
= &pt_ioctl
[minor(dev
)];
445 ptcclose(dev
, flags
, fmt
, p
)
451 register struct tty
*tp
;
453 tp
= pt_tty
[minor(dev
)];
454 (void)(*linesw
[tp
->t_line
].l_modem
)(tp
, 0);
457 * XXX MDMBUF makes no sense for ptys but would inhibit the above
458 * l_modem(). CLOCAL makes sense but isn't supported. Special
459 * l_modem()s that ignore carrier drop make no sense for ptys but
460 * may be in use because other parts of the line discipline make
461 * sense for ptys. Recover by doing everything that a normal
462 * ttymodem() would have done except for sending a SIGHUP.
464 if (tp
->t_state
& TS_ISOPEN
) {
465 tp
->t_state
&= ~(TS_CARR_ON
| TS_CONNECTED
);
466 tp
->t_state
|= TS_ZOMBIE
;
467 ttyflush(tp
, FREAD
| FWRITE
);
470 tp
->t_oproc
= 0; /* mark closed */
475 ptcread(dev
, uio
, flag
)
480 register struct tty
*tp
= pt_tty
[minor(dev
)];
481 struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
486 * We want to block until the slave
487 * is open, and there's something to read;
488 * but if we lost the slave or we're NBIO,
489 * then return the appropriate error instead.
492 if (tp
->t_state
&TS_ISOPEN
) {
493 if (pti
->pt_flags
&PF_PKT
&& pti
->pt_send
) {
494 error
= ureadc((int)pti
->pt_send
, uio
);
497 if (pti
->pt_send
& TIOCPKT_IOCTL
) {
498 cc
= min(uio
->uio_resid
,
499 sizeof(tp
->t_termios
));
500 uiomove((caddr_t
)&tp
->t_termios
, cc
,
506 if (pti
->pt_flags
&PF_UCNTL
&& pti
->pt_ucntl
) {
507 error
= ureadc((int)pti
->pt_ucntl
, uio
);
513 if (tp
->t_outq
.c_cc
&& (tp
->t_state
&TS_TTSTOP
) == 0)
516 if ((tp
->t_state
& TS_CONNECTED
) == 0)
517 return (0); /* EOF */
518 if (flag
& IO_NDELAY
)
519 return (EWOULDBLOCK
);
520 error
= tsleep(TSA_PTC_READ(tp
), TTIPRI
| PCATCH
, "ptcin", 0);
524 if (pti
->pt_flags
& (PF_PKT
|PF_UCNTL
))
525 error
= ureadc(0, uio
);
526 while (uio
->uio_resid
> 0 && error
== 0) {
527 cc
= q_to_b(&tp
->t_outq
, buf
, min(uio
->uio_resid
, BUFSIZ
));
530 error
= uiomove(buf
, cc
, uio
);
538 register struct tty
*tp
;
541 struct pt_ioctl
*pti
= &pt_ioctl
[minor(tp
->t_dev
)];
544 /* note: FLUSHREAD and FLUSHWRITE already ok */
546 flush
= TIOCPKT_STOP
;
547 pti
->pt_flags
|= PF_STOPPED
;
549 pti
->pt_flags
&= ~PF_STOPPED
;
550 pti
->pt_send
|= flush
;
551 /* change of perspective */
561 ptcselect(dev
, rw
, p
)
566 register struct tty
*tp
= pt_tty
[minor(dev
)];
567 struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
570 if ((tp
->t_state
& TS_CONNECTED
) == 0)
576 * Need to block timeouts (ttrstart).
579 if ((tp
->t_state
&TS_ISOPEN
) &&
580 tp
->t_outq
.c_cc
&& (tp
->t_state
&TS_TTSTOP
) == 0) {
587 case 0: /* exceptional */
588 if ((tp
->t_state
&TS_ISOPEN
) &&
589 ((pti
->pt_flags
&PF_PKT
&& pti
->pt_send
) ||
590 (pti
->pt_flags
&PF_UCNTL
&& pti
->pt_ucntl
)))
592 selrecord(p
, &pti
->pt_selr
);
597 if (tp
->t_state
&TS_ISOPEN
) {
598 if (pti
->pt_flags
& PF_REMOTE
) {
599 if (tp
->t_canq
.c_cc
== 0)
602 if (tp
->t_rawq
.c_cc
+ tp
->t_canq
.c_cc
< TTYHOG
-2)
604 if (tp
->t_canq
.c_cc
== 0 && (tp
->t_iflag
&ICANON
))
608 selrecord(p
, &pti
->pt_selw
);
616 ptcwrite(dev
, uio
, flag
)
618 register struct uio
*uio
;
621 register struct tty
*tp
= pt_tty
[minor(dev
)];
622 register u_char
*cp
= NULL
;
624 u_char locbuf
[BUFSIZ
];
626 struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
630 if ((tp
->t_state
&TS_ISOPEN
) == 0)
632 if (pti
->pt_flags
& PF_REMOTE
) {
635 while ((uio
->uio_resid
> 0 || cc
> 0) &&
636 tp
->t_canq
.c_cc
< TTYHOG
- 1) {
638 cc
= min(uio
->uio_resid
, BUFSIZ
);
639 cc
= min(cc
, TTYHOG
- 1 - tp
->t_canq
.c_cc
);
641 error
= uiomove((caddr_t
)cp
, cc
, uio
);
644 /* check again for safety */
645 if ((tp
->t_state
& TS_ISOPEN
) == 0) {
646 /* adjust as usual */
647 uio
->uio_resid
+= cc
;
652 cc
= b_to_q((char *)cp
, cc
, &tp
->t_canq
);
654 * XXX we don't guarantee that the canq size
655 * is >= TTYHOG, so the above b_to_q() may
656 * leave some bytes uncopied. However, space
657 * is guaranteed for the null terminator if
658 * we don't fail here since (TTYHOG - 1) is
659 * not a multiple of CBSIZE.
665 /* adjust for data copied in but not written */
666 uio
->uio_resid
+= cc
;
667 (void) putc(0, &tp
->t_canq
);
669 wakeup(TSA_PTS_READ(tp
));
672 while (uio
->uio_resid
> 0 || cc
> 0) {
674 cc
= min(uio
->uio_resid
, BUFSIZ
);
676 error
= uiomove((caddr_t
)cp
, cc
, uio
);
679 /* check again for safety */
680 if ((tp
->t_state
& TS_ISOPEN
) == 0) {
681 /* adjust for data copied in but not written */
682 uio
->uio_resid
+= cc
;
687 if ((tp
->t_rawq
.c_cc
+ tp
->t_canq
.c_cc
) >= TTYHOG
- 2 &&
688 (tp
->t_canq
.c_cc
> 0 || !(tp
->t_iflag
&ICANON
))) {
689 wakeup(TSA_HUP_OR_INPUT(tp
));
692 (*linesw
[tp
->t_line
].l_rint
)(*cp
++, tp
);
701 * Come here to wait for slave to open, for space
702 * in outq, or space in rawq, or an empty canq.
704 if ((tp
->t_state
& TS_CONNECTED
) == 0) {
705 /* adjust for data copied in but not written */
706 uio
->uio_resid
+= cc
;
709 if (flag
& IO_NDELAY
) {
710 /* adjust for data copied in but not written */
711 uio
->uio_resid
+= cc
;
713 return (EWOULDBLOCK
);
716 error
= tsleep(TSA_PTC_WRITE(tp
), TTOPRI
| PCATCH
, "ptcout", 0);
718 /* adjust for data copied in but not written */
719 uio
->uio_resid
+= cc
;
726 /* XXX we eventually want to go to this model,
727 * but premier can't change the cdevsw */
732 if (minor(dev
) >= npty
)
735 return &pt_tty
[minor(dev
)];
742 ptyioctl(dev
, cmd
, data
, flag
)
748 ptyioctl(dev
, cmd
, data
, flag
, p
)
756 register struct tty
*tp
= pt_tty
[minor(dev
)];
757 register struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
758 register u_char
*cc
= tp
->t_cc
;
762 * IF CONTROLLER STTY THEN MUST FLUSH TO PREVENT A HANG.
763 * ttywflush(tp) will hang if there are characters in the outq.
765 if (cmd
== TIOCEXT
) {
767 * When the EXTPROC bit is being toggled, we need
768 * to send an TIOCPKT_IOCTL if the packet driver
772 if (pti
->pt_flags
& PF_PKT
) {
773 pti
->pt_send
|= TIOCPKT_IOCTL
;
774 ptcwakeup(tp
, FREAD
);
776 tp
->t_lflag
|= EXTPROC
;
778 if ((tp
->t_lflag
& EXTPROC
) &&
779 (pti
->pt_flags
& PF_PKT
)) {
780 pti
->pt_send
|= TIOCPKT_IOCTL
;
781 ptcwakeup(tp
, FREAD
);
783 tp
->t_lflag
&= ~EXTPROC
;
788 if (cdevsw
[major(dev
)]->d_open
== ptcopen
)
790 if (cdevsw
[major(dev
)].d_open
== ptcopen
)
796 * We aviod calling ttioctl on the controller since,
797 * in that case, tp must be the controlling terminal.
799 *(int *)data
= tp
->t_pgrp
? tp
->t_pgrp
->pg_id
: 0;
804 if (pti
->pt_flags
& PF_UCNTL
)
806 pti
->pt_flags
|= PF_PKT
;
808 pti
->pt_flags
&= ~PF_PKT
;
813 if (pti
->pt_flags
& PF_PKT
)
815 pti
->pt_flags
|= PF_UCNTL
;
817 pti
->pt_flags
&= ~PF_UCNTL
;
822 pti
->pt_flags
|= PF_REMOTE
;
824 pti
->pt_flags
&= ~PF_REMOTE
;
825 ttyflush(tp
, FREAD
|FWRITE
);
836 ndflush(&tp
->t_outq
, tp
->t_outq
.c_cc
);
840 if (*(unsigned int *)data
>= NSIG
||
841 *(unsigned int *)data
== 0)
843 if ((tp
->t_lflag
&NOFLSH
) == 0)
844 ttyflush(tp
, FREAD
|FWRITE
);
845 pgsignal(tp
->t_pgrp
, *(unsigned int *)data
, 1);
846 if ((*(unsigned int *)data
== SIGINFO
) &&
847 ((tp
->t_lflag
&NOKERNINFO
) == 0))
851 error
= (*linesw
[tp
->t_line
].l_ioctl
)(tp
, cmd
, data
, flag
, p
);
853 error
= ttioctl(tp
, cmd
, data
, flag
, p
);
855 if (pti
->pt_flags
& PF_UCNTL
&&
856 (cmd
& ~0xff) == UIOCCMD(0)) {
858 pti
->pt_ucntl
= (u_char
)cmd
;
859 ptcwakeup(tp
, FREAD
);
866 * If external processing and packet mode send ioctl packet.
868 if ((tp
->t_lflag
&EXTPROC
) && (pti
->pt_flags
& PF_PKT
)) {
877 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
884 pti
->pt_send
|= TIOCPKT_IOCTL
;
885 ptcwakeup(tp
, FREAD
);
890 stop
= (tp
->t_iflag
& IXON
) && CCEQ(cc
[VSTOP
], CTRL('s'))
891 && CCEQ(cc
[VSTART
], CTRL('q'));
892 if (pti
->pt_flags
& PF_NOSTOP
) {
894 pti
->pt_send
&= ~TIOCPKT_NOSTOP
;
895 pti
->pt_send
|= TIOCPKT_DOSTOP
;
896 pti
->pt_flags
&= ~PF_NOSTOP
;
897 ptcwakeup(tp
, FREAD
);
901 pti
->pt_send
&= ~TIOCPKT_DOSTOP
;
902 pti
->pt_send
|= TIOCPKT_NOSTOP
;
903 pti
->pt_flags
|= PF_NOSTOP
;
904 ptcwakeup(tp
, FREAD
);
911 static ptc_devsw_installed
= 0;
914 ptc_drvinit(void *unused
)
921 if( ! ptc_devsw_installed
) {
922 dev
= makedev(CDEV_MAJOR_S
, 0);
923 cdevsw_add(&dev
, &pts_cdevsw
, NULL
);
924 dev
= makedev(CDEV_MAJOR_C
, 0);
925 cdevsw_add(&dev
, &ptc_cdevsw
, NULL
);
926 ptc_devsw_installed
= 1;
928 for ( i
= 0 ; i
<NPTY
; i
++ ) {
932 devfs_add_devswf(&pts_cdevsw
,i
,
934 "tty%c%n",jnames
[j
],k
);
936 devfs_add_devswf(&ptc_cdevsw
,i
,
938 "pty%c%n",jnames
[j
],k
);
944 SYSINIT(ptcdev
,SI_SUB_DRIVERS
,SI_ORDER_MIDDLE
+CDEV_MAJOR_C
,ptc_drvinit
,NULL
)