xref: /openbsd-src/etc/etc.landisk/MAKEDEV (revision bfeff85e8019e4b5ac733549e8efa65256182b92)
1#!/bin/sh -
2#
3# THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.
4# generated from:
5#
6#	OpenBSD: etc.landisk/MAKEDEV.md,v 1.52 2024/03/31 10:14:35 miod 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#	ch*	SCSI media changers
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#	st*	SCSI tape drives
41# Terminal ports:
42#	ttya	on-board serial port
43# Pseudo terminals:
44#	ptm	pty master device
45#	pty*	Set of 62 master pseudo terminals
46#	tty*	Set of 62 slave pseudo terminals
47# Console ports:
48#	ttyC-J*	wscons display devices
49#	wscons	Minimal wscons devices
50#	wskbd*	wscons keyboards
51#	wsmouse*	wscons mice
52#	wsmux	wscons keyboard/mouse mux devices
53# USB devices:
54#	ttyU*	USB serial ports
55#	uall	All USB devices
56#	ugen*	Generic USB devices
57#	uhid*	Generic HID devices
58#	fido	fido/* nodes
59#	ujoy	ujoy/* nodes
60#	ulpt*	Printer devices
61#	usb*	Bus control devices used by usbd for attach/detach
62# Special purpose devices:
63#	audio*	Audio devices
64#	bio	ioctl tunnel pseudo-device
65#	bpf	Berkeley Packet Filter
66#	dt	Dynamic Tracer
67#	diskmap	Disk mapper
68#	fd	fd/* nodes
69#	fuse	Userland Filesystem
70#	hotplug	devices hot plugging
71#	pci*	PCI bus devices
72#	pf	Packet Filter
73#	pppx*	PPP Multiplexer
74#	pppac*	PPP Access Concentrator
75#	radio*	FM tuner devices
76#	*random	In-kernel random data source
77#	rmidi*	Raw MIDI devices
78#	tun*	Network tunnel driver
79#	tap*	Ethernet tunnel driver
80#	uk*	Unknown SCSI devices
81#	video*	Video V4L2 devices
82#	vscsi*	Virtual SCSI controller
83#	kstat	Kernel Statistics
84PATH=/sbin:/usr/sbin:/bin:/usr/bin
85T=$0
86
87# set this to echo for Echo-Only debugging
88[ "$eo" ] || eo=
89
90hex()
91{
92	case $1 in
93	[0-9]) echo -n $1;;
94	10) echo -n a;;
95	11) echo -n b;;
96	12) echo -n c;;
97	13) echo -n d;;
98	14) echo -n e;;
99	15) echo -n f;;
100	esac
101}
102
103alph2d()
104{
105	local t="$1"
106	local p="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
107	local sub=${p%${t}*}
108	echo ${#sub}
109}
110
111h2d()
112{
113	local s="$1"
114	local f=${s%*[0-9a-f]} n=${s#[0-9a-f]*}
115
116	echo $(($(_h2d $f)*16+ $(_h2d $n) ))
117}
118
119_h2d()
120{
121	case $1 in
122	[0-9]) echo -n $1;;
123	a) echo -n 10;;
124	b) echo -n 11;;
125	c) echo -n 12;;
126	d) echo -n 13;;
127	e) echo -n 14;;
128	f) echo -n 15;;
129	esac
130}
131
132unt()
133{
134	# XXX pdksh can't seem to deal with locally scoped variables
135	# in ${foo#$bar} expansions
136	arg="$1"
137	tmp="${arg#[a-zA-Z]*}"
138	tmp="${tmp%*[a-zA-Z]}"
139	while [ "$tmp" != "$arg" ]
140	do
141		arg=$tmp
142		tmp="${arg#[a-zA-Z]*}"
143		tmp="${tmp%*[a-zA-Z]}"
144	done
145	echo $arg
146}
147
148dodisk()
149{
150	[ "$DEBUG" ] && set -x
151	n=$(($((${5}*${7:-16}))+${6})) count=0
152	[ 0$7 -ne 8 ] && l="i j k l m n o p"
153	for d in a b c d e f g h $l
154	do
155		M $1$2$d	b $3 $(($n+$count)) 640 operator
156		M r$1$2$d	c $4 $(($n+$count)) 640 operator
157		let count=count+1
158	done
159}
160
161dodisk2()
162{
163	n=$(($(($5*${7:-16}))+$6))
164	M $1$2a b $3 $n 640 operator
165	M r$1$2a c $4 $n 640 operator
166	n=$(($n+2))
167	M $1$2c b $3 $n 640 operator
168	M r$1$2c c $4 $n 640 operator
169}
170
171# M name b/c major minor [mode] [group]
172RMlist[0]="rm -f"
173
174mkl() {
175	: ${mklist[0]:=";mknod"}
176	mklist[${#mklist[*]}]=" -m $1 $2 $3 $4 $5"
177}
178
179M() {
180	RMlist[${#RMlist[*]}]=$1
181	mkl ${5-666} $1 $2 $3 $4
182	G=${6:-wheel}
183	[ "$7" ] && {
184		MKlist[${#MKlist[*]}]="&& chown $7:$G $1"
185	} || {
186		case $G in
187		wheel)
188			[ ${#whlist[*]} = 0 ] && whlist[0]="&& chgrp wheel"
189			whlist[${#whlist[*]}]="$1"
190		;;
191		operator)
192			[ ${#oplist[*]} = 0 ] && oplist[0]="&& chgrp operator"
193			oplist[${#oplist[*]}]="$1"
194		;;
195		*)
196			MKlist[${#MKlist[*]}]="&& chgrp $G $1";
197		esac
198	}
199	return 0
200}
201
202R() {
203[ "$DEBUG" ] && set -x
204for i in "$@"
205do
206U=`unt $i`
207[ "$U" ] || U=0
208
209case $i in
210ramdisk)
211	R std bpf wd0 wd1 sd0 rd0 wsmouse
212	R st0 ttyC0 wskbd0 bio diskmap random
213	;;
214
215std)
216	M console	c 0 0 600
217	M tty		c 1 0
218	M mem		c 2 0 640 kmem
219	M kmem		c 2 1 640 kmem
220	M null		c 2 2
221	M zero		c 2 12
222	M stdin		c 7 0
223	M stdout	c 7 1
224	M stderr	c 7 2
225	M ksyms		c 8 0 640 kmem
226	M klog		c 6 0 600
227	;;
228
229kstat)
230	M kstat c 51 0 640
231	;;
232
233vscsi*)
234	M vscsi$U c 99 $U 600
235	;;
236
237video*)
238	M video$U  c 77 $U 600
239	MKlist[${#MKlist[*]}]=";[ -e video ] || ln -s video$U video"
240	;;
241
242uk*)
243	M uk$U c 28 $U 640 operator
244	;;
245
246tap*)
247	M tap$U c 104 $U 600
248	;;
249
250tun*)
251	M tun$U c 33 $U 600
252	;;
253
254rmidi*)
255	M rmidi$U c 57 $U 660 _sndiop
256	;;
257
258*random)
259	M urandom c 40 0 644
260	RMlist[${#RMlist[*]}]=random
261	MKlist[${#MKlist[*]}]=";ln -s urandom random"
262	;;
263
264radio*)
265	M radio$U	c 97 $U
266	MKlist[${#MKlist[*]}]=";[ -e radio ] || ln -s radio$U radio"
267	;;
268
269pppac*)
270	M pppac$U c 107 $U 600
271	;;
272
273pppx*)
274	M pppx$U c 102 $U 600
275	;;
276
277pf)
278	M pf c 46 0 600
279	;;
280
281pci*)
282	M pci$U	c 88 $U 600
283	MKlist[${#MKlist[*]}]=";[ -h pci ] || ln -sf pci0 pci"
284	;;
285
286hotplug)
287	M hotplug c 37 $U 400
288	;;
289
290fuse)
291	M fuse$U c 103 $U 600
292	;;
293
294fd)
295	RMlist[${#RMlist[*]}]=";mkdir -p fd;rm -f" n=0
296	while [ $n -lt 64 ];do M fd/$n c 7 $n;n=$(($n+1));done
297	MKlist[${#MKlist[*]}]=";chmod 555 fd"
298	;;
299
300diskmap)
301	M diskmap c 101 0 640 operator
302	;;
303
304dt)
305	M dt c 30 0 600
306	;;
307
308bpf)
309	M bpf c 22 0 600
310	M bpf0 c 22 0 600
311	;;
312
313bio)
314	M bio c 38 0 600
315	;;
316
317audio*)
318	M audio$U	c 36 $U 660 _sndiop
319	M audioctl$U	c 36 $(($U+192)) 660 _sndiop
320	;;
321
322usb*)
323	[ "$i" = "usb" ] && u= || u=$U
324	M usb$u c 64 $U 640
325	;;
326
327ulpt*)
328	M ulpt$U c 66 $U 600
329	;;
330
331ujoy)
332	RMlist[${#RMlist[*]}]=";mkdir -p ujoy;rm -f" n=0
333	while [ $n -lt 4 ];do M ujoy/$n c 108 $n 444;n=$(($n+1));done
334	MKlist[${#MKlist[*]}]=";chmod 555 ujoy"
335	;;
336
337fido)
338	RMlist[${#RMlist[*]}]=";mkdir -p fido;rm -f" n=0
339	while [ $n -lt 4 ];do M fido/$n c 106 $n 666;n=$(($n+1));done
340	MKlist[${#MKlist[*]}]=";chmod 555 fido"
341	;;
342
343uhid*)
344	M uhid$U c 65 $U 600
345	;;
346
347ugen*)
348	n=$(($U*16))
349	for j in 0{0,1,2,3,4,5,6,7,8,9} 1{0,1,2,3,4,5}
350	do
351		M ugen$U.$j c 70 $(($n+10#$j)) 600
352	done
353	;;
354
355uall)
356	R ttyU0 ttyU1 ttyU2 ttyU3 ugen0 ugen1 ugen2 ugen3 ugen4 ugen5
357	R ugen6 ugen7 ulpt0 ulpt1 ujoy fido uhid0 uhid1 uhid2 uhid3
358	R uhid4 uhid5 uhid6 uhid7 usb0 usb1 usb2 usb3 usb4 usb5 usb6
359	R usb7
360	;;
361
362ttyU[0-9a-zA-Z])
363	U=${i#ttyU*}
364	o=$(alph2d $U)
365	M ttyU$U c 68 $o 660 dialer root
366	M cuaU$U c 68 $(($o+128)) 660 dialer root
367	;;
368
369wsmux|wsmouse|wskbd)
370	M wsmouse c 63 0 600
371	M wskbd c 63 1 600
372	;;
373
374wsmouse[0-9]*)
375	M wsmouse$U c 62 $U 600
376	;;
377
378wskbd[0-9]*)
379	M wskbd$U c 61 $U 600
380	;;
381
382wscons)
383	R wsmouse0 wsmouse1 wsmouse2 wsmouse3 wsmouse4 wsmouse5
384	R wsmouse6 wsmouse7 wsmouse8 wsmouse9 wskbd0 wskbd1 wskbd2
385	R wskbd3 wskbd4 wskbd5 wskbd6 wskbd7 wskbd8 wskbd9 wsmux
386	R ttyCcfg ttyC0 ttyC1 ttyC2 ttyC3 ttyC4 ttyC5 ttyC6 ttyC7
387	R ttyC8 ttyC9 ttyCa ttyCb
388	;;
389
390tty[C-J]*)
391	U=${i##tty[C-J]}
392	case $i in
393	ttyC*) n=C m=0;;
394	ttyD*) n=D m=256;;
395	ttyE*) n=E m=512;;
396	ttyF*) n=F m=768;;
397	ttyG*) n=G m=1024;;
398	ttyH*) n=H m=1280;;
399	ttyI*) n=I m=1536;;
400	ttyJ*) n=J m=1792;;
401	esac
402	case $U in
403	[0-9a-f]) M tty$n$U c 60 $((16#$U+$m)) 600;;
404	cfg) M tty${n}cfg c 60 $((255+$m)) 600;;
405	*) echo bad unit $U for $i; exit 1;;
406	esac
407	;;
408
409pty*)
410	if [ $U -gt 15 ]; then
411		echo bad unit for pty in: $i
412		continue
413	fi
414	set -A letters p q r s t u v w x y z P Q R S T
415	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 \
416	    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 \
417	    Y Z
418
419	name=${letters[$U]}
420	n=0
421	while [ $n -lt 62 ]
422	do
423		nam=$name${suffixes[$n]}
424		off=$(($U*62))
425		M tty$nam c 4 $(($off+$n))
426		M pty$nam c 5 $(($off+$n))
427		n=$(($n+1))
428	done
429	;;
430
431ptm)
432	M ptm c 98 0 666
433	;;
434
435ttya)
436	M ttya c 11 0 660 dialer root
437	;;
438
439st*)
440	n=$(($U*16))
441	for pre in " " n e en
442	do
443		M ${pre}rst$U	c 25 $n 660 operator
444		n=$(($n+1))
445	done
446	;;
447
448vnd*)
449	dodisk vnd $U 19 19 $U 0
450	;;
451
452rd*)
453	dodisk2 rd $U 18 18 $U 0
454	;;
455
456ch*)
457	M ch$U c 27 $U 660 operator
458	;;
459
460cd*)
461	dodisk2 cd $U 26 26 $U 0
462	;;
463
464local)
465	test -s $T.local && sh $T.local
466	;;
467
468all)
469	R vnd0 vnd1 vnd2 vnd3 sd0 sd1 sd2 sd3 sd4 sd5 sd6 sd7 sd8 sd9
470	R cd0 cd1 rd0 tap0 tap1 tap2 tap3 tun0 tun1 tun2 tun3 bio pty0
471	R diskmap vscsi0 ch0 ttya audio0 audio1 audio2 audio3 kstat dt
472	R bpf fuse pppac pppx hotplug ptm local wscons pci0 pci1 pci2
473	R pci3 uall rmidi0 rmidi1 rmidi2 rmidi3 rmidi4 rmidi5 rmidi6
474	R rmidi7 radio0 video0 video1 video2 video3 uk0 random pf wd0
475	R wd1 wd2 wd3 std st0 st1 fd
476	;;
477
478wd*|sd*)
479	case $i in
480	wd*) dodisk wd $U 16 16 $U 0;;
481	sd*) dodisk sd $U 24 24 $U 0;;
482	esac
483	;;
484
485*)
486	echo $i: unknown device
487	;;
488esac
489done
490}
491R "$@"
492{
493echo -n ${RMlist[*]}
494echo -n ${mklist[*]}
495echo -n ${MKlist[*]}
496echo -n ${whlist[*]}
497echo ${oplist[*]}
498} | if [ "$eo" = "echo" ]; then
499	cat
500else
501	sh
502fi
503