#!/bin/sh
#
# pcmem.sample 1.2 1995/06/11 23:36:44 (David Hinds)
#
# Initialize or shutdown a PCMCIA memory device
#
# The first argument should be either 'start' or 'stop'.  The second
# argument is the base name for the device.  When starting a device,
# there should be two additional arguments, the major and minor device
# numbers.
#
# Three devices will be created:
#
#	/dev/{name}a	- character device, attribute memory
#	/dev/{name}b	- block device, common memory
#	/dev/{name}c	- character device, common memory

usage()
{
    echo "usage: pcmem {start|stop} [device name] [major] [minor]"
    exit 1
}

if [ $# -lt 2 ] ; then usage ; fi

action=$1
name=$2

case "${action:?}" in
'start')
    if [ $# -ne 4 ] ; then usage ; fi
    major=$3
    minor=$4
    rm -f /dev/${name}a /dev/${name}b /dev/${name}c
    mknod /dev/${name}c c ${major} ${minor}
    mknod /dev/${name}a c ${major} `expr ${minor} + 1`
    mknod /dev/${name}b b ${major} ${minor}
    ;;
'stop')
    fuser -k /dev/${name}a /dev/${name}b /dev/${name}c
    umount /dev/${name}b
    rm -f /dev/${name}a /dev/${name}b /dev/${name}c
    ;;
esac
