#!/bin/sh -
#
#	BSDI MAKEDEV,v 2.3 1995/11/06 09:18:39 torek Exp
#
# Copyright (c) 1990 The Regents of the University of California.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
#	This product includes software developed by the University of
#	California, Berkeley and its contributors.
# 4. Neither the name of the University nor the names of its contributors
#    may be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#	@(#)MAKEDEV	5.5 (Berkeley) 5/28/91
#
# Device "make" file.  Valid arguments:
#	std	standard devices
#	local	configuration specific devices
# Tapes:
#	st*	? tape
# Disks:
#	sd*	SCSI disks
#	sr*	SCSI removable
#	fd*	Floppies
# Pseudo terminals:
#	pty*	set of 16 master and slave pseudo terminals
# Printers:
# Call units:
# Special purpose devices:
#	audio
#	bwtwo
#	cgthree
#	cgsix
#	openprom

PATH=/sbin:/bin/:/usr/bin:/usr/sbin:/usr/etc
umask 77
for i
do
case $i in

std)
	mknod console		c 0 0
	mknod tty		c 2 0	; chmod 666 tty
	mknod kmem		c 3 1	; chmod 640 kmem ; chgrp kmem kmem
	mknod mem		c 3 0	; chmod 640 mem ; chgrp kmem mem
	mknod null		c 3 2	; chmod 666 null
	mknod zero		c 3 12	; chmod 666 zero
	mknod eeprom		c 3 11  ; chmod 640 eeprom ; chgrp kmem eeprom
	mknod drum		c 7 0	; chmod 640 drum ; chgrp kmem drum
	mknod klog		c 16 0	; chmod 600 klog
	mknod stdin		c 24 0	; chmod 666 stdin
	mknod stdout		c 24 1	; chmod 666 stdout
	mknod stderr		c 24 2	; chmod 666 stderr
	mkdir fd > /dev/null 2>&1
	(cd fd && eval `echo "" | awk ' BEGIN { \
		for (i = 0; i < 64; i++) \
			printf("mknod %d c 24 %d;", i, i)}'`)
	chown -R bin.bin fd
	chmod 555 fd
	chmod 666 fd/*

	mknod ttya		c 12 0
	mknod ttyb		c 12 1
	mknod fb		c 22 0 ; chmod 666 fb
	mknod mouse		c 13 0 ; chmod 666 mouse
	mknod kbd		c 29 0 ; chmod 666 kbd

	mknod audio		c 69 0; chmod 666 audio
	mknod openprom		c 70 0; chmod 600 openprom
	;;

bwtwo*)
	unit=`expr $i : 'bwtwo\(.*\)'`
	mknod bwtwo$unit	c 27 $unit; chmod 666 bwtwo$unit
	;;

cgthree*)
	unit=`expr $i : 'cgthree\(.*\)'`
	mknod cgthree$unit	c 55 $unit; chmod 666 cgthree$unit
	;;

cgsix*)
	unit=`expr $i : 'cgsix\(.*\)'`
	mknod cgsix$unit	c 67 $unit; chmod 666 cgsix$unit
	;;

bpf*)
	name=bpf
	chr=105
	for unit in 0 1 2 3 4 5 6 7 8 9
	do
		mknod ${name}${unit} c $chr $unit
		chmod 440 ${name}${unit}
	done
	;;

fd*|sd*|sr*)
	umask 2 ; unit=`expr $i : '..\(.*\)'`
	case $i in
	fd*) name=fd; maj=54;;
	sd*) name=sd; maj=17;;
	sr*) name=sr; maj=58;;
	esac
	case $unit in
	[0-9]|[0-9][0-9])
		mknod  ${name}${unit}a	b $maj $unit 0
		mknod  ${name}${unit}b	b $maj $unit 1
		mknod  ${name}${unit}c	b $maj $unit 2
		mknod  ${name}${unit}d	b $maj $unit 3
		mknod  ${name}${unit}e	b $maj $unit 4
		mknod  ${name}${unit}f	b $maj $unit 5
		mknod  ${name}${unit}g	b $maj $unit 6
		mknod  ${name}${unit}h	b $maj $unit 7
		mknod r${name}${unit}a	c $maj $unit 0
		mknod r${name}${unit}b	c $maj $unit 1
		mknod r${name}${unit}c	c $maj $unit 2
		mknod r${name}${unit}d	c $maj $unit 3
		mknod r${name}${unit}e	c $maj $unit 4
		mknod r${name}${unit}f	c $maj $unit 5
		mknod r${name}${unit}g	c $maj $unit 6
		mknod r${name}${unit}h	c $maj $unit 7
		chgrp operator ${name}${unit}[a-h] r${name}${unit}[a-h]
		if [ $name = fd ]; then
			chmod 666 ${name}${unit}[a-h] r${name}${unit}[a-h]
#			rm -f floppy${unit}; ln ${name}${unit}c floppy${unit}
			rm -f fd${unit}; ln ${name}${unit}c fd${unit}
			rm -f rfd${unit}; ln r${name}${unit}c rfd${unit}
#			XXX no densities yet
		else
			chmod 640 ${name}${unit}[a-h] r${name}${unit}[a-h]
		fi
		;;
	*)
		echo bad unit for disk in: $i
		;;
	esac
	umask 77
	;;

st*)
	umask 0
	unit=`expr $i : '..\(.*\)'`
	chr=18
	# SCSI density codes for QIC tape (incomplete)
	# XXX block devices currently unsupported
	qic11=4; qic24=5; qic120=15; qic150=16; qic525=17
	fixed8mm=512;	# High bit indicates fixed length records
	mknod  rst${unit}	c $chr $unit 0
	mknod nrst${unit}	c $chr $unit 1
	mknod  rst${unit}_f8mm	c $chr $unit  $fixed8mm
	mknod nrst${unit}_f8mm	c $chr $unit `expr $fixed8mm + 1`
	mknod  rst${unit}_q11	c $chr $unit `expr $qic11 \* 2`
	mknod nrst${unit}_q11	c $chr $unit `expr $qic11 \* 2 + 1`
	mknod  rst${unit}_q24	c $chr $unit `expr $qic24 \* 2`
	mknod nrst${unit}_q24	c $chr $unit `expr $qic24 \* 2 + 1`
	mknod  rst${unit}_q120	c $chr $unit `expr $qic120 \* 2`
	mknod nrst${unit}_q120	c $chr $unit `expr $qic120 \* 2 + 1`
	mknod  rst${unit}_q150	c $chr $unit `expr $qic150 \* 2`
	mknod nrst${unit}_q150	c $chr $unit `expr $qic150 \* 2 + 1`
	mknod  rst${unit}_q525	c $chr $unit `expr $qic525 \* 2`
	mknod nrst${unit}_q525	c $chr $unit `expr $qic525 \* 2 + 1`
	umask 77
	;;

pty*)
	class=`expr $i : 'pty\(.*\)'`
	case $class in
	0) offset=0 name=p;;
	1) offset=16 name=q;;
	2) offset=32 name=r;;
	3) offset=48 name=s;;
	4) offset=64 name=t;;
	5) offset=80 name=u;;
	6) offset=96 name=v;;
	7) offset=112 name=w;;
	8) offset=128 name=x;;
	9) offset=144 name=y;;
	10) offset=160 name=z;;
	11) offset=176 name=P;;
	12) offset=192 name=Q;;
	13) offset=208 name=R;;
	14) offset=224 name=S;;
	15) offset=240 name=T;;
	*) echo bad unit for pty in: $i;;
	esac
	case $class in
	[0-9]|1[0-5])
		umask 0
		eval `echo $offset $name | awk ' { b=$1; n=$2 } END {
			for (i = 0; i < 16; i++)
				printf("mknod tty%s%x c 20 %d; \
					mknod pty%s%x c 21 %d; ", \
					n, i, b+i, n, i, b+i); }'`
		umask 77
		;;
	esac
	;;

local)
	umask 0
	sh MAKEDEV.local
	;;
*)
	echo $i: unknown device
	;;
esac
done
