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
--- 17 unchanged lines hidden (view full) ---
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)tty_pty.c 8.4 (Berkeley) 2/20/95
34 * $FreeBSD: head/sys/kern/tty_pty.c 74810 2001-03-26 12:41:29Z phk $
35 */
36
37/*
38 * Pseudo-teletype Driver
39 * (Actually two drivers, requiring two entries in 'cdevsw')
40 */
41#include "opt_compat.h"
42#include <sys/param.h>
--- 11 unchanged lines hidden (view full) ---
54#include <sys/signalvar.h>
55#include <sys/malloc.h>
56
57static MALLOC_DEFINE(M_PTY, "ptys", "pty data structures");
58
59static void ptsstart __P((struct tty *tp));
60static void ptsstop __P((struct tty *tp, int rw));
61static void ptcwakeup __P((struct tty *tp, int flag));
62static dev_t ptyinit __P((int n));
63
64static d_open_t ptsopen;
65static d_close_t ptsclose;
66static d_read_t ptsread;
67static d_write_t ptswrite;
68static d_ioctl_t ptyioctl;
69static d_open_t ptcopen;
70static d_close_t ptcclose;
--- 50 unchanged lines hidden (view full) ---
121};
122
123#define PF_PKT 0x08 /* packet mode */
124#define PF_STOPPED 0x10 /* user told stopped */
125#define PF_REMOTE 0x20 /* remote and flow controlled input */
126#define PF_NOSTOP 0x40
127#define PF_UCNTL 0x80 /* user control mode */
128
129/*
130 * This function creates and initializes a pts/ptc pair
131 *
132 * pts == /dev/tty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
133 * ptc == /dev/pty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
134 *
135 * XXX: define and add mapping of upper minor bits to allow more
136 * than 256 ptys.
137 */
138static dev_t
139ptyinit(n)
140 int n;
141{
142 dev_t devs, devc;
143 char *names = "pqrsPQRS";
144 struct pt_ioctl *pt;
145
146 /* For now we only map the lower 8 bits of the minor */
147 if (n & ~0xff)
148 return (NODEV);
149
150 pt = malloc(sizeof(*pt), M_PTY, M_WAITOK | M_ZERO);
151 pt->devs = devs = make_dev(&pts_cdevsw, n,
152 UID_ROOT, GID_WHEEL, 0666, "tty%c%r", names[n / 32], n % 32);
153 pt->devc = devc = make_dev(&ptc_cdevsw, n,
154 UID_ROOT, GID_WHEEL, 0666, "pty%c%r", names[n / 32], n % 32);
155
156 devs->si_drv1 = devc->si_drv1 = pt;
157 devs->si_tty = devc->si_tty = &pt->pt_tty;
158 ttyregister(&pt->pt_tty);
159 return (devc);
160}
161
162/*ARGSUSED*/
163static int
164ptsopen(dev, flag, devtype, p)
165 dev_t dev;
166 int flag, devtype;
167 struct proc *p;
168{
169 register struct tty *tp;
170 int error;
171 struct pt_ioctl *pti;
172
173 if (!dev->si_drv1)
174 ptyinit(minor(dev));
175 if (!dev->si_drv1)
176 return(ENXIO);
177 pti = dev->si_drv1;
178 tp = dev->si_tty;
179 if ((tp->t_state & TS_ISOPEN) == 0) {
180 ttychars(tp); /* Set up default chars */
181 tp->t_iflag = TTYDEF_IFLAG;
182 tp->t_oflag = TTYDEF_OFLAG;
183 tp->t_lflag = TTYDEF_LFLAG;
--- 145 unchanged lines hidden (view full) ---
329 dev_t dev;
330 int flag, devtype;
331 struct proc *p;
332{
333 register struct tty *tp;
334 struct pt_ioctl *pti;
335
336 if (!dev->si_drv1)
337 ptyinit(minor(dev));
338 if (!dev->si_drv1)
339 return(ENXIO);
340 tp = dev->si_tty;
341 if (tp->t_oproc)
342 return (EIO);
343 tp->t_timeout = -1;
344 tp->t_oproc = ptsstart;
345 tp->t_stop = ptsstop;
--- 485 unchanged lines hidden (view full) ---
831 default: return;
832 }
833 if (name[4] >= '0' && name[4] <= '9')
834 u += name[4] - '0';
835 else if (name[4] >= 'a' && name[4] <= 'v')
836 u += name[4] - 'a' + 10;
837 else
838 return;
839 *dev = ptyinit(u);
840 return;
841}
842
843static void
844ptc_drvinit(unused)
845 void *unused;
846{
847 EVENTHANDLER_REGISTER(dev_clone, pty_clone, 0, 1000);
848 cdevsw_add(&pts_cdevsw);
849 cdevsw_add(&ptc_cdevsw);
850}
851
852SYSINIT(ptcdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR_C,ptc_drvinit,NULL)
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
--- 17 unchanged lines hidden (view full) ---
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)tty_pty.c 8.4 (Berkeley) 2/20/95
34 * $FreeBSD: head/sys/kern/tty_pty.c 74810 2001-03-26 12:41:29Z phk $
35 */
36
37/*
38 * Pseudo-teletype Driver
39 * (Actually two drivers, requiring two entries in 'cdevsw')
40 */
41#include "opt_compat.h"
42#include <sys/param.h>
--- 11 unchanged lines hidden (view full) ---
54#include <sys/signalvar.h>
55#include <sys/malloc.h>
56
57static MALLOC_DEFINE(M_PTY, "ptys", "pty data structures");
58
59static void ptsstart __P((struct tty *tp));
60static void ptsstop __P((struct tty *tp, int rw));
61static void ptcwakeup __P((struct tty *tp, int flag));
62static dev_t ptyinit __P((int n));
63
64static d_open_t ptsopen;
65static d_close_t ptsclose;
66static d_read_t ptsread;
67static d_write_t ptswrite;
68static d_ioctl_t ptyioctl;
69static d_open_t ptcopen;
70static d_close_t ptcclose;
--- 50 unchanged lines hidden (view full) ---
121};
122
123#define PF_PKT 0x08 /* packet mode */
124#define PF_STOPPED 0x10 /* user told stopped */
125#define PF_REMOTE 0x20 /* remote and flow controlled input */
126#define PF_NOSTOP 0x40
127#define PF_UCNTL 0x80 /* user control mode */
128
129/*
130 * This function creates and initializes a pts/ptc pair
131 *
132 * pts == /dev/tty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
133 * ptc == /dev/pty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
134 *
135 * XXX: define and add mapping of upper minor bits to allow more
136 * than 256 ptys.
137 */
138static dev_t
139ptyinit(n)
140 int n;
141{
142 dev_t devs, devc;
143 char *names = "pqrsPQRS";
144 struct pt_ioctl *pt;
145
146 /* For now we only map the lower 8 bits of the minor */
147 if (n & ~0xff)
148 return (NODEV);
149
150 pt = malloc(sizeof(*pt), M_PTY, M_WAITOK | M_ZERO);
151 pt->devs = devs = make_dev(&pts_cdevsw, n,
152 UID_ROOT, GID_WHEEL, 0666, "tty%c%r", names[n / 32], n % 32);
153 pt->devc = devc = make_dev(&ptc_cdevsw, n,
154 UID_ROOT, GID_WHEEL, 0666, "pty%c%r", names[n / 32], n % 32);
155
156 devs->si_drv1 = devc->si_drv1 = pt;
157 devs->si_tty = devc->si_tty = &pt->pt_tty;
158 ttyregister(&pt->pt_tty);
159 return (devc);
160}
161
162/*ARGSUSED*/
163static int
164ptsopen(dev, flag, devtype, p)
165 dev_t dev;
166 int flag, devtype;
167 struct proc *p;
168{
169 register struct tty *tp;
170 int error;
171 struct pt_ioctl *pti;
172
173 if (!dev->si_drv1)
174 ptyinit(minor(dev));
175 if (!dev->si_drv1)
176 return(ENXIO);
177 pti = dev->si_drv1;
178 tp = dev->si_tty;
179 if ((tp->t_state & TS_ISOPEN) == 0) {
180 ttychars(tp); /* Set up default chars */
181 tp->t_iflag = TTYDEF_IFLAG;
182 tp->t_oflag = TTYDEF_OFLAG;
183 tp->t_lflag = TTYDEF_LFLAG;
--- 145 unchanged lines hidden (view full) ---
329 dev_t dev;
330 int flag, devtype;
331 struct proc *p;
332{
333 register struct tty *tp;
334 struct pt_ioctl *pti;
335
336 if (!dev->si_drv1)
337 ptyinit(minor(dev));
338 if (!dev->si_drv1)
339 return(ENXIO);
340 tp = dev->si_tty;
341 if (tp->t_oproc)
342 return (EIO);
343 tp->t_timeout = -1;
344 tp->t_oproc = ptsstart;
345 tp->t_stop = ptsstop;
--- 485 unchanged lines hidden (view full) ---
831 default: return;
832 }
833 if (name[4] >= '0' && name[4] <= '9')
834 u += name[4] - '0';
835 else if (name[4] >= 'a' && name[4] <= 'v')
836 u += name[4] - 'a' + 10;
837 else
838 return;
839 *dev = ptyinit(u);
840 return;
841}
842
843static void
844ptc_drvinit(unused)
845 void *unused;
846{
847 EVENTHANDLER_REGISTER(dev_clone, pty_clone, 0, 1000);
848 cdevsw_add(&pts_cdevsw);
849 cdevsw_add(&ptc_cdevsw);
850}
851
852SYSINIT(ptcdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR_C,ptc_drvinit,NULL)