# HG changeset patch # User Paul Boddie # Date 1558715188 -7200 # Node ID 2e760d4f76f1b9debbf4e9899468980fd3632ce0 # Parent b3ffe81236d8746dd547e2c33bd40023869c96a4 Moved various calculations into store_partition from emit_partition. diff -r b3ffe81236d8 -r 2e760d4f76f1 makesd-partition-table --- a/makesd-partition-table Fri May 24 01:05:24 2019 +0200 +++ b/makesd-partition-table Fri May 24 18:26:28 2019 +0200 @@ -38,34 +38,16 @@ emit_partition_fields() { - if [ "$PREVSTART" = '0' ] ; then - FIRSTPART=yes - else - FIRSTPART= - fi - - PREVSTART=`align_cylinder $PREVSTART` - - if [ "$PREVSTART" = '0' ] ; then - PREVSTART=1 - fi - echo -n " start=${PREVSTART}${SFDISK_UNIT_SUFFIX}" - # Obtain any explicitly stated size. + REMAINING=$(($DEVSIZE - $PREVSTART)) + + # Retain any previously calculated size. # Without a size, use start details to calculate a size. # Without start details, claim the rest of the device. - REMAINING=$(($DEVSIZE - $PREVSTART)) - if [ "$PREVSIZE" ] ; then - PREVSIZE=$((($PREVSIZE * $DEVSIZE) / 100)) - PREVSIZE=`align_cylinder $PREVSIZE` - - if [ "$FIRSTPART" ] ; then - PREVSIZE=$(($PREVSIZE - 1)) - fi - + : elif [ "$START" ] ; then PREVSIZE=$((`align_cylinder $START` - $PREVSTART)) else @@ -89,17 +71,38 @@ store_partition() { + # Define the partition start using a specified position. + # Alternatively, use previous start and size information. + # Otherwise, the first partition is being defined. + if [ "$START" ] ; then - PREVSTART=$START + PREVSTART=`align_cylinder $START` elif [ "$PREVSTART" ] && [ "$PREVSIZE" ] ; then - PREVSIZE=$(($PREVSIZE * $DEVSIZE / 100)) - PREVSIZE=`align_cylinder $PREVSIZE` - PREVSTART=$(($PREVSTART + $PREVSIZE)) + PREVSTART=`align_cylinder $(($PREVSTART + $PREVSIZE))` else PREVSTART=0 fi - PREVSIZE=$SIZE + # Ensure that the first partition starts at sector one. + + if [ "$PREVSTART" = '0' ] ; then + PREVSTART=1 + fi + + # Calculate and align the stated size. + # Otherwise, defer the calculation until emitting the details. + + if [ "$SIZE" ] ; then + PREVSIZE=$(($SIZE * $DEVSIZE / 100)) + PREVSIZE=`align_cylinder $PREVSIZE` + + if [ "$PREVSTART" = '1' ] ; then + PREVSIZE=$(($PREVSIZE - 1)) + fi + else + PREVSIZE= + fi + PREVTYPE=$TYPE }