From 5572e8a3db95f179b3433e5ea5f8c6fa2c8c65ab Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Tue, 29 Sep 2009 09:40:53 +0000 Subject: setup-disk: fix find_disks The old way did not detect ida/c0d0. The new should detect it. We also filter out md devices. --- setup-disk.in | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/setup-disk.in b/setup-disk.in index d53fba1..33cc868 100644 --- a/setup-disk.in +++ b/setup-disk.in @@ -146,25 +146,47 @@ find_swap_size() { has_mounted_part() { local p - # parse /proc/mounts for moutned devices + # parse /proc/mounts for mounted devices for p in $(awk '$1 ~ /^\/dev\// {gsub("/dev/", "", $1); print $1}' \ /proc/mounts); do - if [ -e /sys/block/$1/$p ]; then - return 0 - fi + [ -e /sys/block/$1/$p ] && return 0 done return 1 } +has_holders() { + local i + # check if device is used by any md devices + for i in $1/holders/* $1/*/holders/*; do + [ -e "$i" ] && return 0 + done + return 1 +} + +is_available_disk() { + local dev=$1 + local b=$(echo $p | sed 's:/:!:g') + + # check if its a "root" block device and not a partition + [ -e /sys/block/$b ] || return 1 + + # check so it does not have mounted partitions + has_mounted_part $dev && return 1 + + # check so its not part of an md setup + has_holders /sys/block/$b && return 1 + + # check so its not an md device + [ -e /sys/block/$b/md ] && return 1 + + return 0 +} + find_disks() { - local p= disks= + local p= for p in $(awk '$1 ~ /[0-9]+/ {print $4}' /proc/partitions); do - b=$(echo $p | sed 's:/:!:g') - if [ -e /sys/block/$b/device ] && ! has_mounted_part $p; then - disks="$disks $p" - fi + is_available_disk $p && echo -n " $p" done - echo $disks } useall() { -- cgit v1.2.3