# HG changeset patch # User Paul Boddie # Date 1558652724 -7200 # Node ID b3ffe81236d8746dd547e2c33bd40023869c96a4 # Parent a3585c5fc0d1d435161980a530b3632ceb4a5649 Introduced sectors as the working unit and cylinder alignment. diff -r a3585c5fc0d1 -r b3ffe81236d8 makesd-partition-table --- a/makesd-partition-table Thu May 23 22:30:49 2019 +0200 +++ b/makesd-partition-table Fri May 24 01:05:24 2019 +0200 @@ -10,6 +10,12 @@ +# Cylinder size in sectors for alignment purposes. + +HEADS=255 +SECTORS=63 +CYLINDER_SIZE=$(($HEADS * $SECTORS)) + # Global partition number and previous partition details. PARTNUM=1 @@ -32,10 +38,20 @@ emit_partition_fields() { - if [ "$PREVSTART" ] ; then - echo -n " start=${PREVSTART}${SFDISK_UNIT_SUFFIX}" + 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. # Without a size, use start details to calculate a size. # Without start details, claim the rest of the device. @@ -43,9 +59,15 @@ REMAINING=$(($DEVSIZE - $PREVSTART)) if [ "$PREVSIZE" ] ; then - PREVSIZE=$(($PREVSIZE * $DEVSIZE / 100)) + PREVSIZE=$((($PREVSIZE * $DEVSIZE) / 100)) + PREVSIZE=`align_cylinder $PREVSIZE` + + if [ "$FIRSTPART" ] ; then + PREVSIZE=$(($PREVSIZE - 1)) + fi + elif [ "$START" ] ; then - PREVSIZE=$(($START - $PREVSTART)) + PREVSIZE=$((`align_cylinder $START` - $PREVSTART)) else PREVSIZE=$REMAINING fi @@ -59,6 +81,7 @@ if [ "$PREVTYPE" ] ; then echo -n " Id=`partition_type $PREVTYPE`" fi + echo } @@ -70,6 +93,7 @@ PREVSTART=$START elif [ "$PREVSTART" ] && [ "$PREVSIZE" ] ; then PREVSIZE=$(($PREVSIZE * $DEVSIZE / 100)) + PREVSIZE=`align_cylinder $PREVSIZE` PREVSTART=$(($PREVSTART + $PREVSIZE)) else PREVSTART=0 @@ -122,19 +146,33 @@ "$SFDISK" -s "$1" } +# Align to cylinders. + +align_cylinder() +{ + # Round up to the nearest cylinder. + + CYLINDER=$((($1 + $CYLINDER_SIZE - 1) / $CYLINDER_SIZE)) + + # Emit the number of sectors. + + echo $(($CYLINDER * $CYLINDER_SIZE)) +} + # Test sfdisk behaviour and obtain useful information. init_sfdisk() { - if "$SFDISK" -uB -s "$1" > /dev/null 2>&1 ; then - SFDISK_UNIT_SUFFIX= - else - SFDISK_UNIT_SUFFIX="K" - fi + SFDISK_UNIT_SUFFIX= + + # Obtain the device size in 512-byte sectors. - # Obtain the device size in blocks. + DEVSIZE=$((`device_size "$1"` * 2)) - DEVSIZE=`device_size "$1"` + # Find the cylinder-addressable size. + + CYLINDERS=$(($DEVSIZE / $CYLINDER_SIZE)) + DEVSIZE=$(($CYLINDERS * $CYLINDER_SIZE)) } @@ -149,7 +187,7 @@ size for each partition. Each occurrence of the -f option starts a new partition description. -Start positions are indicated as numbers of 1024-byte blocks. +Start positions are indicated as numbers of 512-byte sectors. Sizes are indicated as percentages of the entire device; if omitted, the remainder of the device will be used.