MAKEDEV.tmpl revision 1.104
1#!/bin/sh -
2#	$NetBSD: MAKEDEV.tmpl,v 1.104 2008/04/09 20:19:15 apb Exp $
3#
4# Copyright (c) 2003,2007,2008 The NetBSD Foundation, Inc.
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15# 3. All advertising materials mentioning features or use of this software
16#    must display the following acknowledgement:
17#        This product includes software developed by the NetBSD
18#        Foundation, Inc. and its contributors.
19# 4. Neither the name of The NetBSD Foundation nor the names of its
20#    contributors may be used to endorse or promote products derived
21#    from this software without specific prior written permission.
22#
23# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33# POSSIBILITY OF SUCH DAMAGE.
34#
35#
36###########################################################################
37#
38#   PLEASE RUN "cd ../share/man/man8 ; make makedevs"
39#   AFTER CHANGING THIS FILE, AND COMMIT THE UPDATED MANPAGE!
40#
41###########################################################################
42#
43# Device "make" file.  Valid special arguments:
44#	all	makes all known devices, including local devices.
45#		Tries to make the 'standard' number of each type.
46#	init	A set of devices that is used for MFS /dev by init.
47#		May be equal to "all".
48#	floppy	devices to be put on install floppies
49#	ramdisk	devices to be put into INSTALL kernel ramdisks.
50#	std	standard devices
51#	local	configuration specific devices
52#	wscons	make wscons devices
53#	usbs	make USB devices
54#	isdns	make ISDN devices
55#
56# Tapes:
57#	st*	SCSI tapes
58#	wt*	QIC-interfaced (e.g. not SCSI) 3M cartridge tape
59#	ht*	MASSBUS TM03 and TU??
60#	mt*	MSCP tapes (e.g. TU81, TK50)
61#	tm*	UNIBUS TM11 and TE10 emulations (e.g. Emulex TC-11)
62#	ts*	UNIBUS TS11
63#	ut*	UNIBUS TU45 emulations (e.g. si 9700)
64#	uu*	TU58 cassettes on DL11 controller
65#
66# Disks:
67#	ccd*	concatenated disk devices
68#	cd*	SCSI or ATAPI CD-ROM
69#	cgd*	cryptographic disk devices
70#	raid*	RAIDframe disk devices
71#	sd*	SCSI disks
72#	wd*	"winchester" disk drives (ST506,IDE,ESDI,RLL,...)
73#	bmd*	Nereid bank memory disks
74#	ed*	IBM PS/2 ESDI disk devices
75#	fd*	"floppy" disk drives (3 1/2", 5 1/4")
76#	fss*	Files system snapshot devices
77#	gdrom*	Dreamcast "gigadisc" CD-ROM drive
78#	hk*	UNIBUS RK06 and RK07
79#	hp*	MASSBUS RM??
80#	ld*	Logical disk devices (e.g., hardware RAID)
81#	mcd*	Mitsumi CD-ROM
82#	md*	memory pseudo-disk devices
83#	ofdisk*	OpenFirmware disk devices
84#	ra*	MSCP disks (RA??, RD??)
85#	rb*	730 IDC w/ RB80 and/or RB02
86#	rd*	HDC9224 RD disks on VS2000
87#	rl*	UNIBUS RL02
88#	rx*	MSCP floppy disk (RX33/50/...)
89#	up*	other UNIBUS devices (e.g. on Emulex SC-21V controller)
90#	vnd*	"file" pseudo-disks
91#	xbd*	Xen virtual disks
92#	xd*	Xylogic 753/7053 disks
93#	xy*	Xylogic 450/451 disks
94#
95# Pointing devices:
96#	wsmouse* wscons mouse events
97#	lms*	Logitech bus mouse
98#	mms*	Microsoft bus mouse
99#	qms*	"quadrature mouse"
100#	pms*	PS/2 mouse
101#	mouse	mouse (provides events, for X11)
102#
103# Keyboard devices:
104#	wskbd*	wscons keyboard events
105#	kbd	raw keyboard (provides events, for X11)
106#	kbdctl	keyboard control
107#
108# Terminals/Console ports:
109#	tty[01]*	standard serial ports
110#	tty0*	SB1250 ("sbscn") serial ports (sbmips)
111#	ttyE*	wscons - Workstation console ("wscons") glass-tty emulators
112#	ttyCZ?	Cyclades-Z multiport serial boards.  Each "unit"
113#		makes 64 ports.
114#	ttyCY?	Cyclom-Y multiport serial boards. Each "unit" makes
115#		32 ports.
116#	ttye*	ITE bitmapped consoles
117#	ttyv0	pccons
118#	ttyC?	NS16550 ("com") serial ports
119#	ttyS*	SA1110 serial port (hpcarm)
120#	ttyTX?	TX39 internal serial ports (hpcmips)
121#	ttyB?	DEC 3000 ZS8530 ("scc") serial ports (alpha)
122#	ttyA*	mfc serial ports (amiga)
123#	ttyB*	msc serial ports (amiga)
124#	ttyC*	com style serial ports (DraCo, HyperCom) (amiga)
125#		On the DraCo, units 0 and 1 are the built-in "modem" and
126#		"mouse" ports, if configured.
127#	ttyA0   8530 Channel A (formerly ser02) (atari)
128#	ttyA1	8530 Channel B (formerly mdm02) (atari)
129#	ttyB0	UART on first 68901 (formerly mdm01) (atari)
130#	ixpcom	IXP12x0 COM ports
131#	epcom	EP93xx COM ports
132#	ttyM?	HP200/300 4 port serial mux interface (hp300)
133#	ttya	"ttya" system console (luna68k)
134#	ttyb	second system serial port (luna68k)
135#	tty*	Onboard serial ports (mvme68k)
136#		On the mvme147 these are: ttyZ1, ttyZ2 and ttyZ3.
137#		On the mvme167, and '177: ttyC1, ttyC2 and ttyC3.
138#		Note that tty[CZ]0 is grabbed by the console device
139#		so is not created by default
140#	dc*	PMAX 4 channel serial interface (kbd, mouse, modem, printer)
141#	scc*	82530 serial interface (pmax)
142#	ttyZ*	Zilog 8530 ("zstty") serial ports
143#	tty[abcd]	Built-in serial ports (sparc)
144#	tty*	Z88530 serial controllers (sparc64)
145#	ttyh*	SAB82532 serial controllers (sparc64)
146#	tty[a-j]	Built-in serial ports (sun2, sun3)
147#	ttyC?	pccons (arc)
148#	dz*	UNIBUS DZ11 and DZ32 (vax)
149#	dh*	UNIBUS DH11 and emulations (e.g. Able DMAX, Emulex CS-11) (vax)
150#	dmf*	UNIBUS DMF32 (vax)
151#	dhu*    UNIBUS DHU11 (vax)
152#	dmz*    UNIBUS DMZ32 (vax)
153#	dl*	UNIBUS DL11 (vax)
154#	xencons	Xen virtual console
155#
156# Terminal multiplexors:
157#	dc*	4 channel serial interface (keyboard, mouse, modem, printer)
158#	dh*	UNIBUS DH11 and emulations (e.g. Able DMAX, Emulex CS-11)
159#	dhu*	UNIBUS DHU11
160#	dl*	UNIBUS DL11
161#	dmf*	UNIBUS DMF32
162#	dmz*	UNIBUS DMZ32
163#	dz*	UNIBUS DZ11 and DZ32
164#	scc*	82530 serial interface
165#
166# Call units:
167#	dn*	UNIBUS DN11 and emulations (e.g. Able Quadracall)
168#
169# Pseudo terminals:
170#	ptm	pty multiplexor device.
171#	pty*	set of 16 master and slave pseudo terminals
172#	opty	first 16 ptys, to save inodes on install media
173#	ipty	first 2 ptys, for install media use only
174#
175# Printers:
176#	arcpp*	Archimedes parallel port
177#	lpt*	stock lp
178#	lpa*	interruptless lp
179#	par*	Amiga motherboard parallel port
180#
181# USB devices:
182#	usb*	USB control devices
183#	uhid*	USB generic HID devices
184#	ulpt*	USB printer devices
185#	ugen*	USB generic devices
186#	urio*	USB Diamond Rio 500 devices
187#	uscanner*	USB scanners
188#	ttyU*	USB modems
189#	ttyY*	USB serial adapters
190#
191# ISDN devices:
192#	isdn	communication between userland isdnd and kernel
193#	isdnctl	control device
194#	isdnbchan* raw b-channel access
195#	isdntel*	telephony device
196#	isdnteld*	telephony dialout device
197#	isdntrc*	trace device
198#
199# Video devices:
200#	bwtwo*	monochromatic frame buffer
201#	cgtwo*	8-bit color frame buffer
202#	cgthree*	8-bit color frame buffer
203#	cgfour*	8-bit color frame buffer
204#	cgsix*	accelerated 8-bit color frame buffer
205#	cgeight*	24-bit color frame buffer
206#	etvme	Tseng et-compatible cards on VME (atari)
207#	ik*	UNIBUS interface to Ikonas frame buffer
208#	leo	Circad Leonardo VME-bus true color (atari)
209#	ps*	UNIBUS interface to Picture System 2
210#	qv*	QVSS (MicroVAX) display
211#	tcx*	accelerated 8/24-bit color frame buffer
212#
213# Maple bus devices:
214#	maple	Maple bus control devices
215#	mlcd*	Maple bus LCD devices
216#	mmem*	Maple bus storage devices
217#
218# IEEE1394 bus devices:
219#	fw*	IEEE1394 bus generic node access devices
220#	fwmem*	IEEE1394 bus physical memory of the remote node access devices
221#
222# Special purpose devices:
223#	ad*	UNIBUS interface to Data Translation A/D converter
224#	agp*	AGP GART devices
225#	altq	ALTQ control interface
226#	amr*	AMI MegaRaid control device
227#	apm	power management device
228#	audio*	audio devices
229#	bell*	OPM bell device (x68k)
230#	bktr	Brooktree 848/849/878/879 based TV cards
231#	bpf	packet filter
232#	bthub	Bluetooth Device Hub control interface
233#	cfs*	Coda file system device
234#	ch*	SCSI media changer
235#	cir*	Consumer IR
236#	clockctl clock control for non root users
237#	cpuctl	CPU control
238#	crypto	hardware crypto access driver
239#	dmoverio hardware-assisted data movers
240#	dpt*	DPT/Adaptec EATA RAID management interface
241#	dpti*	DPT/Adaptec I2O RAID management interface
242#	fb*	PMAX generic framebuffer pseudo-device
243#	fd	file descriptors
244#	grf*	graphics frame buffer device
245#	hil	HP300 HIL input devices
246#	icp	ICP-Vortex/Intel RAID control interface
247#	iic*	IIC bus device
248#	io	x86 IOPL access for COMPAT_10, COMPAT_FREEBSD
249#	iop*	I2O IOP control interface
250#	ipl	IP Filter
251#	irframe* IrDA physical frame
252#	ite*	terminal emulator interface to HP300 graphics devices
253#	joy*	joystick device
254#	kttcp	kernel ttcp helper device
255#	lkm	loadable kernel modules interface
256#	lockstat kernel locking statistics
257#	magma*	Magma multiport serial/parallel cards
258#	midi*	MIDI
259#	mlx*	Mylex DAC960 control interface
260#	mly*	Mylex AcceleRAID/eXtremeRAID control interface
261#	np*	UNIBUS Ethernet co-processor interface, for downloading.
262#	nsmb*	SMB requester
263#	openfirm OpenFirmware accessor
264#	pad*	Pseudo-audio device driver
265#	pci*	PCI bus access devices
266#	pf	PF packet filter
267#	pow*	power management device (x68k)
268#	putter	Pass-to-Userspace Transporter
269#	px*	PixelStamp Xserver access
270#	radio*	radio devices
271#	random	Random number generator
272#	rtc*	RealTimeClock
273#	satlink* PlanetConnect satellite receiver driver
274#	scsibus* SCSI busses
275#	se*	SCSI Ethernet
276#	ses*	SES/SAF-TE SCSI Devices
277#	speaker	PC speaker		(XXX - installed)
278#	sram	battery backuped memory (x68k)
279#	ss*	SCSI scanner
280#	stic*	PixelStamp interface chip
281#	sysmon	System Monitoring hardware
282#	tap*	virtual Ethernet device
283#	tun*	network tunnel driver
284#	twa	3ware Apache control interface
285#	twe	3ware Escalade control interface
286#	uk*	unknown SCSI device
287#	veriexec verified executable fingerprint loader
288#	vmegen*	generic VME access
289#	view*	generic interface to graphic displays (Amiga)
290#	wsfont*	console font control
291#	wsmux*	wscons event multiplexor
292#	xenevt	Xen event interface
293
294
295#
296# Apart from a few lines right at the end, this file should consist
297# entirely of function definitions.
298#
299# This file is used both as a standalone script (via "sh ./MAKEDEV all"
300# or similar), and as a function library (via "MAKEDEV_AS_LIBRARY=1 .
301# MAKEDEV" from MAKEDEV.local).
302#
303
304usage()
305{
306	cat 1>&2 << _USAGE_
307Usage: ${0##*/} [-fMs] [-m mknod] [-p pax] [-t mtree] special [...]
308	Create listed special devices.  Options:
309	-f		Force permissions to be updated on existing devices.
310	-M		Create memory file system.
311	-m mknod	Name of mknod(8) program.  [\$TOOL_MKNOD or mknod]
312	-p pax  	Name of pax(1) program.  [\$TOOL_PAX or pax]
313	-s		Generate mtree(8) specfile instead of creating devices.
314	-t mtree	Name of mtree(8) program.  [\$TOOL_MTREE or mtree]
315
316_USAGE_
317	exit 1
318}
319
320# zeropad width number
321#	display number with a zero (`0') padding of width digits.
322#
323zeropad()
324{
325	case $(($1 - ${#2})) in
326	5)	echo 00000$2;;
327	4)	echo 0000$2;;
328	3)	echo 000$2;;
329	2)	echo 00$2;;
330	1)	echo 0$2;;
331	0)	echo $2;;
332	*)	die "bad padding" ;;
333	esac
334}
335
336# hexprint number
337#	display (base10) number as hexadecimal
338#
339hexprint()
340{
341	val="$(($1 + 0))"
342	hex=
343	set -- 0 1 2 3 4 5 6 7 8 9 a b c d e f
344	while [ "$val" -gt 0 ]; do
345		eval hex=\$$(($val % 16 + 1))\$hex
346		val="$(($val / 16))"
347	done
348	echo "${hex:-0}"
349}
350
351# linecount multiline_string
352#	count the number of lines in the string
353#
354linecount()
355{
356	local IFS='
357' # just a newline, no other white space between the quotes
358	set -- $1
359	echo $#
360}
361
362# nooutput -12 cmd [args...]
363#	run a command with stdout and/or stderr ignored.
364#	"nooutput -2 cmd" is like "cmd 2>/dev/null",
365#	except it should work even if /dev/null doesn't [yet] exist.
366#
367nooutput()
368{
369	local flags="$1" ; shift
370	local junk
371	case "$flags" in
372	"-1")	junk="$( "$@" )" ;;
373	"-2")	exec 4>&1 ; junk="$( "$@" 2>&1 1>&4 )" ; exec 4>&- ;;
374	"-12")	junk="$( "$@" 2>&1 )" ;;
375	*)	warn "Incorrect use of nooutput" ;;
376	esac
377}
378
379# check_pax path_to_pax
380#	Check whether pax exists and supports the command line options
381#	and input format that we will want to use.
382#
383check_pax()
384{
385	local pax="$1"
386	echo ". type=dir optional" | nooutput -12 "${pax}" -r -w -M -pe .
387}
388
389# check_mtree path_to_mtree
390#	Check whether mtree exists and supports the command line options
391#	and input format that we will want to use.
392#
393check_mtree()
394{
395	local mtree="$1"
396	echo ". type=dir optional" | nooutput -12 "${mtree}" -e -U
397}
398
399# setup args...
400#	Parse command line arguments, exit on error.
401#	Callers should shift $((OPTIND - 1)) afterwards.
402#
403setup()
404{
405	PATH=/sbin:/usr/sbin:/bin:/usr/bin:/rescue
406
407	: ${TOOL_MKNOD:=mknod}
408	: ${TOOL_MTREE:=mtree}
409	: ${TOOL_PAX:=pax}
410	do_create_mfs=false
411	do_force=false
412	do_mknod=false
413	do_pax=false
414	do_mtree=false
415	do_redirect=false
416	do_specfile=false
417	opts=
418	while getopts Mfm:p:st: ch; do
419		# Note that $opts is only for options pased through to
420		# MAKEDEV.local, not for all options.
421		case ${ch} in
422		M)
423			# "-M" sets do_create_mfs;
424			# "-M -M" is for use from init(8), and sets do_redirect
425			do_redirect=$do_create_mfs
426			do_create_mfs=true
427			;;
428		f)	do_force=true
429			opts="${opts} -f"
430			;;
431		m)	TOOL_MKNOD=${OPTARG}
432			do_mknod=true
433			opts="${opts} -m ${OPTARG}"
434			;;
435		p)	TOOL_PAX="${OPTARG}"
436			if check_pax "${TOOL_PAX}"; then
437				do_pax=true
438				# do not add this to $opts; we will later
439				# add "-s" instead.
440			else
441				warn "Ignored -p option:" \
442					"${TOOL_PAX} is missing or broken"
443				do_mknod=true
444			fi
445			;;
446		s)	do_specfile=true
447			opts="${opts} -s"
448			;;
449		t)	TOOL_MTREE="${OPTARG}"
450			if check_mtree "${TOOL_MTREE}"; then
451				do_mtree=true
452				# do not add this to $opts; we will later
453				# add "-s" instead.
454			else
455				warn "Ignored -t option:" \
456					"${TOOL_MTREE} is missing or broken"
457				do_mknod=true
458			fi
459			;;
460		*)	usage ;;
461		esac
462	done
463
464	shift $((${OPTIND} - 1))
465	[ $# -gt 0 ] || usage
466
467	u_root="%uid_root%"
468	u_uucp="%uid_uucp%"
469	g_kmem="%gid_kmem%"
470	g_ntpd="%gid_ntpd%"
471	g_operator="%gid_operator%"
472	g_wheel="%gid_wheel%"
473	dialin=0
474	dialout=524288
475	callunit=262144
476
477	# only allow read&write for owner by default
478	umask 077
479
480	# Check if we have fdesc mounted
481	if [ -d fd ]; then
482		case "$(df fd)" in
483		*fdesc*)	nofdesc=false;;
484		*)		nofdesc=true;;
485		esac
486	else
487		nofdesc=true
488	fi
489
490	# do_force requires mknod
491	if $do_force; then
492		if $do_mtree || $do_pax || $do_specfile; then
493			die "-f option works only with mknod"
494		fi
495		do_mknod=true
496	fi
497
498	# If no explicit method was specified on the command line or
499	# forced above, then use one of mtree, pax, or mknod, in that
500	# order of preference.
501	#
502	# mtree is preferred because it's fast and designed for the
503	# purpose.  However, it's unlikely to be available early in the
504	# boot sequence, when init(8) may invoke MAKEDEV(8).
505	#
506	# pax is usually acceptable, and it's likely to be available
507	# early in the boot sequence.  However, it's much slower than mtree.
508	#
509	# mknod is just very slow, because the shell has to fork for
510	# each device node.
511	#
512	if ! ( $do_mtree || $do_pax || $do_mknod || $do_specfile ); then
513		if check_mtree "${TOOL_MTREE}"; then
514			do_mtree=true
515		elif check_pax "${TOOL_PAX}"; then
516			do_pax=true
517		else
518			do_mknod=true
519		fi
520	fi
521
522	# Now we need exactly one node-creation method.
523	case $(( $($do_mtree && echo 1 || echo 0) + \
524		$($do_pax && echo 1 || echo 0) + \
525		$($do_mknod && echo 1 || echo 0) + \
526		$($do_specfile && echo 1 || echo 0) ))
527	in
528	1)	: OK ;;
529	*)	die "-m, -p, -s, and -t options are mutually exclusive" ;;
530	esac
531
532	# If we are using mknod, then decide what options to pass it.
533	if $do_mknod; then
534		MKNOD="${TOOL_MKNOD:-mknod} -F netbsd"
535		if $do_force; then
536			MKNOD="${MKNOD} -R"
537		else
538			MKNOD="${MKNOD} -r"
539		fi
540	fi
541
542	# do_mtree or do_pax internally implies do_specfile.
543	# This happens after checking for mutually-exclusive options.
544	if ($do_mtree || $do_pax) && ! $do_specfile; then
545		do_specfile=true
546		opts="${opts} -s"
547	fi
548}
549
550# wrap_makedev makedev_name ...
551#	Invoke a makedev-like function, with additional processing
552#	as appropriate for use from the outer level.
553#
554wrap_makedev()
555{
556	if $do_specfile; then
557		# "." must appear as the first line of the specfile.
558		# "optional" means do not create the directory itself.
559		echo ". type=dir optional"
560	fi
561	"$@"
562}
563
564# makedev_main makedev_name args...
565#	Perform most of the work of the main program.  makedev_name
566#	is typically "makedev", but may be the name of some other
567#	makedev-like function (if we are invoked from MAKEDEV.local or
568#	some other script).  The other args to this function are the
569#	command line args with which the MAKEDEV (or MAKEDEV.local)
570#	script was invoked.
571#
572makedev_main()
573{
574	local makedev="$1" ; shift
575
576	# Parse command line args
577	setup ${1+"$@"}
578	shift $((${OPTIND}-1))
579
580	if $do_create_mfs; then
581		# Count inodes and create mfs file system.
582		# The makedev call merely updates $count_nodes.
583		count_nodes=0
584		$makedev ${1+"$@"}
585		create_mfs_dev $count_nodes
586		unset count_nodes
587	fi
588
589	# If using mtree or pax, then wrap_makedev should print an mtree
590	# specification, which we postprocess to create the device nodes.
591	# Otherwise, wrap_makedev should do all the work itself.
592	if $do_mtree ; then
593		wrap_makedev $makedev ${1+"$@"} \
594		| nooutput -1 "${TOOL_MTREE}" -e -U
595	elif $do_pax ; then
596		wrap_makedev $makedev ${1+"$@"} \
597		| (
598		    # Run pax in an empty directory, so it pays
599		    # attention only to the specfile, without being
600		    # confused by the existing contents of the target
601		    # directory.  Without this, pax would complain "file
602		    # would overwrite itself" for already-existing
603		    # device nodes.
604		    tmpdir=./tmp.$$
605		    mkdir "${tmpdir}" || die "can't create temporary directory"
606		    cd "${tmpdir}" || die "can't cd to temporary directory"
607		    "${TOOL_PAX}" -r -w -M -pe ..
608		    status=$?
609		    cd .. # back to where we started
610		    rmdir "${tmpdir}"
611		    exit $status
612		)
613	else
614		wrap_makedev $makedev ${1+"$@"}
615	fi
616}
617
618#
619# functions available to create nodes:
620#
621# mkdev name [b|c] major minor [mode{=600} [gid{=0} [uid{=0}]]]
622#	create device node `name' with the appropriate permissions
623#
624# lndev src target
625#	create a symlink from src to target
626#
627# makedir dir mode
628#	create directory with appropriate mode
629#
630
631mkdev()
632{
633	if [ -n "$count_nodes" ]; then
634		count_nodes=$((count_nodes + 1))
635		return
636	fi
637	if $do_specfile; then
638		case $2 in
639		b)	type=block ;;
640		c)	type=char ;;
641		esac
642		echo "./$1 type=${type} device=netbsd,$3,$4 mode=${5:-600} gid=${6:-$g_wheel} uid=${7:-$u_root}"
643	else
644		${MKNOD} -m ${5:-600} -g \#${6:-$g_wheel} -u \#${7:-$u_root} $1 $2 $3 $4
645	fi
646}
647
648lndev()
649{
650	if [ -n "$count_nodes" ]; then
651		count_nodes=$((count_nodes + 1))
652		return
653	fi
654	if $do_specfile; then
655		echo "./$2 type=link link=$1 mode=0700 gid=$g_wheel uid=$u_root"
656	else
657		ln -f -s $1 $2
658	fi
659}
660
661makedir()
662{
663	if [ -n "$count_nodes" ]; then
664		count_nodes=$((count_nodes + 1))
665		return
666	fi
667	if $do_specfile; then
668		echo "./$1 type=dir mode=$2 gid=$g_wheel uid=$u_root"
669	else
670		nooutput -2 mkdir $1
671		chmod $2 $1
672	fi
673}
674
675warn()
676{
677	echo 1>&2 "$0: $*"
678}
679
680die()
681{
682	echo 1>&2 "$0: $*"
683	exit 1
684}
685
686# makedev special [...]
687#	the main loop
688#
689makedev()
690{
691
692for i
693do
694
695case $i in
696
697%MD_DEVICES%
698
699all)
700	makedev all_md
701	makedev std fd ptm pty0 pty1 pty2 pty3
702	makedev ccd0 ccd1 ccd2 ccd3
703	makedev cgd0 cgd1 cgd2 cgd3
704	makedev fss0 fss1 fss2 fss3
705	makedev md0 md1
706	makedev raid0 raid1 raid2 raid3 raid4 raid5 raid6 raid7
707	makedev vnd0 vnd1 vnd2 vnd3
708	makedev bpf
709	makedev tun0 tun1 tun2 tun3
710	makedev ipl pf crypto random
711	makedev lkm lockstat clockctl cpuctl
712	makedev atabus0 atabus1 atabus2 atabus3
713	makedev tap tap0 tap1 tap2 tap3
714	makedev gpio gpio0 gpio1 gpio2 gpio3 gpio4 gpio5 gpio6 gpio7
715	makedev pad pad0 pad1 pad2 pad3
716	makedev bthub
717	makedev cfs
718	makedev putter
719	makedev drvctl
720	makedev local # do this last
721	;;
722
723init)
724	# unless overridden by MD entry, this is equal to 'all'
725	makedev all
726	;;
727
728%MI_DEVICES_BEGIN%
729audio)
730	makedev audio0 audio1 audio2 audio3
731	lndev sound0 sound
732	lndev audio0 audio
733	lndev mixer0 mixer
734	lndev audioctl0 audioctl
735	;;
736
737gpio)
738	makedev gpio0 gpio1 gpio2 gpio3 gpio4 gpio5 gpio6 gpio7
739	lndev gpio0 gpio
740	;;
741
742pad)
743	makedev pad0 pad1 pad2 pad3
744	lndev pad0 pad
745	;;
746
747radio)
748	makedev radio0 radio1
749	lndev radio0 radio
750	;;
751
752ramdisk)
753	makedev floppy md0
754	;;
755
756usbs)
757	makedev usb usb0 usb1 usb2 usb3 usb4 usb5 usb6 usb7
758	makedev uhid0 uhid1 uhid2 uhid3
759	makedev ulpt0 ulpt1
760	makedev ttyU0 ttyU1
761	makedev ttyY0 ttyY1
762	makedev urio0
763	makedev uscanner0 uscanner1
764	makedev utoppy0 utoppy1
765	makedev ugen0
766	;;
767
768isdns)
769	makedev isdn isdnctl isdnbchan0 isdnbchan1 isdntel0 isdntel1 isdnteld0 isdnteld1 isdntrc0 isdntrc1
770	;;
771
772std)
773	mkdev		console c %cons_chr% 0	600
774	mkdev		constty c %cons_chr% 1	600
775	mkdev		drum	c %swap_chr% 0	640 $g_kmem
776	mkdev		kmem	c %mem_chr% 1	640 $g_kmem
777	mkdev		mem	c %mem_chr% 0	640 $g_kmem
778	mkdev		null	c %mem_chr% 2	666
779	mkdev		zero	c %mem_chr% 12	666
780	mkdev		klog	c %log_chr% 0	600
781	mkdev		ksyms	c %ksyms_chr% 0 444
782	if $nofdesc; then
783		mkdev	tty	c %ctty_chr% 0		666
784		mkdev	stdin	c %filedesc_chr% 0	666
785		mkdev	stdout	c %filedesc_chr% 1	666
786		mkdev	stderr	c %filedesc_chr% 2	666
787	fi
788	;;
789
790usb)
791	mkdev usb c %usb_chr% 255 444
792	;;
793
794usb*)
795	unit=${i#usb}
796	usb=usb$unit
797	mkdev usb$unit c %usb_chr% $unit
798	;;
799
800uhid*)
801	unit=${i#uhid}
802	mkdev uhid$unit c %uhid_chr% $unit 666
803	;;
804
805ulpt*)
806	unit=${i#ulpt}
807	mkdev ulpt$unit c %ulpt_chr% $unit
808	mkdev ulpn$unit c %ulpt_chr% $(($unit + 64))
809	;;
810
811urio*)
812	unit=${i#urio}
813	mkdev urio$unit c %urio_chr% $unit 666
814	;;
815
816uscanner*)
817	unit=${i#uscanner}
818	mkdev uscanner$unit c %uscanner_chr% $unit
819	;;
820
821utoppy*)
822	unit=${i#utoppy}
823	mkdev utoppy$unit c %utoppy_chr% $unit
824	;;
825
826ttyY*)
827	unit=${i#ttyY}
828	mkdev ttyY$unit c %ucycom_chr% $(($unit + $dialin  )) "" "" $u_uucp
829	mkdev dtyY$unit c %ucycom_chr% $(($unit + $dialout )) "" "" $u_uucp
830	mkdev ctyY$unit c %ucycom_chr% $(($unit + $callunit)) "" "" $u_uucp
831	;;
832
833ttyU*)
834	unit=${i#ttyU}
835	mkdev ttyU$unit c %ucom_chr% $(($unit + $dialin	 )) "" "" $u_uucp
836	mkdev dtyU$unit c %ucom_chr% $(($unit + $dialout )) "" "" $u_uucp
837	mkdev ctyU$unit c %ucom_chr% $(($unit + $callunit)) "" "" $u_uucp
838	;;
839
840ugen*)
841	unit=${i#ugen}
842	for j in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
843	do
844		mkdev ugen$unit.$j c %ugen_chr% $(($unit * 16 + ${j#0}))
845	done
846	;;
847
848wscons)
849	makedev ttyE0 ttyE1 ttyE2 ttyE3 ttyE4 ttyE5 ttyE6 ttyE7
850	makedev wsmouse0 wsmouse1 wsmouse2 wsmouse3
851	makedev wskbd0 wskbd1 wskbd2 wskbd3
852	makedev wsmux0 wsmux1 wsmux2 wsmux3
853	makedev wsmouse wskbd
854	makedev ttyEcfg ttyEstat
855	makedev wsfont
856	;;
857
858wsmouse)
859	mkdev wsmouse c %wsmux_chr% 0
860	;;
861
862wskbd)
863	mkdev wskbd c %wsmux_chr% 1
864	;;
865
866wsmux*)
867	unit=${i#wsmux}
868	mkdev wsmux$unit    c %wsmux_chr% $unit
869	mkdev wsmuxctl$unit c %wsmux_chr% $(($unit + 128)) 200
870	;;
871
872xenevt)
873	mkdev xenevt c %xenevt_chr% 0
874	;;
875
876xsd_kva)
877	mkdev xsd_kva c %xenevt_chr% 1
878	;;
879
880xencons)
881	mkdev xencons c %xencons_chr% 0
882	;;
883
884ttyEstat)
885	mkdev ttyEstat c %wsdisplay_chr% 254
886	;;
887
888ttyEcfg)
889	mkdev ttyEcfg c %wsdisplay_chr% 255
890	;;
891
892ttyE*)
893	unit=${i#ttyE}
894	mkdev ttyE$unit c %wsdisplay_chr% $unit
895	;;
896
897wsmouse*)
898	unit=${i#wsmouse}
899	mkdev wsmouse$unit c %wsmouse_chr% $unit
900	;;
901
902wskbd*)
903	unit=${i#wskbd}
904	mkdev wskbd$unit c %wskbd_chr% $unit
905	;;
906
907fd)
908	if $nofdesc; then
909		makedir fd 755
910		n=0
911		while [ $n -lt 64 ]
912		do
913			mkdev fd/$n c %filedesc_chr% $n 666
914			n=$(($n + 1))
915		done
916	fi
917	;;
918
919wt*)
920	case $i in
921	wt*) name=wt;  unit=${i#wt};	chr=%wt_chr%;	blk=%wt_blk%;;
922	esac
923	for sub in $unit $(($unit+8)) $(($unit+16))
924	do
925		mkdev $name$sub		b $blk $(($sub + 0)) 660 $g_operator
926		mkdev n$name$sub	b $blk $(($sub + 4)) 660 $g_operator
927		mkdev r$name$sub	c $chr $(($sub + 0)) 660 $g_operator
928		mkdev nr$name$sub	c $chr $(($sub + 4)) 660 $g_operator
929	done
930	;;
931
932md*)
933	makedisk_minimal md ${i#md} %md_blk% %md_chr%
934	;;
935
936fss*)
937	case $i in
938	fss*) name=fss; unit=${i#fss};	blk=%fss_blk%;	chr=%fss_chr%
939	esac
940	mkdev $name$unit	b $blk $unit 660 $g_operator
941	mkdev r$name$unit	c $chr $unit 660 $g_operator
942	;;
943
944ss*)
945	case $i in
946	ss*) name=ss;	unit=${i#ss};	chr=%ss_chr%;;
947	esac
948	mkdev $name$unit	c $chr $(($unit * 16 + 0)) 640 $g_operator
949	mkdev n$name$unit	c $chr $(($unit * 16 + 1)) 640 $g_operator
950	mkdev en$name$unit	c $chr $(($unit * 16 + 3)) 640 $g_operator
951	;;
952
953ccd*|cgd*|raid*|vnd*)
954	case $i in
955	ccd*)	name=ccd;	unit=${i#ccd};	blk=%ccd_blk%;	chr=%ccd_chr%;;
956	cgd*)	name=cgd;	unit=${i#cgd};	blk=%cgd_blk%;	chr=%cgd_chr%;;
957	raid*)	name=raid;	unit=${i#raid}; blk=%raid_blk%; chr=%raid_chr%;;
958	vnd*)	name=vnd;	unit=${i#vnd};	blk=%vnd_blk%;	chr=%vnd_chr%;;
959	esac
960	%MKDISK% $name $unit $blk $chr
961	;;
962
963sd*)
964	name=sd; unit=${i#sd};	blk=%sd_blk%;	chr=%sd_chr%
965	%MKDISK% $name $unit $blk $chr
966	;;
967
968wd*)
969	name=wd; unit=${i#wd}; blk=%wd_blk%; chr=%wd_chr%
970	%MKDISK% $name $unit $blk $chr
971	;;
972
973fd*)
974	name=fd; unit=${i#fd}; blk=%fd_blk%; chr=%fd_chr%
975	%MKDISK% $name $unit $blk $chr
976	;;
977
978ld*)
979	name=ld; unit=${i#ld}; blk=%ld_blk%; chr=%ld_chr%
980	%MKDISK% $name $unit $blk $chr
981	;;
982
983bio)
984	mkdev bio c %bio_chr% 0
985	;;
986
987ed*)
988	name=ed; unit=${i#ed}; blk=%ed_blk%; chr=%ed_chr%
989	%MKDISK% $name $unit $blk $chr
990	;;
991
992ofdisk*)
993	name=ofdisk; unit=${i#ofdisk}; blk=%ofdisk_blk%; chr=%ofdisk_chr%
994	%MKDISK% $name $unit $blk $chr
995	;;
996
997xbd*)
998	name=xbd; unit=${i#xbd}; blk=%xbd_blk%; chr=%xbd_chr%
999	%MKDISK% $name $unit $blk $chr
1000	;;
1001
1002dk*)
1003	name=dk; unit=${i#dk}; blk=%dk_blk%; chr=%dk_chr%
1004	minor=0
1005	while [ $minor -le ${i#dk} ]
1006	do
1007		mkdev r$name$minor c $chr $minor 0640 $g_operator
1008		mkdev $name$minor b $blk  $minor 0640 $g_operator
1009		minor=$(($minor + 1))
1010	done
1011	;;
1012
1013ttyCY*)
1014	name=tyCY; chr=%cy_chr%; off=32
1015	unit=${i#t${name}}
1016	minor=$(($unit * $off))
1017	eminor=$(($minor + $off))
1018	while [ $minor -lt $eminor ]
1019	do
1020		nminor=000$minor
1021		nminor=${nminor#${nminor%???}}
1022		mkdev t$name$nminor c $chr $(($minor + $dialin )) "" "" $u_uucp
1023		mkdev d$name$nminor c $chr $(($minor + $dialout)) "" "" $u_uucp
1024		minor=$(($minor + 1))
1025	done
1026	;;
1027
1028ttyCZ*)
1029	name=tyCZ; chr=%cz_chr%; off=64
1030	unit=${i#t${name}}
1031	minor=$(($unit * $off))
1032	eminor=$(($minor + $off))
1033	while [ $minor -lt $eminor ]
1034	do
1035		nminor=0000$minor
1036		nminor=${nminor#${nminor%????}}
1037		mkdev t$name$nminor c $chr $(($minor + $dialin )) "" "" $u_uucp
1038		mkdev d$name$nminor c $chr $(($minor + $dialout)) "" "" $u_uucp
1039		minor=$(($minor + 1))
1040	done
1041	;;
1042
1043
1044tty[0-9]|tty0[0-9])
1045	# some archs have built-in zstty (major %zstty_chr%) instead
1046	# of NS16550; create ttyZ* and hardlink as [dt]ty0*; this
1047	# needs to be before com entry, for archs which have both
1048	unit=${i#tty}
1049	unit=$(($unit + 0))
1050	makedev ttyZ${unit}
1051	lndev ttyZ$unit tty0${unit}
1052	lndev dtyZ$unit dty0${unit}
1053	;;
1054
1055tty0*|tty1*|tty[0-9])
1056	unit=${i#tty}
1057	ounit=00$unit
1058	ounit=${ounit#${ounit%??}}
1059	mkdev tty$ounit c %com_chr% $(($unit + $dialin )) "" "" $u_uucp
1060	mkdev dty$ounit c %com_chr% $(($unit + $dialout)) "" "" $u_uucp
1061	;;
1062
1063ttyC*)
1064		# some archs call com_chr ttyC traditionally
1065	unit=${i#ttyC}; name=ttyC; dname=dtyC; chr=%com_chr%
1066	mkdev  $name$unit c $chr $(($unit + $dialin )) "" "" $u_uucp
1067	mkdev $dname$unit c $chr $(($unit + $dialout)) "" "" $u_uucp
1068	;;
1069
1070ttyh*)
1071	unit=${i#ttyh}; name=ttyh; dname=dtyh; chr=%sabtty_chr%
1072	mkdev  $name$unit c $chr $(($unit + $dialin )) "" "" $u_uucp
1073	mkdev $dname$unit c $chr $(($unit + $dialout)) "" "" $u_uucp
1074	;;
1075
1076ttyTX*)
1077	unit=${i#ttyTX}; name=ttyTX0; dname=dtyTX0; chr=%txcom_chr%
1078	mkdev  $name$unit c $chr $(($unit + $dialin )) "" "" $u_uucp
1079	mkdev $dname$unit c $chr $(($unit + $dialout)) "" "" $u_uucp
1080	;;
1081
1082ttyZ*)
1083	unit=${i#ttyZ}; name=ttyZ; dname=dtyZ; chr=%zstty_chr%
1084	mkdev  $name$unit c $chr $(($unit + $dialin )) "" "" $u_uucp
1085	mkdev $dname$unit c $chr $(($unit + $dialout)) "" "" $u_uucp
1086	;;
1087
1088opty)
1089	for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f
1090	do
1091		case $j in
1092		[0-9])	jn=$j ;;
1093		a)	jn=10 ;;
1094		b)	jn=11 ;;
1095		c)	jn=12 ;;
1096		d)	jn=13 ;;
1097		e)	jn=14 ;;
1098		f)	jn=15 ;;
1099		esac
1100		mkdev ttyp$j c %pts_chr% $jn 666
1101		mkdev ptyp$j c %ptc_chr% $jn 666
1102	done
1103	;;
1104
1105pty*)
1106	class=${i#pty}
1107	d1="p q r s t u v w x y z P Q R S T"
1108	if [ "$class" -ge 64 ]
1109	then
1110		warn "$i: pty unit must be between 0 and 63"
1111		continue
1112	elif [ "$class" -lt 16 ]
1113	then
1114		offset=0
1115		mult=0
1116		d2="0 1 2 3 4 5 6 7 8 9 a b c d e f"
1117	else
1118		class=$(($class - 16))
1119		offset=256
1120		mult=2
1121		d2="g h i j k l m n o p q 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 Y Z"
1122	fi
1123	start=$(($class * 16))
1124	set -- $d2
1125	nt=$#
1126	s1=$(($start / $nt))
1127	set -- $d1
1128	shift $s1
1129	t1=$1
1130	if [ "$t1" = v ]; then
1131		warn "$i: pty unit conflicts with console ttyv0 device"
1132		continue
1133	fi
1134	s2=$(($start % ($nt - $s1 * $mult)))
1135	set -- $d2
1136	shift $s2
1137	t2=$1
1138	unit=$(($start + $offset - $s1 * $mult))
1139	end=$(($unit + 16))
1140	while [ "$unit" -lt "$end" ]
1141	do
1142		mkdev tty$t1$t2 c %pts_chr% $unit 666
1143		mkdev pty$t1$t2 c %ptc_chr% $unit 666
1144		shift
1145		t2=$1
1146		if [ -z "$t2" ]
1147		then
1148			break
1149		fi
1150		unit=$(($unit + 1))
1151	done
1152	;;
1153
1154stic*)
1155	unit=${i#stic}
1156	mkdev stic$unit c %stic_chr% $unit
1157	;;
1158
1159st*)
1160	case $i in
1161	st*) name=st;	unit=${i#st};	chr=%st_chr%;	blk=%st_blk%;;
1162	esac
1163	mkdev $name$unit	b $blk $(($unit * 16 + 0)) 660 $g_operator
1164	mkdev n$name$unit	b $blk $(($unit * 16 + 1)) 660 $g_operator
1165	mkdev e$name$unit	b $blk $(($unit * 16 + 2)) 660 $g_operator
1166	mkdev en$name$unit	b $blk $(($unit * 16 + 3)) 660 $g_operator
1167	mkdev r$name$unit	c $chr $(($unit * 16 + 0)) 660 $g_operator
1168	mkdev nr$name$unit	c $chr $(($unit * 16 + 1)) 660 $g_operator
1169	mkdev er$name$unit	c $chr $(($unit * 16 + 2)) 660 $g_operator
1170	mkdev enr$name$unit	c $chr $(($unit * 16 + 3)) 660 $g_operator
1171	;;
1172
1173ses*|ch*|uk*)
1174	case $i in
1175	ch*)	name=ch;	unit=${i#ch};	chr=%ch_chr%;;
1176	uk*)	name=uk;	unit=${i#uk};	chr=%uk_chr%;;
1177	ses*)	name=ses;	unit=${i#ses};	chr=%ses_chr%;;
1178	esac
1179	mkdev $name$unit c $chr $unit 640 $g_operator
1180	;;
1181
1182cd*)
1183	makedisk_minimal cd ${i#cd} %cd_blk% %cd_chr% %
1184	;;
1185
1186mcd*)
1187	makedisk_minimal mcd ${i#mcd} %mcd_blk% %mcd_chr%
1188	;;
1189
1190gdrom*)
1191	makedisk_minimal gdrom ${i#gdrom} %gdrom_blk% %gdrom_chr%
1192	;;
1193
1194lpt*|lpa*)
1195	case $i in
1196	lpt*) name=lpt; unit=${i#lpt};	chr=%lpt_chr%;	flags=0;;
1197	lpa*) name=lpa; unit=${i#lpa};	chr=%lpt_chr%;	flags=128;;
1198	esac
1199	mkdev $name$unit c $chr $(($unit + $flags))
1200	mkdev lpt${unit}ctl c $chr $(($unit + 256))
1201	;;
1202
1203bpf)
1204	mkdev bpf	c %bpf_chr% 0
1205	lndev bpf bpf0
1206	;;
1207
1208bthub)
1209	mkdev bthub c %bthub_chr% 0
1210	;;
1211
1212tun*)
1213	unit=${i#tun}
1214	mkdev tun$unit c %tun_chr% $unit
1215	;;
1216
1217joy*)
1218	unit=${i#joy}
1219	mkdev joy$unit c %joy_chr% $unit
1220	;;
1221
1222ipl)
1223	mkdev ipl	c %ipl_chr% 0
1224	mkdev ipnat	c %ipl_chr% 1
1225	mkdev ipstate	c %ipl_chr% 2
1226	mkdev ipauth	c %ipl_chr% 3
1227	mkdev ipsync	c %ipl_chr% 4
1228	mkdev ipscan	c %ipl_chr% 5
1229	mkdev iplookup	c %ipl_chr% 6
1230	;;
1231
1232pf)
1233	mkdev pf c %pf_chr% 0
1234	;;
1235
1236crypto)
1237	mkdev crypto c %crypto_chr% 0 666
1238	;;
1239
1240cmos)
1241	mkdev cmos c %cmos_chr% 0 644
1242	;;
1243
1244speaker)
1245	mkdev speaker c %spkr_chr% 0
1246	;;
1247
1248lkm)
1249	mkdev lkm c %lkm_chr% 0 640 $g_kmem
1250	;;
1251
1252lockstat)
1253	mkdev lockstat c %lockstat_chr% 0
1254	;;
1255
1256cpuctl)
1257	mkdev cpuctl c %cpuctl_chr% 0 666
1258	;;
1259
1260audio*)
1261	unit=${i#audio}
1262	audio=audio$unit
1263	sound=sound$unit
1264	mixer=mixer$unit
1265	audioctl=audioctl$unit
1266	: ${unit:-0}
1267	mkdev $sound	c %audio_chr% $(($unit + 0))	666
1268	mkdev $audio	c %audio_chr% $(($unit + 128))	666
1269	mkdev $mixer	c %audio_chr% $(($unit + 16))	666
1270	mkdev $audioctl c %audio_chr% $(($unit + 192))	666
1271	;;
1272
1273gpio*)
1274	unit=${i#gpio}
1275	mkdev gpio$unit c %gpio_chr% $unit 644
1276	;;
1277
1278rmidi*)
1279	unit=${i#rmidi}
1280	mkdev rmidi$unit c %midi_chr% $unit 666
1281	;;
1282
1283music*)
1284	unit=${i#music}
1285	: ${unit:-0}
1286	mkdev music$unit     c %sequencer_chr% $(($unit + 0))	666
1287	mkdev sequencer$unit c %sequencer_chr% $(($unit + 128)) 666
1288	;;
1289
1290radio*)
1291	unit=${i#radio}
1292	: ${unit:-0}
1293	mkdev radio$unit c %radio_chr% $unit 666
1294	;;
1295
1296amr*)
1297	unit=${i#amr}
1298	mkdev amr$unit c %amr_chr% $unit
1299	;;
1300
1301apm)
1302	mkdev apm	c %apm_chr% 0 644
1303	mkdev apmctl	c %apm_chr% 8 644
1304	;;
1305
1306apm)
1307		# hpcmips uses `apmdev_chr' instead of `apm_chr'
1308	mkdev apm	c %apmdev_chr% 0 644
1309	mkdev apmctl	c %apmdev_chr% 8 644
1310	;;
1311
1312satlink*)
1313	unit=${i#satlink}
1314	mkdev satlink$unit c %satlink_chr% $unit 444
1315	;;
1316
1317random)
1318	mkdev random	c %rnd_chr% 0 444
1319	mkdev urandom	c %rnd_chr% 1 644
1320	;;
1321
1322cfs)
1323	makedev cfs0
1324	;;
1325
1326cfs*)
1327	unit=${i#cfs}
1328	mkdev cfs$unit c %vcoda_chr% $unit
1329	;;
1330
1331sysmon)
1332	mkdev sysmon	c %sysmon_chr% 0 644
1333	mkdev watchdog	c %sysmon_chr% 1 644
1334	mkdev power	c %sysmon_chr% 2 640
1335	;;
1336
1337scsibus*)
1338	unit=${i#scsibus}
1339	mkdev scsibus$unit c %scsibus_chr% $unit 644
1340	;;
1341
1342bktr)
1343	makedev bktr0 bktr1
1344	lndev	bktr0	bktr
1345	lndev	tuner0	tuner
1346	lndev	vbi0	vbi
1347	;;
1348
1349bktr*)
1350	unit=${i#bktr}
1351	mkdev bktr$unit		c %bktr_chr% $(($unit + 0))	444
1352	mkdev tuner$unit	c %bktr_chr% $(($unit + 16))	444
1353	mkdev vbi$unit		c %bktr_chr% $(($unit + 32))	444
1354	;;
1355
1356io)
1357	mkdev		io	c %mem_chr% 14	600
1358	;;
1359
1360iop*)
1361	unit=${i#iop}
1362	mkdev iop$unit c %iop_chr% $unit
1363	;;
1364
1365mlx*)
1366	unit=${i#mlx}
1367	mkdev mlx$unit c %mlx_chr% $unit
1368	;;
1369
1370mly*)
1371	unit=${i#mly}
1372	mkdev mly$unit c %mly_chr% $unit
1373	;;
1374
1375twa*)
1376	unit=${i#twa}
1377	mkdev twa$unit c %twa_chr% $unit
1378	;;
1379
1380twe*)
1381	unit=${i#twe}
1382	mkdev twe$unit c %twe_chr% $unit
1383	;;
1384
1385icp*)
1386	unit=${i#icp}
1387	mkdev icp$unit c %icp_chr% $unit
1388	;;
1389
1390agp*)
1391	unit=${i#agp}
1392	mkdev agp$unit c %agp_chr% $unit 644
1393	if [ "$unit" = "0" ]; then
1394		lndev agp$unit agpgart
1395	fi
1396	;;
1397
1398pci*)
1399	unit=${i#pci}
1400	mkdev pci$unit c %pci_chr% $unit 644
1401	;;
1402
1403dpti*)
1404	unit=${i#dpti}
1405	mkdev dpti$unit c %dpti_chr% $unit
1406	;;
1407
1408dpt*)
1409	unit=${i#dpt}
1410	mkdev dpt$unit c %dpt_chr% $unit
1411	;;
1412
1413altq)
1414	makedir altq 755
1415	unit=0
1416	for dev in altq cbq wfq afm fifoq red rio localq hfsc cdnr blue priq
1417	do
1418		mkdev altq/$dev c %altq_chr% $unit 644
1419		unit=$(($unit + 1))
1420	done
1421	;;
1422
1423isdn)
1424	mkdev isdn c %isdn_chr% 0
1425	;;
1426
1427isdnctl)
1428	mkdev isdnctl c %isdnctl_chr% 0
1429	;;
1430
1431isdnbchan*)
1432	unit=${i#isdnbchan}
1433	mkdev isdnbchan$unit c %isdnbchan_chr% $unit
1434	;;
1435
1436isdnteld*)
1437	unit=${i#isdnteld}
1438	mkdev isdnteld$unit c %isdntel_chr% $(($unit + 64))
1439	;;
1440
1441isdntel*)
1442	unit=${i#isdntel}
1443	mkdev isdntel$unit c %isdntel_chr% $unit
1444	;;
1445
1446isdntrc*)
1447	unit=${i#isdntrc}
1448	mkdev isdntrc$unit c %isdntrc_chr% $unit
1449	;;
1450
1451vmegen)
1452	makedev vmegen0 vmegen1 vmegen2 vmegen3
1453	;;
1454
1455vmegen*)
1456	unit=${i#vmegen}
1457	mkdev vmegen$unit c %vmegeneric_chr% $(($unit * 16 + 0))
1458	;;
1459
1460wsfont)
1461	mkdev wsfont c %wsfont_chr% 0
1462	;;
1463
1464cir*)
1465	unit=${i#cir}
1466	mkdev cir$unit c %cir_chr% $unit 666
1467	;;
1468
1469irframe*)
1470	unit=${i#irframe}
1471	mkdev irframe$unit c %irframe_chr% $unit
1472	;;
1473
1474fcom*)
1475	unit=${i#fcom}
1476	mkdev fcom$unit c %fcom_chr% $unit "" "" $u_uucp
1477	;;
1478
1479openfirm)
1480	mkdev openfirm c %openfirm_chr% 0 444
1481	;;
1482
1483pad*)
1484	unit=${i#pad}
1485	mkdev pad$unit c %pad_chr% $unit 444
1486	;;
1487
1488nvram)
1489	mkdev nvram c %nvram_chr% 0 644
1490	;;
1491
1492rtc)
1493	mkdev rtc c %rtc_chr% 0 644
1494	;;
1495
1496clockctl)
1497	mkdev clockctl c %clockctl_chr% 0 660 $g_ntpd
1498	;;
1499
1500nsmb)
1501	makedev nsmb0 nsmb1 nsmb2 nsmb3
1502	;;
1503
1504nsmb*)
1505	unit=${i#nsmb}
1506	mkdev nsmb$unit c %nsmb_chr% $unit 644
1507	;;
1508
1509kttcp)
1510	mkdev kttcp c %kttcp_chr% 0
1511	;;
1512
1513dmoverio)
1514	mkdev dmoverio c %dmoverio_chr% 0 644
1515	;;
1516
1517veriexec)
1518	mkdev veriexec c %veriexec_chr% 0 600
1519	;;
1520
1521ttyv*)
1522	unit=${i#ttyv}
1523	mkdev ttyv$unit c %pc_chr% $unit
1524	;;
1525
1526# arm, acorn32
1527ttyv*)
1528	unit=${i#ttyv}
1529	mkdev ttyv$unit c %physcon_chr% $unit
1530	;;
1531
1532arcpp*)
1533	unit=${i#arcpp}
1534	mkdev arcpp$unit c %arcpp_chr% $unit
1535	;;
1536
1537par*)
1538	unit=${i#par}
1539	case $unit in
1540	0)
1541		mkdev par$unit c %par_chr% $unit
1542		;;
1543	*)
1544		warn "bad unit for par in: $i"
1545		;;
1546	esac
1547	;;
1548
1549ite*|ttye*)
1550	case $i in
1551	ite*)	unit=${i#ite};;
1552	ttye*)	unit=${i#ttye};;
1553	esac
1554	mkdev ttye$unit c %ite_chr% $unit
1555	;;
1556
1557pms*)
1558	unit=${i#pms}
1559	mkdev pms$unit c %opms_chr% $unit
1560	;;
1561
1562qms*)
1563	unit=${i#qms}
1564	mkdev qms$unit c %qms_chr% $unit
1565	;;
1566
1567lms*)
1568	unit=${i#lms}
1569	mkdev lms$unit c %lms_chr% $unit
1570	;;
1571
1572mms*)
1573	unit=${i#mms}
1574	mkdev mms$unit c %mms_chr% $unit
1575	;;
1576
1577mouse-*)
1578	case $i in
1579	mouse-pms*) name=pms ;;
1580	mouse-qms*) name=qms ;;
1581	esac
1582	unit=${i#mouse-${name}}
1583	lndev $name$unit mouse
1584	;;
1585
1586kbd)
1587	mkdev kbd c %kbd_chr% 0
1588	;;
1589
1590kbdctl)
1591	mkdev kbdctl c %kbd_chr% 1
1592	;;
1593
1594vidcconsole0)
1595	mkdev vidcconsole0 c %vidcconsole_chr% 0 640
1596	;;
1597
1598view*)
1599	unit=${i#view}
1600	mkdev view$unit c %view_chr% $unit 666
1601	;;
1602
1603mouse*)
1604	unit=${i#mouse}
1605	case $unit in
1606	0|1)
1607		mkdev mouse$unit c %ms_chr% $unit 666
1608		if [ $unit = 0 ]; then
1609			lndev mouse$unit mouse
1610		fi
1611		;;
1612	*)
1613		warn "bad unit for mouse in: $i"
1614		;;
1615	esac
1616	;;
1617
1618panel)
1619	mkdev panel0 c %panel_chr% 0 660
1620	;;
1621
1622tslcd)
1623	mkdev tslcd0 c %tslcd_chr% 0 660
1624	;;
1625
1626ipty)
1627	mkdev ttyp0 c %pts_chr% 0 666
1628	mkdev ttyp1 c %pts_chr% 1 666
1629	mkdev ptyp0 c %ptc_chr% 0 666
1630	mkdev ptyp1 c %ptc_chr% 1 666
1631	;;
1632
1633ptm)
1634	mkdev ptmx c %ptm_chr% 0 666
1635	mkdev ptm c %ptm_chr% 1 666
1636	;;
1637
1638grf*)
1639	unit=${i#grf}
1640	mkdev grf$unit c %grf_chr% $unit 666
1641	;;
1642
1643etvme)
1644	mkdev etvme c %et_chr% 0
1645	;;
1646
1647leo*)
1648	unit=${i#leo}
1649	mkdev leo$unit c %leo_chr% $unit
1650	;;
1651
1652scif*)
1653	unit=${i#scif}
1654	mkdev scif$unit c %scif_chr% $unit "" "" $u_uucp
1655	;;
1656
1657sci*)
1658	unit=${i#sci}
1659	mkdev sci$unit c %sci_chr% $unit "" "" $u_uucp
1660	;;
1661
1662maple*)
1663	case $i in
1664	mapleA*) name="mapleA"; unit=0;;
1665	mapleB*) name="mapleB"; unit=1;;
1666	mapleC*) name="mapleC"; unit=2;;
1667	mapleD*) name="mapleD"; unit=3;;
1668	esac
1669	subunit=${i#$name}
1670	mkdev $name$subunit c %maple_chr% $(($unit * 8 + 0$subunit))
1671	;;
1672
1673mmem*)
1674	unit=${i#mmem}
1675	for pt in 0	# 1 2 3 4 ... 255
1676	do
1677#		mkdev mmem${unit}.${pt}a  b %mmem_blk% $(($unit * 4096 + $pt * 16 + 0)) 640 $g_operator
1678		mkdev mmem${unit}.${pt}c  b %mmem_blk% $(($unit * 4096 + $pt * 16 + 2)) 640 $g_operator
1679#		mkdev rmmem${unit}.${pt}a c %mmem_chr% $(($unit * 4096 + $pt * 16 + 0)) 640 $g_operator
1680		mkdev rmmem${unit}.${pt}c c %mmem_chr% $(($unit * 4096 + $pt * 16 + 2)) 640 $g_operator
1681	done
1682	;;
1683
1684mlcd*)
1685	unit=${i#mlcd}
1686	for pt in 0	# 1 2 3 4 ... 255
1687	do
1688		mkdev mlcd${unit}.${pt} c %mlcd_chr% $(($unit * 256 + $pt)) 640 $g_operator
1689	done
1690	;;
1691
1692ixpcom*)
1693	unit=${i#ixpcom}
1694	mkdev ixpcom$unit c %ixpcom_chr% $unit "" "" $u_uucp
1695	;;
1696
1697epcom*)
1698	unit=${i#epcom}
1699	mkdev epcom$unit c %epcom_chr% $unit "" "" $u_uucp
1700	;;
1701
1702ucbsnd)
1703	mkdev ucbsnd c %ucbsnd_chr% 0 666
1704	;;
1705
1706adb)
1707	mkdev adb c %aed_chr% 0 666
1708	;;
1709
1710asc*)
1711	unit=${i#asc}
1712	mkdev asc$unit c %asc_chr% $unit 666
1713	;;
1714
1715bwtwo*)
1716	unit=${i#bwtwo}
1717	mkdev bwtwo$unit c %bwtwo_chr% $unit 666
1718	;;
1719
1720cgtwo*)
1721	unit=${i#cgtwo}
1722	mkdev cgtwo$unit c %cgtwo_chr% $unit 666
1723	;;
1724
1725cgthree*)
1726	unit=${i#cgthree}
1727	mkdev cgthree$unit c %cgthree_chr% $unit 666
1728	;;
1729
1730cgfour*)
1731	unit=${i#cgfour}
1732	mkdev cgfour$unit c %cgfour_chr% $unit 666
1733	;;
1734
1735cgsix*)
1736	unit=${i#cgsix}
1737	mkdev cgsix$unit c %cgsix_chr% $unit 666
1738	;;
1739
1740cgeight*)
1741	unit=${i#cgeight}
1742	mkdev cgeight$unit c %cgeight_chr% $unit 666
1743	;;
1744
1745tcx*)
1746	unit=${i#tcx}
1747	mkdev tcx$unit c %tcx_chr% $unit 666
1748	;;
1749
1750xd*|xy*)
1751	case $i in
1752	xd*)	name=xd; unit=${i#xd}; blk=%xd_blk%;	chr=%xd_chr%;;
1753	xy*)	name=xy; unit=${i#xy}; blk=%xy_blk%;	chr=%xy_chr%;;
1754	esac
1755	%MKDISK% $name $unit $blk $chr
1756	;;
1757
1758magma*)
1759	unit=${i#magma}
1760	if [ 0$unit -gt 3 ]; then
1761		warn "bad unit for $i: $unit"
1762		break
1763	fi
1764	for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f
1765	do
1766		case $j in
1767		[0-9])	jn=$j ;;
1768		a)	jn=10 ;;
1769		b)	jn=11 ;;
1770		c)	jn=12 ;;
1771		d)	jn=13 ;;
1772		e)	jn=14 ;;
1773		f)	jn=15 ;;
1774		esac
1775		mkdev tty$unit$j c %mtty_chr% $(($unit * 64 + $jn))
1776	done
1777	mkdev bpp${unit}0 c %mbpp_chr% $(($unit * 64 + 0))
1778	mkdev bpp${unit}1 c %mbpp_chr% $(($unit * 64 + 1))
1779	;;
1780
1781clcd*)
1782	unit=${i#clcd}
1783	if [ 0$unit -gt 7 ]; then
1784		warn "bad unit for $i: $unit"
1785		break
1786	fi
1787	for j in 0 1 2 3 4 5 6 7
1788	do
1789		mkdev ttyA$unit$j c %clcd_chr% $(($unit * 8 + $j + $dialin)) "" "" $u_uucp
1790		mkdev dtyA$unit$j c %clcd_chr% $(($unit * 8 + $j + $dialout)) "" "" $u_uucp
1791	done
1792	;;
1793
1794spif*)
1795	unit=${i#spif}
1796	if [ 0$unit -gt 3 ]; then
1797		warn "bad unit for $i: $unit"
1798		break
1799	fi
1800	for j in 0 1 2 3 4 5 6 7; do
1801		mkdev ttyS$unit$j c 102 $(($unit * 64 + $j)) "" "" $u_uucp
1802	done
1803	mkdev bppS${unit}0 c 103 $(($unit * 64 + 0))
1804	mkdev bppS${unit}1 c 103 $(($unit * 64 + 1))
1805	;;
1806
1807bpp*)
1808	unit=${i#bpp}
1809	mkdev bpp$unit c %bpp_chr% $(($unit + 0))
1810	;;
1811
1812tctrl*)
1813	unit=${i#tctrl}
1814	mkdev tctrl$unit c %tctrl_chr% $unit 666
1815	;;
1816
1817bmd*)
1818	unit=${i#bmd}
1819	mkdev bmd${unit}a  b %bmd_blk% $(($unit * 8 + 0)) 640 $g_operator
1820	mkdev bmd${unit}c  b %bmd_blk% $(($unit * 8 + 2)) 640 $g_operator
1821	mkdev rbmd${unit}a c %bmd_chr% $(($unit * 8 + 0)) 640 $g_operator
1822	mkdev rbmd${unit}c c %bmd_chr% $(($unit * 8 + 2)) 640 $g_operator
1823	;;
1824
1825sram)
1826	mkdev sram c %sram_chr% 0 644
1827	;;
1828
1829pow*)
1830	unit=${i#pow}
1831	case $unit in
1832	0|1)
1833		mkdev pow${unit} c %pow_chr% ${unit} 644
1834		if [ $unit = 0 ]; then
1835			lndev pow${unit} pow
1836		fi
1837		;;
1838	*)
1839		warn "bad unit for pow in: $i"
1840		;;
1841	esac
1842	;;
1843
1844ttyS*)
1845	unit=${i#ttyS}
1846	mkdev ttyS$unit c %sacom_chr% $(($unit + $dialin )) "" "" $u_uucp
1847	mkdev dtyS$unit c %sacom_chr% $(($unit + $dialout)) "" "" $u_uucp
1848	;;
1849
1850atabus*)
1851	unit=${i#atabus}
1852	mkdev atabus$unit c %atabus_chr% $unit 644
1853	;;
1854
1855drvctl)
1856	mkdev drvctl c %drvctl_chr% 0 644
1857	;;
1858
1859isv)
1860	mkdev isv c %isv_chr% 0 644
1861	;;
1862
1863tap*)
1864	unit=${i#tap}
1865	case "$unit" in
1866	[0-9]*)
1867		mkdev tap${unit} c %tap_chr% ${unit} 600
1868		;;
1869	*)
1870		mkdev tap c %tap_chr% 0xfffff 600
1871		;;
1872	esac
1873	;;
1874
1875fw*)
1876	unit=${i#fw}
1877	for j in 0 1 2 3
1878	do
1879		mkdev fw${unit}.${j} c %fw_chr% $((${unit} * 256 + ${j})) 660 ${g_operator}
1880		mkdev fwmem${unit}.${j} c %fw_chr% $((65536 + ${unit} * 256 + ${j})) 660 ${g_operator}
1881	done
1882	;;
1883
1884# create putter device and symlinks for all subsystems using it
1885putter)
1886	mkdev putter c %putter_chr% 0 600
1887	mkdev pud c %putter_chr% 1 600
1888	lndev putter puffs
1889	;;
1890
1891midevend)
1892%MI_DEVICES_END%
1893local)
1894	if [ -f "$0.local" ]; then
1895		umask 0
1896		if [ -n "$count_nodes" ]; then
1897			count_nodes=$((count_nodes + \
1898			    $(linecount "$(sh "$0.local" $opts -s all)") ))
1899		else
1900			sh "$0.local" $opts all
1901		fi
1902		umask 077
1903	else
1904		warn "missing $0.local"
1905	fi
1906	;;
1907
1908*)
1909	warn "$i: unknown device"
1910	;;
1911
1912esac
1913done
1914
1915}
1916
1917
1918# three variants of disk partitions - max 8, max 16, max 16 with highpartoffset
1919# hack; only the one used by port is retained in final MAKEDEV script
1920# routine is called as:
1921# makedisk name unit blk chr
1922makedisk_p8()
1923{
1924	name="$1"; unit="$2"; blk="$3"; chr="$4"
1925
1926	mkdev ${name}${unit}a	b $blk $(($unit * 8 + 0))	640 $g_operator
1927	mkdev ${name}${unit}b	b $blk $(($unit * 8 + 1))	640 $g_operator
1928	mkdev ${name}${unit}c	b $blk $(($unit * 8 + 2))	640 $g_operator
1929	mkdev ${name}${unit}d	b $blk $(($unit * 8 + 3))	640 $g_operator
1930	mkdev ${name}${unit}e	b $blk $(($unit * 8 + 4))	640 $g_operator
1931	mkdev ${name}${unit}f	b $blk $(($unit * 8 + 5))	640 $g_operator
1932	mkdev ${name}${unit}g	b $blk $(($unit * 8 + 6))	640 $g_operator
1933	mkdev ${name}${unit}h	b $blk $(($unit * 8 + 7))	640 $g_operator
1934	mkdev r${name}${unit}a	c $chr $(($unit * 8 + 0))	640 $g_operator
1935	mkdev r${name}${unit}b	c $chr $(($unit * 8 + 1))	640 $g_operator
1936	mkdev r${name}${unit}c	c $chr $(($unit * 8 + 2))	640 $g_operator
1937	mkdev r${name}${unit}d	c $chr $(($unit * 8 + 3))	640 $g_operator
1938	mkdev r${name}${unit}e	c $chr $(($unit * 8 + 4))	640 $g_operator
1939	mkdev r${name}${unit}f	c $chr $(($unit * 8 + 5))	640 $g_operator
1940	mkdev r${name}${unit}g	c $chr $(($unit * 8 + 6))	640 $g_operator
1941	mkdev r${name}${unit}h	c $chr $(($unit * 8 + 7))	640 $g_operator
1942}
1943
1944makedisk_p16()
1945{
1946	name="$1"; unit="$2"; blk="$3"; chr="$4"
1947
1948	mkdev ${name}${unit}a	b $blk $(($unit * 16 + 0))	640 $g_operator
1949	mkdev ${name}${unit}b	b $blk $(($unit * 16 + 1))	640 $g_operator
1950	mkdev ${name}${unit}c	b $blk $(($unit * 16 + 2))	640 $g_operator
1951	mkdev ${name}${unit}d	b $blk $(($unit * 16 + 3))	640 $g_operator
1952	mkdev ${name}${unit}e	b $blk $(($unit * 16 + 4))	640 $g_operator
1953	mkdev ${name}${unit}f	b $blk $(($unit * 16 + 5))	640 $g_operator
1954	mkdev ${name}${unit}g	b $blk $(($unit * 16 + 6))	640 $g_operator
1955	mkdev ${name}${unit}h	b $blk $(($unit * 16 + 7))	640 $g_operator
1956	mkdev ${name}${unit}i	b $blk $(($unit * 16 + 8))	640 $g_operator
1957	mkdev ${name}${unit}j	b $blk $(($unit * 16 + 9))	640 $g_operator
1958	mkdev ${name}${unit}k	b $blk $(($unit * 16 + 10))	640 $g_operator
1959	mkdev ${name}${unit}l	b $blk $(($unit * 16 + 11))	640 $g_operator
1960	mkdev ${name}${unit}m	b $blk $(($unit * 16 + 12))	640 $g_operator
1961	mkdev ${name}${unit}n	b $blk $(($unit * 16 + 13))	640 $g_operator
1962	mkdev ${name}${unit}o	b $blk $(($unit * 16 + 14))	640 $g_operator
1963	mkdev ${name}${unit}p	b $blk $(($unit * 16 + 15))	640 $g_operator
1964	mkdev r${name}${unit}a	c $chr $(($unit * 16 + 0))	640 $g_operator
1965	mkdev r${name}${unit}b	c $chr $(($unit * 16 + 1))	640 $g_operator
1966	mkdev r${name}${unit}c	c $chr $(($unit * 16 + 2))	640 $g_operator
1967	mkdev r${name}${unit}d	c $chr $(($unit * 16 + 3))	640 $g_operator
1968	mkdev r${name}${unit}e	c $chr $(($unit * 16 + 4))	640 $g_operator
1969	mkdev r${name}${unit}f	c $chr $(($unit * 16 + 5))	640 $g_operator
1970	mkdev r${name}${unit}g	c $chr $(($unit * 16 + 6))	640 $g_operator
1971	mkdev r${name}${unit}h	c $chr $(($unit * 16 + 7))	640 $g_operator
1972	mkdev r${name}${unit}i	c $chr $(($unit * 16 + 8))	640 $g_operator
1973	mkdev r${name}${unit}j	c $chr $(($unit * 16 + 9))	640 $g_operator
1974	mkdev r${name}${unit}k	c $chr $(($unit * 16 + 10))	640 $g_operator
1975	mkdev r${name}${unit}l	c $chr $(($unit * 16 + 11))	640 $g_operator
1976	mkdev r${name}${unit}m	c $chr $(($unit * 16 + 12))	640 $g_operator
1977	mkdev r${name}${unit}n	c $chr $(($unit * 16 + 13))	640 $g_operator
1978	mkdev r${name}${unit}o	c $chr $(($unit * 16 + 14))	640 $g_operator
1979	mkdev r${name}${unit}p	c $chr $(($unit * 16 + 15))	640 $g_operator
1980}
1981
1982makedisk_p16high()
1983{
1984	ho=524280	# offset for partition 9 to 16
1985	name="$1"; unit="$2"; blk="$3"; chr="$4"
1986
1987	mkdev ${name}${unit}a	b $blk $(($unit * 8 + 0))	640 $g_operator
1988	mkdev ${name}${unit}b	b $blk $(($unit * 8 + 1))	640 $g_operator
1989	mkdev ${name}${unit}c	b $blk $(($unit * 8 + 2))	640 $g_operator
1990	mkdev ${name}${unit}d	b $blk $(($unit * 8 + 3))	640 $g_operator
1991	mkdev ${name}${unit}e	b $blk $(($unit * 8 + 4))	640 $g_operator
1992	mkdev ${name}${unit}f	b $blk $(($unit * 8 + 5))	640 $g_operator
1993	mkdev ${name}${unit}g	b $blk $(($unit * 8 + 6))	640 $g_operator
1994	mkdev ${name}${unit}h	b $blk $(($unit * 8 + 7))	640 $g_operator
1995	mkdev ${name}${unit}i	b $blk $(($unit * 8 + $ho + 8)) 640 $g_operator
1996	mkdev ${name}${unit}j	b $blk $(($unit * 8 + $ho + 9)) 640 $g_operator
1997	mkdev ${name}${unit}k	b $blk $(($unit * 8 + $ho + 10)) 640 $g_operator
1998	mkdev ${name}${unit}l	b $blk $(($unit * 8 + $ho + 11)) 640 $g_operator
1999	mkdev ${name}${unit}m	b $blk $(($unit * 8 + $ho + 12)) 640 $g_operator
2000	mkdev ${name}${unit}n	b $blk $(($unit * 8 + $ho + 13)) 640 $g_operator
2001	mkdev ${name}${unit}o	b $blk $(($unit * 8 + $ho + 14)) 640 $g_operator
2002	mkdev ${name}${unit}p	b $blk $(($unit * 8 + $ho + 15)) 640 $g_operator
2003	mkdev r${name}${unit}a	c $chr $(($unit * 8 + 0))	640 $g_operator
2004	mkdev r${name}${unit}b	c $chr $(($unit * 8 + 1))	640 $g_operator
2005	mkdev r${name}${unit}c	c $chr $(($unit * 8 + 2))	640 $g_operator
2006	mkdev r${name}${unit}d	c $chr $(($unit * 8 + 3))	640 $g_operator
2007	mkdev r${name}${unit}e	c $chr $(($unit * 8 + 4))	640 $g_operator
2008	mkdev r${name}${unit}f	c $chr $(($unit * 8 + 5))	640 $g_operator
2009	mkdev r${name}${unit}g	c $chr $(($unit * 8 + 6))	640 $g_operator
2010	mkdev r${name}${unit}h	c $chr $(($unit * 8 + 7))	640 $g_operator
2011	mkdev r${name}${unit}i	c $chr $(($unit * 8 + $ho + 8)) 640 $g_operator
2012	mkdev r${name}${unit}j	c $chr $(($unit * 8 + $ho + 9)) 640 $g_operator
2013	mkdev r${name}${unit}k	c $chr $(($unit * 8 + $ho + 10)) 640 $g_operator
2014	mkdev r${name}${unit}l	c $chr $(($unit * 8 + $ho + 11)) 640 $g_operator
2015	mkdev r${name}${unit}m	c $chr $(($unit * 8 + $ho + 12)) 640 $g_operator
2016	mkdev r${name}${unit}n	c $chr $(($unit * 8 + $ho + 13)) 640 $g_operator
2017	mkdev r${name}${unit}o	c $chr $(($unit * 8 + $ho + 14)) 640 $g_operator
2018	mkdev r${name}${unit}p	c $chr $(($unit * 8 + $ho + 15)) 640 $g_operator
2019}
2020
2021# make only the very few basic disk device nodes - 'a' partition
2022# and raw partition
2023makedisk_minimal()
2024{
2025	name=$1; unit=$2; blk=$3; chr=$4
2026	doff=%DISKMINOROFFSET%
2027	ro=%RAWDISK_OFF%
2028	rn=%RAWDISK_NAME%
2029
2030	mkdev ${name}${unit}a	b $blk $(($unit * $doff + 0))	640 $g_operator
2031	mkdev ${name}${unit}$rn b $blk $(($unit * $doff + $ro)) 640 $g_operator
2032	mkdev r${name}${unit}a	c $chr $(($unit * $doff + 0))	640 $g_operator
2033	mkdev r${name}${unit}$rn c $chr $(($unit * $doff + $ro)) 640 $g_operator
2034}
2035
2036# create_mfs_dev nodes
2037#	Create a memory file system for a given number of device nodes,
2038#	and mount it.  Attempts to use mount_tmpfs, or falls back to
2039#	mount_mfs.
2040#
2041#	If do_redirect, then also redirect output to the console.
2042#
2043create_mfs_dev()
2044{
2045	ndevnodes=${1-1200}
2046	dev_mountpoint=${PWD:-/dev}
2047
2048	# Number of inodes is the specified number of device nodes, plus
2049	# a margin to allow for extra device nodes created later.
2050	ninode=$((ndevnodes * 11 / 10))
2051	# Add 2 reserved inodes (needed for both mfs and tmpfs), and round
2052	# up to a multiple of 32 (needed for mfs, not needed for tmpfs).
2053	ninode=$(( (ninode + 2 + 31) / 32 * 32 ))
2054	# This file system size calculation is exact for mount_mfs(8)
2055	# with 512-byte sectors; it's larger than necessary
2056	# for mount_tmpfs(8).  40960 bytes (80 blocks) is the minimum size
2057	# allowed by mount_mfs.
2058	fs_bytes=$((8192 + 2 * 8192 + 4096 + ninode*(128+18) + 8192))
2059	[ "$fs_bytes" -lt 40960 ] && fs_bytes=40960
2060	fs_blocks=$((fs_bytes/512))
2061
2062	# Try tmpfs; if that fails try mfs.
2063	if mount_tmpfs -s $fs_bytes -n $ninode -m 0755 \
2064		-o union tmpfs "$dev_mountpoint"
2065	then
2066	    fstype=tmpfs
2067	elif mount_mfs -b 4096 -f 512 -s $fs_blocks -n $ninode -p 0755 \
2068		-o union swap "$dev_mountpoint"
2069	then
2070	    fstype=mfs
2071	else
2072	    die "Failed to create memory file system"
2073	fi
2074
2075	# Our current directory was in the lower file system; change it to
2076	# the newly mounted upper file system.
2077	cd "$dev_mountpoint"
2078
2079	if $do_redirect; then
2080		# Redirect stdout and stderr to console
2081		mknod -m 600 -g 0 -u 0 temp_console c 0 0
2082		exec >temp_console 2>&1
2083		rm temp_console
2084	fi
2085
2086	echo "Created $fstype $dev_mountpoint" \
2087		"($fs_blocks blocks, $ninode inodes)"
2088}
2089
2090#
2091# MAIN: If MAKEDEV_AS_LIBRARY is set, then we are being used as a
2092# function library, so just return.  Otherwise, do all the real work.
2093#
2094[ -n "${MAKEDEV_AS_LIBRARY}" ] && return
2095makedev_main makedev ${1+"$@"}
2096