#!/bin/sh -
#
# Generated from:
#	NetBSD: MAKEDEV.awk,v 1.18 2007/04/08 09:35:25 scw Exp 
#	NetBSD: MAKEDEV.tmpl,v 1.85 2007/03/21 23:07:00 dyoung Exp 
#	NetBSD: etc.sgimips/MAKEDEV.conf,v 1.8 2007/01/15 23:35:12 hubertf Exp 
#
# Copyright (c) 2003,2007 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
#        This product includes software developed by the NetBSD
#        Foundation, Inc. and its contributors.
# 4. Neither the name of The NetBSD Foundation nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#
###########################################################################
#
#
# Device "make" file.  Valid special arguments:
#	all	makes all known devices, including local devices.
#		Tries to make the 'standard' number of each type.
#	init	A set of devices that is used for MFS /dev by init.
#		May be equal to "all".
#	floppy	devices to be put on install floppies
#	ramdisk	devices to be put into INSTALL kernel ramdisks.
#	std	standard devices
#	local	configuration specific devices
#	wscons	make wscons devices
#	usbs	make USB devices
#	isdns	make ISDN devices
#

#
# Apart from a few lines right at the end, this file should consist
# entirely of function definitions.
#
# This file is used both as a standalone script (via "sh ./MAKEDEV all"
# or similar), and as a function library (via "MAKEDEV_AS_LIBRARY=1 .
# MAKEDEV" from MAKEDEV.local).
#

usage()
{
	cat 1>&2 << _USAGE_
Usage: ${0##*/} [-f] [-m mknod] [-s]  special [...]
	Create listed special devices.  Options:
	-f		Force permissions to be updated on existing devices.
	-m mknod	Name of mknod(8) program.  [\$TOOL_MKNOD or mknod]
	-s		Generate mtree(8) specfile instead of creating devices.

_USAGE_
	exit 1
}

# zeropad width number
#	display number with a zero (`0') padding of width digits.
#
zeropad()
{
	case $(($1 - ${#2})) in
	5)	echo 00000$2;;
	4)	echo 0000$2;;
	3)	echo 000$2;;
	2)	echo 00$2;;
	1)	echo 0$2;;
	0)	echo $2;;
	*)	echo "$0: bad padding" 1>&2; exit 1;;
	esac
}

# hexprint number
#	display (base10) number as hexadecimal
#
hexprint()
{
	val="$(($1 + 0))"
	hex=
	set -- 0 1 2 3 4 5 6 7 8 9 a b c d e f
	while [ "$val" -gt 0 ]; do
		eval hex=\$$(($val % 16 + 1))\$hex
		val="$(($val / 16))"
	done
	echo "${hex:-0}"
}

setup()
{
	PATH=/sbin:/usr/sbin:/bin:/usr/bin:/rescue

	do_create_mfs=false
	do_force=false
	do_pax=false
	do_redirect=false
	do_specfile=false
	opts=
	while getopts Mfm:p:s ch; do
		# Options that should not be passed through to
		# MAKEDEV.local are not added to $opts.
		case ${ch} in
		M)
			# "-M" sets do_create_mfs;
			# "-M -M" also sets do_redirect
			do_redirect=$do_create_mfs
			do_create_mfs=true
			;;
		f)	do_force=true
			opts="${opts} -f"
			;;
		m)	TOOL_MKNOD=${OPTARG}
			opts="${opts} -m ${OPTARG}"
			;;
		p)	TOOL_PAX="${OPTARG}"
			if ( echo "" | "${TOOL_PAX}" -w -M ); then
				do_pax=true
			else
				warn "Ignored -p option:" \
					"${TOOL_PAX} is missing or broken"
			fi
			;;
		s)	do_specfile=true
			opts="${opts} -s"
			;;
		*)	usage ;;
		esac
	done

	shift $((${OPTIND} - 1))
	[ $# -gt 0 ] || usage

	MKNOD="${TOOL_MKNOD:-mknod} -F netbsd"
	if $do_force; then
		MKNOD="${MKNOD} -R"
	else
		MKNOD="${MKNOD} -r"
	fi

	u_root="0"
	u_uucp="66"
	g_kmem="2"
	g_ntpd="15"
	g_operator="5"
	g_wheel="0"
	dialin=0
	dialout=524288
	callunit=262144

	# only allow read&write for owner by default
	umask 077

	# Check if we have fdesc mounted
	if [ -d fd ]; then
		case "$(df fd)" in
		*fdesc*)	nofdesc=false;;
		*)		nofdesc=true;;
		esac
	else
		nofdesc=true
	fi

	if $do_pax && ! $do_specfile; then
		do_specfile=true
		opts="${opts} -s"
	fi
}

#
# functions available to create nodes:
#
# mkdev name [b|c] major minor [mode{=600} [gid{=0} [uid{=0}]]]
#	create device node `name' with the appropriate permissions
#
# lndev src target
#	create a symlink from src to target
#
# makedir dir mode
#	create directory with appropriate mode
#

mkdev()
{
	if [ -n "$count_nodes" ]; then
		count_nodes=$((count_nodes + 1))
		return
	fi
	if $do_specfile; then
		case $2 in
		b)	type=block ;;
		c)	type=char ;;
		esac
		echo "./$1 type=${type} device=netbsd,$3,$4 mode=${5:-600} gid=${6:-$g_wheel} uid=${7:-$u_root}"
	else
		${MKNOD} -m ${5:-600} -g \#${6:-$g_wheel} -u \#${7:-$u_root} $1 $2 $3 $4
	fi
}

lndev()
{
	if [ -n "$count_nodes" ]; then
		count_nodes=$((count_nodes + 1))
		return
	fi
	if $do_specfile; then
		echo "./$2 type=link link=$1 mode=0700 gid=$g_wheel uid=$u_root"
	else
		ln -f -s $1 $2
	fi
}

makedir()
{
	if [ -n "$count_nodes" ]; then
		count_nodes=$((count_nodes + 1))
		return
	fi
	if $do_specfile; then
		echo "./$1 type=dir mode=$2 gid=$g_wheel uid=$u_root"
	else
		mkdir $1 2>/dev/null
		chmod $2 $1
	fi
}

warn()
{
	echo 1>&2 "$0: $*"
}

# wrap_makedev makedev ...
wrap_makedev()
{
	if $do_specfile; then
		# "optional" tells pax(1) not to create the directory itself.
		echo ". type=dir optional"
	fi
	eval "$@"
}

# makedev special [...]
#	the main loop
#
makedev()
{

for i
do

case $i in

# When creating a /dev file system on MFS, init makes a FS that leaves
# only 890 (or so) inodes free.  Therefore the "init" case (used by
# init for that purpose) must be a trimmed down list.
init)
	makedev std
	makedev sd0 sd1 sd2 sd3
	makedev st0 st1 ch0 cd0 cd1
	makedev ss0 ss1 uk0 uk1
	makedev ttyC0 ttyC1
	makedev ttyZ0 ttyZ1
	makedev bpf
	makedev raid0
	makedev md0
	makedev usbs
	makedev ipty
	makedev local
	;;

all_md)
	makedev init
	makedev isdns
	makedev audio
	makedev scsibus0 scsibus1 scsibus2 scsibus3
	makedev ses0 ses1 ses2 ses3
	makedev pci0 pci1 pci2 pci3 pci4 pci5 pci6 pci7
	makedev wscons
	makedev lpa0 lpa1 lpa2
	makedev lpt0 lpt1 lpt2
	;;

minimal)
	makedev std
	makedev sd0 sd1 sd2 sd3 opty st0 st1 ch0 cd0 cd1 ccd0 ccd1 md0
	makedev ttyC0 ttyC1
	makedev ttyZ0 ttyZ1
	;;

all)
	makedev all_md
	makedev std fd ptm pty0 pty1 pty2 pty3
	makedev ccd0 ccd1 ccd2 ccd3
	makedev cgd0 cgd1 cgd2 cgd3
	makedev fss0 fss1 fss2 fss3
	makedev md0 md1
	makedev raid0 raid1 raid2 raid3 raid4 raid5 raid6 raid7
	makedev vnd0 vnd1 vnd2 vnd3
	makedev bpf
	makedev tun0 tun1 tun2 tun3
	makedev ipl pf crypto random systrace
	makedev lkm lockstat clockctl
	makedev atabus0 atabus1 atabus2 atabus3
	makedev tap tap0 tap1 tap2 tap3
	makedev gpio gpio0 gpio1 gpio2 gpio3 gpio4 gpio5 gpio6 gpio7
	makedev bthub
	makedev puffs
	makedev local # do this last
	;;

init)
	# unless overridden by MD entry, this is equal to 'all'
	makedev all
	;;

audio)
	makedev audio0 audio1 audio2 audio3
	lndev sound0 sound
	lndev audio0 audio
	lndev mixer0 mixer
	lndev audioctl0 audioctl
	;;

gpio)
	makedev gpio0 gpio1 gpio2 gpio3 gpio4 gpio5 gpio6 gpio7
	lndev gpio0 gpio
	;;

radio)
	makedev radio0 radio1
	lndev radio0 radio
	;;

ramdisk)
	makedev floppy md0
	;;

usbs)
	makedev usb usb0 usb1 usb2 usb3 usb4 usb5 usb6 usb7
	makedev uhid0 uhid1 uhid2 uhid3
	makedev ulpt0 ulpt1
	makedev ttyU0 ttyU1
	makedev ttyY0 ttyY1
	makedev urio0
	makedev uscanner0 uscanner1
	makedev utoppy0 utoppy1
	makedev ugen0
	;;

isdns)
	makedev isdn isdnctl isdnbchan0 isdnbchan1 isdntel0 isdntel1 isdnteld0 isdnteld1 isdntrc0 isdntrc1
	;;

std)
	mkdev		console	c 0 0	600
	mkdev		constty	c 0 1	600
	mkdev		drum	c 1 0	640 $g_kmem
	mkdev		kmem	c 20 1	640 $g_kmem
	mkdev		mem	c 20 0	640 $g_kmem
	mkdev		null	c 20 2	666
	mkdev		zero	c 20 12	666
	mkdev		klog	c 24 0	600
	mkdev		ksyms	c 77 0	444
	if $nofdesc; then
		mkdev	tty	c 21 0		666
		mkdev	stdin	c 26 0	666
		mkdev	stdout	c 26 1	666
		mkdev	stderr	c 26 2	666
	fi
	;;

usb)
	mkdev usb c 71 255 444
	;;

usb*)
	unit=${i#usb}
	usb=usb$unit
	mkdev usb$unit c 71 $unit
	;;

uhid*)
	unit=${i#uhid}
	mkdev uhid$unit c 72 $unit 666
	;;

ulpt*)
	unit=${i#ulpt}
	mkdev ulpt$unit c 73 $unit
	mkdev ulpn$unit c 73 $(($unit + 64))
	;;

urio*)
	unit=${i#urio}
	mkdev urio$unit c 68 $unit 666
	;;

uscanner*)
	unit=${i#uscanner}
	mkdev uscanner$unit c 76 $unit
	;;

utoppy*)
	unit=${i#utoppy}
	mkdev utoppy$unit c 174 $unit
	;;

ttyY*)
	unit=${i#ttyY}
	mkdev ttyY$unit c 172 $(($unit + $dialin  )) "" "" $u_uucp
	mkdev dtyY$unit c 172 $(($unit + $dialout )) "" "" $u_uucp
	mkdev ctyY$unit c 172 $(($unit + $callunit)) "" "" $u_uucp
	;;

ttyU*)
	unit=${i#ttyU}
	mkdev ttyU$unit c 69 $(($unit + $dialin  )) "" "" $u_uucp
	mkdev dtyU$unit c 69 $(($unit + $dialout )) "" "" $u_uucp
	mkdev ctyU$unit c 69 $(($unit + $callunit)) "" "" $u_uucp
	;;

ugen*)
	unit=${i#ugen}
	for j in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
	do
		mkdev ugen$unit.$j c 70 $(($unit * 16 + ${j#0}))
	done
	;;

wscons)
	makedev ttyE0 ttyE1 ttyE2 ttyE3 ttyE4 ttyE5 ttyE6 ttyE7
	makedev wsmouse0 wsmouse1 wsmouse2 wsmouse3
	makedev wskbd0 wskbd1 wskbd2 wskbd3
	makedev wsmux0 wsmux1 wsmux2 wsmux3
	makedev wsmouse wskbd
	makedev ttyEcfg ttyEstat
	makedev wsfont
	;;

wsmouse)
	mkdev wsmouse c 53 0
	;;

wskbd)
	mkdev wskbd c 53 1
	;;

wsmux*)
	unit=${i#wsmux}
	mkdev wsmux$unit    c 53 $unit
	mkdev wsmuxctl$unit c 53 $(($unit + 128)) 200
	;;

ttyEstat)
	mkdev ttyEstat c 50 254
	;;

ttyEcfg)
	mkdev ttyEcfg c 50 255
	;;

ttyE*)
	unit=${i#ttyE}
	mkdev ttyE$unit c 50 $unit
	;;

wsmouse*)
	unit=${i#wsmouse}
	mkdev wsmouse$unit c 52 $unit
	;;

wskbd*)
	unit=${i#wskbd}
	mkdev wskbd$unit c 51 $unit
	;;

fd)
	if $nofdesc; then
		makedir fd 755
		n=0
		while [ $n -lt 64 ]
		do
			mkdev fd/$n c 26 $n 666
			n=$(($n + 1))
		done
	fi
	;;

md*)
	makedisk_minimal md ${i#md} 2 2
	;;

fss*)
	case $i in
	fss*) name=fss; unit=${i#fss};	blk=163;	chr=163
	esac
	mkdev $name$unit	b $blk $unit 660 $g_operator
	mkdev r$name$unit	c $chr $unit 660 $g_operator
	;;

ss*)
	case $i in
	ss*) name=ss;	unit=${i#ss};	chr=32;;
	esac
	mkdev $name$unit	c $chr $(($unit * 16 + 0)) 640 $g_operator
	mkdev n$name$unit	c $chr $(($unit * 16 + 1)) 640 $g_operator
	mkdev en$name$unit	c $chr $(($unit * 16 + 3)) 640 $g_operator
	;;

ccd*|cgd*|raid*|vnd*)
	case $i in
	ccd*)	name=ccd;	unit=${i#ccd};	blk=3;	chr=3;;
	cgd*)	name=cgd;	unit=${i#cgd};	blk=6;	chr=6;;
	raid*)	name=raid;	unit=${i#raid}; blk=5; chr=5;;
	vnd*)	name=vnd;	unit=${i#vnd};	blk=4;	chr=4;;
	esac
	makedisk_p16 $name $unit $blk $chr
	;;

sd*)
	name=sd; unit=${i#sd};	blk=10;	chr=10
	makedisk_p16 $name $unit $blk $chr
	;;

wd*)
	name=wd; unit=${i#wd}; blk=13; chr=13
	makedisk_p16 $name $unit $blk $chr
	;;

ld*)
	name=ld; unit=${i#ld}; blk=14; chr=14
	makedisk_p16 $name $unit $blk $chr
	;;

dk*)
	name=dk; unit=${i#dk}; blk=168; chr=168
	minor=0
	while [ $minor -le ${i#dk} ]
	do
		mkdev r$name$minor c $chr $minor 0640 $g_operator
		mkdev $name$minor b $blk  $minor 0640 $g_operator
		minor=$(($minor + 1))
	done
	;;

tty[0-9]|tty0[0-9])
	# some archs have built-in zstty (major 35) instead
	# of NS16550; create ttyZ* and hardlink as [dt]ty0*; this
	# needs to be before com entry, for archs which have both
	unit=${i#tty}
	unit=$(($unit + 0))
	makedev ttyZ${unit}
	lndev ttyZ$unit tty0${unit}
	lndev dtyZ$unit dty0${unit}
	;;

tty0*|tty1*|tty[0-9])
	unit=${i#tty}
	ounit=00$unit
	ounit=${ounit#${ounit%??}}
	mkdev tty$ounit c 36 $(($unit + $dialin )) "" "" $u_uucp
	mkdev dty$ounit c 36 $(($unit + $dialout)) "" "" $u_uucp
	;;

ttyC*)
		# some archs call com_chr ttyC traditionally
	unit=${i#ttyC}; name=ttyC; dname=dtyC; chr=36
	mkdev  $name$unit c $chr $(($unit + $dialin )) "" "" $u_uucp
	mkdev $dname$unit c $chr $(($unit + $dialout)) "" "" $u_uucp
	;;

ttyZ*)
	unit=${i#ttyZ}; name=ttyZ; dname=dtyZ; chr=35
	mkdev  $name$unit c $chr $(($unit + $dialin )) "" "" $u_uucp
	mkdev $dname$unit c $chr $(($unit + $dialout)) "" "" $u_uucp
	;;

opty)
	for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f
	do
		case $j in
		[0-9])	jn=$j ;;
		a)	jn=10 ;;
		b)	jn=11 ;;
		c)	jn=12 ;;
		d)	jn=13 ;;
		e)	jn=14 ;;
		f)	jn=15 ;;
		esac
		mkdev ttyp$j c 22 $jn 666
		mkdev ptyp$j c 23 $jn 666
	done
	;;

pty*)
	class=${i#pty}
	d1="p q r s t u v w x y z P Q R S T"
	if [ "$class" -ge 64 ]
	then
		warn "$i: pty unit must be between 0 and 63"
		continue
	elif [ "$class" -lt 16 ]
	then
		offset=0
		mult=0
		d2="0 1 2 3 4 5 6 7 8 9 a b c d e f"
	else
		class=$(($class - 16))
		offset=256
		mult=2
		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"
	fi
	start=$(($class * 16))
	set -- $d2
	nt=$#
	s1=$(($start / $nt))
	set -- $d1
	shift $s1
	t1=$1
	if [ "$t1" = v ]; then
		warn "$i: pty unit conflicts with console ttyv0 device"
		continue
	fi
	s2=$(($start % ($nt - $s1 * $mult)))
	set -- $d2
	shift $s2
	t2=$1
	unit=$(($start + $offset - $s1 * $mult))
	end=$(($unit + 16))
	while [ "$unit" -lt "$end" ]
	do
		mkdev tty$t1$t2 c 22 $unit 666
		mkdev pty$t1$t2 c 23 $unit 666
		shift
		t2=$1
		if [ -z "$t2" ]
		then
			break
		fi
		unit=$(($unit + 1))
	done
	;;

st*)
	case $i in
	st*) name=st;	unit=${i#st};	chr=11;	blk=11;;
	esac
	mkdev $name$unit	b $blk $(($unit * 16 + 0)) 660 $g_operator
	mkdev n$name$unit	b $blk $(($unit * 16 + 1)) 660 $g_operator
	mkdev e$name$unit	b $blk $(($unit * 16 + 2)) 660 $g_operator
	mkdev en$name$unit	b $blk $(($unit * 16 + 3)) 660 $g_operator
	mkdev r$name$unit	c $chr $(($unit * 16 + 0)) 660 $g_operator
	mkdev nr$name$unit	c $chr $(($unit * 16 + 1)) 660 $g_operator
	mkdev er$name$unit	c $chr $(($unit * 16 + 2)) 660 $g_operator
	mkdev enr$name$unit	c $chr $(($unit * 16 + 3)) 660 $g_operator
	;;

ses*|ch*|uk*)
	case $i in
	ch*)	name=ch;	unit=${i#ch};	chr=33;;
	uk*)	name=uk;	unit=${i#uk};	chr=31;;
	ses*)	name=ses;	unit=${i#ses};	chr=44;;
	esac
	mkdev $name$unit c $chr $unit 640 $g_operator
	;;

cd*)
	makedisk_minimal cd ${i#cd} 12 12 %
	;;

lpt*|lpa*)
	case $i in
	lpt*) name=lpt;	unit=${i#lpt};	chr=78;	flags=0;;
	lpa*) name=lpa;	unit=${i#lpa};	chr=78;	flags=128;;
	esac
	mkdev $name$unit c $chr $(($unit + $flags))
	mkdev lpt${unit}ctl c $chr $(($unit + 256))
	;;

bpf)
	mkdev bpf	c 27 0
	lndev bpf bpf0
	;;

bthub)
	mkdev bthub c 175 0
	;;

tun*)
	unit=${i#tun}
	mkdev tun$unit c 28 $unit
	;;

ipl)
	mkdev ipl	c 29 0
	mkdev ipnat	c 29 1
	mkdev ipstate	c 29 2
	mkdev ipauth	c 29 3
	mkdev ipsync	c 29 4
	mkdev ipscan	c 29 5
	mkdev iplookup	c 29 6
	;;

pf)
	mkdev pf c 161 0
	;;

crypto)
	mkdev crypto c 160 0 666
	;;

lkm)
	mkdev lkm c 25 0 640 $g_kmem
	;;

lockstat)
	mkdev lockstat c 177 0
	;;

audio*)
	unit=${i#audio}
	audio=audio$unit
	sound=sound$unit
	mixer=mixer$unit
	audioctl=audioctl$unit
	: ${unit:-0}
	mkdev $sound    c 64 $(($unit + 0))	666
	mkdev $audio    c 64 $(($unit + 128))	666
	mkdev $mixer    c 64 $(($unit + 16))	666
	mkdev $audioctl c 64 $(($unit + 192))	666
	;;

gpio*)
	unit=${i#gpio}
	mkdev gpio$unit c 173 $unit 644
	;;

rmidi*)
	unit=${i#rmidi}
	mkdev rmidi$unit c 74 $unit 666
	;;

music*)
	unit=${i#music}
	: ${unit:-0}
	mkdev music$unit     c 75 $(($unit + 0))	666
	mkdev sequencer$unit c 75 $(($unit + 128))	666
	;;

amr*)
	unit=${i#amr}
	mkdev amr$unit c 176 $unit
	;;

random)
	mkdev random	c 30 0 444
	mkdev urandom	c 30 1 644
	;;

scsibus*)
	unit=${i#scsibus}
	mkdev scsibus$unit c 34 $unit 644
	;;

bktr)
	makedev bktr0 bktr1
	lndev	bktr0	bktr
	lndev	tuner0	tuner
	lndev	vbi0	vbi
	;;

io)
	mkdev		io	c 20 14	600
	;;

twa*)
	unit=${i#twa}
	mkdev twa$unit c 187 $unit
	;;

pci*)
	unit=${i#pci}
	mkdev pci$unit c 65 $unit 644
	;;

isdn)
	mkdev isdn c 38 0
	;;

isdnctl)
	mkdev isdnctl c 39 0
	;;

isdnbchan*)
	unit=${i#isdnbchan}
	mkdev isdnbchan$unit c 40 $unit
	;;

isdnteld*)
	unit=${i#isdnteld}
	mkdev isdnteld$unit c 42 $(($unit + 64))
	;;

isdntel*)
	unit=${i#isdntel}
	mkdev isdntel$unit c 42 $unit
	;;

isdntrc*)
	unit=${i#isdntrc}
	mkdev isdntrc$unit c 41 $unit
	;;

vmegen)
	makedev vmegen0 vmegen1 vmegen2 vmegen3
	;;

wsfont)
	mkdev wsfont c 54 0
	;;

cir*)
	unit=${i#cir}
	mkdev cir$unit c 67 $unit 666
	;;

irframe*)
	unit=${i#irframe}
	mkdev irframe$unit c 66 $unit
	;;

clockctl)
	mkdev clockctl c 60 0 660 $g_ntpd
	;;

nsmb)
	makedev nsmb0 nsmb1 nsmb2 nsmb3
	;;

nsmb*)
	unit=${i#nsmb}
	mkdev nsmb$unit c 98 $unit 644
	;;

systrace)
	mkdev systrace c 63 0 644
	;;

veriexec)
	mkdev veriexec c 170 0 600
	;;

mouse-*)
	case $i in
	mouse-pms*) name=pms ;;
	mouse-qms*) name=qms ;;
	esac
	unit=${i#mouse-${name}}
	lndev $name$unit mouse
	;;

ipty)
	mkdev ttyp0 c 22 0 666
	mkdev ttyp1 c 22 1 666
	mkdev ptyp0 c 23 0 666
	mkdev ptyp1 c 23 1 666
	;;

ptm)
	mkdev ptmx c 165 0 666
	mkdev ptm c 165 1 666
	;;

spif*)
	unit=${i#spif}
	if [ 0$unit -gt 3 ]; then
		warn "bad unit for $i: $unit"
		break
	fi
	for j in 0 1 2 3 4 5 6 7; do
		mkdev ttyS$unit$j c 102 $(($unit * 64 + $j)) "" "" $u_uucp
	done
	mkdev bppS${unit}0 c 103 $(($unit * 64 + 0))
	mkdev bppS${unit}1 c 103 $(($unit * 64 + 1))
	;;

atabus*)
	unit=${i#atabus}
	mkdev atabus$unit c 166 $unit 644
	;;

drvctl)
	mkdev drvctl c 167 0 644
	;;

tap*)
	unit=${i#tap}
	case "$unit" in
	[0-9]*)
		mkdev tap${unit} c 169 ${unit} 600
		;;
	*)
		mkdev tap c 169 0xfffff 600
		;;
	esac
	;;

fw*)
	unit=${i#fw}
	for j in 0 1 2 3
	do
		mkdev fw${unit}.${j} c 171 $((${unit} * 256 + ${j})) 660 ${g_operator}
		mkdev fwmem${unit}.${j} c 171 $((65536 + ${unit} * 256 + ${j})) 660 ${g_operator}
	done
	;;

puffs)
	mkdev puffs c 178 0x7ffff 600
	;;

local)
	if [ -f "$0.local" ]; then
		umask 0
		if [ -n "$count_nodes" ]; then
			sh "$0.local" $opts -s all | \
			while read l; do
				count_nodes=$((count_nodes + 1))
			done
		else
			sh "$0.local" $opts all
		fi
		umask 077
	else
		warn "missing $0.local"
	fi
	;;

*)
	warn "$i: unknown device"
	;;

esac
done

}


# three variants of disk partitions - max 8, max 16, max 16 with highpartoffset
# hack; only the one used by port is retained in final MAKEDEV script
# routine is called as:
# makedisk name unit blk chr
makedisk_p8()
{
	name="$1"; unit="$2"; blk="$3"; chr="$4"

	mkdev ${name}${unit}a	b $blk $(($unit * 8 + 0))	640 $g_operator
	mkdev ${name}${unit}b	b $blk $(($unit * 8 + 1))	640 $g_operator
	mkdev ${name}${unit}c	b $blk $(($unit * 8 + 2))	640 $g_operator
	mkdev ${name}${unit}d	b $blk $(($unit * 8 + 3))	640 $g_operator
	mkdev ${name}${unit}e	b $blk $(($unit * 8 + 4))	640 $g_operator
	mkdev ${name}${unit}f	b $blk $(($unit * 8 + 5))	640 $g_operator
	mkdev ${name}${unit}g	b $blk $(($unit * 8 + 6))	640 $g_operator
	mkdev ${name}${unit}h	b $blk $(($unit * 8 + 7))	640 $g_operator
	mkdev r${name}${unit}a	c $chr $(($unit * 8 + 0))	640 $g_operator
	mkdev r${name}${unit}b	c $chr $(($unit * 8 + 1))	640 $g_operator
	mkdev r${name}${unit}c	c $chr $(($unit * 8 + 2))	640 $g_operator
	mkdev r${name}${unit}d	c $chr $(($unit * 8 + 3))	640 $g_operator
	mkdev r${name}${unit}e	c $chr $(($unit * 8 + 4))	640 $g_operator
	mkdev r${name}${unit}f	c $chr $(($unit * 8 + 5))	640 $g_operator
	mkdev r${name}${unit}g	c $chr $(($unit * 8 + 6))	640 $g_operator
	mkdev r${name}${unit}h	c $chr $(($unit * 8 + 7))	640 $g_operator
}

makedisk_p16()
{
	name="$1"; unit="$2"; blk="$3"; chr="$4"

	mkdev ${name}${unit}a	b $blk $(($unit * 16 + 0))	640 $g_operator
	mkdev ${name}${unit}b	b $blk $(($unit * 16 + 1))	640 $g_operator
	mkdev ${name}${unit}c	b $blk $(($unit * 16 + 2))	640 $g_operator
	mkdev ${name}${unit}d	b $blk $(($unit * 16 + 3))	640 $g_operator
	mkdev ${name}${unit}e	b $blk $(($unit * 16 + 4))	640 $g_operator
	mkdev ${name}${unit}f	b $blk $(($unit * 16 + 5))	640 $g_operator
	mkdev ${name}${unit}g	b $blk $(($unit * 16 + 6))	640 $g_operator
	mkdev ${name}${unit}h	b $blk $(($unit * 16 + 7))	640 $g_operator
	mkdev ${name}${unit}i	b $blk $(($unit * 16 + 8))	640 $g_operator
	mkdev ${name}${unit}j	b $blk $(($unit * 16 + 9))	640 $g_operator
	mkdev ${name}${unit}k	b $blk $(($unit * 16 + 10))	640 $g_operator
	mkdev ${name}${unit}l	b $blk $(($unit * 16 + 11))	640 $g_operator
	mkdev ${name}${unit}m	b $blk $(($unit * 16 + 12))	640 $g_operator
	mkdev ${name}${unit}n	b $blk $(($unit * 16 + 13))	640 $g_operator
	mkdev ${name}${unit}o	b $blk $(($unit * 16 + 14))	640 $g_operator
	mkdev ${name}${unit}p	b $blk $(($unit * 16 + 15))	640 $g_operator
	mkdev r${name}${unit}a	c $chr $(($unit * 16 + 0))	640 $g_operator
	mkdev r${name}${unit}b	c $chr $(($unit * 16 + 1))	640 $g_operator
	mkdev r${name}${unit}c	c $chr $(($unit * 16 + 2))	640 $g_operator
	mkdev r${name}${unit}d	c $chr $(($unit * 16 + 3))	640 $g_operator
	mkdev r${name}${unit}e	c $chr $(($unit * 16 + 4))	640 $g_operator
	mkdev r${name}${unit}f	c $chr $(($unit * 16 + 5))	640 $g_operator
	mkdev r${name}${unit}g	c $chr $(($unit * 16 + 6))	640 $g_operator
	mkdev r${name}${unit}h	c $chr $(($unit * 16 + 7))	640 $g_operator
	mkdev r${name}${unit}i	c $chr $(($unit * 16 + 8))	640 $g_operator
	mkdev r${name}${unit}j	c $chr $(($unit * 16 + 9))	640 $g_operator
	mkdev r${name}${unit}k	c $chr $(($unit * 16 + 10))	640 $g_operator
	mkdev r${name}${unit}l	c $chr $(($unit * 16 + 11))	640 $g_operator
	mkdev r${name}${unit}m	c $chr $(($unit * 16 + 12))	640 $g_operator
	mkdev r${name}${unit}n	c $chr $(($unit * 16 + 13))	640 $g_operator
	mkdev r${name}${unit}o	c $chr $(($unit * 16 + 14))	640 $g_operator
	mkdev r${name}${unit}p	c $chr $(($unit * 16 + 15))	640 $g_operator
}

makedisk_p16high()
{
	ho=524280	# offset for partition 9 to 16
	name="$1"; unit="$2"; blk="$3"; chr="$4"

	mkdev ${name}${unit}a	b $blk $(($unit * 8 + 0))	640 $g_operator
	mkdev ${name}${unit}b	b $blk $(($unit * 8 + 1))	640 $g_operator
	mkdev ${name}${unit}c	b $blk $(($unit * 8 + 2))	640 $g_operator
	mkdev ${name}${unit}d	b $blk $(($unit * 8 + 3))	640 $g_operator
	mkdev ${name}${unit}e	b $blk $(($unit * 8 + 4))	640 $g_operator
	mkdev ${name}${unit}f	b $blk $(($unit * 8 + 5))	640 $g_operator
	mkdev ${name}${unit}g	b $blk $(($unit * 8 + 6))	640 $g_operator
	mkdev ${name}${unit}h	b $blk $(($unit * 8 + 7))	640 $g_operator
	mkdev ${name}${unit}i	b $blk $(($unit * 8 + $ho + 8))	640 $g_operator
	mkdev ${name}${unit}j	b $blk $(($unit * 8 + $ho + 9))	640 $g_operator
	mkdev ${name}${unit}k	b $blk $(($unit * 8 + $ho + 10)) 640 $g_operator
	mkdev ${name}${unit}l	b $blk $(($unit * 8 + $ho + 11)) 640 $g_operator
	mkdev ${name}${unit}m	b $blk $(($unit * 8 + $ho + 12)) 640 $g_operator
	mkdev ${name}${unit}n	b $blk $(($unit * 8 + $ho + 13)) 640 $g_operator
	mkdev ${name}${unit}o	b $blk $(($unit * 8 + $ho + 14)) 640 $g_operator
	mkdev ${name}${unit}p	b $blk $(($unit * 8 + $ho + 15)) 640 $g_operator
	mkdev r${name}${unit}a	c $chr $(($unit * 8 + 0))	640 $g_operator
	mkdev r${name}${unit}b	c $chr $(($unit * 8 + 1))	640 $g_operator
	mkdev r${name}${unit}c	c $chr $(($unit * 8 + 2))	640 $g_operator
	mkdev r${name}${unit}d	c $chr $(($unit * 8 + 3))	640 $g_operator
	mkdev r${name}${unit}e	c $chr $(($unit * 8 + 4))	640 $g_operator
	mkdev r${name}${unit}f	c $chr $(($unit * 8 + 5))	640 $g_operator
	mkdev r${name}${unit}g	c $chr $(($unit * 8 + 6))	640 $g_operator
	mkdev r${name}${unit}h	c $chr $(($unit * 8 + 7))	640 $g_operator
	mkdev r${name}${unit}i	c $chr $(($unit * 8 + $ho + 8))	640 $g_operator
	mkdev r${name}${unit}j	c $chr $(($unit * 8 + $ho + 9))	640 $g_operator
	mkdev r${name}${unit}k	c $chr $(($unit * 8 + $ho + 10)) 640 $g_operator
	mkdev r${name}${unit}l	c $chr $(($unit * 8 + $ho + 11)) 640 $g_operator
	mkdev r${name}${unit}m	c $chr $(($unit * 8 + $ho + 12)) 640 $g_operator
	mkdev r${name}${unit}n	c $chr $(($unit * 8 + $ho + 13)) 640 $g_operator
	mkdev r${name}${unit}o	c $chr $(($unit * 8 + $ho + 14)) 640 $g_operator
	mkdev r${name}${unit}p	c $chr $(($unit * 8 + $ho + 15)) 640 $g_operator
}

# make only the very few basic disk device nodes - 'a' partition
# and raw partition
makedisk_minimal()
{
	name=$1; unit=$2; blk=$3; chr=$4
	doff=16
	ro=2
	rn=c

	mkdev ${name}${unit}a	b $blk $(($unit * $doff + 0))	640 $g_operator
	mkdev ${name}${unit}$rn	b $blk $(($unit * $doff + $ro))	640 $g_operator
	mkdev r${name}${unit}a	c $chr $(($unit * $doff + 0))	640 $g_operator
	mkdev r${name}${unit}$rn c $chr $(($unit * $doff + $ro)) 640 $g_operator
}

create_mfs_dev()
{
	ninode=$((${1-1200} * 11 / 10))
	fs_size=$((8192 + 2 * 8192 + 4096 + ninode*(128+18) + 8192))
	fs_size=$((fs_size/512))
	[ "$fs_size" -lt 80 ] && fs_size=80

	dev_mountpoint=${PWD:-/dev}
	mount_mfs -b 4096 -f 512 -s $fs_size -n $ninode -p 07555 -o union swap $dev_mountpoint

	cd $dev_mountpoint
	if $do_redirect; then
		# Redirect stdout and stderr to console
		mknod -m 600 -g 0 -u 0 temp_console c 0 0
		exec >temp_console 2>&1
		rm temp_console
	fi
	echo "Created mfs $dev_mountpoint ($fs_size blocks, $ninode inodes)"
}

#
# MAIN: If MAKEDEV_AS_LIBRARY is set, then we are being used as a
# function library, so just return.  Otherwise, call the setup function
# to parse command line args and set some other variables; then call the
# makedev function to create requested devices.
#
[ -n "${MAKEDEV_AS_LIBRARY}" ] && return

setup ${1+"$@"}
shift $((${OPTIND}-1))

if $do_create_mfs; then
	# Count inodes and create mfs file system
	count_nodes=0
	makedev ${1+"$@"}
	create_mfs_dev $count_nodes
	unset count_nodes
fi

if $do_pax ; then
	# wrap_makedev will print an mtree specification;
	# pax will create device nodes.
	wrap_makedev makedev ${1+"$@"} | ${TOOL_PAX} -r -w -M .
else
	wrap_makedev makedev ${1+"$@"}
fi
