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