#!/bin/bash
####################################################################
#      File: S02make-devices
#      Name: Au Nguyen
#
#      Description:
#       Initialization of /dev/loop or any other device files
#       Derived from S02make-devices
#       Actual location on disk: /isan/etc/rc.d/rcS.d/
#
# Copyright (c) 2011, 2015 by Cisco Systems, Inc.
# All rights reserved.
#####################################################################

. /etc/init.d/mod_ins/module-load-functions

case $1 in
    start)
        for part in 0 1 2 3 4 5 6 7
        do
            if [ ! -b /dev/loop$part ]; then
                mknod /dev/loop$part b 7 $part
            fi
        done

        if [ ! -c /dev/mem ] ; then
            rm -f /dev/mem
            mknod /dev/mem c 1 1
        fi
        chmod 640 /dev/mem

        if [ ! -c /dev/kmem ] ; then
            rm -f /dev/kmem
            mknod /dev/kmem c 1 2
        fi
        chmod 644 /dev/kmem

        if [ ! -c /dev/zero ] ; then
            rm -f /dev/zero
            mknod /dev/zero c 1 5
        fi
        chmod 666 /dev/zero

        chmod 644 /dev/rtc

        if [ ! -c /dev/ttyS0 ] ; then
            rm -f /dev/ttyS0
            mknod /dev/ttyS0 c 4 64
        fi
        chmod 644 /dev/ttyS0

        if [ ! -c /dev/ttyS1 ] ; then
            rm -f /dev/ttyS1
            mknod /dev/ttyS1 c 4 65
        fi
        chmod 644 /dev/ttyS1

        if [ ! -c /dev/ttyS2 ] ; then
            rm -f /dev/ttyS2
            mknod /dev/ttyS2 c 4 66
        fi
        chmod 644 /dev/ttyS2

        if [ ! -c /dev/tty ] ; then
            mknod /dev/tty c 5 0
        fi
        chmod 666 /dev/tty

        mknod /dev/tracedevice c 217 0
        chmod 644 /dev/tracedevice

        #if [ ! -c /dev/tty ] ; then
            #rm -f /dev/tty
            #mknod /dev/tty c 5 0
        #fi
        #chmod 666 /dev/tty
        # for some reason SCP is not working with the above settings.
        # Making it a symlink to /dev/ttyS0 is working.
        #ln -s /dev/ttyS0 /dev/tty

        mknod /dev/plx c 243 0
        chmod 666 /dev/plx

        #mknod /dev/random c 1 8
        #mknod /dev/urandom c 1 9


    ;;
esac
