From e3704216f11875ab0191560bb3bf07bbd9ebe194 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Wed, 18 May 2011 19:26:12 -0400 Subject: [PATCH] Refactor block device detection for looser requirements Not all devices will have a type file in sysfs, but this doesn't exclude them from being valid block devices. Notably, this affects devices created by virtio_blk and LVM devices. --- src/core/libs/lib-blockdevices-filesystems.sh | 35 ++++++++++++++---------- 1 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index 5b078a7..d422ee1 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -210,21 +210,26 @@ getlabel() { finddisks() { shopt -s nullglob - # Block Devices - for dev in /sys/block/*; do - if [[ -f $dev/device/type ]]; then - local type - read type < /sys/block/${dev##*/}/device/type - # Block Devices with size =< 0 may be an empty card reader - read size < /sys/block/${dev##*/}/size - # Type 5 is a ROM Device - Optical Drives - if [[ $type != 5 ]] && (( $size > 0 )); then - source "$dev/uevent" - echo -ne "/dev/$DEVNAME $1" - unset DEVNAME - fi - fi - done +# Block Devices +for dev in /sys/block/*; do + # devices without a size are no good + [[ -e $dev/size ]] || continue + + read -r size < "$dev/size" + (( size )) || continue + + # type 5 is a CDROM + if [[ -e $dev/device/type ]]; then + read -r type < "$dev/device/type" + (( type == 5 )) && continue + fi + + unset DEVTYPE + . "$dev/uevent" + [[ $DEVTYPE = disk ]] || continue + + printf '%s\n' "${dev##*/} $1" +done # cciss controllers for dev in /dev/cciss/*; do -- 1.7.5.1