1#!/bin/sh -
2#
3# THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.
4# generated from:
5#
6#	OpenBSD: etc.i386/MAKEDEV.md,v 1.96 2022/11/09 19:35:23 krw Exp
7#	OpenBSD: MAKEDEV.common,v 1.122 2025/01/08 23:09:25 kirill Exp
8#	OpenBSD: MAKEDEV.mi,v 1.83 2016/09/11 03:06:31 deraadt Exp
9#	OpenBSD: MAKEDEV.sub,v 1.14 2005/02/07 06:14:18 david Exp
10#
11#
12# Copyright (c) 2001-2004 Todd T. Fries <todd@OpenBSD.org>
13#
14# Permission to use, copy, modify, and distribute this software for any
15# purpose with or without fee is hereby granted, provided that the above
16# copyright notice and this permission notice appear in all copies.
17#
18# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
19# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
20# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
21# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
23# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
24# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25#
26# Device "make" file.  Valid arguments:
27#	all	makes all known devices, including local devices.
28#		Tries to make the ``standard'' number of each type.
29#	ramdisk	Ramdisk kernel devices
30#	std	Standard devices
31#	local	Configuration specific devices
32# Disks:
33#	cd*	ATAPI and SCSI CD-ROM drives
34#	fd*	Floppy disk drives (3 1/2", 5 1/4")
35#	rd*	"rd" pseudo-disks
36#	sd*	SCSI disks, including flopticals
37#	vnd*	"file" pseudo-disk devices
38#	wd*	"winchester" disk drives (ST506, IDE, ESDI, RLL, ...)
39# Tapes:
40#	ch*	SCSI media changers
41#	st*	SCSI tape drives
42# Terminal ports:
43#	tty[0-7][0-9a-f]	NS16x50 serial ports
44#	ttyc*	Cyclades serial ports
45# Pseudo terminals:
46#	ptm	pty master device
47#	pty*	Set of 62 master pseudo terminals
48#	tty*	Set of 62 slave pseudo terminals
49# Console ports:
50#	ttyC-J*	wscons display devices
51#	wscons	Minimal wscons devices
52#	wskbd*	wscons keyboards
53#	wsmux	wscons keyboard/mouse mux devices
54# Pointing devices:
55#	wsmouse*	wscons mice
56# Printers:
57#	lpa*	Polled printer port
58#	lpt*	IEEE 1284 centronics printer
59# USB devices:
60#	ttyU*	USB serial ports
61#	uall	All USB devices
62#	ugen*	Generic USB devices
63#	uhid*	Generic HID devices
64#	fido	fido/* nodes
65#	ujoy	ujoy/* nodes
66#	ulpt*	Printer devices
67#	usb*	Bus control devices used by usbd for attach/detach
68# Special purpose devices:
69#	amdmsr	AMD MSR access device
70#	apm	Power management device
71#	audio*	Audio devices
72#	bio	ioctl tunnel pseudo-device
73#	bktr*	Video frame grabbers
74#	bpf	Berkeley Packet Filter
75#	dt	Dynamic Tracer
76#	diskmap	Disk mapper
77#	dri	Direct Rendering Infrastructure
78#	fd	fd/* nodes
79#	fuse	Userland Filesystem
80#	gpio*	General Purpose Input/Output
81#	hotplug	devices hot plugging
82#	ipmi*	IPMI BMC access
83#	joy*	Joystick driver
84#	kcov	Kernel code coverage tracing
85#	nvram	NVRAM access
86#	pci*	PCI bus devices
87#	pctr*	PC Performance Tuning Register access device
88#	pf	Packet Filter
89#	pppx*	PPP Multiplexer
90#	pppac*	PPP Access Concentrator
91#	radio*	FM tuner devices
92#	*random	In-kernel random data source
93#	rmidi*	Raw MIDI devices
94#	speaker	PC speaker
95#	tun*	Network tunnel driver
96#	tap*	Ethernet tunnel driver
97#	tuner*	Tuner devices
98#	uk*	Unknown SCSI devices
99#	video*	Video V4L2 devices
100#	vscsi*	Virtual SCSI controller
101#	pvbus*	paravirtual device tree root
102#	kstat	Kernel Statistics
103PATH=/sbin:/usr/sbin:/bin:/usr/bin
104T=$0
105
106# set this to echo for Echo-Only debugging
107[ "$eo" ] || eo=
108
109hex()
110{
111	case $1 in
112	[0-9]) echo -n $1;;
113	10) echo -n a;;
114	11) echo -n b;;
115	12) echo -n c;;
116	13) echo -n d;;
117	14) echo -n e;;
118	15) echo -n f;;
119	esac
120}
121
122alph2d()
123{
124	local t="$1"
125	local p="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
126	local sub=${p%${t}*}
127	echo ${#sub}
128}
129
130h2d()
131{
132	local s="$1"
133	local f=${s%*[0-9a-f]} n=${s#[0-9a-f]*}
134
135	echo $(($(_h2d $f)*16+ $(_h2d $n) ))
136}
137
138_h2d()
139{
140	case $1 in
141	[0-9]) echo -n $1;;
142	a) echo -n 10;;
143	b) echo -n 11;;
144	c) echo -n 12;;
145	d) echo -n 13;;
146	e) echo -n 14;;
147	f) echo -n 15;;
148	esac
149}
150
151unt()
152{
153	# XXX pdksh can't seem to deal with locally scoped variables
154	# in ${foo#$bar} expansions
155	arg="$1"
156	tmp="${arg#[a-zA-Z]*}"
157	tmp="${tmp%*[a-zA-Z]}"
158	while [ "$tmp" != "$arg" ]
159	do
160		arg=$tmp
161		tmp="${arg#[a-zA-Z]*}"
162		tmp="${tmp%*[a-zA-Z]}"
163	done
164	echo $arg
165}
166
167dodisk()
168{
169	[ "$DEBUG" ] && set -x
170	n=$(($((${5}*${7:-16}))+${6})) count=0
171	[ 0$7 -ne 8 ] && l="i j k l m n o p"
172	for d in a b c d e f g h $l
173	do
174		M $1$2$d	b $3 $(($n+$count)) 640 operator
175		M r$1$2$d	c $4 $(($n+$count)) 640 operator
176		let count=count+1
177	done
178}
179
180dodisk2()
181{
182	n=$(($(($5*${7:-16}))+$6))
183	M $1$2a b $3 $n 640 operator
184	M r$1$2a c $4 $n 640 operator
185	n=$(($n+2))
186	M $1$2c b $3 $n 640 operator
187	M r$1$2c c $4 $n 640 operator
188}
189
190# M name b/c major minor [mode] [group]
191RMlist[0]="rm -f"
192
193mkl() {
194	: ${mklist[0]:=";mknod"}
195	mklist[${#mklist[*]}]=" -m $1 $2 $3 $4 $5"
196}
197
198M() {
199	RMlist[${#RMlist[*]}]=$1
200	mkl ${5-666} $1 $2 $3 $4
201	G=${6:-wheel}
202	[ "$7" ] && {
203		MKlist[${#MKlist[*]}]="&& chown $7:$G $1"
204	} || {
205		case $G in
206		wheel)
207			[ ${#whlist[*]} = 0 ] && whlist[0]="&& chgrp wheel"
208			whlist[${#whlist[*]}]="$1"
209		;;
210		operator)
211			[ ${#oplist[*]} = 0 ] && oplist[0]="&& chgrp operator"
212			oplist[${#oplist[*]}]="$1"
213		;;
214		*)
215			MKlist[${#MKlist[*]}]="&& chgrp $G $1";
216		esac
217	}
218	return 0
219}
220
221R() {
222[ "$DEBUG" ] && set -x
223for i in "$@"
224do
225U=`unt $i`
226[ "$U" ] || U=0
227
228case $i in
229ramdisk)
230	R std bpf fd0 wd0 sd0 tty00 tty01 rd0 bio diskmap
231	R st0 cd0 ttyC0 wskbd0 wskbd1 wskbd2 apm random
232	;;
233
234std)
235	M console	c 0 0 600
236	M tty		c 1 0
237	M mem		c 2 0 640 kmem
238	M kmem		c 2 1 640 kmem
239	M null		c 2 2
240	M zero		c 2 12
241	M stdin		c 22 0
242	M stdout	c 22 1
243	M stderr	c 22 2
244	M ksyms		c 50 0 640 kmem
245	M klog		c 7 0 600
246	M xf86		c 2 4 600
247	;;
248
249ttyc*)
250	M ttyc$U c 38 $U 660 dialer root
251	M cuac$U c 38 $(($U+128)) 660 dialer root
252	;;
253
254kstat)
255	M kstat c 51 0 640
256	;;
257
258pvbus*)
259	M pvbus$U c 95 $U 640
260	;;
261
262vscsi*)
263	M vscsi$U c 90 $U 600
264	;;
265
266video*)
267	M video$U  c 44 $U 600
268	MKlist[${#MKlist[*]}]=";[ -e video ] || ln -s video$U video"
269	;;
270
271uk*)
272	M uk$U c 20 $U 640 operator
273	;;
274
275tuner*)
276	M tuner$U c 49 $(($(($U*2))+16)) 644
277	;;
278
279tap*)
280	M tap$U c 94 $U 600
281	;;
282
283tun*)
284	M tun$U c 40 $U 600
285	;;
286
287speaker)
288	M speaker c 27 0 600
289	;;
290
291rmidi*)
292	M rmidi$U c 52 $U 660 _sndiop
293	;;
294
295*random)
296	M urandom c 45 0 644
297	RMlist[${#RMlist[*]}]=random
298	MKlist[${#MKlist[*]}]=";ln -s urandom random"
299	;;
300
301radio*)
302	M radio$U	c 76 $U
303	MKlist[${#MKlist[*]}]=";[ -e radio ] || ln -s radio$U radio"
304	;;
305
306pppac*)
307	M pppac$U c 99 $U 600
308	;;
309
310pppx*)
311	M pppx$U c 92 $U 600
312	;;
313
314pf)
315	M pf c 73 0 600
316	;;
317
318pctr)
319	M pctr c 46 0 644
320	;;
321
322pci*)
323	M pci$U	c 72 $U 600
324	MKlist[${#MKlist[*]}]=";[ -h pci ] || ln -sf pci0 pci"
325	;;
326
327nvram)
328	M nvram c 84 0 440 kmem
329	;;
330
331kcov)
332	M kcov c 19 0 600
333	;;
334
335joy*)
336	M joy$U c 26 $U 666
337	;;
338
339ipmi*)
340	M ipmi$U c 96 $U 600
341	;;
342
343hotplug)
344	M hotplug c 82 $U 400
345	;;
346
347gpio*)
348	M gpio$U c 83 $U 600
349	;;
350
351fuse)
352	M fuse$U c 93 $U 600
353	;;
354
355fd)
356	RMlist[${#RMlist[*]}]=";mkdir -p fd;rm -f" n=0
357	while [ $n -lt 64 ];do M fd/$n c 22 $n;n=$(($n+1));done
358	MKlist[${#MKlist[*]}]=";chmod 555 fd"
359	;;
360
361dri)
362	RMlist[${#RMlist[*]}]=";mkdir -p dri;rm -f"
363	n=0
364	while [ $n -lt 4 ]
365	do
366		M dri/card$n c 88 $n 600
367		r=$(($n+128))
368		M dri/renderD$r c 88 $r 600
369		n=$(($n+1))
370	done
371	MKlist[${#MKlist[*]}]=";chmod 555 dri"
372	;;
373
374diskmap)
375	M diskmap c 91 0 640 operator
376	;;
377
378dt)
379	M dt c 30 0 600
380	;;
381
382bpf)
383	M bpf c 23 0 600
384	M bpf0 c 23 0 600
385	;;
386
387bktr*)
388	M bktr$U c 49 $U 644
389	;;
390
391bio)
392	M bio c 79 0 600
393	;;
394
395audio*)
396	M audio$U	c 42 $U 660 _sndiop
397	M audioctl$U	c 42 $(($U+192)) 660 _sndiop
398	;;
399
400apm*)
401	M apm	c 21 0 644
402	M apmctl	c 21 8 644
403	;;
404
405amdmsr*)
406	M amdmsr c 89 $U
407	;;
408
409usb*)
410	[ "$i" = "usb" ] && u= || u=$U
411	M usb$u c 61 $U 640
412	;;
413
414ulpt*)
415	M ulpt$U c 64 $U 600
416	;;
417
418ujoy)
419	RMlist[${#RMlist[*]}]=";mkdir -p ujoy;rm -f" n=0
420	while [ $n -lt 4 ];do M ujoy/$n c 100 $n 444;n=$(($n+1));done
421	MKlist[${#MKlist[*]}]=";chmod 555 ujoy"
422	;;
423
424fido)
425	RMlist[${#RMlist[*]}]=";mkdir -p fido;rm -f" n=0
426	while [ $n -lt 4 ];do M fido/$n c 98 $n 666;n=$(($n+1));done
427	MKlist[${#MKlist[*]}]=";chmod 555 fido"
428	;;
429
430uhid*)
431	M uhid$U c 62 $U 600
432	;;
433
434ugen*)
435	n=$(($U*16))
436	for j in 0{0,1,2,3,4,5,6,7,8,9} 1{0,1,2,3,4,5}
437	do
438		M ugen$U.$j c 63 $(($n+10#$j)) 600
439	done
440	;;
441
442uall)
443	R ttyU0 ttyU1 ttyU2 ttyU3 ugen0 ugen1 ugen2 ugen3 ugen4 ugen5
444	R ugen6 ugen7 ulpt0 ulpt1 ujoy fido uhid0 uhid1 uhid2 uhid3
445	R uhid4 uhid5 uhid6 uhid7 usb0 usb1 usb2 usb3 usb4 usb5 usb6
446	R usb7
447	;;
448
449ttyU[0-9a-zA-Z])
450	U=${i#ttyU*}
451	o=$(alph2d $U)
452	M ttyU$U c 66 $o 660 dialer root
453	M cuaU$U c 66 $(($o+128)) 660 dialer root
454	;;
455
456lpt*|lpa*)
457	case $i in
458	lpt*) n=lpt f=0;;
459	lpa*) n=lpa f=128;;
460	esac
461	M $n$U c 16 $(($U+$f)) 600
462	;;
463
464wsmouse[0-9]*)
465	M wsmouse$U c 68 $U 600
466	;;
467
468wsmux|wsmouse|wskbd)
469	M wsmouse c 69 0 600
470	M wskbd c 69 1 600
471	;;
472
473wskbd[0-9]*)
474	M wskbd$U c 67 $U 600
475	;;
476
477wscons)
478	R wsmouse0 wsmouse1 wsmouse2 wsmouse3 wsmouse4 wsmouse5
479	R wsmouse6 wsmouse7 wsmouse8 wsmouse9 wskbd0 wskbd1 wskbd2
480	R wskbd3 wskbd4 wskbd5 wskbd6 wskbd7 wskbd8 wskbd9 wsmux
481	R ttyCcfg ttyC0 ttyC1 ttyC2 ttyC3 ttyC4 ttyC5 ttyC6 ttyC7
482	R ttyC8 ttyC9 ttyCa ttyCb
483	;;
484
485tty[C-J]*)
486	U=${i##tty[C-J]}
487	case $i in
488	ttyC*) n=C m=0;;
489	ttyD*) n=D m=256;;
490	ttyE*) n=E m=512;;
491	ttyF*) n=F m=768;;
492	ttyG*) n=G m=1024;;
493	ttyH*) n=H m=1280;;
494	ttyI*) n=I m=1536;;
495	ttyJ*) n=J m=1792;;
496	esac
497	case $U in
498	[0-9a-f]) M tty$n$U c 12 $((16#$U+$m)) 600;;
499	cfg) M tty${n}cfg c 12 $((255+$m)) 600;;
500	*) echo bad unit $U for $i; exit 1;;
501	esac
502	;;
503
504pty*)
505	if [ $U -gt 15 ]; then
506		echo bad unit for pty in: $i
507		continue
508	fi
509	set -A letters p q r s t u v w x y z P Q R S T
510	set -A suffixes 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q \
511	    r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X \
512	    Y Z
513
514	name=${letters[$U]}
515	n=0
516	while [ $n -lt 62 ]
517	do
518		nam=$name${suffixes[$n]}
519		off=$(($U*62))
520		M tty$nam c 5 $(($off+$n))
521		M pty$nam c 6 $(($off+$n))
522		n=$(($n+1))
523	done
524	;;
525
526ptm)
527	M ptm c 81 0 666
528	;;
529
530tty[0-7][0-9a-f])
531	U=${i#tty*}
532	o=$(h2d $U)
533	M tty$U c 8 $o 660 dialer root
534	M cua$U c 8 $(($o+128)) 660 dialer root
535	;;
536
537st*)
538	n=$(($U*16))
539	for pre in " " n e en
540	do
541		M ${pre}rst$U	c 14 $n 660 operator
542		n=$(($n+1))
543	done
544	;;
545
546ch*)
547	M ch$U c 17 $U 660 operator
548	;;
549
550vnd*)
551	dodisk vnd $U 14 41 $U 0
552	;;
553
554rd*)
555	dodisk2 rd $U 17 47 $U 0
556	;;
557
558fd*)
559	typnam=$U${i#fd[01]*}
560	case $typnam in
561	0|1)	typnum=0;; # no type specified, assume A
562	*A)	typnum=0; typnam=0;;
563	*B)	typnum=1;;
564	*C)	typnum=2;;
565	*D)	typnum=3;;
566	*E)	typnum=4;;
567	*F)	typnum=5;;
568	*G)	typnum=6;;
569	*H)	typnum=7;;
570	*)	echo bad type $typnam for $i; exit 1;;
571	esac
572	case $U in
573	0|1)	blk=2; chr=9;;
574	*)	echo bad unit $U for $i; exit 1;;
575	esac
576	nam=fd${typnam}
577	n=$(($(($U*128))+$(($typnum*16))))
578	M ${nam}a	b $blk $n 640 operator
579	M ${nam}b	b $blk $(($n+1)) 640 operator
580	M ${nam}c	b $blk $(($n+2)) 640 operator
581	M ${nam}i	b $blk $(($n+8)) 640 operator
582	M r${nam}a	c $chr $n 640 operator
583	M r${nam}b	c $chr $(($n+1)) 640 operator
584	M r${nam}c	c $chr $(($n+2)) 640 operator
585	M r${nam}i	c $chr $(($n+8)) 640 operator
586	;;
587
588cd*)
589	dodisk2 cd $U 6 15 $U 0
590	;;
591
592local)
593	test -s $T.local && sh $T.local
594	;;
595
596all)
597	R ipmi0 amdmsr dri nvram gpio0 gpio1 gpio2 bktr0 vnd0 vnd1
598	R vnd2 vnd3 sd0 sd1 sd2 sd3 sd4 sd5 sd6 sd7 sd8 sd9 cd0 cd1
599	R rd0 tap0 tap1 tap2 tap3 tun0 tun1 tun2 tun3 bio pty0 fd1
600	R fd1B fd1C fd1D fd1E fd1F fd1G fd1H fd0 fd0B fd0C fd0D fd0E
601	R fd0F fd0G fd0H diskmap vscsi0 ch0 audio0 audio1 audio2
602	R audio3 kstat dt kcov bpf pvbus0 pvbus1 fuse pppac pppx
603	R hotplug ptm local wscons pci0 pci1 pci2 pci3 uall rmidi0
604	R rmidi1 rmidi2 rmidi3 rmidi4 rmidi5 rmidi6 rmidi7 tuner0
605	R radio0 speaker video0 video1 video2 video3 uk0 random joy0
606	R joy1 lpa0 lpa1 lpa2 lpt0 lpt1 lpt2 tty00 tty01 tty02 tty03
607	R tty04 tty05 tty06 tty07 tty08 tty09 tty0a tty0b ttyc0 ttyc1
608	R ttyc2 ttyc3 ttyc4 ttyc5 ttyc6 ttyc7 apm pf pctr wd0 wd1 wd2
609	R wd3 std st0 st1 fd
610	;;
611
612wd*|sd*)
613	case $i in
614	wd*) dodisk wd $U 0 3 $U 0;;
615	sd*) dodisk sd $U 4 13 $U 0;;
616	esac
617	;;
618
619*)
620	echo $i: unknown device
621	;;
622esac
623done
624}
625R "$@"
626{
627echo -n ${RMlist[*]}
628echo -n ${mklist[*]}
629echo -n ${MKlist[*]}
630echo -n ${whlist[*]}
631echo ${oplist[*]}
632} | if [ "$eo" = "echo" ]; then
633	cat
634else
635	sh
636fi
637