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