Deleted Added
full compact
pty.c (64880) pty.c (65374)
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
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 64880 2000-08-20 21:34:39Z phk $
34 * $FreeBSD: head/sys/kern/tty_pty.c 65374 2000-09-02 19:17:34Z phk $
35 */
36
37/*
38 * Pseudo-teletype Driver
39 * (Actually two drivers, requiring two entries in 'cdevsw')
40 */
41#include "opt_compat.h"
35 */
36
37/*
38 * Pseudo-teletype Driver
39 * (Actually two drivers, requiring two entries in 'cdevsw')
40 */
41#include "opt_compat.h"
42#include "opt_devfs.h"
43#include <sys/param.h>
44#include <sys/systm.h>
45#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
46#include <sys/ioctl_compat.h>
47#endif
48#include <sys/proc.h>
49#include <sys/tty.h>
50#include <sys/conf.h>
51#include <sys/fcntl.h>
52#include <sys/poll.h>
53#include <sys/kernel.h>
54#include <sys/vnode.h>
55#include <sys/signalvar.h>
56#include <sys/malloc.h>
57
42#include <sys/param.h>
43#include <sys/systm.h>
44#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
45#include <sys/ioctl_compat.h>
46#endif
47#include <sys/proc.h>
48#include <sys/tty.h>
49#include <sys/conf.h>
50#include <sys/fcntl.h>
51#include <sys/poll.h>
52#include <sys/kernel.h>
53#include <sys/vnode.h>
54#include <sys/signalvar.h>
55#include <sys/malloc.h>
56
58#ifdef DEVFS
59#include <sys/eventhandler.h>
60#include <fs/devfs/devfs.h>
61#endif
62
63MALLOC_DEFINE(M_PTY, "ptys", "pty data structures");
64
65static void ptsstart __P((struct tty *tp));
66static void ptsstop __P((struct tty *tp, int rw));
67static void ptcwakeup __P((struct tty *tp, int flag));
68static dev_t ptyinit __P((int n));
69
70static d_open_t ptsopen;

--- 101 unchanged lines hidden (view full) ---

172 dev_t dev;
173 int flag, devtype;
174 struct proc *p;
175{
176 register struct tty *tp;
177 int error;
178 struct pt_ioctl *pti;
179
57MALLOC_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;

--- 101 unchanged lines hidden (view full) ---

166 dev_t dev;
167 int flag, devtype;
168 struct proc *p;
169{
170 register struct tty *tp;
171 int error;
172 struct pt_ioctl *pti;
173
180#ifndef DEVFS
181 {
182 int minr = lminor(dev);
183 /*
184 * If we openned this device, ensure we have the
185 * next one too, so people can open it.
186 */
187 if (minr < 255) {
188 dev_t nextdev = makedev(major(dev), minr + 1);
189 if (!nextdev->si_drv1) {
190 ptyinit(minr + 1);
191 }
192 }
193 if (!dev->si_drv1)
194 ptyinit(minor(dev));
174 if (!dev->si_drv1)
175 ptyinit(minor(dev));
195 }
196#endif
197 if (!dev->si_drv1)
198 return(ENXIO);
199 pti = dev->si_drv1;
200 tp = dev->si_tty;
201 if ((tp->t_state & TS_ISOPEN) == 0) {
202 ttychars(tp); /* Set up default chars */
203 tp->t_iflag = TTYDEF_IFLAG;
204 tp->t_oflag = TTYDEF_OFLAG;

--- 145 unchanged lines hidden (view full) ---

350ptcopen(dev, flag, devtype, p)
351 dev_t dev;
352 int flag, devtype;
353 struct proc *p;
354{
355 register struct tty *tp;
356 struct pt_ioctl *pti;
357
176 if (!dev->si_drv1)
177 return(ENXIO);
178 pti = dev->si_drv1;
179 tp = dev->si_tty;
180 if ((tp->t_state & TS_ISOPEN) == 0) {
181 ttychars(tp); /* Set up default chars */
182 tp->t_iflag = TTYDEF_IFLAG;
183 tp->t_oflag = TTYDEF_OFLAG;

--- 145 unchanged lines hidden (view full) ---

329ptcopen(dev, flag, devtype, p)
330 dev_t dev;
331 int flag, devtype;
332 struct proc *p;
333{
334 register struct tty *tp;
335 struct pt_ioctl *pti;
336
358#ifndef DEVFS
359 if (!dev->si_drv1)
360 ptyinit(minor(dev));
337 if (!dev->si_drv1)
338 ptyinit(minor(dev));
361#endif
362 if (!dev->si_drv1)
363 return(ENXIO);
364 tp = dev->si_tty;
365 if (tp->t_oproc)
366 return (EIO);
367 tp->t_timeout = -1;
368 tp->t_oproc = ptsstart;
369 tp->t_stop = ptsstop;

--- 451 unchanged lines hidden (view full) ---

821 }
822 }
823 return (error);
824}
825
826
827static void ptc_drvinit __P((void *unused));
828
339 if (!dev->si_drv1)
340 return(ENXIO);
341 tp = dev->si_tty;
342 if (tp->t_oproc)
343 return (EIO);
344 tp->t_timeout = -1;
345 tp->t_oproc = ptsstart;
346 tp->t_stop = ptsstop;

--- 451 unchanged lines hidden (view full) ---

798 }
799 }
800 return (error);
801}
802
803
804static void ptc_drvinit __P((void *unused));
805
829#ifdef DEVFS
830static void pty_clone __P((void *arg, char *name, int namelen, dev_t *dev));
831
832static void
833pty_clone(arg, name, namelen, dev)
834 void *arg;
835 char *name;
836 int namelen;
837 dev_t *dev;

--- 22 unchanged lines hidden (view full) ---

860 else if (name[4] >= 'a' && name[4] <= 'v')
861 u += name[4] - 'a' + 10;
862 else
863 return;
864 *dev = ptyinit(u);
865 return;
866}
867
806static void pty_clone __P((void *arg, char *name, int namelen, dev_t *dev));
807
808static void
809pty_clone(arg, name, namelen, dev)
810 void *arg;
811 char *name;
812 int namelen;
813 dev_t *dev;

--- 22 unchanged lines hidden (view full) ---

836 else if (name[4] >= 'a' && name[4] <= 'v')
837 u += name[4] - 'a' + 10;
838 else
839 return;
840 *dev = ptyinit(u);
841 return;
842}
843
868
869#endif
870
871static void
872ptc_drvinit(unused)
873 void *unused;
874{
844static void
845ptc_drvinit(unused)
846 void *unused;
847{
875#ifdef DEVFS
876 EVENTHANDLER_REGISTER(devfs_clone, pty_clone, 0, 1000);
877#else
848 EVENTHANDLER_REGISTER(dev_clone, pty_clone, 0, 1000);
878 cdevsw_add(&pts_cdevsw);
879 cdevsw_add(&ptc_cdevsw);
849 cdevsw_add(&pts_cdevsw);
850 cdevsw_add(&ptc_cdevsw);
880 ptyinit(0);
881#endif
882}
883
884SYSINIT(ptcdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR_C,ptc_drvinit,NULL)
851}
852
853SYSINIT(ptcdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR_C,ptc_drvinit,NULL)