#!/bin/sh -
#
# Generated from:
#	NetBSD: MAKEDEV.awk,v 1.16 2005/06/14 20:47:46 he Exp 
#	NetBSD: MAKEDEV.tmpl,v 1.67 2006/10/22 23:02:08 pooka Exp 
#	NetBSD: etc.i386/MAKEDEV.conf,v 1.10 2006/07/26 10:31:00 tron Exp 
#
# Copyright (c) 2003 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
#

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/rescue


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()
{
	case $1 in
	[0-9])	echo $1 ;;
	10)	echo a ;;
	11)	echo b ;;
	12)	echo c ;;
	13)	echo d ;;
	14)	echo e ;;
	15)	echo f ;;
	*)	echo $(hexprint $(($1 / 16)))$(hexprint $(($1 % 16))) ;;
	esac
}

do_force=false
do_specfile=false
while getopts fm:s ch; do
	case ${ch} in
	f)	do_force=true ;;
	m)	TOOL_MKNOD=${OPTARG} ;;
	s)	do_specfile=true ;;
	*)	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_specfile; then
	echo ". type=dir"
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 $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 $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 $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: $*"
}



# makedev special [...]
#	the main loop
#

makedev()
{

for i
do

case $i in

# As of 2005-03-15, the "init" case must not create more than 1024 entries.
init)
	makedev std wscons wt0 fd0 fd1 wd0 wd1 wd2 wd3 sd0 sd1 sd2 sd3 sd4
	makedev tty0 tty1
	makedev st0 st1 ch0 cd0 cd1 mcd0 vnd0
	makedev bpf
	makedev ccd0 md0 ch0 random
	makedev cgd0 cgd1
	makedev amr0 iop0 mlx0 mly0 dpti0 dpt0 twe0 icp0
	makedev ed0 ed1
	makedev raid0
	makedev ld0 ld1 ld2 ld3
	makedev xbd0 xbd1 xencons
	makedev usbs
	makedev ipty
	makedev local
	;;

all_md)
	makedev init
	makedev tty2 tty3
	makedev lpa0 lpa1 lpa2
	makedev lpt0 lpt1 lpt2
	makedev ss0 uk0 uk1
	makedev speaker joy0 joy1
	makedev apm satlink0
	makedev audio
	makedev radio
	makedev isdns
	makedev music rmidi0 rmidi1 rmidi2 rmidi3 rmidi4 rmidi5 rmidi6 rmidi7
	makedev scsibus0 scsibus1 scsibus2 scsibus3
	makedev sysmon
	makedev bktr
	makedev ttyCZ0 ttyCY0
	makedev agp0
	makedev pci0 pci1 pci2 pci3 pci4 pci5 pci6 pci7
	makedev altq
	makedev cir0 cir1 irframe0 irframe1
	makedev dmoverio
	makedev kttcp
	makedev nsmb
	;;

xen)
	makedev xenevt xencons xsd_kva
	;;

floppy)
	makedev std wt0 fd0 fd1 wd0 wd1 wd2 wd3 sd0 sd1 sd2 sd3 sd4 st0 st1
	makedev tty0 tty1 tty2 cd0 cd1 mcd0 ttyv0 opty ld0 ld1 ld2 ld3 ed0 ed1
	;;

ramdisk)
	makedev floppy md0
	;;

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 ses0 ses1 ses2 ses3
	makedev vnd0 vnd1 vnd2 vnd3
	makedev bpf
	makedev tun0 tun1 tun2 tun3
	makedev ipl pf crypto random systrace
	makedev lkm lockstat clockctl
	makedev local
	makedev atabus0 atabus1 atabus2 atabus3
	makedev tap tap0 tap1 tap2 tap3
	makedev gpio gpio0 gpio1 gpio2 gpio3 gpio4 gpio5 gpio6 gpio7
	makedev bthub
	;;

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 4 0	640 $g_kmem
	mkdev		kmem	c 2 1	640 $g_kmem
	mkdev		mem	c 2 0	640 $g_kmem
	mkdev		null	c 2 2	666
	mkdev		zero	c 2 12	666
	mkdev		klog	c 7 0	600
	mkdev		ksyms	c 101 0	444
	if $nofdesc; then
		mkdev	tty	c 1 0		666
		mkdev	stdin	c 22 0	666
		mkdev	stdout	c 22 1	666
		mkdev	stderr	c 22 2	666
	fi
	;;

usb)
	mkdev usb c 55 255 444
	;;

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

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

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

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

uscanner*)
	unit=${i#uscanner}
	mkdev uscanner$unit c 75 $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 66 $(($unit + $dialin  )) "" "" $u_uucp
	mkdev dtyU$unit c 66 $(($unit + $dialout )) "" "" $u_uucp
	mkdev ctyU$unit c 66 $(($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 64 $(($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 65 0
	;;

wskbd)
	mkdev wskbd c 65 1
	;;

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

xenevt)
	mkdev xenevt c 141 0
	;;

xsd_kva)
	mkdev xsd_kva c 141 1
	;;

xencons)
	mkdev xencons c 143 0
	;;

ttyEstat)
	mkdev ttyEstat c 47 254
	;;

ttyEcfg)
	mkdev ttyEcfg c 47 255
	;;

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

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

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

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

wt*)
	case $i in
	wt*) name=wt;  unit=${i#wt};	chr=10;	blk=3;;
	esac
	for sub in $unit $(($unit+8)) $(($unit+16))
	do
		mkdev $name$sub		b $blk $(($sub + 0)) 660 $g_operator
		mkdev n$name$sub	b $blk $(($sub + 4)) 660 $g_operator
		mkdev r$name$sub	c $chr $(($sub + 0)) 660 $g_operator
		mkdev nr$name$sub	c $chr $(($sub + 4)) 660 $g_operator
	done
	;;

md*)
	makedisk_minimal md ${i#md} 17 24
	;;

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=19;;
	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=16;	chr=18;;
	cgd*)	name=cgd;	unit=${i#cgd};	blk=21;	chr=93;;
	raid*)	name=raid;	unit=${i#raid}; blk=18; chr=62;;
	vnd*)	name=vnd;	unit=${i#vnd};	blk=14;	chr=41;;
	esac
	makedisk_p16high $name $unit $blk $chr
	;;

sd*)
	name=sd; unit=${i#sd};	blk=4;	chr=13
	makedisk_p16high $name $unit $blk $chr
	;;

wd*)
	name=wd; unit=${i#wd}; blk=0; chr=3
	makedisk_p16high $name $unit $blk $chr
	;;

fd*)
	name=fd; unit=${i#fd}; blk=2; chr=9
	makedisk_p16high $name $unit $blk $chr
	;;

ld*)
	name=ld; unit=${i#ld}; blk=19; chr=69
	makedisk_p16high $name $unit $blk $chr
	;;

ed*)
	name=ed; unit=${i#ed}; blk=20; chr=79
	makedisk_p16high $name $unit $blk $chr
	;;

xbd*)
	name=xbd; unit=${i#xbd}; blk=142; chr=142
	makedisk_p16high $name $unit $blk $chr
	;;

dk*)
	name=dk; unit=${i#dk}; blk=168; chr=168
	minor=0 
	while [ $minor -lt ${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
	;;
	
ttyCY*)
	name=tyCY; chr=38; off=32
	unit=${i#t${name}}
	minor=$(($unit * $off))
	eminor=$(($minor + $off))
	while [ $minor -lt $eminor ]
	do
		# nminor=$(zeropad 3 $minor)
		nminor=000$minor
		nminor=${nminor#${nminor%???}}
		mkdev t$name$nminor c $chr $(($minor + $dialin )) "" "" $u_uucp
		mkdev d$name$nminor c $chr $(($minor + $dialout)) "" "" $u_uucp
		minor=$(($minor + 1))
	done
	;;

ttyCZ*)
	name=tyCZ; chr=73; off=64
	unit=${i#t${name}}
	minor=$(($unit * $off))
	eminor=$(($minor + $off))
	while [ $minor -lt $eminor ]
	do
		# nminor=$(zeropad 4 $minor)
		nminor=0000$minor
		nminor=${nminor#${nminor%????}}
		mkdev t$name$nminor c $chr $(($minor + $dialin )) "" "" $u_uucp
		mkdev d$name$nminor c $chr $(($minor + $dialout)) "" "" $u_uucp
		minor=$(($minor + 1))
	done
	;;


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

ttyC*)
		# some archs call com_chr ttyC traditionally
	unit=${i#ttyC}; name=ttyC; dname=dtyC; chr=8
	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 5 $jn 666
		mkdev ptyp$j c 6 $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 5 $unit 666
		mkdev pty$t1$t2 c 6 $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=14;	blk=5;;
	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=17;;
	uk*)	name=uk;	unit=${i#uk};	chr=20;;
	ses*)	name=ses;	unit=${i#ses};	chr=74;;
	esac
	mkdev $name$unit c $chr $unit 640 $g_operator
	;;

cd*)
	makedisk_minimal cd ${i#cd} 6 15 %
	;;

mcd*)
	makedisk_minimal mcd ${i#mcd} 7 39
	;;

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

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

bthub)
	mkdev bthub c 175 0
	;;

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

joy*)
	unit=${i#joy}
	mkdev joy$unit c 26 $unit
	;;

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

pf)
	mkdev pf c 161 0
	;;

crypto)
	mkdev crypto c 160 0 666
	;;

speaker)
	mkdev speaker c 27 0
	;;

lkm)
	mkdev lkm c 28 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 42 $(($unit + 0))	666
	mkdev $audio    c 42 $(($unit + 128))	666
	mkdev $mixer    c 42 $(($unit + 16))	666
	mkdev $audioctl c 42 $(($unit + 192))	666
	;;

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

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

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

radio*)
	unit=${i#radio}
	: ${unit:-0}
	mkdev radio$unit c 87 $unit 666
	;;

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

apm)
	mkdev apm	c 21 0 644
	mkdev apmctl	c 21 8 644
	;;

satlink*)
	unit=${i#satlink}
	mkdev satlink$unit c 45 $unit 444
	;;

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

cfs*)
	unit=${i#cfs}
	mkdev cfs$unit c 60 $unit
	;;

sysmon)
	mkdev sysmon	c 67 0 644
	mkdev watchdog	c 67 1 644
	mkdev power	c 67 2 640
	;;

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

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

bktr*)
	unit=${i#bktr}
	mkdev bktr$unit		c 71 $(($unit + 0))	444
	mkdev tuner$unit	c 71 $(($unit + 16))	444
	mkdev vbi$unit		c 71 $(($unit + 32))	444
	;;

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

mlx*)
	unit=${i#mlx}
	mkdev mlx$unit c 78 $unit
	;;

mly*)
	unit=${i#mly}
	mkdev mly$unit c 80 $unit
	;;

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

twe*)
	unit=${i#twe}
	mkdev twe$unit c 97 $unit
	;;

icp*)
	unit=${i#icp}
	mkdev icp$unit c 102 $unit
	;;

agp*)
	unit=${i#agp}
	mkdev agp$unit c 82 $unit 644
	if [ "$unit" = "0" ]; then
		lndev agp$unit agpgart
	fi
	;;

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

dpti*)
	unit=${i#dpti}
	mkdev dpti$unit c 84 $unit
	;;

dpt*)
	unit=${i#dpt}
	mkdev dpt$unit c 96 $unit
	;;

altq)
	makedir altq 755
	unit=0
	for dev in altq cbq wfq afm fifoq red rio localq hfsc cdnr blue priq
	do
		mkdev altq/$dev c 77 $unit 644
		unit=$(($unit + 1))
	done
	;;

isdn)
	mkdev isdn c 50 0
	;;

isdnctl)
	mkdev isdnctl c 51 0
	;;

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

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

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

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

vmegen)
	makedev vmegen0 vmegen1 vmegen2 vmegen3
	;;

vmegen*)
	unit=${i#vmegen}
	mkdev vmegen$unit c 68 $(($unit * 16 + 0))
	;;

wsfont)
	mkdev wsfont c 81 0
	;;

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

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

clockctl)
	mkdev clockctl c 89 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 90 0 644
	;;

kttcp)
	mkdev kttcp c 91 0
	;;

dmoverio)
	mkdev dmoverio c 92 0 644
	;;

veriexec)
	mkdev veriexec c 170 0 600
	;;

ttyv*)
	unit=${i#ttyv}
	mkdev ttyv$unit c 12 $unit
	;;

# arm, acorn32
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 5 0 666
	mkdev ttyp1 c 5 1 666
	mkdev ptyp0 c 6 0 666
	mkdev ptyp1 c 6 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
		sh $0.local all
		umask 077
	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=8
	ro=3
	rn=d

	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
}

makedev $*
