From: Max Vozeler <m...@nusquama.org> Consolidates identical code.
[Not yet tested, only for review.] --- packages/partman/partman-base/lib/base.sh | 33 ++++++++++++++++++ packages/partman/partman-crypto/lib/crypto-base.sh | 36 +++++--------------- packages/partman/partman-lvm/lib/lvm-base.sh | 29 +--------------- packages/partman/partman-md/lib/md-base.sh | 29 +--------------- 4 files changed, 44 insertions(+), 83 deletions(-) diff --git a/packages/partman/partman-base/lib/base.sh b/packages/partman/partman-base/lib/base.sh index 95ff807..8c91aed 100644 --- a/packages/partman/partman-base/lib/base.sh +++ b/packages/partman/partman-base/lib/base.sh @@ -1103,6 +1103,39 @@ partman_unlock_unit() { cd "$cwd" } +partman_list_allowed() { + local allowed_func=$1 + local IFS + local partitions + local freenum=1 + for dev in $DEVICES/*; do + [ -d $dev ] || continue + cd $dev + + open_dialog PARTITIONS + partitions="$(read_paragraph)" + close_dialog + + local id size fs path + IFS="$TAB" + echo "$partitions" | + while { read x1 id size x4 fs path x7; [ "$id" ]; }; do + restore_ifs + if $allowed_func "$dev" "$id"; then + if [ "$fs" = free ]; then + printf "%s\t%s\t%s\t%s free #%d\n" "$dev" "$id" "$size" "$(mapdevfs "$(cat "$dev/device")")" "$freenum" + freenum="$(($freenum + 1))" + else + printf "%s\t%s\t%s\t%s\n" "$dev" "$id" "$size" "$(mapdevfs "$path")" + fi + fi + IFS="$TAB" + done + restore_ifs + done +} + + [ "$PARTMAN_TEST" ] || log '*******************************************************' # Local Variables: diff --git a/packages/partman/partman-crypto/lib/crypto-base.sh b/packages/partman/partman-crypto/lib/crypto-base.sh index 82e16de..0d28e21 100644 --- a/packages/partman/partman-crypto/lib/crypto-base.sh +++ b/packages/partman/partman-crypto/lib/crypto-base.sh @@ -1,35 +1,17 @@ . /lib/partman/lib/base.sh . /lib/partman/lib/commit.sh -crypto_list_allowed() { - local IFS - local partitions - local freenum=1 - for dev in $DEVICES/*; do - if [ ! -d "$dev" ] || [ -f "$dev/crypt_realdev" ]; then - continue - fi - cd "$dev" +# Would this partition be allowed as a physical volume for crypto? +crypto_allowed() { + local dev=$1 + local id=$2 - open_dialog PARTITIONS - partitions="$(read_paragraph)" - close_dialog + # Allow unless this is a crypto device + [ ! -f "$dev/crypto_realdev" ] +} - local id size fs path - IFS="$TAB" - echo "$partitions" | - while { read x1 id size x4 fs path x7; [ "$id" ]; }; do - restore_ifs - if [ "$fs" = free ]; then - printf "%s\t%s\t%s\t%s free #%d\n" "$dev" "$id" "$size" "$(mapdevfs "$(cat "$dev/device")")" "$freenum" - freenum="$(($freenum + 1))" - else - printf "%s\t%s\t%s\t%s\n" "$dev" "$id" "$size" "$(mapdevfs "$path")" - fi - IFS="$TAB" - done - restore_ifs - done +crypto_list_allowed() { + partman_list_allowed crypto_allowed } crypto_list_allowed_free() { diff --git a/packages/partman/partman-lvm/lib/lvm-base.sh b/packages/partman/partman-lvm/lib/lvm-base.sh index 97aeb0b..a1425d9 100644 --- a/packages/partman/partman-lvm/lib/lvm-base.sh +++ b/packages/partman/partman-lvm/lib/lvm-base.sh @@ -241,34 +241,7 @@ pv_allowed () { } pv_list_allowed () { - local IFS - local partitions - local freenum=1 - for dev in $DEVICES/*; do - [ -d $dev ] || continue - cd $dev - - open_dialog PARTITIONS - partitions="$(read_paragraph)" - close_dialog - - local id size fs path - IFS="$TAB" - echo "$partitions" | - while { read x1 id size x4 fs path x7; [ "$id" ]; }; do - restore_ifs - if pv_allowed "$dev" "$id"; then - if [ "$fs" = free ]; then - printf "%s\t%s\t%s\t%s free #%d\n" "$dev" "$id" "$size" "$(mapdevfs "$(cat "$dev/device")")" "$freenum" - freenum="$(($freenum + 1))" - else - printf "%s\t%s\t%s\t%s\n" "$dev" "$id" "$size" "$(mapdevfs "$path")" - fi - fi - IFS="$TAB" - done - restore_ifs - done + partman_list_allowed pv_allowed } pv_list_allowed_free () { diff --git a/packages/partman/partman-md/lib/md-base.sh b/packages/partman/partman-md/lib/md-base.sh index a927014..2685182 100644 --- a/packages/partman/partman-md/lib/md-base.sh +++ b/packages/partman/partman-md/lib/md-base.sh @@ -60,34 +60,7 @@ md_allowed () { } md_list_allowed () { - local IFS - local partitions - local freenum=1 - for dev in $DEVICES/*; do - [ -d $dev ] || continue - cd $dev - - open_dialog PARTITIONS - partitions="$(read_paragraph)" - close_dialog - - local id size fs path - IFS="$TAB" - echo "$partitions" | - while { read x1 id size x4 fs path x7; [ "$id" ]; }; do - restore_ifs - if md_allowed "$dev" "$id"; then - if [ "$fs" = free ]; then - printf "%s\t%s\t%s\t%s free #%d\n" "$dev" "$id" "$size" "$(mapdevfs "$(cat "$dev/device")")" "$freenum" - freenum="$(($freenum + 1))" - else - printf "%s\t%s\t%s\t%s\n" "$dev" "$id" "$size" "$(mapdevfs "$path")" - fi - fi - IFS="$TAB" - done - restore_ifs - done + partman_list_allowed md_allowed } md_list_allowed_free () { -- 1.6.3.3 -- To UNSUBSCRIBE, email to debian-boot-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org