Deleted Added
full compact
34c34
< * $Id: tty_pty.c,v 1.60 1999/05/30 16:52:57 phk Exp $
---
> * $Id: tty_pty.c,v 1.61 1999/05/31 11:27:38 phk Exp $
43d42
< #include "opt_devfs.h"
57a57
> #include <sys/malloc.h>
59,61c59
< #ifdef DEVFS
< #include <sys/devfsext.h>
< #endif /*DEVFS*/
---
> MALLOC_DEFINE(M_PTY, "ptys", "pty data structures");
63,65d60
< #ifdef notyet
< static void ptyattach __P((int n));
< #endif
67a63
> static void ptyinit __P((int n));
128,145d123
< #if NPTY == 1
< #undef NPTY
< #define NPTY 32 /* crude XXX */
< #warning You have only one pty defined, redefining to 32.
< #endif
<
< #ifdef DEVFS
< #define MAXUNITS (8 * 32)
< static void *devfs_token_pts[MAXUNITS];
< static void *devfs_token_ptc[MAXUNITS];
< static const char jnames[] = "pqrsPQRS";
< #if NPTY > MAXUNITS
< #undef NPTY
< #define NPTY MAXUNITS
< #warning Can't have more than 256 pty's with DEVFS defined.
< #endif
< #endif
<
148,153c126
< /*
< * pts == /dev/tty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
< * ptc == /dev/pty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
< */
< static struct tty pt_tty[NPTY]; /* XXX */
< static struct pt_ioctl {
---
> struct pt_ioctl {
158,159c131,132
< } pt_ioctl[NPTY]; /* XXX */
< static int npty = NPTY; /* for pstat -t */
---
> struct tty pt_tty;
> };
167d139
< #ifdef notyet
169c141
< * Establish n (or default if n is 1) ptys in the system.
---
> * This function creates and initializes a pts/ptc pair
171c143,147
< * XXX cdevsw & pstat require the array `pty[]' to be an array
---
> * pts == /dev/tty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
> * ptc == /dev/pty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
> *
> * XXX: define and add mapping of upper minor bits to allow more
> * than 256 ptys.
174c150
< ptyattach(n)
---
> ptyinit(n)
177,179c153,155
< char *mem;
< register u_long ntb;
< #define DEFAULT_NPTY 32
---
> dev_t devs, devc;
> char *names = "pqrsPQRS";
> struct pt_ioctl *pt;
181,190c157,169
< /* maybe should allow 0 => none? */
< if (n <= 1)
< n = DEFAULT_NPTY;
< ntb = n * sizeof(struct tty);
< mem = malloc(ntb + ALIGNBYTES + n * sizeof(struct pt_ioctl),
< M_DEVBUF, M_WAITOK);
< pt_tty = (struct tty *)mem;
< mem = (char *)ALIGN(mem + ntb);
< pt_ioctl = (struct pt_ioctl *)mem;
< npty = n;
---
> /* For now we only map the lower 8 bits of the minor */
> if (n & ~0xff)
> return;
>
> devs = make_dev(&pts_cdevsw, n,
> 0, 0, 0666, "tty%c%r", names[n / 32], n % 32);
> devc = make_dev(&ptc_cdevsw, n,
> 0, 0, 0666, "pty%c%r", names[n / 32], n % 32);
>
> pt = malloc(sizeof(*pt), M_PTY, M_WAITOK);
> bzero(pt, sizeof(*pt));
> devs->si_drv1 = devc->si_drv1 = pt;
> devs->si_tty_tty = devc->si_tty_tty = &pt->pt_tty;
192d170
< #endif
204,206c182,186
< if (minor(dev) >= npty)
< return (ENXIO);
< tp = &pt_tty[minor(dev)];
---
> if (!dev->si_drv1)
> ptyinit(minor(dev));
> if (!dev->si_drv1)
> return(ENXIO);
> tp = dev->si_tty_tty;
241c221
< tp = &pt_tty[minor(dev)];
---
> tp = dev->si_tty_tty;
255,256c235,236
< register struct tty *tp = &pt_tty[minor(dev)];
< register struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
---
> register struct tty *tp = dev->si_tty_tty;
> register struct pt_ioctl *pti = dev->si_drv1;
311c291
< tp = &pt_tty[minor(dev)];
---
> tp = dev->si_tty_tty;
325c305
< register struct pt_ioctl *pti = &pt_ioctl[minor(tp->t_dev)];
---
> register struct pt_ioctl *pti = tp->t_dev->si_drv1;
341c321
< struct pt_ioctl *pti = &pt_ioctl[minor(tp->t_dev)];
---
> struct pt_ioctl *pti = tp->t_dev->si_drv1;
362,364c342,346
< if (minor(dev) >= npty)
< return (ENXIO);
< tp = &pt_tty[minor(dev)];
---
> if (!dev->si_drv1)
> ptyinit(minor(dev));
> if (!dev->si_drv1)
> return(ENXIO);
> tp = dev->si_tty_tty;
368,370d349
< #ifdef sun4c
< tp->t_stop = ptsstop;
< #endif
373c352
< pti = &pt_ioctl[minor(dev)];
---
> pti = dev->si_drv1;
389c368
< tp = &pt_tty[minor(dev)];
---
> tp = dev->si_tty_tty;
416,417c395,396
< register struct tty *tp = &pt_tty[minor(dev)];
< struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
---
> register struct tty *tp = dev->si_tty_tty;
> struct pt_ioctl *pti = dev->si_drv1;
477c456
< struct pt_ioctl *pti = &pt_ioctl[minor(tp->t_dev)];
---
> struct pt_ioctl *pti = tp->t_dev->si_drv1;
502,503c481,482
< register struct tty *tp = &pt_tty[minor(dev)];
< struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
---
> register struct tty *tp = dev->si_tty_tty;
> struct pt_ioctl *pti = dev->si_drv1;
552c531
< register struct tty *tp = &pt_tty[minor(dev)];
---
> register struct tty *tp = dev->si_tty_tty;
557c536
< struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
---
> struct pt_ioctl *pti = dev->si_drv1;
660c639
< if (minor(dev) >= npty)
---
> if (minor(dev) & ~0xff)
663c642
< return &pt_tty[minor(dev)];
---
> return dev->si_tty_tty;
675,676c654,655
< register struct tty *tp = &pt_tty[minor(dev)];
< register struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
---
> register struct tty *tp = dev->si_tty_tty;
> register struct pt_ioctl *pti = dev->si_drv1;
836d814
< static int ptc_devsw_installed;
838a817
>
843,845c822
< #ifdef DEVFS
< int i,j,k;
< #endif
---
> static int ptc_devsw_installed;
851,864d827
< #ifdef DEVFS
< for ( i = 0 ; i<NPTY ; i++ ) {
< j = i / 32;
< k = i % 32;
< devfs_token_pts[i] =
< devfs_add_devswf(&pts_cdevsw,i,
< DV_CHR,0,0,0666,
< "tty%c%r",jnames[j],k);
< devfs_token_ptc[i] =
< devfs_add_devswf(&ptc_cdevsw,i,
< DV_CHR,0,0,0666,
< "pty%c%r",jnames[j],k);
< }
< #endif