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