View | Details | Raw Unified | Return to bug 25866
Collapse All | Expand All

(-)etc/MAKEDEV (-22 / +27 lines)
Lines 231-236 Link Here
231
  echo $(((($1 >> 8) << 16) | ($1 % 256)))
231
  echo $(((($1 >> 8) << 16) | ($1 % 256)))
232
}
232
}
233
233
234
# Convert pty (class,instance) to minor number
235
# Handle pty minor numbers greater than 256
236
ptyminor()
237
{
238
	echo $(( (( ($1 + $2) &~ 255) << 8) | (($1 + $2) & 255) ))
239
}
240
241
# *MUST* be the same as in sys/kern/tty_pty.c and lib/libutil/pty.c
242
ptyclassnames=pqrstuwxyzPQRSTUVWXYZ
243
ptyinstancenames=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
244
nptyclass=${#ptyclassnames}
245
nptyinstance=${#ptyinstancenames}
246
234
# Raw partition for disks
247
# Raw partition for disks
235
dkrawpart=2
248
dkrawpart=2
236
249
Lines 707-740 Link Here
707
	done	
720
	done	
708
	;;
721
	;;
709
pty*)
722
pty*)
710
	class=`expr $i : 'pty\(.*\)'`
711
	case $class in
712
	0) offset=0 name=p;;
713
	1) offset=32 name=q;;
714
	2) offset=64 name=r;;
715
	3) offset=96 name=s;;
716
# Note that xterm (at least) only look at p-s.
717
	4) offset=128 name=P;;
718
	5) offset=160 name=Q;;
719
	6) offset=192 name=R;;
720
	7) offset=224 name=S;;
721
	# This still leaves [tuTU].
722
	*) echo bad unit for pty in: $i;;
723
	esac
724
	umask 0
723
	umask 0
725
	case $class in
724
	class=`expr $i : 'pty\(.*\)'`
726
	0|1|2|3|4|5|6|7)
725
	if [ -n "$class" -a "$class" -lt $nptyclass ]; then
726
		name=$(echo $ptyclassnames |
727
		       dd bs=1 skip=$class count=1 2>/dev/null)
728
		offset=$(($class * $nptyintance))
727
		i=0
729
		i=0
728
		while [ $i -lt 32 ]; do
730
		while [ $i -lt $nptyintance ]; do
729
#			This was an awk substr() before.
731
#			This was an awk substr() before.
730
			c=$(echo 0123456789abcdefghijklmnopqrstuv |
732
			c=$(echo $ptyinstancenames |
731
			    dd bs=1 skip=$i count=1 2>/dev/null)
733
			    dd bs=1 skip=$i count=1 2>/dev/null)
732
			mknod tty$name$c c 5 $(($offset + $i))
734
			minor=$(ptyminor $offset $i)
733
			mknod pty$name$c c 6 $(($offset + $i))
735
			rm -f tty$name$c pty$name$c
736
			mknod tty$name$c c 5 $minor
737
			mknod pty$name$c c 6 $minor
734
			i=$(($i + 1))
738
			i=$(($i + 1))
735
		done
739
		done
736
		;;
740
	else
737
	esac
741
		echo bad unit for pty in: $i
742
	fi
738
	umask 77
743
	umask 77
739
	;;
744
	;;
740
745
(-)lib/libutil/pty.c (-2 / +6 lines)
Lines 53-58 Link Here
53
#include <unistd.h>
53
#include <unistd.h>
54
#include <libutil.h>
54
#include <libutil.h>
55
55
56
/* *MUST* be the same as in sys/kern/tty_pty.c and etc/MAKEDEV */
57
#define ptyclassnames	"pqrstuwxyzPQRSTUVWXYZ"
58
#define ptyinstancenames "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
59
56
int
60
int
57
openpty(amaster, aslave, name, termp, winp)
61
openpty(amaster, aslave, name, termp, winp)
58
	int *amaster, *aslave;
62
	int *amaster, *aslave;
Lines 70-78 Link Here
70
	else
74
	else
71
		ttygid = -1;
75
		ttygid = -1;
72
76
73
	for (cp1 = "pqrsPQRS"; *cp1; cp1++) {
77
	for (cp1 = ptyclassnames; *cp1; cp1++) {
74
		line[8] = *cp1;
78
		line[8] = *cp1;
75
		for (cp2 = "0123456789abcdefghijklmnopqrstuv"; *cp2; cp2++) {
79
		for (cp2 = ptyinstancenames; *cp2; cp2++) {
76
			line[5] = 'p';
80
			line[5] = 'p';
77
			line[9] = *cp2;
81
			line[9] = *cp2;
78
			if ((master = open(line, O_RDWR, 0)) == -1) {
82
			if ((master = open(line, O_RDWR, 0)) == -1) {
(-)share/man/man4/pty.4 (-3 / +3 lines)
Lines 191-200 Link Here
191
is required.
191
is required.
192
.El
192
.El
193
.Sh FILES
193
.Sh FILES
194
.Bl -tag -width /dev/tty[p-sP-S][0-9a-v]x -compact
194
.Bl -tag -width /dev/tty[p-uw-zP-Z][0-9a-zA-Z]x -compact
195
.It Pa /dev/pty[p-sP-S][0-9a-v]
195
.It Pa /dev/pty[p-uw-zP-Z][0-9a-zA-Z]
196
master pseudo terminals
196
master pseudo terminals
197
.It Pa /dev/tty[p-sP-S][0-9a-v]
197
.It Pa /dev/tty[p-uw-zP-Z][0-9a-zA-Z]
198
slave pseudo terminals
198
slave pseudo terminals
199
.El
199
.El
200
.Sh DIAGNOSTICS
200
.Sh DIAGNOSTICS
(-)sys/kern/tty_pty.c (-21 / +48 lines)
Lines 129-161 Link Here
129
#define	PF_NOSTOP	0x40
129
#define	PF_NOSTOP	0x40
130
#define PF_UCNTL	0x80		/* user control mode */
130
#define PF_UCNTL	0x80		/* user control mode */
131
131
132
/* the opposite of lminor() */
133
#define ptyminor(x)	((((x) &~ 255) << 8) | ((x) & 255))
134
/* *MUST* be the same as in lib/libutil/pty.c and etc/MAKEDEV */
135
#define ptyclassnames	"pqrstuwxyzPQRSTUVWXYZ"
136
#define ptyinstancenames "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
137
#define nptyclass	(sizeof(ptyclassnames)-1)
138
#define nptyinstance	(sizeof(ptyinstancenames)-1)
139
#define npty		(nptyclass*nptyinstance)
140
132
/*
141
/*
133
 * This function creates and initializes a pts/ptc pair
142
 * This function creates and initializes a pts/ptc pair
143
 *
144
 * pts == /dev/tty[p-uw-zP-Z][0-9a-zA-Z]
145
 * ptc == /dev/pty[p-uw-zP-Z][0-9a-zA-Z]
134
 *
146
 *
135
 * pts == /dev/tty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
147
 * don't use the "v" master/slave pair bcoz it clash w/ the syscons driver.
136
 * ptc == /dev/pty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
148
 * same assertion about the less used Cronyx/Sigma (xyz) and Rocketport (R)
149
 * drivers.
137
 *
150
 *
138
 * XXX: define and add mapping of upper minor bits to allow more 
139
 *      than 256 ptys.
140
 */
151
 */
141
static void
152
static void
142
ptyinit(n)
153
ptyinit(n)
143
	int n;
154
	int n;
144
{
155
{
145
	dev_t devs, devc;
156
	dev_t devs, devc;
146
	char *names = "pqrsPQRS";
157
	char *classes = ptyclassnames;
158
	char *instances = ptyinstancenames;
147
	struct pt_ioctl *pt;
159
	struct pt_ioctl *pt;
148
160
149
	/* For now we only map the lower 8 bits of the minor */
161
#ifdef notdef
150
	if (n & ~0xff)
162
	if (bootverbose)
163
		printf ("ptyinit: n(%d) <= %d\n", n, npty);
164
#endif
165
	/* be safe */
166
	if (n >= npty)
151
		return;
167
		return;
152
168
#ifdef notdef
169
	if (bootverbose)
170
		printf ("ptyinit: makedev([tp]ty%c%c)\n",
171
			classes[n / nptyinstance], instances[n % nptyinstance]);
172
#endif
153
	pt = malloc(sizeof(*pt), M_PTY, M_WAITOK);
173
	pt = malloc(sizeof(*pt), M_PTY, M_WAITOK);
154
	bzero(pt, sizeof(*pt));
174
	bzero(pt, sizeof(*pt));
155
	pt->devs = devs = make_dev(&pts_cdevsw, n,
175
	pt->devs = devs = make_dev(&pts_cdevsw, ptyminor(n),
156
	    0, 0, 0666, "tty%c%r", names[n / 32], n % 32);
176
	    0, 0, 0666, "tty%c%c",
157
	pt->devc = devc = make_dev(&ptc_cdevsw, n,
177
	    classes[n / nptyinstance], instances[n % nptyinstance]);
158
	    0, 0, 0666, "pty%c%r", names[n / 32], n % 32);
178
	pt->devc = devc = make_dev(&ptc_cdevsw, ptyminor(n),
179
	    0, 0, 0666, "pty%c%c",
180
	    classes[n / nptyinstance], instances[n % nptyinstance]);
159
181
160
	devs->si_drv1 = devc->si_drv1 = pt;
182
	devs->si_drv1 = devc->si_drv1 = pt;
161
	devs->si_tty = devc->si_tty = &pt->pt_tty;
183
	devs->si_tty = devc->si_tty = &pt->pt_tty;
Lines 171-177 Link Here
171
{
193
{
172
	register struct tty *tp;
194
	register struct tty *tp;
173
	int error;
195
	int error;
174
	int minr;
196
	int minr, nextminr;
175
	dev_t nextdev;
197
	dev_t nextdev;
176
	struct pt_ioctl *pti;
198
	struct pt_ioctl *pti;
177
199
Lines 181-194 Link Here
181
	 * next one too, so people can open it.
203
	 * next one too, so people can open it.
182
	 */
204
	 */
183
	minr = lminor(dev);
205
	minr = lminor(dev);
184
	if (minr < 255) {
206
	nextminr = minr+1;
185
		nextdev = makedev(major(dev), minr + 1);
207
	if (nextminr < npty) {
186
		if (!nextdev->si_drv1) {
208
		nextdev = makedev(major(dev), ptyminor(nextminr));
187
			ptyinit(minr + 1);
209
		if (!nextdev->si_drv1)
188
		}
210
			ptyinit(nextminr);
189
	}
211
	}
190
	if (!dev->si_drv1)
212
	if (!dev->si_drv1)
191
		ptyinit(minor(dev));
213
		ptyinit(minr);
214
#ifdef notdef
215
	if (bootverbose)
216
		printf ("ptyopen: makedev(%d:%#x)\n",
217
			major(dev), ptyminor(minr));
218
#endif
192
	if (!dev->si_drv1)
219
	if (!dev->si_drv1)
193
		return(ENXIO);	
220
		return(ENXIO);	
194
	pti = dev->si_drv1;
221
	pti = dev->si_drv1;
Lines 351-359 Link Here
351
	struct pt_ioctl *pti;
378
	struct pt_ioctl *pti;
352
379
353
	if (!dev->si_drv1)
380
	if (!dev->si_drv1)
354
		ptyinit(minor(dev));
381
		ptyinit(lminor(dev));
355
	if (!dev->si_drv1)
382
	if (!dev->si_drv1)
356
		return(ENXIO);	
383
		return(ENXIO);
357
	tp = dev->si_tty;
384
	tp = dev->si_tty;
358
	if (tp->t_oproc)
385
	if (tp->t_oproc)
359
		return (EIO);
386
		return (EIO);

Return to bug 25866