From owner-freebsd-stable Sat Feb 17 23:36:13 2001 Delivered-To: freebsd-stable@freebsd.org Received: from lafontaine.cybercable.fr (lafontaine.cybercable.fr [212.198.0.202]) by hub.freebsd.org (Postfix) with SMTP id 74D8C37B401 for ; Sat, 17 Feb 2001 23:36:03 -0800 (PST) Received: (qmail 46765090 invoked from network); 18 Feb 2001 07:35:57 -0000 Received: from d165.dhcp212-231.cybercable.fr (HELO gits.dyndns.org) ([212.198.231.165]) (envelope-sender ) by lafontaine.cybercable.fr (qmail-ldap-1.03) with SMTP for ; 18 Feb 2001 07:35:57 -0000 Received: (from root@localhost) by gits.dyndns.org (8.11.1/8.11.1) id f1I7ZqB51624; Sun, 18 Feb 2001 08:35:52 +0100 (CET) (envelope-from clefevre@poboxes.com) To: "Steve O'Hara-Smith" Cc: clefevre@poboxes.com, bobb+freebsd-stable@redbrick.dcu.ie, freebsd-stable@FreeBSD.ORG Subject: Re: More than 256 pty's (revised) References: <20010216172854.A67979@enigma.redbrick.dcu.ie> <20010216202737.1807da64.steveo@eircom.net> <66i9w8zd.fsf@gits.dyndns.org> <20010217180139.5269c474.steveo@eircom.net> X-Face: V|+c;4!|B?E%BE^{E6);aI.[<97Zd*>^#%Y5Cxv;%Y[PT-LW3;A:fRrJ8+^k"e7@+30g0YD0*^^3jgyShN7o?a]C la*Zv'5NA,=963bM%J^o]C Reply-To: Cyrille Lefevre In-Reply-To: "Steve O'Hara-Smith"'s message of "Sat, 17 Feb 2001 18:01:39 +0100" From: Cyrille Lefevre Date: 18 Feb 2001 08:35:47 +0100 Message-ID: Lines: 273 User-Agent: Gnus/5.0807 (Gnus v5.8.7) XEmacs/21.1 (Channel Islands) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG "Steve O'Hara-Smith" writes: > On 17 Feb 2001 17:49:10 +0100 > Cyrille Lefevre wrote: > > Seems to take it up to 704 ptys (now try explaining quickly how *that* > number comes up). Don't you also need to disable the test in ptsopen() on in fact, I made a small mistake in calculation of this magic number since /dev/tty[vxyzR]* shouldn't be counted. the magic number really is, using the first pty letter : ((('z' - 'p' + 1) * 2) - 5) * 32 = 17 * 32 = 544 ptys ^ ^ ^^ 0-9a-v |- p-z plus P-Z |- less vxyzR after that, you have to play w/ the second pty letter by extending the set from 0-9a-v to 0-9a-zA-Z, in that case, the limit is : 17 * 62 = 1054 ptys [snip, forgive my first quick, dirty and wrong (sorry) patch which didn't handle well the minor number, see bellow for something much better, but untested, yet, you're welcome to do it :)] > I was contemplating something with a /dev/pty/* and /dev/tty/* and > a really mindless naming convention that wouldn't ever bottom out. I hadn't > even started working on it. same about /dev/dsk/*, /dev/rmt/*, etc. the problem would be the compatibility w/ programs using ptys. xterm, as an example, only knowns ptys as : /dev/[tp]ty[pqrstuvwxyzPQRSTUVWXYZ][0123456789abcdefghijklmnopqrstuv] Index: etc/MAKEDEV =================================================================== RCS file: /home/ncvs/src/etc/MAKEDEV,v retrieving revision 1.243.2.20 diff -u -r1.243.2.20 MAKEDEV --- etc/MAKEDEV 2001/02/03 16:16:40 1.243.2.20 +++ etc/MAKEDEV 2001/02/18 07:23:03 @@ -225,6 +225,19 @@ echo $m } +# Convert pty (class,instance) to minor number +# Handle pty minor numbers greater than 256 +ptyminor() +{ + echo $(( (( ($1 + $2) &~ 255) << 8) | (($1 + $2) & 255) )) +} + +# *MUST* be the same as in sys/kern/tty_pty.c and lib/libutil/pty.c +ptyclassnames=pqrstuwPQSTUVWXYZ +ptyinstancenames=0123456789abcdefghijklmnopqrstuv +nptyclass=${#ptyclassnames} +nptyinstance=${#ptyinstancenames} + # Raw partition for disks dkrawpart=2 @@ -701,34 +714,25 @@ done ;; pty*) - class=`expr $i : 'pty\(.*\)'` - case $class in - 0) offset=0 name=p;; - 1) offset=32 name=q;; - 2) offset=64 name=r;; - 3) offset=96 name=s;; -# Note that xterm (at least) only look at p-s. - 4) offset=128 name=P;; - 5) offset=160 name=Q;; - 6) offset=192 name=R;; - 7) offset=224 name=S;; - # This still leaves [tuTU]. - *) echo bad unit for pty in: $i;; - esac umask 0 - case $class in - 0|1|2|3|4|5|6|7) + class=`expr $i : 'pty\(.*\)'` + if [ -n "$class" -a "$class" -lt $nptyclass ]; then + name=$(echo $ptyclassnames | + dd bs=1 skip=$class count=1 2>/dev/null) + offset=$(($class * 32)) i=0 while [ $i -lt 32 ]; do # This was an awk substr() before. - c=$(echo 0123456789abcdefghijklmnopqrstuv | + c=$(echo $ptyinstancenames | dd bs=1 skip=$i count=1 2>/dev/null) - mknod tty$name$c c 5 $(($offset + $i)) - mknod pty$name$c c 6 $(($offset + $i)) + minor=$(ptyminor $offset $i) + mknod tty$name$c c 5 $minor + mknod pty$name$c c 6 $minor i=$(($i + 1)) done - ;; - esac + else + echo bad unit for pty in: $i + fi umask 77 ;; Index: lib/libutil/pty.c =================================================================== RCS file: /home/ncvs/src/lib/libutil/pty.c,v retrieving revision 1.10 diff -u -r1.10 pty.c --- lib/libutil/pty.c 1999/08/28 00:05:51 1.10 +++ lib/libutil/pty.c 2001/02/18 07:23:18 @@ -53,6 +53,10 @@ #include #include +/* *MUST* be the same as in sys/kern/tty_pty.c and etc/MAKEDEV */ +#define ptyclassnames "pqrstuwPQSTUVWXYZ" +#define ptyinstancenames "0123456789abcdefghijklmnopqrstuv" + int openpty(amaster, aslave, name, termp, winp) int *amaster, *aslave; @@ -70,9 +74,9 @@ else ttygid = -1; - for (cp1 = "pqrsPQRS"; *cp1; cp1++) { + for (cp1 = ptyclassnames; *cp1; cp1++) { line[8] = *cp1; - for (cp2 = "0123456789abcdefghijklmnopqrstuv"; *cp2; cp2++) { + for (cp2 = ptyinstancenames; *cp2; cp2++) { line[5] = 'p'; line[9] = *cp2; if ((master = open(line, O_RDWR, 0)) == -1) { Index: share/man/man4/pty.4 =================================================================== RCS file: /home/ncvs/src/share/man/man4/pty.4,v retrieving revision 1.8.2.1 diff -u -r1.8.2.1 pty.4 --- share/man/man4/pty.4 2000/12/08 14:59:07 1.8.2.1 +++ share/man/man4/pty.4 2001/02/18 07:17:36 @@ -191,10 +191,10 @@ is required. .El .Sh FILES -.Bl -tag -width /dev/tty[p-sP-S][0-9a-v]x -compact -.It Pa /dev/pty[p-sP-S][0-9a-v] +.Bl -tag -width /dev/tty[p-uwPQS-Z][0-9a-v]x -compact +.It Pa /dev/pty[p-uwPQS-Z][0-9a-v] master pseudo terminals -.It Pa /dev/tty[p-sP-S][0-9a-v] +.It Pa /dev/tty[p-uwPQS-Z][0-9a-v] slave pseudo terminals .El .Sh DIAGNOSTICS Index: sys/kern/tty_pty.c =================================================================== RCS file: /home/ncvs/src/sys/kern/tty_pty.c,v retrieving revision 1.74 diff -u -r1.74 tty_pty.c --- sys/kern/tty_pty.c 2000/02/09 03:32:11 1.74 +++ sys/kern/tty_pty.c 2001/02/18 07:32:05 @@ -127,33 +127,46 @@ #define PF_NOSTOP 0x40 #define PF_UCNTL 0x80 /* user control mode */ +#define ptyminor(x) ((((x) &~ 255) << 8) | ((x) & 255)) +/* *MUST* be the same as in lib/libutil/pty.c and etc/MAKEDEV */ +#define ptyclassnames "pqrstuwPQSTUVWXYZ" +#define ptyinstancenames "0123456789abcdefghijklmnopqrstuv" +#define nptyclass (sizeof(ptyclassnames)-1) +#define nptyinstance (sizeof(ptyinstancenames)-1) +#define npty (nptyclass*nptyinstance) + /* * This function creates and initializes a pts/ptc pair + * + * pts == /dev/tty[pqrstuwPQSTUVWXYZ][0123456789abcdefghijklmnopqrstuv] + * ptc == /dev/pty[pqrstuwPQSTUVWXYZ][0123456789abcdefghijklmnopqrstuv] * - * pts == /dev/tty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv] - * ptc == /dev/pty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv] + * don't use the following master/slave pairs since they names clash w/ + * other drivers (maybe this should be the reverse?) : * - * XXX: define and add mapping of upper minor bits to allow more - * than 256 ptys. + * ttyv == syscons + * tty[xyz] == Cronyx/Sigma + * ttyR == Rocketport + * */ static void ptyinit(n) int n; { dev_t devs, devc; - char *names = "pqrsPQRS"; + char *names = ptyclassnames; struct pt_ioctl *pt; - /* For now we only map the lower 8 bits of the minor */ - if (n & ~0xff) + /* be safe */ + if (n > npty) return; pt = malloc(sizeof(*pt), M_PTY, M_WAITOK); bzero(pt, sizeof(*pt)); pt->devs = devs = make_dev(&pts_cdevsw, n, - 0, 0, 0666, "tty%c%r", names[n / 32], n % 32); + 0, 0, 0666, "tty%c%r", names[n / nptyinstance], n % nptyinstance); pt->devc = devc = make_dev(&ptc_cdevsw, n, - 0, 0, 0666, "pty%c%r", names[n / 32], n % 32); + 0, 0, 0666, "pty%c%r", names[n / nptyinstance], n % nptyinstance); devs->si_drv1 = devc->si_drv1 = pt; devs->si_tty = devc->si_tty = &pt->pt_tty; @@ -169,7 +182,7 @@ { register struct tty *tp; int error; - int minr; + int minr, nextminr; dev_t nextdev; struct pt_ioctl *pti; @@ -179,14 +192,15 @@ * next one too, so people can open it. */ minr = lminor(dev); - if (minr < 255) { - nextdev = makedev(major(dev), minr + 1); + nextminr = minr+1; + if (nextminr < npty) { + nextdev = makedev(major(dev), ptyminor(nextminr)); if (!nextdev->si_drv1) { - ptyinit(minr + 1); + ptyinit(nextminr); } } if (!dev->si_drv1) - ptyinit(minor(dev)); + ptyinit(minr); if (!dev->si_drv1) return(ENXIO); pti = dev->si_drv1; @@ -349,9 +363,9 @@ struct pt_ioctl *pti; if (!dev->si_drv1) - ptyinit(minor(dev)); + ptyinit(lminor(dev)); if (!dev->si_drv1) - return(ENXIO); + return(ENXIO); tp = dev->si_tty; if (tp->t_oproc) return (EIO); Cyrille. -- home: mailto:clefevre@poboxes.com UNIX is user-friendly; it's just particular work: mailto:Cyrille.Lefevre@edf.fr about who it chooses to be friends with. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-stable" in the body of the message