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