#!/bin/sh

forceUnMountDevice() {
    local aDevice=$1 ; shift

    [ -r /proc/mounts ] || return 0
    [ -x /bin/umount ] || return 0

    local vDevice
    local vMountpoint
    local vFsType
    local vOptions
    local vDump
    local vOrder

    while read vDevice vMountpoint vFsType vOptions vDump vOrder ; do
        if [ "${vDevice}" = "${aDevice}" ] ; then
            /bin/umount -fl ${vMountpoint}
        fi
    done < /proc/mounts
    return 0
}

if [[ "${HALD_ACTION}" = "remove" ]] ; then
    forceUnMountDevice ${HAL_PROP_BLOCK_DEVICE}
    sleep .5
elif [[ "${HALD_ACTION}" = "add" ]] ; then
    if [[ "${HAL_PROP_INFO_UDI}" != "/org/freedesktop/Hal/devices/computer" ]] ; then
        sleep .5
    fi
fi

exec /usr/sbin/hal-fstab-sync "$@"
