Index: tty_pty.c =================================================================== RCS file: /usr/cvs/src/sys/kern/tty_pty.c,v retrieving revision 1.152 diff -u -r1.152 tty_pty.c --- tty_pty.c 3 Jul 2007 17:45:52 -0000 1.152 +++ tty_pty.c 8 Nov 2007 15:15:09 -0000 @@ -40,6 +40,7 @@ #include "opt_tty.h" #include #include +#include #include #include #include @@ -127,9 +128,6 @@ * * 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. */ static struct cdev * ptyinit(struct cdev *devc, struct thread *td) @@ -137,9 +135,10 @@ struct ptsc *pt; int n; - n = minor(devc); - /* For now we only map the lower 8 bits of the minor */ - if (n & ~0xff) + n = minor2unit(minor(devc)); + + /* We only allow for up to 32 ptys per char in "names". */ + if (n >= 32 * strlen(names)) return (NULL); devc->si_flags &= ~SI_CHEAPCLONE; @@ -760,32 +759,26 @@ pty_clone(void *arg, struct ucred *cr, char *name, int namelen, struct cdev **dev) { + char *cp; int u; if (*dev != NULL) return; if (bcmp(name, "pty", 3) != 0) return; - if (name[5] != '\0') + if (name[5] != '\0' || name[3] == '\0') return; - switch (name[3]) { - case 'p': u = 0; break; - case 'q': u = 32; break; - case 'r': u = 64; break; - case 's': u = 96; break; - case 'P': u = 128; break; - case 'Q': u = 160; break; - case 'R': u = 192; break; - case 'S': u = 224; break; - default: return; - } + cp = index(names, name[3]); + if (cp == NULL) + return; + u = (cp - names) * 32; if (name[4] >= '0' && name[4] <= '9') u += name[4] - '0'; else if (name[4] >= 'a' && name[4] <= 'v') u += name[4] - 'a' + 10; else return; - *dev = make_dev_credf(MAKEDEV_REF, &ptc_cdevsw, u, cr, + *dev = make_dev_credf(MAKEDEV_REF, &ptc_cdevsw, unit2minor(u), cr, UID_ROOT, GID_WHEEL, 0666, "pty%c%r", names[u / 32], u % 32); (*dev)->si_flags |= SI_CHEAPCLONE; return;