#!/bin/sh
file=`basename $0`
num=$1

if [ $num -eq 1 ]; then
	host="ata5/host4"; target="target4:0:0"; path="4:0:0:0"
else 
	host="ata4/host3"; target="target3:0:0"; path="3:0:0:0"
fi

#Check partitions
field="\$1"
partitions=`mount | awk -F' ' "/media\/disk$num/{print $field}" | xargs -n 10`

#Umount partitions
if [ ! -z "$partitions" ] ; then
	echo 1 > /sys/devices/pci0000:00/0000:00:1f.2/$host/$target/$path/delete
	echo $file: WARNING! /media/disk${num}pn should be unmounted before disk is removed
	echo $file: Force to umount them
	for i in $partitions; do 
		umount  $i
	done
fi

echo mxhtspd: Check disk $num status ok
