From ef97849676d0a8ce8909ac138c2887b1e6b069ed Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 23 Sep 2011 16:20:26 +0200 Subject: [PATCH] distinguish between disk size and extended partition size Signed-off-by: Steven Armstrong --- .../__partition_msdos_apply/gencode-remote | 46 +++++++++++++++---- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/conf/type/__partition_msdos_apply/gencode-remote b/conf/type/__partition_msdos_apply/gencode-remote index d352abdb..1d5c33cb 100755 --- a/conf/type/__partition_msdos_apply/gencode-remote +++ b/conf/type/__partition_msdos_apply/gencode-remote @@ -23,7 +23,8 @@ die() { exit 1 } debug() { - echo "[__partition_msdos_apply] $@" >&2 + #echo "[__partition_msdos_apply] $@" >&2 + : } # Convert a size specifier 1G 100M or 50% into the corresponding numeric MB. @@ -57,32 +58,43 @@ cat "$__type/files/lib.sh" partitions="$__object/explorer/partitions" objects=$(find "$__global/object/__partition_msdos" -path "*.cdist") current_device="" +available_device_size= +available_extended_size= available_size= primary_count=0 for object in $objects; do device="$(cat "$object/parameter/device")" if [ "$current_device" != "$device" ]; then - echo "create_disklabel $device" + echo "create_disklabel \"$device\" || die 'Failed to create disklabel for $device'" current_device="$device" device_name=$(echo ${device} | sed -e 's:^/dev/::;s:/:\\/:g') - available_size=$(( $(awk "/${device_name}\$/ { print \$3; }" "$partitions") / 1024)) + available_device_size=$(( $(awk "/${device_name}\$/ { print \$3; }" "$partitions") / 1024)) # make sure we don't go past the end of the drive - available_size=$((available_size - 2)) + available_device_size=$((available_device_size - 2)) + available_extended_size=0 primary_count=0 debug "----- $device" debug "current_device=$current_device" - debug "available_size=$available_size" + debug "available_device_size=$available_device_size" fi type="$(cat "$object/parameter/type")" partition="$(cat "$object/parameter/partition")" minor="$(cat "$object/parameter/minor")" - if [ "${minor}" -lt "5" ]; then - primary_count=$(( $primary_count + 1 )) - fi bootable="$(cat "$object/parameter/bootable")" size="$(cat "$object/parameter/size")" + + + if [ "${minor}" -lt "5" ]; then + # Primary partitions + primary_count=$(( $primary_count + 1 )) + available_size=$available_device_size + else + # Logical partitions + available_size=$available_extended_size + fi + if [ "$size" = "+" ]; then # use rest of device partition_size="" @@ -92,6 +104,18 @@ for object in $objects; do available_size="$(( $available_size - $partition_size ))" fi + if [ "${minor}" -lt "5" ]; then + # Primary partitions + available_device_size=$available_size + if [ "$type" = "extended" -o "$type" = "5" ]; then + # Extended partition + available_extended_size=$partition_size + fi + else + # Logical paritions + available_extended_size=$available_size + fi + [ "$partition_size" = "-1" ] && die "could not translate size '$size' to a usable value" debug "----- $partition" debug "primary_count=$primary_count" @@ -104,7 +128,11 @@ for object in $objects; do debug "size=$size" debug "partition_size=$partition_size" debug "available_size=$available_size" + debug "available_device_size=$available_device_size" + debug "available_extended_size=$available_extended_size" + debug "----------" - echo "create_partition $device $minor $partition_size $type $primary_count" + echo "create_partition '$device' '$minor' '$partition_size' '$type' '$primary_count' \ + || die 'Failed to create partition: $partition'" done