#! /bin/sh -
#
# Usage: pccard_scsi <device name>
#
# example: pccard_scsi aic0
#
# T. Ichinoseki
#

# default value of delay (second)
pccard_scsi_delay=2

# Suck in the configuration variables
if [ -f /etc/defaults/rc.conf ]; then
	. /etc/defaults/rc.conf
elif [ -f /etc/rc.conf ]; then
	. /etc/rc.conf
fi

device=$1
bus=`camcontrol devlist -v | \
     sed -e "s/^scbus\([0-9]\) on ${device} bus [0-9]:\$/\1/p" -e "d"`

if [ "$bus" ]; then
	if [ "$pccard_scsi_delay" ]; then
	    if [ ${pccard_scsi_delay} -gt 0 ]; then
		if [ ${pccard_scsi_delay} -gt 15 ]; then
		    # set muximum delay to 15 seconds
		    pccard_scsi_delay=15
		fi
		sleep ${pccard_scsi_delay}
	    fi
	fi
	camcontrol reset $bus
	camcontrol rescan $bus
fi
