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