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