#!/bin/ash

if [ -f /etc/rc.d/functions_x ] ; then
	. /etc/rc.d/functions_x #want fx_drv_* functions
fi

for i in /sys/block/*
do
	DRV=${i##*/} #basename
	if ! fx_drv_is_ok ${DRV} ; then
		continue
	fi
	vendor="" model="" size="" removable="" usb=""
	blockdev=/dev/${DRV}

	[ -f /sys/block/${DRV}/device/vendor ] && read -r vendor < /sys/block/${DRV}/device/vendor
	[ -f /sys/block/${DRV}/device/model ] && read -r model < /sys/block/${DRV}/device/model
	[ -f /sys/block/${DRV}/size ] && read -r size < /sys/block/${DRV}/size
	info="$vendor" ; [ -n "$model" ] && info="$info $model"

	type=drive #default
	case $(readlink /sys/block/${DRV}) in */usb*)
		type="usbdrv" ; usb=yes ;;
	esac

	case ${DRV} in
		fd*) continue ;;
		mmc*) type=card ;;
		sr*) type=optical ;;
	esac
	size=$(fx_format_bytes $(($size * 512)) )
	echo "${blockdev}|$type|$info|$size"
done
