#!/bin/sh
#
# memory 1.21 1997/09/05 04:50:17 (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.
#
# This script creates character devices for direct access to the PCMCIA
# address spaces:
#
#	/dev/{name}c	- common memory direct access device
#	/dev/{name}a	- attribute memory direct access device
#
# It also creates character and block devices for accessing the first
# attribute and common memory partitions:
#
#       /dev/{name}c0c  - common memory, character device
#       /dev/{name}c0b  - common memory, block device
#       /dev/{name}a0c  - attribute memory, character device
#
# The script passes an extended device address to 'memory.opts' in the 
# ADDRESS variable, to retrieve device-specific configuration options
# for the common-memory block device.
#
# The address format is "scheme,socket" where "scheme" is the current
# PCMCIA device configuration scheme, and "socket" is the socket number.
#

. ./shared

# Get device attributes
get_info $DEVICE

# Load site-specific settings
ADDRESS="$SCHEME,$SOCKET"
. $0.opts

case "$ACTION" in

'start')
    rm -f /dev/${DEVICE}[ca] /dev/${DEVICE}[ca]0[bc]
    mknod /dev/${DEVICE}c0c c $MAJOR `expr $MINOR`
    mknod /dev/${DEVICE}c0b b $MAJOR `expr $MINOR`
    mknod /dev/${DEVICE}a0c c $MAJOR `expr $MINOR + 4`
    mknod /dev/${DEVICE}c c $MAJOR `expr $MINOR + 8`
    mknod /dev/${DEVICE}a c $MAJOR `expr $MINOR + 8 + 4`
    add_blkdev /dev/${DEVICE}c0b || exit 1
    ;;

'check')
    fuser -s /dev/${DEVICE}[ca] /dev/${DEVICE}[ca]0c && exit 1
    fuser -s -m /dev/${DEVICE}c0b && exit 1
    ;;

'stop')
    fuser -s -k /dev/${DEVICE}[ca] /dev/${DEVICE}[ca]0[bc]
    rm_blkdev /dev/${DEVICE}c0b || exit 1
    rm -f /dev/${DEVICE}[ca] /dev/${DEVICE}[ca]0[bc]
    ;;

'cksum')
    chk_simple "$3,$SOCKET,$INSTANCE" || exit 1
    ;;
    
'suspend'|'resume')
    ;;

*)
    usage
    ;;

esac

exit 0
