#!/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=`hal-find-by-property --key linux.subsystem --string scsi_host`

    for I in $DEVS; do
	SYS_PATH=`/usr/bin/hal-get-property --udi $I --key linux.sysfs_path`
	TARGET=0
	for J in $SYS_PATH/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 $SYS_PATH"
	    echo "- - -" > $SYS_PATH/scan
	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
}
