# # shared 1.6 1997/09/05 04:50:30 (David Hinds) # # modified 1997/11/10 22:48 (G D Rijhwani) # (added the display variable) # display="/dev/tty9" usage () { echo "usage: $0 [action] [device name]" echo " actions: start check stop suspend resume" exit 1 } is_true () { [ "$1" = "y" -o "$1" = "Y" -o "$1" = "yes" -o "$1" = "YES" ] } is_func () { [ "`type -type $1`" = "function" ] } add_blkdev () { # usage: add_blkdev [device] if is_true $DO_FSTAB ; then echo "$1 $MOUNTPT ${FSTYPE:-auto} ${OPTS:-defaults} 0 0" >> /etc/fstab fi if is_true $DO_FSCK ; then /sbin/fsck -Ta $1 || return 1 fi if is_true $DO_MOUNT ; then mount -v ${OPTS:+-o $OPTS} ${FSTYPE:+-t $FSTYPE} $1 \ $MOUNTPT || return 1 fi return 0 } add_parts () { # usage: add_parts [address] [parts] RET=0 for PART in ${2:-"."} ; do # Get mount options for particular partitions if [ "$PART" != "." ] ; then ADDRESS="$1,$PART" unset DO_FSTAB DO_FSCK DO_MOUNT . $0.opts fi add_blkdev /dev/$DEVICE${PARTS:+$PART} || RET=1 done return $RET } rm_blkdev () { # usage: rm_blkdev [device] test -b $1 || return 1 fuser -s -k -m $1 if mount | fgrep "$1 on" ; then umount -v $1 || return 1 fi if is_true $DO_FSTAB ; then fgrep -v $1 /etc/fstab > /etc/fstab.N mv /etc/fstab.N /etc/fstab fi } rm_parts () { # usage: rm_parts [address] [parts] BLK=/dev/$DEVICE test -b $BLK || return 1 for PART in "$2" ; do if [ "$PART" != "" ] ; then ADDRESS="$1,$PART" unset DO_FSTAB DO_FSCK DO_MOUNT . $0.opts fi if is_true $DO_FSTAB ; then fgrep -v "$BLK$PART " /etc/fstab > /etc/fstab.N mv /etc/fstab.N /etc/fstab fi done fuser -s -k -m /dev/${DEVICE}* LIST=`mount | sed -ne "s+^\($BLK[0-9]*\) .*+\1+p"` if [ "$LIST" != "" ] ; then for MT in $LIST ; do umount -v $MT || return 1 done fi } chk_simple () { # usage: chk_simple [new-address] ADDRESS="" OLD=`set | grep -v '^OLD=' | md5sum` ADDRESS=$1 . $0.opts ADDRESS="" NEW=`set | grep -v '^OLD=' | md5sum` [ "$OLD" = "$NEW" ] } chk_parts () { # usage: chk_parts [new-address] OLD_ADDR=$ADDRESS chk_simple $1 || return 1 for PART in ${PARTS:-"."} ; do ADDRESS="$OLD_ADDR,$PART" . $0.opts chk_simple "$1,$PART" || return 1 done } grep_stab () { # this should be cheaper than invoking "grep" local CLASS DRIVER DEV while read SOCKET CLASS DRIVER INSTANCE DEV MAJOR MINOR ; do if [ "$1" = "$DEV" ] ; then return 0 ; fi done return 1 } get_info () { if [ -s /var/run/pcmcia-scheme ] ; then SCHEME=`cat /var/run/pcmcia-scheme` else SCHEME="default" fi grep_stab $1 < /var/run/stab || usage } # A bit of stuff to do right away... if [ $# -lt 2 ] ; then usage ; fi ACTION=$1 ; DEVICE=$2