#!/bin/sh
#
# scsi 1.28 1997/03/18 06:47:42 (David Hinds)
#
# Initialize or shutdown a PCMCIA SCSI adapter
#
# The first argument should be either 'start' or 'stop'.  The second
# argument is the base name for the device.
#
# The script passes an extended device address to 'scsi.opts' in the
# ADDRESS variable, to retrieve device-specific configuration options.
# The address format is "scheme,device,socket,channel,id,lun[,part]"
# where "scheme" is the PCMCIA configuration scheme; "device" is the
# SCSI device type (sd, sr, st, sg); "socket" is the socket number;
# "channel", "id", and "lun" are the SCSI device ID's; and "part" is,
# optionally, the partition number.
#
# The script first calls scsi.opts for the entire device.  If
# scsi.opts returns with the PARTS variable set, then this variable
# contains a list of partitions for which options should be read.
#

. ./shared

# If we're running on a 1.2.X system, use hard-wired list
if [ "$DEVICE" = "n/a" ] ; then
    . ./scsi.opts
    if [ "$SCSI_DEVICES" != "" ] ; then
	export SCSI_DEVICES
	for DEVICE in $SCSI_DEVICES ; do
	    $0 $ACTION $DEVICE
	done
    fi
    exit 0
fi

# Get device attributes
if [ "$SCSI_DEVICES" = "" ] ; then
    get_info $DEVICE
else
    if [ -s /var/run/pcmcia-scheme ] ; then
	SCHEME=`cat /var/run/pcmcia-scheme`
    else
	SCHEME="default"
    fi
    SOCKET=0
fi
case "$DEVICE" in
sd*)  TYPE="sd" ;;
st*)  TYPE="st" ;;
scd*) TYPE="sr" ;;
sg*)  TYPE="sg" ;;
esac
eval `/sbin/scsi_info /dev/$DEVICE` || usage

# Load site-specific settings
ADDRESS="$SCHEME,$TYPE,$SOCKET,$SCSI_ID"
. ./scsi.opts

case "$ACTION" in

'start')
    add_parts $ADDRESS $PARTS || exit 1
    ;;

'check')
    if [ -b /dev/$DEVICE ] ; then
	fuser -s -m /dev/${DEVICE}* && exit 1
    elif [ -c /dev/$DEVICE ] ; then
	fuser -s /dev/${DEVICE}* && exit 1
    fi
    ;;

'stop')
    if [ -b /dev/$DEVICE ] ; then
	rm_parts $ADDRESS $PARTS
    else
	fuser -s -k /dev/$DEVICE
    fi
    exit $?
    ;;

'suspend'|'resume')
    ;;

*)
    usage
    ;;

esac

exit 0
