# HG changeset patch # User Paul Boddie # Date 1558722274 -7200 # Node ID af4351d5e9224c92e3f4dfab56dcbfea10b63242 # Parent ad94fc90209636628c8892c95dacc459d6814e8d Introduced a summary script that takes partitioning arguments and produces a partitioning summary. This summary is then processed by the table script to generate suitable input for sfdisk. diff -r ad94fc902096 -r af4351d5e922 makesd-partition-summary --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/makesd-partition-summary Fri May 24 20:24:34 2019 +0200 @@ -0,0 +1,84 @@ +#!/bin/sh + +# Emit a partition summary for a device employing parameters such as the start, +# size, and type. + +PROGNAME=`basename "$0"` +THISDIR=`dirname "$0"` + + + +# Emit any partition details as a complete record. + +emit_partition() +{ + echo "${START:--}\t${SIZE:--}\t${TYPE:--}" +} + +# Reset the current partition details. + +reset_partition() +{ + START= + SIZE= + TYPE= +} + +# Emit the current partition details and proceed to the next partition. + +next_partition() +{ + if [ "$START" ] || [ "$SIZE" ] || [ "$TYPE" ] ; then + emit_partition + reset_partition + fi +} + + + +# Emit the help message if requested. + +if [ "$1" = '--help' ] ; then + cat 1>&2 < | -p | -s )... + +Produce partition descriptions, indicating partition type, start position and +size for each partition. Each new occurrence of an active option starts a new +partition description. + +Each line of the produced description is tab-separated with '-' indicating an +empty field. +EOF + exit 0 +fi + +# Process the arguments, building a partition description. + +reset_partition + +while [ "$1" ] ; do + case "$1" in + -f ) + if [ "$TYPE" ] ; then next_partition ; fi + TYPE="$2" + shift 2 + ;; + -p ) + if [ "$START" ] ; then next_partition ; fi + START="$2" + shift 2 + ;; + -s ) + if [ "$SIZE" ] ; then next_partition ; fi + SIZE="$2" + shift 2 + ;; + * ) + shift 1 + ;; + esac +done + +# Terminate any unfinished partition. + +next_partition diff -r ad94fc902096 -r af4351d5e922 makesd-partition-table --- a/makesd-partition-table Fri May 24 18:27:02 2019 +0200 +++ b/makesd-partition-table Fri May 24 20:24:34 2019 +0200 @@ -75,7 +75,7 @@ # Alternatively, use previous start and size information. # Otherwise, the first partition is being defined. - if [ "$START" ] ; then + if [ "$START" ] && [ "$START" != '-' ] ; then PREVSTART=`align_cylinder $START` elif [ "$PREVSTART" ] && [ "$PREVSIZE" ] ; then PREVSTART=`align_cylinder $(($PREVSTART + $PREVSIZE))` @@ -92,7 +92,7 @@ # Calculate and align the stated size. # Otherwise, defer the calculation until emitting the details. - if [ "$SIZE" ] ; then + if [ "$SIZE" ] && [ "$SIZE" != '-' ] ; then PREVSIZE=$(($SIZE * $DEVSIZE / 100)) PREVSIZE=`align_cylinder $PREVSIZE` @@ -106,24 +106,12 @@ PREVTYPE=$TYPE } -# Reset the current partition details. - -reset_partition() -{ - START= - SIZE= - TYPE= -} - # Emit the current partition details and proceed to the next partition. next_partition() { - if [ "$START" ] || [ "$SIZE" ] || [ "$TYPE" ] ; then - emit_partition - store_partition - reset_partition - fi + emit_partition + store_partition } # Convert the partition type to an sdisk-compatible identifier. @@ -187,6 +175,19 @@ +# Process the arguments, building a partition description. + +read_fields() +{ + OLDIFS=$IFS + IFS=`echo -n '\t'` read START SIZE TYPE + STATUS=$? + IFS=$OLDIFS + return $STATUS +} + + + # Emit the help message if requested. if [ "$1" = '--help' ] ; then @@ -241,37 +242,10 @@ init_sfdisk "$DEV" -# Process the arguments, building a partition description. - -reset_partition - -while [ "$1" ] ; do - case "$1" in - -f ) - if [ "$TYPE" ] ; then next_partition ; fi - TYPE="$2" - shift 2 - ;; - -p ) - if [ "$START" ] ; then next_partition ; fi - START="$2" - shift 2 - ;; - -s ) - if [ "$SIZE" ] ; then next_partition ; fi - SIZE="$2" - shift 2 - ;; - * ) - shift 1 - ;; - esac +while read_fields ; do + next_partition done -# Terminate any unfinished partition, emitting the previous partition. - -next_partition - # Emit the last partition. emit_partition