xref: /netbsd-src/etc/MAKEDEV.tmpl (revision 4d342c046e3288fb5a1edcd33cfec48c41c80664)
1#!/bin/sh -
2#	$NetBSD: MAKEDEV.tmpl,v 1.221 2020/07/26 15:47:27 jdolecek 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#	lua	Lua device
46#	wscons	make wscons devices
47#	usbs	make USB 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#	dk*	wedge disk slices
61#	ccd*	concatenated disk devices
62#	cd*	SCSI or ATAPI CD-ROM
63#	cgd*	cryptographic disk devices
64#	raid*	RAIDframe disk devices
65#	sd*	SCSI disks
66#	wd*	"winchester" disk drives (ST506,IDE,ESDI,RLL,...)
67#	bmd*	Nereid bank memory disks
68#	ed*	IBM PS/2 ESDI disk devices
69#	fd*	"floppy" disk drives (3 1/2", 5 1/4")
70#	fss*	Files system snapshot devices
71#	gdrom*	Dreamcast "gigadisc" CD-ROM drive
72#	hk*	UNIBUS RK06 and RK07
73#	hp*	MASSBUS RM??
74#	ld*	Logical disk devices (e.g., hardware RAID)
75#	mcd*	Mitsumi CD-ROM
76#	md*	memory pseudo-disk devices
77#	ofdisk*	OpenFirmware disk devices
78#	ra*	MSCP disks (RA??, RD??)
79#	rb*	730 IDC w/ RB80 and/or RB02
80#	rd*	HDC9224 RD disks on VS2000
81#	rl*	UNIBUS RL02
82#	rx*	MSCP floppy disk (RX33/50/...)
83#	up*	other UNIBUS devices (e.g. on Emulex SC-21V controller)
84#	vnd*	"file" pseudo-disks
85#	xbd*	Xen virtual disks
86#	xd*	Xylogic 753/7053 disks
87#	xy*	Xylogic 450/451 disks
88#
89# Pointing devices:
90#	wsmouse* wscons mouse events
91#	lms*	Logitech bus mouse
92#	mms*	Microsoft bus mouse
93#	qms*	"quadrature mouse"
94#	pms*	PS/2 mouse
95#	mouse	mouse (provides events, for X11)
96#
97# Keyboard devices:
98#	wskbd*	wscons keyboard events
99#	kbd	raw keyboard (provides events, for X11)
100#	kbdctl	keyboard control
101#
102# Terminals/Console ports:
103#	tty[01]*	standard serial ports
104#	tty0*	SB1250 ("sbscn") serial ports (sbmips)
105#	ttyE*	wscons - Workstation console ("wscons") glass-tty emulators
106#	ttyCZ?	Cyclades-Z multiport serial boards.  Each "unit"
107#		makes 64 ports.
108#	ttyCY?	Cyclom-Y multiport serial boards. Each "unit" makes
109#		32 ports.
110#	ttye*	ITE bitmapped consoles
111#	ttyv0	pccons
112#	ttyC?	NS16550 ("com") serial ports
113#	ttyS*	SA1110 serial port (hpcarm)
114#	ttyTX?	TX39 internal serial ports (hpcmips)
115#	ttyB?	DEC 3000 ZS8530 ("scc") serial ports (alpha)
116#	ttyA*	mfc serial ports (amiga)
117#	ttyB*	msc serial ports (amiga)
118#	ttyC*	com style serial ports (DraCo, HyperCom) (amiga)
119#		On the DraCo, units 0 and 1 are the built-in "modem" and
120#		"mouse" ports, if configured.
121#	ttyA0   8530 Channel A (formerly ser02) (atari)
122#	ttyA1	8530 Channel B (formerly mdm02) (atari)
123#	ttyB0	UART on first 68901 (formerly mdm01) (atari)
124#	ixpcom	IXP12x0 COM ports
125#	epcom	EP93xx COM ports
126#	plcom	ARM PL01[01] serial ports
127#	wmcom	EPOC Windermere COM ports
128#	ttyM?	HP200/300 4 port serial mux interface (hp300)
129#	ttya	"ttya" system console (luna68k)
130#	ttyb	second system serial port (luna68k)
131#	tty*	Onboard serial ports (mvme68k)
132#		On the mvme147 these are: ttyZ1, ttyZ2 and ttyZ3.
133#		On the mvme167, and '177: ttyC1, ttyC2 and ttyC3.
134#		Note that tty[CZ]0 is grabbed by the console device
135#		so is not created by default
136#	dc*	PMAX 4 channel serial interface (kbd, mouse, modem, printer)
137#	scc*	82530 serial interface (pmax)
138#	ttyZ*	Zilog 8530 ("zstty") serial ports
139#	tty[abcd]	Built-in serial ports (sparc)
140#	tty*	Z88530 serial controllers (sparc64)
141#	ttyh*	SAB82532 serial controllers (sparc64)
142#	tty[a-j]	Built-in serial ports (sun2, sun3)
143#	ttyC?	pccons (arc)
144#	dz*	UNIBUS DZ11 and DZ32 (vax)
145#	dh*	UNIBUS DH11 and emulations (e.g. Able DMAX, Emulex CS-11) (vax)
146#	dmf*	UNIBUS DMF32 (vax)
147#	dhu*    UNIBUS DHU11 (vax)
148#	dmz*    UNIBUS DMZ32 (vax)
149#	dl*	UNIBUS DL11 (vax)
150#	xencons	Xen virtual console
151#
152# Terminal multiplexors:
153#	dc*	4 channel serial interface (keyboard, mouse, modem, printer)
154#	dh*	UNIBUS DH11 and emulations (e.g. Able DMAX, Emulex CS-11)
155#	dhu*	UNIBUS DHU11
156#	dl*	UNIBUS DL11
157#	dmf*	UNIBUS DMF32
158#	dmz*	UNIBUS DMZ32
159#	dz*	UNIBUS DZ11 and DZ32
160#	scc*	82530 serial interface
161#
162# Call units:
163#	dn*	UNIBUS DN11 and emulations (e.g. Able Quadracall)
164#
165# Pseudo terminals:
166#	ptm	pty multiplexor device, and pts directory
167#	pty*	set of 16 master and slave pseudo terminals
168#	opty	first 16 ptys, to save inodes on install media
169#	ipty	first 2 ptys, for install media use only
170#
171# Printers:
172#	arcpp*	Archimedes parallel port
173#	lpt*	stock lp
174#	lpa*	interruptless lp
175#	par*	Amiga motherboard parallel port
176#	cpi*	Macintosh Nubus CSI parallel printer card
177#
178# USB devices:
179#	usb*	USB control devices
180#	uhid*	USB generic HID devices
181#	ulpt*	USB printer devices
182#	ugen*	USB generic devices
183#	uscanner*	USB scanners
184#	ttyHS*	USB Option N.V. modems
185#	ttyU*	USB modems
186#	ttyY*	USB serial adapters
187#
188# Video devices:
189#	bwtwo*	monochromatic frame buffer
190#	cgtwo*	8-bit color frame buffer
191#	cgthree*	8-bit color frame buffer
192#	cgfour*	8-bit color frame buffer
193#	cgsix*	accelerated 8-bit color frame buffer
194#	cgeight*	24-bit color frame buffer
195#	etvme	Tseng et-compatible cards on VME (atari)
196#	ik*	UNIBUS interface to Ikonas frame buffer
197#	leo	Circad Leonardo VME-bus true color (atari)
198#	ps*	UNIBUS interface to Picture System 2
199#	qv*	QVSS (MicroVAX) display
200#	tcx*	accelerated 8/24-bit color frame buffer
201#
202# Maple bus devices:
203#	maple	Maple bus control devices
204#	mlcd*	Maple bus LCD devices
205#	mmem*	Maple bus storage devices
206#
207# IEEE1394 bus devices:
208#	fw*	IEEE1394 bus generic node access devices
209#	fwmem*	IEEE1394 bus physical memory of the remote node access devices
210#
211# Special purpose devices:
212#	ad*	UNIBUS interface to Data Translation A/D converter
213#	agp*	AGP GART devices
214#	altq	ALTQ control interface
215#	amr*	AMI MegaRaid control device
216#	apm	power management device
217#	audio*	audio devices
218#	bell*	OPM bell device (x68k)
219#	bktr	Brooktree 848/849/878/879 based TV cards
220#	bpf	packet filter
221#	bthub	Bluetooth Device Hub control interface
222#	cfs*	Coda file system device
223#	ch*	SCSI media changer
224#	cir*	Consumer IR
225#	clockctl clock control for non root users
226#	cpuctl	CPU control
227#	crypto	hardware crypto access driver
228#	dmoverio hardware-assisted data movers
229#	dpt*	DPT/Adaptec EATA RAID management interface
230#	dpti*	DPT/Adaptec I2O RAID management interface
231#	drm*	Direct Rendering Manager interface
232#	dtv*	Digital TV interface
233#	fb*	PMAX generic framebuffer pseudo-device
234#	fd	file descriptors
235#	gpiopps* 1PPS signals on GPIO pins
236#	grf*	graphics frame buffer device
237#	hdaudio* High Definition audio control device
238#	hdmicec* HDMI CEC devices
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#	ipmi*	OpenIPMI compatible interface
245#	ipl	IP Filter
246#	irframe* IrDA physical frame
247#	ite*	terminal emulator interface to HP300 graphics devices
248#	joy*	joystick device
249#	kttcp	kernel ttcp helper device
250#	lockstat kernel locking statistics
251#	magma*	Magma multiport serial/parallel cards
252#	midi*	MIDI
253#	mfi*	LSI MegaRAID/MegaSAS control interface
254#	mlx*	Mylex DAC960 control interface
255#	mly*	Mylex AcceleRAID/eXtremeRAID control interface
256#	np*	UNIBUS Ethernet co-processor interface, for downloading.
257#	npf	NPF packet filter
258#	nvme*	Non-Volatile Memory Host Controller Interface device driver
259#	nvme*ns* Non-Volatile Memory namespace
260#	nvmm	NetBSD Virtual Machine Monitor
261#	openfirm OpenFirmware accessor
262#	pad*	Pseudo-audio device driver
263#	pci*	PCI bus access devices
264#	pf	PF packet filter
265#	putter	Pass-to-Userspace Transporter
266#	px*	PixelStamp Xserver access
267#	qemufwcfg* QEMU Firmware Configuration
268#	radio*	radio devices
269#	random	Random number generator
270#	rtc*	RealTimeClock
271#	scsibus* SCSI busses
272#	se*	SCSI Ethernet
273#	ses*	SES/SAF-TE SCSI Devices
274#	speaker	PC speaker		(XXX - installed)
275#	spi*	SPI bus device
276#	sram	battery backuped memory (x68k)
277#	srt*	source-address based routing
278#	ss*	SCSI scanner
279#	stic*	PixelStamp interface chip
280#	sysmon	System Monitoring hardware
281#	tap*	virtual Ethernet device
282#	tprof	task profiler
283#	tun*	network tunnel driver
284#	twa	3ware Apache control interface
285#	twe	3ware Escalade control interface
286#	uk*	unknown SCSI device
287#	veriexec Veriexec fingerprint loader
288#	vhci	virtual host controller interface
289#	video*	video capture devices
290#	view*	generic interface to graphic displays (Amiga)
291#	wsfont*	console font control
292#	wsmux*	wscons event multiplexor
293#	xenevt	Xen event interface
294#
295# iSCSI communication devices
296#	iscsi*	iSCSI driver and /sbin/iscsid communication
297#
298# Trusted Computing devices
299#	tpm	Trusted Platform Module
300#
301# Debugging and tracing
302#	dtrace	Dynamic tracing framework
303
304
305#
306# NOTE:
307#
308# * MAKEDEV is used both as a standalone script (via "sh ./MAKEDEV
309#   all" or similar), and as a function library for MAKEDEV.local (via
310#   "MAKEDEV_AS_LIBRARY=1 . MAKEDEV").  Because of this, the script
311#   should consist almost entirely of function definitions, apart from a
312#   few lines right at the end.
313#
314# * MAKEDEV may be executed in an environment that is missing some
315#   common commands.  For example, it may be executed from a minimal
316#   system used during installation, or it may be executed early in the
317#   boot sequence before most file systems have been mounted.  It may
318#   also be executed in a cross-build environment on a non-NetBSD host.
319#
320
321usage()
322{
323	cat 1>&2 << _USAGE_
324Usage: ${0##*/} [-fMsu] [-m mknod] [-p pax] [-t mtree] special [...]
325	Create listed special devices.  Options:
326	-f		Force permissions to be updated on existing devices.
327	-M		Create memory file system.
328	-m mknod	Name of mknod(8) program.  [\$TOOL_MKNOD or mknod]
329	-p pax  	Name of pax(1) program.  [\$TOOL_PAX or pax]
330	-s		Generate mtree(8) specfile instead of creating devices.
331	-t mtree	Name of mtree(8) program.  [\$TOOL_MTREE or mtree]
332	-u		Don't re-create devices that already exist.
333
334_USAGE_
335	exit 1
336}
337
338# zeropad width number
339#	display number with a zero (`0') padding of width digits.
340#
341zeropad()
342{
343	case $(($1 - ${#2})) in
344	5)	echo 00000$2;;
345	4)	echo 0000$2;;
346	3)	echo 000$2;;
347	2)	echo 00$2;;
348	1)	echo 0$2;;
349	0)	echo $2;;
350	*)	die "bad padding" ;;
351	esac
352}
353
354# hexprint number
355#	display (base10) number as hexadecimal
356#
357hexprint()
358{
359	val="$(($1 + 0))"
360	hex=
361	set -- 0 1 2 3 4 5 6 7 8 9 a b c d e f
362	while [ "$val" -gt 0 ]; do
363		eval hex=\$$(($val % 16 + 1))\$hex
364		val="$(($val / 16))"
365	done
366	echo "${hex:-0}"
367}
368
369# linecount multiline_string
370#	count the number of lines in the string
371#
372linecount()
373{
374	local IFS='
375' # just a newline, no other white space between the quotes
376	set -- $1
377	echo $#
378}
379
380# nooutput -12 cmd [args...]
381#	run a command with stdout and/or stderr ignored.
382#	"nooutput -1 cmd" is like "cmd >/dev/null";
383#	"nooutput -2 cmd" is like "{ cmd ; } 2>/dev/null";
384#	"nooutput -12 cmd" is like "{ cmd ; } >/dev/null 2>&1";
385#	except they should work even if /dev/null doesn't [yet] exist.
386#
387#	The "{...}" wrapper used in cases where stderr is redirected
388#	serves to capture shell error messages such as "cmd: not found".
389#
390nooutput()
391{
392	local flags="$1" ; shift
393	local junk
394	case "$flags" in
395	"-1")	junk="$( "$@" )" ;;
396	"-2")	( exec 4>&1 ; junk="$( { "$@" ; } 2>&1 1>&4 )" ) ;;
397	"-12")	junk="$( { "$@" ; } 2>&1 )" ;;
398	*)	warn "Incorrect use of nooutput" ;;
399	esac
400}
401
402# check_pax path_to_pax
403#	Check whether pax exists and supports the command line options
404#	and input format that we will want to use.
405#
406check_pax()
407{
408	local pax="$1"
409	echo ". type=dir optional" | nooutput -12 "${pax}" -r -w -M -pe .
410}
411
412# check_mtree path_to_mtree
413#	Check whether mtree exists and supports the command line options
414#	and input format that we will want to use.
415#
416check_mtree()
417{
418	local mtree="$1"
419	echo ". type=dir optional" | nooutput -12 "${mtree}" -e -U
420}
421
422# setup args...
423#	Parse command line arguments, exit on error.
424#	Callers should shift $((OPTIND - 1)) afterwards.
425#
426setup()
427{
428	PATH=/sbin:/usr/sbin:/bin:/usr/bin:/rescue
429
430	: ${HOST_SH:=sh}
431	: ${TOOL_MKNOD:=mknod}
432	: ${TOOL_MTREE:=mtree}
433	: ${TOOL_PAX:=pax}
434	status=0
435	do_create_mfs=false
436	do_force=false
437	do_mknod=false
438	do_pax=false
439	do_mtree=false
440	do_redirect=false
441	do_specfile=false
442	do_update=false
443	opts=
444	while getopts Mfm:p:st:u ch; do
445		# Note that $opts is only for options pased through to
446		# MAKEDEV.local, not for all options.
447		case ${ch} in
448		M)
449			# "-M" sets do_create_mfs;
450			# "-M -M" is for use from init(8), and sets do_redirect
451			do_redirect=$do_create_mfs
452			do_create_mfs=true
453			;;
454		f)	do_force=true
455			opts="${opts} -f"
456			;;
457		m)	TOOL_MKNOD=${OPTARG}
458			do_mknod=true
459			opts="${opts} -m ${OPTARG}"
460			;;
461		p)	TOOL_PAX="${OPTARG}"
462			if check_pax "${TOOL_PAX}"; then
463				do_pax=true
464				# do not add this to $opts; we will later
465				# add "-s" instead.
466			else
467				warn "Ignored -p option:" \
468					"${TOOL_PAX} is missing or broken"
469				do_mknod=true
470			fi
471			;;
472		s)	do_specfile=true
473			opts="${opts} -s"
474			;;
475		t)	TOOL_MTREE="${OPTARG}"
476			if check_mtree "${TOOL_MTREE}"; then
477				do_mtree=true
478				# do not add this to $opts; we will later
479				# add "-s" instead.
480			else
481				warn "Ignored -t option:" \
482					"${TOOL_MTREE} is missing or broken"
483				do_mknod=true
484			fi
485			;;
486		u)
487			do_update=true
488			opts="${opts} -u"
489			;;
490		*)	usage ;;
491		esac
492	done
493
494	shift $((${OPTIND} - 1))
495	[ $# -gt 0 ] || usage
496
497	u_root="%uid_root%"
498	u_uucp="%uid_uucp%"
499	g_gpio="%gid__gpio%"
500	g_kmem="%gid_kmem%"
501	g_ntpd="%gid_ntpd%"
502	g_nvmm="%gid_nvmm%"
503	g_operator="%gid_operator%"
504	g_wheel="%gid_wheel%"
505	dialin=0
506	dialout=524288
507	callunit=262144
508
509	# only allow read&write for owner by default
510	umask 077
511
512	# Set fdesc_mounted=true if the fdesc file system is mounted
513	# on the current directory (typically "/dev").
514	# Later, this will be used to suppress creation of device nodes
515	# that are supplied by the fdesc file system.
516	#
517	fdesc_mounted=false
518	if [ -d fd ]; then
519		# Parse the output from "mount -u -o nosuchoption .".
520		# We don't parse the output from df(1) because that's
521		# less likely to be available on install media.
522		#
523		# If the current directory is a mount point for the
524		# fdesc file system, then the expected output (whether
525		# or not the current user is root) is:
526		#	mount_fdesc: -o suchoption: option not supported.
527		#
528		# If the current directory is not a mount point, then
529		# the expected output is:
530		#	mount: .: unknown special file or file system.
531		#
532		# If we are not running on NetBSD, or mount(8) is not
533		# found, then we should get some other error message.
534		#
535		case "$({ LC_ALL=C mount -u -o nosuchoption . ; } 2>&1)" in
536		*mount_fdesc*)	fdesc_mounted=true ;;
537		esac
538	fi
539
540	# do_force requires mknod
541	if $do_force; then
542		if $do_mtree || $do_pax || $do_specfile; then
543			die "-f option works only with mknod"
544		fi
545		do_mknod=true
546	fi
547
548	# do_force and do_update do not work together
549	if $do_force && $do_update; then
550		die "-f and -u options do not work together"
551	fi
552
553	# If no explicit method was specified on the command line or
554	# forced above, then use one of mtree, pax, or mknod, in that
555	# order of preference.
556	#
557	# mtree is preferred because it's fast and designed for the
558	# purpose.  However, it's unlikely to be available early in the
559	# boot sequence, when init(8) may invoke MAKEDEV(8).
560	#
561	# pax is usually acceptable, and it's likely to be available
562	# early in the boot sequence.  However, it's much slower than mtree.
563	#
564	# mknod is just very slow, because the shell has to fork for
565	# each device node.
566	#
567
568	case ",${do_mtree},,${do_pax},,${do_mknod},,${do_specfile}," in
569	( ,false,,false,,false,,false, )
570		if check_mtree "${TOOL_MTREE}"; then
571			do_mtree=true
572		elif check_pax "${TOOL_PAX}"; then
573			do_pax=true
574		else
575			do_mknod=true
576		fi
577		;;
578	( *,true,*,true,* )
579		die "-m, -p, -s, and -t options are mutually exclusive"
580		;;
581	esac
582
583	# If we are using mknod, then decide what options to pass it.
584	MKNOD="${TOOL_MKNOD:-mknod} -F netbsd"
585	if $do_mknod; then
586		if $do_force; then
587			MKNOD="${MKNOD} -R"
588		else
589			MKNOD="${MKNOD} -r"
590		fi
591	fi
592
593	# do_mtree or do_pax internally implies do_specfile.
594	# This happens after checking for mutually-exclusive options.
595	if $do_mtree || $do_pax && ! $do_specfile; then
596		do_specfile=true
597		opts="${opts} -s"
598	fi
599}
600
601# specfile_before
602#	This is called before the bulk of the makedev processing,
603#	if do_specfile is set.
604#
605#	It simply prints ". type=dir optional", which must be the
606#	first line of the specfile.
607#
608specfile_before()
609{
610	echo ". type=dir optional"
611}
612
613# mtree_after
614#	Output in specfile format is piped into this function.
615#
616#	It uses mtree to create the devices defined in the specfile.
617#
618mtree_after()
619{
620	nooutput -1 "${TOOL_MTREE}" -e -U
621}
622
623# pax_after
624#	Output in specfile format is piped into this function.
625#
626#	It uses pax to create the devices defined in the specfile.
627#
628pax_after()
629{
630	# Run pax in an empty directory, so it pays
631	# attention only to the specfile, without being
632	# confused by the existing contents of the target
633	# directory.  Without this, pax would complain "file
634	# would overwrite itself" for already-existing
635	# device nodes.
636	tmpdir=./tmp.$$
637	mkdir "${tmpdir}" || die "can't create temporary directory"
638	cd "${tmpdir}" || die "can't cd to temporary directory"
639	"${TOOL_PAX}" -r -w -M -pe ..
640	pax_status=$?
641	cd .. # back to where we started
642	rmdir "${tmpdir}"
643	return $pax_status
644}
645
646# makedev_main makedev_name args...
647#	Perform most of the work of the main program.  makedev_name
648#	is typically "makedev", but may be the name of some other
649#	makedev-like function (if we are invoked from MAKEDEV.local or
650#	some other script).  The other args to this function are the
651#	command line args with which the MAKEDEV (or MAKEDEV.local)
652#	script was invoked.
653#
654makedev_main()
655{
656	local makedev="$1" ; shift
657
658	# Parse command line args
659	setup ${1+"$@"}
660	shift $((${OPTIND}-1))
661
662	if $do_create_mfs; then
663		# Count inodes and create mfs file system.
664		# The makedev call merely updates $count_nodes.
665		count_nodes=0
666		$makedev ${1+"$@"}
667		create_mfs_dev $count_nodes
668		unset count_nodes
669	fi
670
671	# Set before, middle, and after variables, so we can do
672	# something like "( $before && $middle ) | $after",
673	# except it will have to be more complex so we can capture
674	# the exit status from both sides of the pipe.
675	#
676	if $do_specfile; then
677		before=specfile_before
678	else
679		before=:
680	fi
681	middle='$makedev ${1+"$@"} && (exit $status)'
682	if $do_mtree; then
683		after=mtree_after
684	elif $do_pax ; then
685		after=pax_after
686	else
687		after=cat
688	fi
689
690	# Actually perform the "{ $before && $middle } | $after" commands.
691	#
692	# We go to some trouble to ensure that, if any of
693	# $before, $middle, or $after fails, then we also
694	# exit with a non-zero status.
695	#
696	# In the block below, fd 3 is a copy of the original stdout,
697	# and fd 4 goes to a subshell that analyses the exit status
698	# status from the other commands.
699	#
700	{
701		exec 3>&1;
702		{
703			{ eval "$before" && eval "$middle"; echo $? >&4; } \
704			| { eval "$after"; echo $? >&4; } \
705		} 4>&1 1>&3 \
706		| (
707			read status1;
708			read status2;
709			case "$status1,$status2" in
710			0,0) exit 0;;
711			0,*) exit $status2;;
712			*,*) exit $status1;;
713			esac
714		)
715	}
716}
717
718#
719# functions available to create nodes:
720#
721# mkdev name [b|c] major minor [mode{=600} [gid{=0} [uid{=0}]]]
722#	create device node `name' with the appropriate permissions
723#
724# lndev src target
725#	create a symlink from src to target
726#
727# makedir dir mode
728#	create directory with appropriate mode
729#
730
731mkdev()
732{
733	if [ -n "$count_nodes" ]; then
734		count_nodes=$((count_nodes + 1))
735		return
736	fi
737	if $do_update && test -e $1; then
738		return
739	fi
740	if $do_specfile; then
741		case $2 in
742		b)	type=block ;;
743		c)	type=char ;;
744		esac
745		echo "./$1 type=${type} device=netbsd,$3,$4 mode=${5:-600} gid=${6:-$g_wheel} uid=${7:-$u_root}"
746	else
747		${MKNOD} -m ${5:-600} -g \#${6:-$g_wheel} -u \#${7:-$u_root} $1 $2 $3 $4
748	fi
749}
750
751lndev()
752{
753	if [ -n "$count_nodes" ]; then
754		count_nodes=$((count_nodes + 1))
755		return
756	fi
757	if $do_update && test -e $2; then
758		return
759	fi
760	if $do_specfile; then
761		echo "./$2 type=link link=$1 mode=0700 gid=$g_wheel uid=$u_root"
762	else
763		ln -f -s $1 $2
764	fi
765}
766
767makedir()
768{
769	if [ -n "$count_nodes" ]; then
770		count_nodes=$((count_nodes + 1))
771		return
772	fi
773	if $do_update && test -e $1; then
774		return
775	fi
776	if $do_specfile; then
777		echo "./$1 type=dir mode=$2 gid=$g_wheel uid=$u_root"
778	else
779		nooutput -2 mkdir $1
780		chmod $2 $1
781	fi
782}
783
784warn()
785{
786	echo 1>&2 "$0: $*"
787	status=1
788}
789
790die()
791{
792	echo 1>&2 "$0: $*"
793	exit 1
794}
795
796# makedev special [...]
797#	the main loop
798#
799makedev()
800{
801
802for i
803do
804
805case $i in
806
807%MD_DEVICES%
808
809all)
810	makedev all_md
811	makedev std fd ptm
812	makedev dk0 dk1 dk2 dk3 dk4 dk5 dk6 dk7
813	makedev dk8 dk9 dk10 dk11 dk12 dk13 dk14 dk15
814	makedev dk16 dk17 dk18 dk19 dk20 dk21 dk22 dk23
815	makedev dk24 dk25 dk26 dk27 dk28 dk29 dk30 dk31
816	makedev ccd0 ccd1 ccd2 ccd3
817	makedev cgd0 cgd1 cgd2 cgd3 cgd4 cgd5 cgd6 cgd7
818	makedev fss0 fss1 fss2 fss3
819	makedev md0 md1
820	makedev raid0 raid1 raid2 raid3 raid4 raid5 raid6 raid7
821	makedev vnd0 vnd1 vnd2 vnd3
822	makedev iscsi0
823	makedev bpf npf
824	makedev tun0 tun1 tun2 tun3
825	makedev ipl pf crypto random
826	makedev lockstat clockctl cpuctl
827	makedev atabus0 atabus1 atabus2 atabus3 atabus4 atabus5 atabus6 atabus7
828	makedev srt0 srt1 srt2 srt3
829	makedev tap tap0 tap1 tap2 tap3
830	makedev gpio gpio0 gpio1 gpio2 gpio3 gpio4 gpio5 gpio6 gpio7
831	makedev gpiopps0
832	makedev pad pad0 pad1 pad2 pad3
833	makedev bthub
834	makedev putter
835	makedev drvctl
836	makedev video
837	makedev dtv
838	makedev drm0 drm1 drm2 drm3
839	makedev altmem
840	makedev zfs
841	makedev lua
842	makedev hdmicec0
843	makedev dtrace
844	makedev veriexec
845	makedev autofs
846	makedev fw0 fw1 fw2 fw3
847	makedev ipmi0
848	makedev qemufwcfg
849	makedev local # do this last
850	;;
851
852init)
853	# unless overridden by MD entry, this is equal to 'all'
854	makedev all opty
855	;;
856
857%MI_DEVICES_BEGIN%
858audio)
859	makedev audio0 audio1 audio2 audio3
860	makedev hdaudio0 hdaudio1 hdaudio2 hdaudio3
861	lndev sound0 sound
862	lndev audio0 audio
863	lndev mixer0 mixer
864	lndev audioctl0 audioctl
865	;;
866
867gpio)
868	makedev gpio0 gpio1 gpio2 gpio3 gpio4 gpio5 gpio6 gpio7
869	lndev gpio0 gpio
870	;;
871
872gpiopps)
873	makedev gpiopps0
874	lndev gpiopps0 gpiopps
875	;;
876
877lua)
878	makedev lua0
879	lndev lua0 lua
880	;;
881
882pad)
883	makedev pad0 pad1 pad2 pad3
884	lndev pad0 pad
885	;;
886
887qemufwcfg)
888	makedev qemufwcfg0
889	lndev qemufwcfg0 qemufwcfg
890	;;
891
892radio)
893	makedev radio0 radio1
894	lndev radio0 radio
895	;;
896
897video)
898	makedev video0 video1 video2 video3
899	;;
900
901dtv)
902	makedev dtv0 dtv1 dtv2 dtv3
903	;;
904
905iic)
906	makedev iic0 iic1 iic2 iic3
907	;;
908
909altmem)
910	makedev altmem0 altmem1
911	;;
912
913ramdisk)
914	makedev floppy md0
915	;;
916
917usbs)
918	makedev usb usb0 usb1 usb2 usb3 usb4 usb5 usb6 usb7
919	makedev usb8 usb9 usb10 usb11 usb12 usb13 usb14 usb15
920	makedev uhid0 uhid1 uhid2 uhid3 uhid4 uhid5
921	makedev uhid6 uhid7 uhid8 uhid9 uhid10 uhid11
922	makedev uhid12 uhid13 uhid14 uhid15
923	makedev ulpt0 ulpt1
924	makedev ttyU0 ttyU1 ttyU2 ttyU3 ttyU4 ttyU5 ttyU6 ttyU7
925	makedev ttyY0 ttyY1
926	makedev ttyHS0
927	makedev uscanner0 uscanner1
928	makedev utoppy0 utoppy1
929	makedev ugen0 ugen1 ugen2 ugen3
930	;;
931
932std)
933	mkdev		console c %cons_chr% 0	600
934	mkdev		constty c %cons_chr% 1	600
935	mkdev		drum	c %swap_chr% 0	640 $g_kmem
936	mkdev		kmem	c %mem_chr% 1	640 $g_kmem
937	mkdev		mem	c %mem_chr% 0	640 $g_kmem
938	mkdev		null	c %mem_chr% 2	666
939	mkdev		full	c %mem_chr% 11	666
940	mkdev		zero	c %mem_chr% 12	666
941	mkdev		klog	c %log_chr% 0	600
942	mkdev		ksyms	c %ksyms_chr% 0 440 $g_kmem
943	mkdev		random	c %rnd_chr% 0	444
944	mkdev		urandom	c %rnd_chr% 1	644
945	if ! $fdesc_mounted; then
946		mkdev	tty	c %ctty_chr% 0		666
947		mkdev	stdin	c %filedesc_chr% 0	666
948		mkdev	stdout	c %filedesc_chr% 1	666
949		mkdev	stderr	c %filedesc_chr% 2	666
950	fi
951	;;
952
953usb)
954	mkdev usb c %usb_chr% 255 444
955	;;
956
957usb[0-9]*)
958	unit=${i#usb}
959	usb=usb$unit
960	mkdev usb$unit c %usb_chr% $unit
961	;;
962
963uhid[0-9]*)
964	unit=${i#uhid}
965	mkdev uhid$unit c %uhid_chr% $unit 666
966	;;
967
968ulpt[0-9]*)
969	unit=${i#ulpt}
970	mkdev ulpt$unit c %ulpt_chr% $unit
971	mkdev ulpn$unit c %ulpt_chr% $(($unit + 64))
972	;;
973
974uscanner[0-9]*)
975	unit=${i#uscanner}
976	mkdev uscanner$unit c %uscanner_chr% $unit
977	;;
978
979utoppy[0-9]*)
980	unit=${i#utoppy}
981	mkdev utoppy$unit c %utoppy_chr% $unit
982	;;
983
984ttyHS[0-9]*)
985	unit=${i#ttyHS}
986	for j in 00 01 02 03 04 05 06 07 08 09 10
987	do
988		base=$(($unit * 16 + ${j#0}))
989		mkdev ttyHS$unit.$j c %uhso_chr% $(($base + $dialin  )) "" "" $u_uucp
990		mkdev dtyHS$unit.$j c %uhso_chr% $(($base + $dialout )) "" "" $u_uucp
991		mkdev ctyHS$unit.$j c %uhso_chr% $(($base + $callunit)) "" "" $u_uucp
992	done
993	;;
994
995ttyY[0-9]*)
996	unit=${i#ttyY}
997	mkdev ttyY$unit c %ucycom_chr% $(($unit + $dialin  )) "" "" $u_uucp
998	mkdev dtyY$unit c %ucycom_chr% $(($unit + $dialout )) "" "" $u_uucp
999	mkdev ctyY$unit c %ucycom_chr% $(($unit + $callunit)) "" "" $u_uucp
1000	;;
1001
1002ucom[0-9]*)
1003	makedev ttyU${i#ucom}
1004	;;
1005
1006ttyU[0-9]*)
1007	unit=${i#ttyU}
1008	mkdev ttyU$unit c %ucom_chr% $(($unit + $dialin	 )) "" "" $u_uucp
1009	mkdev dtyU$unit c %ucom_chr% $(($unit + $dialout )) "" "" $u_uucp
1010	mkdev ctyU$unit c %ucom_chr% $(($unit + $callunit)) "" "" $u_uucp
1011	;;
1012
1013ugen[0-9]*)
1014	unit=${i#ugen}
1015	for j in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
1016	do
1017		mkdev ugen$unit.$j c %ugen_chr% $(($unit * 16 + ${j#0}))
1018	done
1019	;;
1020
1021wscons)
1022	makedev ttyE0 ttyE1 ttyE2 ttyE3 ttyE4 ttyE5 ttyE6 ttyE7
1023	makedev ttyF0 ttyF1 ttyF2 ttyF3 ttyF4 ttyF5 ttyF6 ttyF7
1024	makedev ttyG0 ttyG1 ttyG2 ttyG3 ttyG4 ttyG5 ttyG6 ttyG7
1025	makedev ttyH0 ttyH1 ttyH2 ttyH3 ttyH4 ttyH5 ttyH6 ttyH7
1026	makedev wsmouse0 wsmouse1 wsmouse2 wsmouse3
1027	makedev wskbd0 wskbd1 wskbd2 wskbd3
1028	makedev wsmux0 wsmux1 wsmux2 wsmux3
1029	makedev wsmouse wskbd
1030	makedev ttyEcfg ttyEstat
1031	makedev ttyFcfg ttyFstat
1032	makedev ttyGcfg ttyGstat
1033	makedev ttyHcfg ttyHstat
1034	makedev wsfont
1035	;;
1036
1037wsmouse)
1038	mkdev wsmouse c %wsmux_chr% 0
1039	;;
1040
1041wskbd)
1042	mkdev wskbd c %wsmux_chr% 1
1043	;;
1044
1045wsmux[0-9]*)
1046	unit=${i#wsmux}
1047	mkdev wsmux$unit    c %wsmux_chr% $unit
1048	mkdev wsmuxctl$unit c %wsmux_chr% $(($unit + 128)) 200
1049	;;
1050
1051xenevt)
1052	mkdev xenevt c %xenevt_chr% 0
1053	;;
1054
1055xsd_kva)
1056	mkdev xsd_kva c %xenevt_chr% 1
1057	;;
1058
1059xencons)
1060	mkdev xencons c %xencons_chr% 0
1061	;;
1062
1063ttyEstat)
1064	mkdev ttyEstat c %wsdisplay_chr% 254
1065	;;
1066
1067ttyEcfg)
1068	mkdev ttyEcfg c %wsdisplay_chr% 255
1069	;;
1070
1071ttyE[0-9]*)
1072	unit=${i#ttyE}
1073	mkdev ttyE$unit c %wsdisplay_chr% $unit
1074	;;
1075
1076ttyFstat)
1077	mkdev ttyFstat c %wsdisplay_chr% 510
1078	;;
1079
1080ttyFcfg)
1081	mkdev ttyFcfg c %wsdisplay_chr% 511
1082	;;
1083
1084ttyF[0-9]*)
1085	unit=${i#ttyF}
1086	mkdev ttyF$unit c %wsdisplay_chr% $(($unit + 256))
1087	;;
1088
1089ttyGstat)
1090	mkdev ttyGstat c %wsdisplay_chr% 766
1091	;;
1092
1093ttyGcfg)
1094	mkdev ttyGcfg c %wsdisplay_chr% 767
1095	;;
1096
1097ttyG[0-9]*)
1098	unit=${i#ttyG}
1099	mkdev ttyG$unit c %wsdisplay_chr% $(($unit + 512))
1100	;;
1101
1102ttyHstat)
1103	mkdev ttyHstat c %wsdisplay_chr% 1022
1104	;;
1105
1106ttyHcfg)
1107	mkdev ttyHcfg c %wsdisplay_chr% 1023
1108	;;
1109
1110ttyH[0-9]*)
1111	unit=${i#ttyH}
1112	mkdev ttyH$unit c %wsdisplay_chr% $(($unit + 768))
1113	;;
1114
1115wsmouse[0-9]*)
1116	unit=${i#wsmouse}
1117	mkdev wsmouse$unit c %wsmouse_chr% $unit
1118	;;
1119
1120wskbd[0-9]*)
1121	unit=${i#wskbd}
1122	mkdev wskbd$unit c %wskbd_chr% $unit
1123	;;
1124
1125fd)
1126	if ! $fdesc_mounted; then
1127		# Create the "fd" subdirectory, and devices "fd/0" to "fd/63"
1128		makedir fd 755
1129		n=0
1130		while [ $n -lt 64 ]
1131		do
1132			mkdev fd/$n c %filedesc_chr% $n 666
1133			n=$(($n + 1))
1134		done
1135	fi
1136	;;
1137
1138wt[0-9]*)
1139	name=wt;  unit=${i#wt};	chr=%wt_chr%;	blk=%wt_blk%
1140	for sub in $unit $(($unit+8)) $(($unit+16))
1141	do
1142		mkdev $name$sub		b $blk $(($sub + 0)) 660 $g_operator
1143		mkdev n$name$sub	b $blk $(($sub + 4)) 660 $g_operator
1144		mkdev r$name$sub	c $chr $(($sub + 0)) 660 $g_operator
1145		mkdev nr$name$sub	c $chr $(($sub + 4)) 660 $g_operator
1146	done
1147	;;
1148
1149md[0-9]*)
1150	makedisk_minimal md ${i#md} %md_blk% %md_chr%
1151	;;
1152
1153fss[0-9]*)
1154	name=fss; unit=${i#fss};	blk=%fss_blk%;	chr=%fss_chr%
1155	mkdev $name$unit	b $blk $unit 660 $g_operator
1156	mkdev r$name$unit	c $chr $unit 660 $g_operator
1157	;;
1158
1159ss[0-9]*)
1160	name=ss;	unit=${i#ss};	chr=%ss_chr%
1161	mkdev $name$unit	c $chr $(($unit * 16 + 0)) 640 $g_operator
1162	mkdev n$name$unit	c $chr $(($unit * 16 + 1)) 640 $g_operator
1163	mkdev en$name$unit	c $chr $(($unit * 16 + 3)) 640 $g_operator
1164	;;
1165
1166ccd[0-9]*|cgd[0-9]*|raid[0-9]*|vnd[0-9]*)
1167	case $i in
1168	ccd*)	name=ccd;	unit=${i#ccd};	blk=%ccd_blk%;	chr=%ccd_chr%;;
1169	cgd*)	name=cgd;	unit=${i#cgd};	blk=%cgd_blk%;	chr=%cgd_chr%;;
1170	raid*)	name=raid;	unit=${i#raid}; blk=%raid_blk%; chr=%raid_chr%;;
1171	vnd*)	name=vnd;	unit=${i#vnd};	blk=%vnd_blk%;	chr=%vnd_chr%;;
1172	esac
1173	%MKDISK% $name $unit $blk $chr
1174	;;
1175
1176sd[0-9]*)
1177	name=sd; unit=${i#sd};	blk=%sd_blk%;	chr=%sd_chr%
1178	%MKDISK% $name $unit $blk $chr
1179	;;
1180
1181ace[0-9]*)
1182	name=ace; unit=${i#ace};	blk=%ace_blk%;		chr=%ace_chr%
1183	%MKDISK% $name $unit $blk $chr
1184	;;
1185
1186eflash[0-9]*)
1187	name=eflash; unit=${i#eflash};	blk=%eflash_blk%;	chr=%eflash_chr%
1188	%MKDISK% $name $unit $blk $chr
1189	;;
1190
1191wd[0-9]*)
1192	name=wd; unit=${i#wd}; blk=%wd_blk%; chr=%wd_chr%
1193	%MKDISK% $name $unit $blk $chr
1194	;;
1195
1196fd[0-9]*)
1197	name=fd; unit=${i#fd}; blk=%fd_blk%; chr=%fd_chr%
1198	%MKDISK% $name $unit $blk $chr
1199	;;
1200
1201ld[0-9]*)
1202	name=ld; unit=${i#ld}; blk=%ld_blk%; chr=%ld_chr%
1203	%MKDISK% $name $unit $blk $chr
1204	;;
1205
1206flash[0-9]*)
1207	unit=${i#flash}
1208	flash=flash$unit
1209	mkdev flash$unit b %flash_blk% $unit
1210	mkdev rflash$unit c %flash_chr% $unit
1211	;;
1212
1213spiflash[0-9]*)
1214	unit=${i#spiflash}
1215	spiflash=spiflash$unit
1216	mkdev spiflash$unit b %spiflash_blk% $unit
1217	mkdev rspiflash$unit c %spiflash_chr% $unit
1218	;;
1219
1220altmem[0-9]*)
1221	name=altmem; unit=${i#altmem}; blk=%altmem_blk%; chr=%altmem_chr%
1222	%MKDISK% $name $unit $blk $chr
1223	;;
1224
1225bio)
1226	mkdev bio c %bio_chr% 0
1227	;;
1228
1229ed[0-9]*)
1230	name=ed; unit=${i#ed}; blk=%ed_blk%; chr=%ed_chr%
1231	%MKDISK% $name $unit $blk $chr
1232	;;
1233
1234ofdisk[0-9]*)
1235	name=ofdisk; unit=${i#ofdisk}; blk=%ofdisk_blk%; chr=%ofdisk_chr%
1236	%MKDISK% $name $unit $blk $chr
1237	;;
1238
1239xbd[0-9]*)
1240	name=xbd; unit=${i#xbd}; blk=%xbd_blk%; chr=%xbd_chr%
1241	%MKDISK% $name $unit $blk $chr
1242	;;
1243
1244dk[0-9]*)
1245	name=dk; unit=${i#dk}; blk=%dk_blk%; chr=%dk_chr%
1246	mkdev r$name$unit c $chr $unit 0640 $g_operator
1247	mkdev $name$unit b $blk  $unit 0640 $g_operator
1248	;;
1249
1250tprof)
1251	mkdev tprof c %tprof_chr% 0
1252	;;
1253
1254ttyCY[0-9]*)
1255	# Each unit number creates 32 pairs of {tty,dty} device nodes:
1256	# ttyCY0 => device nodes [td]tyCY000 to [td]tyCY031;
1257	# ttyCY1 => device nodes [td]tyCY032 to [td]tyCY063;
1258	name=tyCY; chr=%cy_chr%; off=32
1259	unit=${i#t${name}}
1260	minor=$(($unit * $off))
1261	eminor=$(($minor + $off))
1262	while [ $minor -lt $eminor ]
1263	do
1264		nminor=000$minor
1265		nminor=${nminor#${nminor%???}}
1266		mkdev t$name$nminor c $chr $(($minor + $dialin )) "" "" $u_uucp
1267		mkdev d$name$nminor c $chr $(($minor + $dialout)) "" "" $u_uucp
1268		minor=$(($minor + 1))
1269	done
1270	;;
1271
1272ttyCZ[0-9]*)
1273	# Each unit number creates 64 pairs of {tty,dty} device nodes:
1274	# ttyCZ0 => device nodes [td]tyCZ0000 to [td]tyCZ0063;
1275	# ttyCZ1 => device nodes [td]tyCZ0064 to [td]tyCZ0127;
1276	name=tyCZ; chr=%cz_chr%; off=64
1277	unit=${i#t${name}}
1278	minor=$(($unit * $off))
1279	eminor=$(($minor + $off))
1280	while [ $minor -lt $eminor ]
1281	do
1282		nminor=0000$minor
1283		nminor=${nminor#${nminor%????}}
1284		mkdev t$name$nminor c $chr $(($minor + $dialin )) "" "" $u_uucp
1285		mkdev d$name$nminor c $chr $(($minor + $dialout)) "" "" $u_uucp
1286		minor=$(($minor + 1))
1287	done
1288	;;
1289
1290
1291tty[0-9]|tty0[0-9])
1292	# some archs have built-in zstty (major %zstty_chr%) instead
1293	# of NS16550; create ttyZ* and hardlink as [dt]ty0*; this
1294	# needs to be before com entry, for archs which have both
1295	unit=${i#tty}
1296	unit=$(($unit + 0))
1297	makedev ttyZ${unit}
1298	lndev ttyZ$unit tty0${unit}
1299	lndev dtyZ$unit dty0${unit}
1300	;;
1301
1302tty[0-9]*)
1303	unit=${i#tty}
1304	ounit=00$unit
1305	ounit=${ounit#${ounit%??}}
1306	mkdev tty$ounit c %com_chr% $(($unit + $dialin )) "" "" $u_uucp
1307	mkdev dty$ounit c %com_chr% $(($unit + $dialout)) "" "" $u_uucp
1308	;;
1309
1310ttyC[0-9]*)
1311		# some archs call com_chr ttyC traditionally
1312	unit=${i#ttyC}; name=ttyC; dname=dtyC; chr=%com_chr%
1313	mkdev  $name$unit c $chr $(($unit + $dialin )) "" "" $u_uucp
1314	mkdev $dname$unit c $chr $(($unit + $dialout)) "" "" $u_uucp
1315	;;
1316
1317ttyh[0-9]*)
1318	unit=${i#ttyh}; name=ttyh; dname=dtyh; chr=%sabtty_chr%
1319	mkdev  $name$unit c $chr $(($unit + $dialin )) "" "" $u_uucp
1320	mkdev $dname$unit c $chr $(($unit + $dialout)) "" "" $u_uucp
1321	;;
1322
1323ttyTX[0-9]*)
1324	unit=${i#ttyTX}; name=ttyTX0; dname=dtyTX0; chr=%txcom_chr%
1325	mkdev  $name$unit c $chr $(($unit + $dialin )) "" "" $u_uucp
1326	mkdev $dname$unit c $chr $(($unit + $dialout)) "" "" $u_uucp
1327	;;
1328
1329ttyZ[0-9]*)
1330	unit=${i#ttyZ}; name=ttyZ; dname=dtyZ; chr=%zstty_chr%
1331	mkdev  $name$unit c $chr $(($unit + $dialin )) "" "" $u_uucp
1332	mkdev $dname$unit c $chr $(($unit + $dialout)) "" "" $u_uucp
1333	;;
1334
1335opty)
1336	# Create 16 device nodes, [pt]typ0 to [pt]typf,
1337	# same as "MAKEDEV pty0".
1338	for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f
1339	do
1340		case $j in
1341		[0-9])	jn=$j ;;
1342		a)	jn=10 ;;
1343		b)	jn=11 ;;
1344		c)	jn=12 ;;
1345		d)	jn=13 ;;
1346		e)	jn=14 ;;
1347		f)	jn=15 ;;
1348		esac
1349		mkdev ttyp$j c %pts_chr% $jn 666
1350		mkdev ptyp$j c %ptc_chr% $jn 666
1351	done
1352	;;
1353
1354pty[0-9]*)
1355	# Each unit number creates up to 16 pairs of {tty,pty} device nodes:
1356	# pty0 => 16 pairs, [tp]typ0 to [tp]typf
1357	# pty1 => 16 pairs, [tp]tyq0 to [tp]tyqf
1358	# pty16 => 16 pairs, [tp]typg to [tp]typv
1359	# pty17 => 16 pairs, [tp]typw to [tp]typL
1360	# pty18 => 14 pairs, [tp]typM to [tp]typZ
1361	warn "$i: creating BSD style tty nodes with ptyfs is a security issue"
1362	class=${i#pty}
1363	d1="p q r s t u v w x y z P Q R S T"
1364	if [ "$class" -ge 64 ]
1365	then
1366		warn "$i: pty unit must be between 0 and 63"
1367		continue
1368	elif [ "$class" -lt 16 ]
1369	then
1370		# pty[p-zP-T][0-9a-f]
1371		offset=0
1372		mult=0
1373		d2="0 1 2 3 4 5 6 7 8 9 a b c d e f"
1374	else
1375		# pty[p-zP-T][g-zA-Z]
1376		class=$(($class - 16))
1377		offset=256
1378		mult=2
1379		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"
1380	fi
1381	start=$(($class * 16))
1382	set -- $d2
1383	nt=$#
1384	s1=$(($start / $nt))
1385	set -- $d1
1386	shift $s1
1387	t1=$1
1388	if [ "$t1" = v ]; then
1389		warn "$i: pty unit conflicts with console ttyv0 device"
1390		continue
1391	fi
1392	s2=$(($start % ($nt - $s1 * $mult)))
1393	set -- $d2
1394	shift $s2
1395	t2=$1
1396	unit=$(($start + $offset - $s1 * $mult))
1397	end=$(($unit + 16))
1398	while [ "$unit" -lt "$end" ]
1399	do
1400		mkdev tty$t1$t2 c %pts_chr% $unit 666
1401		mkdev pty$t1$t2 c %ptc_chr% $unit 666
1402		shift
1403		t2=$1
1404		if [ -z "$t2" ]
1405		then
1406			break
1407		fi
1408		unit=$(($unit + 1))
1409	done
1410	;;
1411
1412stic[0-9]*)
1413	unit=${i#stic}
1414	mkdev stic$unit c %stic_chr% $unit
1415	;;
1416
1417st[0-9]*)
1418	name=st;	unit=${i#st};	chr=%st_chr%;	blk=%st_blk%
1419	mkdev $name$unit	b $blk $(($unit * 16 + 0)) 660 $g_operator
1420	mkdev n$name$unit	b $blk $(($unit * 16 + 1)) 660 $g_operator
1421	mkdev e$name$unit	b $blk $(($unit * 16 + 2)) 660 $g_operator
1422	mkdev en$name$unit	b $blk $(($unit * 16 + 3)) 660 $g_operator
1423	mkdev r$name$unit	c $chr $(($unit * 16 + 0)) 660 $g_operator
1424	mkdev nr$name$unit	c $chr $(($unit * 16 + 1)) 660 $g_operator
1425	mkdev er$name$unit	c $chr $(($unit * 16 + 2)) 660 $g_operator
1426	mkdev enr$name$unit	c $chr $(($unit * 16 + 3)) 660 $g_operator
1427	;;
1428
1429ses[0-9]*|ch[0-9]*|uk[0-9]*)
1430	case $i in
1431	ch*)	name=ch;	unit=${i#ch};	chr=%ch_chr%;;
1432	uk*)	name=uk;	unit=${i#uk};	chr=%uk_chr%;;
1433	ses*)	name=ses;	unit=${i#ses};	chr=%ses_chr%;;
1434	esac
1435	mkdev $name$unit c $chr $unit 640 $g_operator
1436	;;
1437
1438cd[0-9]*)
1439	makedisk_minimal cd ${i#cd} %cd_blk% %cd_chr%
1440	;;
1441
1442mcd[0-9]*)
1443	makedisk_minimal mcd ${i#mcd} %mcd_blk% %mcd_chr%
1444	;;
1445
1446gdrom[0-9]*)
1447	makedisk_minimal gdrom ${i#gdrom} %gdrom_blk% %gdrom_chr%
1448	;;
1449
1450lpt[0-9]*|lpa[0-9]*)
1451	case $i in
1452	lpt*) name=lpt; unit=${i#lpt};	chr=%lpt_chr%;	flags=0;;
1453	lpa*) name=lpa; unit=${i#lpa};	chr=%lpt_chr%;	flags=128;;
1454	esac
1455	mkdev $name$unit c $chr $(($unit + $flags))
1456	mkdev lpt${unit}ctl c $chr $(($unit + 256))
1457	;;
1458
1459bpf)
1460	mkdev bpf	c %bpf_chr% 0
1461	lndev bpf bpf0
1462	;;
1463
1464npf)
1465	mkdev npf	c %npf_chr% 0
1466	;;
1467
1468bthub)
1469	mkdev bthub c %bthub_chr% 0
1470	;;
1471
1472tun[0-9]*)
1473	unit=${i#tun}
1474	mkdev tun$unit c %tun_chr% $unit
1475	;;
1476
1477joy[0-9]*)
1478	unit=${i#joy}
1479	mkdev joy$unit c %joy_chr% $unit
1480	;;
1481
1482ipl)
1483	mkdev ipl	c %ipl_chr% 0
1484	mkdev ipnat	c %ipl_chr% 1
1485	mkdev ipstate	c %ipl_chr% 2
1486	mkdev ipauth	c %ipl_chr% 3
1487	mkdev ipsync	c %ipl_chr% 4
1488	mkdev ipscan	c %ipl_chr% 5
1489	mkdev iplookup	c %ipl_chr% 6
1490	;;
1491
1492pf)
1493	mkdev pf c %pf_chr% 0
1494	;;
1495
1496crypto)
1497	mkdev crypto c %crypto_chr% 0 666
1498	;;
1499
1500cmos)
1501	mkdev cmos c %cmos_chr% 0 644
1502	;;
1503
1504speaker)
1505	mkdev speaker c %spkr_chr% 0
1506	;;
1507
1508lockstat)
1509	mkdev lockstat c %lockstat_chr% 0
1510	;;
1511
1512cpuctl)
1513	mkdev cpuctl c %cpuctl_chr% 0 666
1514	;;
1515
1516audio|audio[0-9]*)
1517	unit=${i#audio}
1518	audio=audio$unit
1519	sound=sound$unit
1520	mixer=mixer$unit
1521	audioctl=audioctl$unit
1522	: ${unit:-0}
1523	mkdev $sound	c %audio_chr% $(($unit + 0))	666
1524	mkdev $audio	c %audio_chr% $(($unit + 128))	666
1525	mkdev $mixer	c %audio_chr% $(($unit + 16))	666
1526	mkdev $audioctl c %audio_chr% $(($unit + 192))	666
1527	;;
1528
1529hdaudio[0-9]*)
1530	unit=${i#hdaudio}
1531	mkdev hdaudio$unit c %hdaudio_chr% $unit 644
1532	;;
1533
1534hdmicec[0-9]*)
1535	uint=${i#hdmicec}
1536	mkdev hdmicec$unit c %hdmicec_chr% $unit 644
1537	;;
1538
1539gpio[0-9]*)
1540	unit=${i#gpio}
1541	mkdev gpio$unit c %gpio_chr% $unit 664 $g_gpio
1542	;;
1543
1544gpiopps[0-9]*)
1545	unit=${i#gpiopps}
1546	mkdev gpiopps$unit c %gpiopps_chr% $unit 664 $g_gpio
1547	;;
1548
1549lua[0-9]*)
1550	unit=${i#lua}
1551	mkdev lua$unit c %lua_chr% $unit 664
1552	;;
1553
1554rmidi[0-9]*)
1555	unit=${i#rmidi}
1556	mkdev rmidi$unit c %midi_chr% $unit 666
1557	;;
1558
1559music|music[0-9]*)
1560	unit=${i#music}
1561	: ${unit:-0}
1562	mkdev music$unit     c %sequencer_chr% $(($unit + 0))	666
1563	mkdev sequencer$unit c %sequencer_chr% $(($unit + 128)) 666
1564	;;
1565
1566radio|radio[0-9]*)
1567	unit=${i#radio}
1568	: ${unit:-0}
1569	mkdev radio$unit c %radio_chr% $unit 666
1570	;;
1571
1572video|video[0-9]*)
1573	unit=${i#video}
1574	: ${unit:-0}
1575	mkdev video$unit c %video_chr% $unit 666
1576	;;
1577
1578dtv[0-9]*)
1579	unit=${i#dtv}
1580	makedir dvb 755
1581	makedir dvb/adapter$unit 755
1582	mkdev dvb/adapter$unit/frontend0 c %dtv_chr% $(($unit + 0)) 666
1583	mkdev dvb/adapter$unit/demux0 c %dtv_chr% $(($unit + 16)) 666
1584	mkdev dvb/adapter$unit/dvr0 c %dtv_chr% $(($unit + 32)) 666
1585	;;
1586
1587iic[0-9]*)
1588	unit=${i#iic}
1589	: ${unit:-0}
1590	mkdev iic$unit c %iic_chr% $unit 600
1591	;;
1592
1593spi[0-9]*)
1594	unit=${i#spi}
1595	: ${unit:-0}
1596	mkdev spi$unit c %spi_chr% $unit 600
1597	;;
1598
1599amr[0-9]*)
1600	unit=${i#amr}
1601	mkdev amr$unit c %amr_chr% $unit
1602	;;
1603
1604apm)
1605	mkdev apm	c %apm_chr% 0 644
1606	mkdev apmctl	c %apm_chr% 8 644
1607	;;
1608
1609apm)
1610		# hpcmips uses `apmdev_chr' instead of `apm_chr'
1611	mkdev apm	c %apmdev_chr% 0 644
1612	mkdev apmctl	c %apmdev_chr% 8 644
1613	;;
1614
1615random)
1616	mkdev random	c %rnd_chr% 0 444
1617	mkdev urandom	c %rnd_chr% 1 644
1618	;;
1619
1620cfs)
1621	makedev cfs0
1622	;;
1623
1624cfs[0-9]*)
1625	unit=${i#cfs}
1626	mkdev cfs$unit c %vcoda_chr% $unit
1627	;;
1628
1629sysmon)
1630	mkdev sysmon	c %sysmon_chr% 0 644
1631	mkdev watchdog	c %sysmon_chr% 1 644
1632	mkdev power	c %sysmon_chr% 2 640
1633	;;
1634
1635scsibus[0-9]*)
1636	unit=${i#scsibus}
1637	mkdev scsibus$unit c %scsibus_chr% $unit 644
1638	;;
1639
1640bktr)
1641	makedev bktr0 bktr1
1642	lndev	bktr0	bktr
1643	lndev	tuner0	tuner
1644	lndev	vbi0	vbi
1645	;;
1646
1647bktr[0-9]*)
1648	unit=${i#bktr}
1649	mkdev bktr$unit		c %bktr_chr% $(($unit + 0))	444
1650	mkdev tuner$unit	c %bktr_chr% $(($unit + 16))	444
1651	mkdev vbi$unit		c %bktr_chr% $(($unit + 32))	444
1652	;;
1653
1654io)
1655	mkdev		io	c %mem_chr% 14	600
1656	;;
1657
1658iop[0-9]*)
1659	unit=${i#iop}
1660	mkdev iop$unit c %iop_chr% $unit
1661	;;
1662
1663mfi[0-9]*)
1664	unit=${i#mfi}
1665	mkdev mfi$unit c %mfi_chr% $unit
1666	;;
1667
1668mlx[0-9]*)
1669	unit=${i#mlx}
1670	mkdev mlx$unit c %mlx_chr% $unit
1671	;;
1672
1673mly[0-9]*)
1674	unit=${i#mly}
1675	mkdev mly$unit c %mly_chr% $unit
1676	;;
1677
1678twa[0-9]*)
1679	unit=${i#twa}
1680	mkdev twa$unit c %twa_chr% $unit
1681	;;
1682
1683twe[0-9]*)
1684	unit=${i#twe}
1685	mkdev twe$unit c %twe_chr% $unit
1686	;;
1687
1688icp[0-9]*)
1689	unit=${i#icp}
1690	mkdev icp$unit c %icp_chr% $unit
1691	;;
1692
1693agp[0-9]*)
1694	unit=${i#agp}
1695	mkdev agp$unit c %agp_chr% $unit 644
1696	if [ "$unit" = "0" ]; then
1697		lndev agp$unit agpgart
1698	fi
1699	;;
1700
1701pci[0-9]*)
1702	unit=${i#pci}
1703	mkdev pci$unit c %pci_chr% $unit 640
1704	;;
1705
1706dpti[0-9]*)
1707	unit=${i#dpti}
1708	mkdev dpti$unit c %dpti_chr% $unit
1709	;;
1710
1711dpt[0-9]*)
1712	unit=${i#dpt}
1713	mkdev dpt$unit c %dpt_chr% $unit
1714	;;
1715
1716altq)
1717	makedir altq 755
1718	unit=0
1719	for dev in altq cbq wfq afm fifoq red rio localq hfsc cdnr blue priq jobs
1720	do
1721		mkdev altq/$dev c %altq_chr% $unit 644
1722		unit=$(($unit + 1))
1723	done
1724	;;
1725
1726wsfont)
1727	mkdev wsfont c %wsfont_chr% 0
1728	;;
1729
1730cir[0-9]*)
1731	unit=${i#cir}
1732	mkdev cir$unit c %cir_chr% $unit 666
1733	;;
1734
1735irframe[0-9]*)
1736	unit=${i#irframe}
1737	mkdev irframe$unit c %irframe_chr% $unit
1738	;;
1739
1740fcom[0-9]*)
1741	unit=${i#fcom}
1742	mkdev fcom$unit c %fcom_chr% $unit "" "" $u_uucp
1743	;;
1744
1745openfirm)
1746	mkdev openfirm c %openfirm_chr% 0 444
1747	;;
1748
1749pad[0-9]*)
1750	unit=${i#pad}
1751	mkdev pad$unit c %pad_chr% $unit 444
1752	;;
1753
1754qemufwcfg[0-9]*)
1755	unit=${i#qemufwcfg}
1756	mkdev qemufwcfg$unit c %qemufwcfg_chr% $unit 660
1757	;;
1758
1759vio9p[0-9]*)
1760	unit=${i#vio9p}
1761	mkdev vio9p$unit c %vio9p_chr% $unit 660
1762	;;
1763
1764fault)
1765	mkdev fault c %fault_chr% 0
1766	;;
1767
1768nvram)
1769	mkdev nvram c %nvram_chr% 0 644
1770	;;
1771
1772rtc)
1773	mkdev rtc c %rtc_chr% 0 644
1774	;;
1775
1776clockctl)
1777	mkdev clockctl c %clockctl_chr% 0 660 $g_ntpd
1778	;;
1779
1780kttcp)
1781	mkdev kttcp c %kttcp_chr% 0
1782	;;
1783
1784dmoverio)
1785	mkdev dmoverio c %dmoverio_chr% 0 644
1786	;;
1787
1788veriexec)
1789	mkdev veriexec c %veriexec_chr% 0 600
1790	;;
1791
1792vhci[0-7]*)
1793	unit=${i#vhci}
1794	mkdev vhci$unit c %vhci_chr% $unit
1795	;;
1796
1797ttyv[0-9]*)
1798	unit=${i#ttyv}
1799	mkdev ttyv$unit c %pc_chr% $unit
1800	;;
1801
1802# arm, acorn32
1803ttyv[0-9]*)
1804	unit=${i#ttyv}
1805	mkdev ttyv$unit c %physcon_chr% $unit
1806	;;
1807
1808arcpp[0-9]*)
1809	unit=${i#arcpp}
1810	mkdev arcpp$unit c %arcpp_chr% $unit
1811	;;
1812
1813par[0-9]*)
1814	unit=${i#par}
1815	case $unit in
1816	0)
1817		mkdev par$unit c %par_chr% $unit
1818		;;
1819	*)
1820		warn "bad unit for par in: $i"
1821		;;
1822	esac
1823	;;
1824
1825cpi[0-9]*)
1826	unit=${i#cpi}
1827	mkdev cpi$unit c %cpi_chr% $unit
1828	;;
1829
1830ite[0-9]*|ttye[0-9]*)
1831	case $i in
1832	ite*)	unit=${i#ite};;
1833	ttye*)	unit=${i#ttye};;
1834	esac
1835	mkdev ttye$unit c %ite_chr% $unit
1836	;;
1837
1838pms[0-9]*)
1839	unit=${i#pms}
1840	mkdev pms$unit c %opms_chr% $unit
1841	;;
1842
1843qms[0-9]*)
1844	unit=${i#qms}
1845	mkdev qms$unit c %qms_chr% $unit
1846	;;
1847
1848lms[0-9]*)
1849	unit=${i#lms}
1850	mkdev lms$unit c %lms_chr% $unit
1851	;;
1852
1853mms[0-9]*)
1854	unit=${i#mms}
1855	mkdev mms$unit c %mms_chr% $unit
1856	;;
1857
1858mouse-pms[0-9]*|mouse-qms[0-9]*)
1859	case $i in
1860	mouse-pms*) name=pms ;;
1861	mouse-qms*) name=qms ;;
1862	esac
1863	unit=${i#mouse-${name}}
1864	lndev $name$unit mouse
1865	;;
1866
1867kbd)
1868	mkdev kbd c %kbd_chr% 0
1869	;;
1870
1871kbdctl)
1872	mkdev kbdctl c %kbd_chr% 1
1873	;;
1874
1875vidcconsole0)
1876	mkdev vidcconsole0 c %vidcconsole_chr% 0 640
1877	;;
1878
1879view[0-9]*)
1880	unit=${i#view}
1881	mkdev view$unit c %view_chr% $unit 666
1882	;;
1883
1884mouse[0-9]*)
1885	unit=${i#mouse}
1886	case $unit in
1887	0|1)
1888		mkdev mouse$unit c %ms_chr% $unit 666
1889		if [ $unit = 0 ]; then
1890			lndev mouse$unit mouse
1891		fi
1892		;;
1893	*)
1894		warn "bad unit for mouse in: $i"
1895		;;
1896	esac
1897	;;
1898
1899panel)
1900	mkdev panel0 c %panel_chr% 0 660
1901	;;
1902
1903tslcd)
1904	mkdev tslcd0 c %tslcd_chr% 0 660
1905	;;
1906
1907ipty)
1908	mkdev ttyp0 c %pts_chr% 0 666
1909	mkdev ttyp1 c %pts_chr% 1 666
1910	mkdev ptyp0 c %ptc_chr% 0 666
1911	mkdev ptyp1 c %ptc_chr% 1 666
1912	;;
1913
1914ptm)
1915	makedir pts 755
1916	mkdev ptmx c %ptm_chr% 0 666
1917	mkdev ptm c %ptm_chr% 1 666
1918	;;
1919
1920grf[0-9]*)
1921	unit=${i#grf}
1922	mkdev grf$unit c %grf_chr% $unit 666
1923	;;
1924
1925etvme)
1926	mkdev etvme c %et_chr% 0
1927	;;
1928
1929leo[0-9]*)
1930	unit=${i#leo}
1931	mkdev leo$unit c %leo_chr% $unit
1932	;;
1933
1934scif[0-9]*)
1935	unit=${i#scif}
1936	mkdev scif$unit c %scif_chr% $(($unit + $dialin )) "" "" $u_uucp
1937	mkdev dscif$unit c %scif_chr% $(($unit + $dialout)) "" "" $u_uucp
1938	;;
1939
1940sci[0-9]*)
1941	unit=${i#sci}
1942	mkdev sci$unit c %sci_chr% $(($unit + $dialin )) "" "" $u_uucp
1943	mkdev dsci$unit c %sci_chr% $(($unit + $dialout)) "" "" $u_uucp
1944	;;
1945
1946maple[ABCD]|maple[ABCD][0-9]*)
1947	case $i in
1948	mapleA*) name="mapleA"; unit=0;;
1949	mapleB*) name="mapleB"; unit=1;;
1950	mapleC*) name="mapleC"; unit=2;;
1951	mapleD*) name="mapleD"; unit=3;;
1952	esac
1953	subunit=${i#$name}
1954	mkdev $name$subunit c %maple_chr% $(($unit * 8 + 0$subunit))
1955	;;
1956
1957mmem[0-9]*)
1958	unit=${i#mmem}
1959	for pt in 0	# 1 2 3 4 ... 255
1960	do
1961#		mkdev mmem${unit}.${pt}a  b %mmem_blk% $(($unit * 4096 + $pt * 16 + 0)) 640 $g_operator
1962		mkdev mmem${unit}.${pt}c  b %mmem_blk% $(($unit * 4096 + $pt * 16 + 2)) 640 $g_operator
1963#		mkdev rmmem${unit}.${pt}a c %mmem_chr% $(($unit * 4096 + $pt * 16 + 0)) 640 $g_operator
1964		mkdev rmmem${unit}.${pt}c c %mmem_chr% $(($unit * 4096 + $pt * 16 + 2)) 640 $g_operator
1965	done
1966	;;
1967
1968mlcd[0-9]*)
1969	unit=${i#mlcd}
1970	for pt in 0	# 1 2 3 4 ... 255
1971	do
1972		mkdev mlcd${unit}.${pt} c %mlcd_chr% $(($unit * 256 + $pt)) 640 $g_operator
1973	done
1974	;;
1975
1976ixpcom[0-9]*)
1977	unit=${i#ixpcom}
1978	mkdev ixpcom$unit c %ixpcom_chr% $unit "" "" $u_uucp
1979	;;
1980
1981epcom[0-9]*)
1982	unit=${i#epcom}
1983	mkdev epcom$unit c %epcom_chr% $unit "" "" $u_uucp
1984	;;
1985
1986plcom[0-9]*)
1987	unit=${i#plcom}
1988	mkdev plcom$unit c %plcom_chr% $unit "" "" $u_uucp
1989	mkdev dplcom$unit c %plcom_chr% $(($unit + $dialout)) "" "" $u_uucp
1990	;;
1991
1992wmcom[0-9]*)
1993	unit=${i#wmcom}
1994	mkdev wmcom$unit c %wmcom_chr% $unit "" "" $u_uucp
1995	;;
1996
1997ucbsnd)
1998	mkdev ucbsnd c %ucbsnd_chr% 0 666
1999	;;
2000
2001adb)
2002	mkdev adb c %aed_chr% 0 666
2003	;;
2004
2005asc[0-9]*)
2006	unit=${i#asc}
2007	mkdev asc$unit c %asc_chr% $unit 666
2008	;;
2009
2010bwtwo[0-9]*)
2011	unit=${i#bwtwo}
2012	mkdev bwtwo$unit c %bwtwo_chr% $unit 666
2013	;;
2014
2015cgtwo[0-9]*)
2016	unit=${i#cgtwo}
2017	mkdev cgtwo$unit c %cgtwo_chr% $unit 666
2018	;;
2019
2020cgthree[0-9]*)
2021	unit=${i#cgthree}
2022	mkdev cgthree$unit c %cgthree_chr% $unit 666
2023	;;
2024
2025cgfour[0-9]*)
2026	unit=${i#cgfour}
2027	mkdev cgfour$unit c %cgfour_chr% $unit 666
2028	;;
2029
2030cgsix[0-9]*)
2031	unit=${i#cgsix}
2032	mkdev cgsix$unit c %cgsix_chr% $unit 666
2033	;;
2034
2035cgeight[0-9]*)
2036	unit=${i#cgeight}
2037	mkdev cgeight$unit c %cgeight_chr% $unit 666
2038	;;
2039
2040tcx[0-9]*)
2041	unit=${i#tcx}
2042	mkdev tcx$unit c %tcx_chr% $unit 666
2043	;;
2044
2045xd[0-9]*|xy[0-9]*)
2046	case $i in
2047	xd*)	name=xd; unit=${i#xd}; blk=%xd_blk%;	chr=%xd_chr%;;
2048	xy*)	name=xy; unit=${i#xy}; blk=%xy_blk%;	chr=%xy_chr%;;
2049	esac
2050	%MKDISK% $name $unit $blk $chr
2051	;;
2052
2053magma[0-9]*)
2054	unit=${i#magma}
2055	if [ 0$unit -gt 3 ]; then
2056		warn "bad unit for $i: $unit"
2057		break
2058	fi
2059	for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f
2060	do
2061		case $j in
2062		[0-9])	jn=$j ;;
2063		a)	jn=10 ;;
2064		b)	jn=11 ;;
2065		c)	jn=12 ;;
2066		d)	jn=13 ;;
2067		e)	jn=14 ;;
2068		f)	jn=15 ;;
2069		esac
2070		mkdev tty$unit$j c %mtty_chr% $(($unit * 64 + $jn))
2071	done
2072	mkdev bpp${unit}0 c %mbpp_chr% $(($unit * 64 + 0))
2073	mkdev bpp${unit}1 c %mbpp_chr% $(($unit * 64 + 1))
2074	;;
2075
2076clcd[0-9]*)
2077	unit=${i#clcd}
2078	if [ 0$unit -gt 7 ]; then
2079		warn "bad unit for $i: $unit"
2080		break
2081	fi
2082	for j in 0 1 2 3 4 5 6 7
2083	do
2084		mkdev ttyA$unit$j c %clcd_chr% $(($unit * 8 + $j + $dialin)) "" "" $u_uucp
2085		mkdev dtyA$unit$j c %clcd_chr% $(($unit * 8 + $j + $dialout)) "" "" $u_uucp
2086	done
2087	;;
2088
2089spif[0-9]*)
2090	unit=${i#spif}
2091	if [ 0$unit -gt 3 ]; then
2092		warn "bad unit for $i: $unit"
2093		break
2094	fi
2095	for j in 0 1 2 3 4 5 6 7; do
2096		mkdev ttyS$unit$j c %stty_chr% $(($unit * 64 + $j)) "" "" $u_uucp
2097	done
2098	mkdev bppS${unit}0 c %sbpp_chr% $(($unit * 64 + 0))
2099	mkdev bppS${unit}1 c %sbpp_chr% $(($unit * 64 + 1))
2100	;;
2101
2102bpp|bpp[0-9]*)
2103	unit=${i#bpp}
2104	mkdev bpp$unit c %bpp_chr% $(($unit + 0))
2105	;;
2106
2107tctrl[0-9]*)
2108	unit=${i#tctrl}
2109	mkdev tctrl$unit c %tctrl_chr% $unit 666
2110	;;
2111
2112bmd[0-9]*)
2113	unit=${i#bmd}
2114	mkdev bmd${unit}a  b %bmd_blk% $(($unit * 8 + 0)) 640 $g_operator
2115	mkdev bmd${unit}c  b %bmd_blk% $(($unit * 8 + 2)) 640 $g_operator
2116	mkdev rbmd${unit}a c %bmd_chr% $(($unit * 8 + 0)) 640 $g_operator
2117	mkdev rbmd${unit}c c %bmd_chr% $(($unit * 8 + 2)) 640 $g_operator
2118	;;
2119
2120sram)
2121	mkdev sram c %sram_chr% 0 644
2122	;;
2123
2124ttyS[0-9]*)
2125	unit=${i#ttyS}
2126	mkdev ttyS$unit c %sacom_chr% $(($unit + $dialin )) "" "" $u_uucp
2127	mkdev dtyS$unit c %sacom_chr% $(($unit + $dialout)) "" "" $u_uucp
2128	;;
2129
2130atabus[0-9]*)
2131	unit=${i#atabus}
2132	mkdev atabus$unit c %atabus_chr% $unit 644
2133	;;
2134
2135drm[0-9]*)
2136	unit=${i#drm}
2137	makedir dri 755
2138	mkdev dri/card$unit c %drm_chr% $unit 660
2139	;;
2140
2141drvctl)
2142	mkdev drvctl c %drvctl_chr% 0 644
2143	;;
2144
2145isv)
2146	mkdev isv c %isv_chr% 0 644
2147	;;
2148
2149tap|tap[0-9]*)
2150	unit=${i#tap}
2151	case "$unit" in
2152	[0-9]*)
2153		mkdev tap${unit} c %tap_chr% ${unit} 600
2154		;;
2155	"")
2156		mkdev tap c %tap_chr% 0xfffff 600
2157		;;
2158	esac
2159	;;
2160
2161srt[0-9]*)
2162	unit=${i#srt}
2163	mkdev srt$unit c %srt_chr% $unit 600
2164	;;
2165
2166tpm)
2167	mkdev tpm c %tpm_chr% 0 600
2168	;;
2169
2170dtrace)
2171	makedir dtrace 755
2172	mkdev dtrace/dtrace c %dtrace_chr% 0 600
2173	;;
2174
2175fw[0-9]*)
2176	unit=${i#fw}
2177	for j in 0 1 2 3
2178	do
2179		mkdev fw${unit}.${j} c %fw_chr% $((${unit} * 256 + ${j})) 660 ${g_operator}
2180		mkdev fwmem${unit}.${j} c %fw_chr% $((65536 + ${unit} * 256 + ${j})) 660 ${g_operator}
2181	done
2182	;;
2183
2184# create putter device and symlinks for all subsystems using it
2185putter)
2186	mkdev putter c %putter_chr% 0 600
2187	mkdev pud c %putter_chr% 1 600
2188	lndev putter puffs
2189	;;
2190
2191zfs)
2192	mkdev zfs c %zfs_chr% 0 600
2193	makedir zpool 755
2194	;;
2195
2196iscsi[0-9]*)
2197	unit=${i#iscsi}
2198	mkdev iscsi${unit} c %iscsi_chr% $unit 600
2199	;;
2200
2201vchiq)
2202	mkdev vchiq c %vchiq_chr% 0 600
2203	;;
2204
2205nvme[0-9]*ns[0-9]*)
2206	unit=${i#nvme}
2207	unit=${unit%ns*}
2208	subunit=${i#nvme${unit}ns}
2209	if [ 0$subunit -le 0 ] || [ 0$subunit -ge 65536 ]; then
2210		warn "bad nsid for $i: $subunit"
2211		break
2212	fi
2213	mkdev nvme${unit}ns$subunit c %nvme_chr% $(($unit * 65536 + $subunit))
2214	;;
2215
2216nvme[0-9]*)
2217	unit=${i#nvme}
2218	mkdev nvme$unit c %nvme_chr% $(($unit * 65536))
2219	;;
2220
2221nvmm)
2222	mkdev nvmm c %nvmm_chr% 0 640 $g_nvmm
2223	;;
2224
2225autofs)
2226	mkdev autofs c %autofs_chr% 0 600
2227	;;
2228
2229kcov)
2230        mkdev kcov c %kcov_chr% 0
2231        ;;
2232
2233ipmi[0-9]*)
2234	unit=${i#ipmi}
2235	mkdev ipmi${unit} c %ipmi_chr% $unit 600
2236	;;
2237
2238xmm[0-9])
2239	unit=${i#xmm}
2240	makedir xmm${unit} 755
2241	mkdev xmm${unit}/rpc c %wwanc_chr% $(($unit * 65536 + 1))
2242	mkdev ttyXMM${unit}0 c %wwanc_chr% $(($unit * 65536 + 2))
2243	mkdev ttyXMM${unit}1 c %wwanc_chr% $(($unit * 65536 + 4))
2244	;;
2245
2246midevend)
2247%MI_DEVICES_END%
2248local)
2249	if [ -f "$0.local" ]; then
2250		umask 0
2251		if [ -n "$count_nodes" ]; then
2252			count_nodes=$((count_nodes + \
2253			    $(linecount "$("$HOST_SH" "$0.local" $opts -s all)") ))
2254		else
2255			"$HOST_SH" "$0.local" $opts all
2256		fi
2257		umask 077
2258	fi
2259	;;
2260
2261*)
2262	warn "$i: unknown device"
2263	;;
2264
2265esac
2266done
2267
2268}
2269
2270
2271# three variants of disk partitions - max 8, max 16, max 16 with highpartoffset
2272# hack; only the one used by port is retained in final MAKEDEV script
2273# routine is called as:
2274# makedisk name unit blk chr
2275makedisk_p8()
2276{
2277	name="$1"; unit="$2"; blk="$3"; chr="$4"
2278
2279	ro=%RAWDISK_OFF%
2280	mkdev ${name}${unit}	b $blk $(($unit * 8 + $ro))	640 $g_operator
2281	mkdev r${name}${unit}	c $chr $(($unit * 8 + $ro))	640 $g_operator
2282
2283	mkdev ${name}${unit}a	b $blk $(($unit * 8 + 0))	640 $g_operator
2284	mkdev ${name}${unit}b	b $blk $(($unit * 8 + 1))	640 $g_operator
2285	mkdev ${name}${unit}c	b $blk $(($unit * 8 + 2))	640 $g_operator
2286	mkdev ${name}${unit}d	b $blk $(($unit * 8 + 3))	640 $g_operator
2287	mkdev ${name}${unit}e	b $blk $(($unit * 8 + 4))	640 $g_operator
2288	mkdev ${name}${unit}f	b $blk $(($unit * 8 + 5))	640 $g_operator
2289	mkdev ${name}${unit}g	b $blk $(($unit * 8 + 6))	640 $g_operator
2290	mkdev ${name}${unit}h	b $blk $(($unit * 8 + 7))	640 $g_operator
2291	mkdev r${name}${unit}a	c $chr $(($unit * 8 + 0))	640 $g_operator
2292	mkdev r${name}${unit}b	c $chr $(($unit * 8 + 1))	640 $g_operator
2293	mkdev r${name}${unit}c	c $chr $(($unit * 8 + 2))	640 $g_operator
2294	mkdev r${name}${unit}d	c $chr $(($unit * 8 + 3))	640 $g_operator
2295	mkdev r${name}${unit}e	c $chr $(($unit * 8 + 4))	640 $g_operator
2296	mkdev r${name}${unit}f	c $chr $(($unit * 8 + 5))	640 $g_operator
2297	mkdev r${name}${unit}g	c $chr $(($unit * 8 + 6))	640 $g_operator
2298	mkdev r${name}${unit}h	c $chr $(($unit * 8 + 7))	640 $g_operator
2299}
2300
2301makedisk_p12high()
2302{
2303	ho=524280	# offset for partition 9 to 11 (same as ...p16high)
2304	name="$1"; unit="$2"; blk="$3"; chr="$4"
2305
2306	ro=%RAWDISK_OFF%
2307	mkdev ${name}${unit}	b $blk $(($unit * 8 + $ro))	640 $g_operator
2308	mkdev r${name}${unit}	c $chr $(($unit * 8 + $ro))	640 $g_operator
2309
2310	mkdev ${name}${unit}a	b $blk $(($unit * 8 + 0))	640 $g_operator
2311	mkdev ${name}${unit}b	b $blk $(($unit * 8 + 1))	640 $g_operator
2312	mkdev ${name}${unit}c	b $blk $(($unit * 8 + 2))	640 $g_operator
2313	mkdev ${name}${unit}d	b $blk $(($unit * 8 + 3))	640 $g_operator
2314	mkdev ${name}${unit}e	b $blk $(($unit * 8 + 4))	640 $g_operator
2315	mkdev ${name}${unit}f	b $blk $(($unit * 8 + 5))	640 $g_operator
2316	mkdev ${name}${unit}g	b $blk $(($unit * 8 + 6))	640 $g_operator
2317	mkdev ${name}${unit}h	b $blk $(($unit * 8 + 7))	640 $g_operator
2318	mkdev ${name}${unit}i	b $blk $(($unit * 8 + $ho + 8)) 640 $g_operator
2319	mkdev ${name}${unit}j	b $blk $(($unit * 8 + $ho + 9)) 640 $g_operator
2320	mkdev ${name}${unit}k	b $blk $(($unit * 8 + $ho + 10)) 640 $g_operator
2321	mkdev ${name}${unit}l	b $blk $(($unit * 8 + $ho + 11)) 640 $g_operator
2322	mkdev r${name}${unit}a	c $chr $(($unit * 8 + 0))	640 $g_operator
2323	mkdev r${name}${unit}b	c $chr $(($unit * 8 + 1))	640 $g_operator
2324	mkdev r${name}${unit}c	c $chr $(($unit * 8 + 2))	640 $g_operator
2325	mkdev r${name}${unit}d	c $chr $(($unit * 8 + 3))	640 $g_operator
2326	mkdev r${name}${unit}e	c $chr $(($unit * 8 + 4))	640 $g_operator
2327	mkdev r${name}${unit}f	c $chr $(($unit * 8 + 5))	640 $g_operator
2328	mkdev r${name}${unit}g	c $chr $(($unit * 8 + 6))	640 $g_operator
2329	mkdev r${name}${unit}h	c $chr $(($unit * 8 + 7))	640 $g_operator
2330	mkdev r${name}${unit}i	c $chr $(($unit * 8 + $ho + 8)) 640 $g_operator
2331	mkdev r${name}${unit}j	c $chr $(($unit * 8 + $ho + 9)) 640 $g_operator
2332	mkdev r${name}${unit}k	c $chr $(($unit * 8 + $ho + 10)) 640 $g_operator
2333	mkdev r${name}${unit}l	c $chr $(($unit * 8 + $ho + 11)) 640 $g_operator
2334}
2335
2336makedisk_p16()
2337{
2338	name="$1"; unit="$2"; blk="$3"; chr="$4"
2339
2340	ro=%RAWDISK_OFF%
2341	mkdev ${name}${unit}	b $blk $(($unit * 16 + $ro))	640 $g_operator
2342	mkdev r${name}${unit}	c $chr $(($unit * 16 + $ro))	640 $g_operator
2343
2344	mkdev ${name}${unit}a	b $blk $(($unit * 16 + 0))	640 $g_operator
2345	mkdev ${name}${unit}b	b $blk $(($unit * 16 + 1))	640 $g_operator
2346	mkdev ${name}${unit}c	b $blk $(($unit * 16 + 2))	640 $g_operator
2347	mkdev ${name}${unit}d	b $blk $(($unit * 16 + 3))	640 $g_operator
2348	mkdev ${name}${unit}e	b $blk $(($unit * 16 + 4))	640 $g_operator
2349	mkdev ${name}${unit}f	b $blk $(($unit * 16 + 5))	640 $g_operator
2350	mkdev ${name}${unit}g	b $blk $(($unit * 16 + 6))	640 $g_operator
2351	mkdev ${name}${unit}h	b $blk $(($unit * 16 + 7))	640 $g_operator
2352	mkdev ${name}${unit}i	b $blk $(($unit * 16 + 8))	640 $g_operator
2353	mkdev ${name}${unit}j	b $blk $(($unit * 16 + 9))	640 $g_operator
2354	mkdev ${name}${unit}k	b $blk $(($unit * 16 + 10))	640 $g_operator
2355	mkdev ${name}${unit}l	b $blk $(($unit * 16 + 11))	640 $g_operator
2356	mkdev ${name}${unit}m	b $blk $(($unit * 16 + 12))	640 $g_operator
2357	mkdev ${name}${unit}n	b $blk $(($unit * 16 + 13))	640 $g_operator
2358	mkdev ${name}${unit}o	b $blk $(($unit * 16 + 14))	640 $g_operator
2359	mkdev ${name}${unit}p	b $blk $(($unit * 16 + 15))	640 $g_operator
2360	mkdev r${name}${unit}a	c $chr $(($unit * 16 + 0))	640 $g_operator
2361	mkdev r${name}${unit}b	c $chr $(($unit * 16 + 1))	640 $g_operator
2362	mkdev r${name}${unit}c	c $chr $(($unit * 16 + 2))	640 $g_operator
2363	mkdev r${name}${unit}d	c $chr $(($unit * 16 + 3))	640 $g_operator
2364	mkdev r${name}${unit}e	c $chr $(($unit * 16 + 4))	640 $g_operator
2365	mkdev r${name}${unit}f	c $chr $(($unit * 16 + 5))	640 $g_operator
2366	mkdev r${name}${unit}g	c $chr $(($unit * 16 + 6))	640 $g_operator
2367	mkdev r${name}${unit}h	c $chr $(($unit * 16 + 7))	640 $g_operator
2368	mkdev r${name}${unit}i	c $chr $(($unit * 16 + 8))	640 $g_operator
2369	mkdev r${name}${unit}j	c $chr $(($unit * 16 + 9))	640 $g_operator
2370	mkdev r${name}${unit}k	c $chr $(($unit * 16 + 10))	640 $g_operator
2371	mkdev r${name}${unit}l	c $chr $(($unit * 16 + 11))	640 $g_operator
2372	mkdev r${name}${unit}m	c $chr $(($unit * 16 + 12))	640 $g_operator
2373	mkdev r${name}${unit}n	c $chr $(($unit * 16 + 13))	640 $g_operator
2374	mkdev r${name}${unit}o	c $chr $(($unit * 16 + 14))	640 $g_operator
2375	mkdev r${name}${unit}p	c $chr $(($unit * 16 + 15))	640 $g_operator
2376}
2377
2378makedisk_p16high()
2379{
2380	ho=524280	# offset for partition 9 to 16
2381	name="$1"; unit="$2"; blk="$3"; chr="$4"
2382
2383	ro=%RAWDISK_OFF%
2384	mkdev ${name}${unit}	b $blk $(($unit * 8 + $ro))	640 $g_operator
2385	mkdev r${name}${unit}	c $chr $(($unit * 8 + $ro))	640 $g_operator
2386
2387	mkdev ${name}${unit}a	b $blk $(($unit * 8 + 0))	640 $g_operator
2388	mkdev ${name}${unit}b	b $blk $(($unit * 8 + 1))	640 $g_operator
2389	mkdev ${name}${unit}c	b $blk $(($unit * 8 + 2))	640 $g_operator
2390	mkdev ${name}${unit}d	b $blk $(($unit * 8 + 3))	640 $g_operator
2391	mkdev ${name}${unit}e	b $blk $(($unit * 8 + 4))	640 $g_operator
2392	mkdev ${name}${unit}f	b $blk $(($unit * 8 + 5))	640 $g_operator
2393	mkdev ${name}${unit}g	b $blk $(($unit * 8 + 6))	640 $g_operator
2394	mkdev ${name}${unit}h	b $blk $(($unit * 8 + 7))	640 $g_operator
2395	mkdev ${name}${unit}i	b $blk $(($unit * 8 + $ho + 8)) 640 $g_operator
2396	mkdev ${name}${unit}j	b $blk $(($unit * 8 + $ho + 9)) 640 $g_operator
2397	mkdev ${name}${unit}k	b $blk $(($unit * 8 + $ho + 10)) 640 $g_operator
2398	mkdev ${name}${unit}l	b $blk $(($unit * 8 + $ho + 11)) 640 $g_operator
2399	mkdev ${name}${unit}m	b $blk $(($unit * 8 + $ho + 12)) 640 $g_operator
2400	mkdev ${name}${unit}n	b $blk $(($unit * 8 + $ho + 13)) 640 $g_operator
2401	mkdev ${name}${unit}o	b $blk $(($unit * 8 + $ho + 14)) 640 $g_operator
2402	mkdev ${name}${unit}p	b $blk $(($unit * 8 + $ho + 15)) 640 $g_operator
2403	mkdev r${name}${unit}a	c $chr $(($unit * 8 + 0))	640 $g_operator
2404	mkdev r${name}${unit}b	c $chr $(($unit * 8 + 1))	640 $g_operator
2405	mkdev r${name}${unit}c	c $chr $(($unit * 8 + 2))	640 $g_operator
2406	mkdev r${name}${unit}d	c $chr $(($unit * 8 + 3))	640 $g_operator
2407	mkdev r${name}${unit}e	c $chr $(($unit * 8 + 4))	640 $g_operator
2408	mkdev r${name}${unit}f	c $chr $(($unit * 8 + 5))	640 $g_operator
2409	mkdev r${name}${unit}g	c $chr $(($unit * 8 + 6))	640 $g_operator
2410	mkdev r${name}${unit}h	c $chr $(($unit * 8 + 7))	640 $g_operator
2411	mkdev r${name}${unit}i	c $chr $(($unit * 8 + $ho + 8)) 640 $g_operator
2412	mkdev r${name}${unit}j	c $chr $(($unit * 8 + $ho + 9)) 640 $g_operator
2413	mkdev r${name}${unit}k	c $chr $(($unit * 8 + $ho + 10)) 640 $g_operator
2414	mkdev r${name}${unit}l	c $chr $(($unit * 8 + $ho + 11)) 640 $g_operator
2415	mkdev r${name}${unit}m	c $chr $(($unit * 8 + $ho + 12)) 640 $g_operator
2416	mkdev r${name}${unit}n	c $chr $(($unit * 8 + $ho + 13)) 640 $g_operator
2417	mkdev r${name}${unit}o	c $chr $(($unit * 8 + $ho + 14)) 640 $g_operator
2418	mkdev r${name}${unit}p	c $chr $(($unit * 8 + $ho + 15)) 640 $g_operator
2419}
2420
2421# make only the very few basic disk device nodes - 'a' partition
2422# and raw partition
2423makedisk_minimal()
2424{
2425	name=$1; unit=$2; blk=$3; chr=$4
2426	doff=%DISKMINOROFFSET%
2427	ro=%RAWDISK_OFF%
2428	rn=%RAWDISK_NAME%
2429
2430	mkdev ${name}${unit}	b $blk $(($unit * $doff + $ro))	640 $g_operator
2431	mkdev r${name}${unit}	c $chr $(($unit * $doff + $ro))	640 $g_operator
2432
2433	mkdev ${name}${unit}a	b $blk $(($unit * $doff + 0))	640 $g_operator
2434	mkdev ${name}${unit}$rn b $blk $(($unit * $doff + $ro)) 640 $g_operator
2435	mkdev r${name}${unit}a	c $chr $(($unit * $doff + 0))	640 $g_operator
2436	mkdev r${name}${unit}$rn c $chr $(($unit * $doff + $ro)) 640 $g_operator
2437}
2438
2439# create_mfs_dev nodes
2440#	Create a memory file system for a given number of device nodes,
2441#	and mount it.  Attempts to use mount_tmpfs, or falls back to
2442#	mount_mfs.
2443#
2444#	If do_redirect, then also redirect output to the console.
2445#
2446create_mfs_dev()
2447{
2448	ndevnodes=${1-1200}
2449	dev_mountpoint=${PWD:-/dev}
2450
2451	# Number of inodes is the specified number of device nodes, plus
2452	# a margin to allow for extra device nodes created later.
2453	ninode=$((ndevnodes * 11 / 10))
2454	# Add 2 reserved inodes (needed for both mfs and tmpfs), and round
2455	# up to a multiple of 32 (needed for mfs, not needed for tmpfs).
2456	ninode=$(( (ninode + 2 + 31) / 32 * 32 ))
2457	# Try tmpfs; if that fails try mfs.
2458	#
2459	# For tmpfs, allocate 16KB and 512 byte per node.
2460	# Actual requirements are much lower, but the size limit
2461	# is only intended to avoid accidental writing to /dev.
2462	fs_bytes=$((16384 + ninode * 512))
2463	if mount_tmpfs -s $fs_bytes -n $ninode -m 0755 \
2464		-o union tmpfs "$dev_mountpoint"
2465	then
2466		fstype=tmpfs
2467	else
2468		# This file system size calculation is exact for mount_mfs(8)
2469		# with 512-byte sectors.  40960 bytes (80 blocks) is the
2470		# minimum size allowed by mount_mfs.
2471		fs_bytes=$((8192 + 2 * 8192 + 4096 + ninode*512 + 8192))
2472		[ "$fs_bytes" -lt 40960 ] && fs_bytes=40960
2473		fs_blocks=$((fs_bytes/512))
2474		if mount_mfs -b 4096 -f 512 -s $fs_blocks -n $ninode -p 0755 \
2475		    -o union swap "$dev_mountpoint"
2476		then
2477			fstype=mfs
2478		else
2479			die "Failed to create memory file system"
2480		fi
2481	fi
2482
2483	# Our current directory was in the lower file system; change it to
2484	# the newly mounted upper file system.
2485	cd "$dev_mountpoint"
2486
2487	if $do_redirect; then
2488		# Redirect stdout and stderr to console
2489		${MKNOD} -m 600 -g 0 -u 0 temp_console c %CONSOLE_CMAJOR% 0
2490		exec >temp_console 2>&1
2491		rm temp_console
2492	fi
2493
2494	echo "Created $fstype $dev_mountpoint" \
2495		"($fs_bytes byte, $ninode inodes)"
2496}
2497
2498#
2499# MAIN: If MAKEDEV_AS_LIBRARY is set, then we are being used as a
2500# function library, so just return.  Otherwise, do all the real work.
2501#
2502[ -n "${MAKEDEV_AS_LIBRARY}" ] && return
2503makedev_main makedev ${1+"$@"}
2504