distinguish between disk size and extended partition size

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2011-09-23 16:20:26 +02:00
parent 721119a34f
commit ef97849676

View file

@ -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