First find blocks by-name, then fallback to parsing sysfs

This commit is contained in:
topjohnwu 2018-07-03 02:57:57 +08:00
parent 6c4d81b1e9
commit b5b8c4b725
1 changed files with 8 additions and 0 deletions

View File

@ -45,6 +45,14 @@ toupper() {
}
find_block() {
for BLOCK in "$@"; do
DEVICE=`find /dev/block -type l -iname $BLOCK | head -n 1` 2>/dev/null
if [ ! -z $DEVICE ]; then
readlink -f $DEVICE
return 0
fi
done
# Fallback by parsing sysfs uevents
for uevent in /sys/dev/block/*/uevent; do
local DEVNAME=`grep_prop DEVNAME $uevent`
local PARTNAME=`grep_prop PARTNAME $uevent`