#!/bin/sh
#
# Copyright (C) 2006 Holger Macht <holger@homac.de>
#
# Author: Holger Macht <holger@homac.de>
#
# This file is released under the GPLv2.
#

scan_scsi_hosts() {
    DEVS=`find /sys/class/scsi_host -name scan`

    for I in $DEVS; do
	echo checking $I
	TARGET=0
	for J in `dirname $I`/device/target*; do
	    test -e $J && TARGET=1
	done
	# if we had undocked properly before, the target is no longer there.
	# this avoids the rescanning of all devices (builtin disk etc).
	if [ $TARGET = 0 ]; then
            # rescan the host
	    echo "rescanning $I"
	    echo "- - -" > $I
	else
	    echo skipping $I host
	fi
    done
}

unregister_cdroms() {
    DEVS=`hal-find-by-capability --capability storage.cdrom`

    for I in $DEVS; do
	echo $I
	SYS_PATH=`hal-get-property --udi $I --key linux.sysfs_path`
	echo "unregistered $SYS_PATH"
	echo 1 > $SYS_PATH/device/delete
    done
}
