#! /bin/sh
#
# test.block - run udev(8) on each block device in /sys/block

if [ $# = "0" ] ; then
	echo
	echo "usage: $0 <action>"
	echo "where <action> is \"add\" or \"remove\""
	echo
	exit 1
fi

SYSFSDIR=/sys		# change this for a nonstand sysfs mount point
BIN=../udev		# location of your udev binary
export ACTION=$1	# 'add' or 'remove'

# do the block devices first
for i in ${SYSFSDIR}/block/*; do
	# add each drive
	export DEVPATH=${i#${SYSFSDIR}}
	$BIN block

	# add each partition, on each device
	for j in $i/*; do
		if [ -f $j/dev ]; then
			export DEVPATH=${j#${SYSFSDIR}}
			$BIN block
		fi
	done
done

# now all the devices in the class directories
for i in ${SYSFSDIR}/class/*; do
	for j in $i/*; do
		if [ -f $j/dev ]; then
			export DEVPATH=${j#${SYSFSDIR}}
			CLASS=`echo ${i#${SYSFSDIR}} | cut --delimiter='/' --fields=3-`
			$BIN $CLASS
		fi
	done
done