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