NetBSD/etc/etc.cesfic/MAKEDEV

203 lines
3.7 KiB
Bash

#!/bin/sh -
# $NetBSD: MAKEDEV,v 1.12 2003/10/10 22:47:11 jdolecek Exp $
#
###########################################################################
#
# PLEASE RUN "cd ../share/man/man8 ; make makedevs"
# AFTER CHANGING THIS FILE, AND COMMIT THE UPDATED MANPAGE!
#
###########################################################################
#
# Device "make" file. Valid arguments:
# all makes all known devices, including local devices.
# Tries to make the 'standard' number of each type.
# init A set of devices that is used for MFS /dev by init.
# May be equal to "all".
# std standard devices
#
# Terminal ports:
# tty* serial ports
#
# Pseudo terminals:
# pty* set of 62 master and slave pseudo terminals
#
# Special purpose devices:
# bpf* packet filter
# clockctl clock control for non root users
# fd file descriptors
# lkm loadable kernel modules interface
# random Random number generator, see rnd(4)
# systrace syscall tracer
# tun* network tunnel driver
# pf PF packet filter
# crypto hardware crypto access driver
#
dialin=0
dialout=524288
PATH=/sbin:/usr/sbin:/bin:/usr/bin
umask 77
# Check if we have fdesc mounted
if [ -d fd ]; then
case "`df fd`" in
*fdesc*) nofdesc=false;;
*) nofdesc=true;;
esac
else
nofdesc=true
fi
makedev()
{
for i
do
case $i in
init|all)
makedev std
makedev tty0 tty1 pty0
makedev bpf0 bpf1 bpf2 bpf3 bpf4 bpf5 bpf6 bpf7
makedev lkm random
makedev clockctl
makedev local
;;
std)
rm -f console constty drum mem kmem null zero klog
mknod console c 0 0
mknod constty c 0 1
mknod drum c 3 0 ; chmod 640 drum ; chgrp kmem drum
mknod kmem c 2 1 ; chmod 640 kmem ; chgrp kmem kmem
mknod mem c 2 0 ; chmod 640 mem ; chgrp kmem mem
mknod null c 2 2 ; chmod 666 null
mknod zero c 2 12 ; chmod 666 zero
mknod klog c 6 0 ; chmod 600 klog
mknod ksyms c 25 0 ; chmod 444 ksyms
if $nofdesc; then
rm -f tty stdin stdout stderr
mknod tty c 1 0 ; chmod 666 tty
mknod stdin c 11 0 ; chmod 666 stdin
mknod stdout c 11 1 ; chmod 666 stdout
mknod stderr c 11 2 ; chmod 666 stderr
fi
;;
bpf*|tun*)
case $i in
bpf*) name=bpf; unit=${i#bpf}; chr=12;;
tun*) name=tun; unit=${i#tun}; chr=13;;
esac
rm -f $name$unit
mknod $name$unit c $chr $unit
;;
pty*)
class=${i#pty}
set -- p q r s t u v w x y z P Q R S T
if [ "$class" -ge $# ]; then
echo "$MAKEDEV: $i: pty unit must be between 0 and 15"
continue
fi
shift $class
name=$1
if [ "$name" = v ]; then
echo "$MAKEDEV: $i: pty unit conflicts with console ttyv0 device."
continue
fi
rm -f tty$name[0-9a-zA-Z] pty$name[0-9a-zA-Z]
jn=0
unit=$(($class * 16))
names=
set -- - 0 1 2 3 4 5 6 7 8 9 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 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
while
shift
j=$1
[ -n "$j" ]
do
if [ $j = g ]; then
unit=$(($unit + $class * 30 + 256 - 16))
fi
mknod tty$name$j c 4 $unit
mknod pty$name$j c 5 $unit
names="$names tty$name$j pty$name$j"
unit=$(($unit + 1))
done
chmod 666 $names
unset names
;;
random)
rm -f random urandom
mknod random c 21 0
mknod urandom c 21 1
chmod 444 random
chmod 644 urandom
;;
tty*)
ounit=${i#???}
ounit=$(($ounit + 0))
if [ $ounit -lt 10 ]; then
unit=0$ounit
rm -f com$ounit
else
unit=$ounit
fi
rm -f tty$unit dty$unit
mknod tty$unit c 10 $(($ounit + $dialin ))
mknod dty$unit c 10 $(($ounit + $dialout))
chown uucp tty$unit dty$unit
;;
pf)
rm -f pf
mknod pf c 161 0
chmod 600 pf
;;
crypto)
rm -f crypto
mknod crypto c 160 0
chmod 666 crypto
;;
lkm)
rm -f lkm
mknod lkm c 14 0
chgrp kmem lkm
chmod 640 lkm
;;
clockctl)
rm -f clockctl
mknod clockctl c 22 0
chgrp ntpd clockctl
chmod 660 clockctl
;;
local)
if [ -f "$0.local" ]; then
umask 0
sh $0.local all
umask 77
fi
;;
*)
echo $i: unknown device
;;
esac
done
}
makedev $*