1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/makesd-partition-summary Fri May 24 20:24:34 2019 +0200
1.3 @@ -0,0 +1,84 @@
1.4 +#!/bin/sh
1.5 +
1.6 +# Emit a partition summary for a device employing parameters such as the start,
1.7 +# size, and type.
1.8 +
1.9 +PROGNAME=`basename "$0"`
1.10 +THISDIR=`dirname "$0"`
1.11 +
1.12 +
1.13 +
1.14 +# Emit any partition details as a complete record.
1.15 +
1.16 +emit_partition()
1.17 +{
1.18 + echo "${START:--}\t${SIZE:--}\t${TYPE:--}"
1.19 +}
1.20 +
1.21 +# Reset the current partition details.
1.22 +
1.23 +reset_partition()
1.24 +{
1.25 + START=
1.26 + SIZE=
1.27 + TYPE=
1.28 +}
1.29 +
1.30 +# Emit the current partition details and proceed to the next partition.
1.31 +
1.32 +next_partition()
1.33 +{
1.34 + if [ "$START" ] || [ "$SIZE" ] || [ "$TYPE" ] ; then
1.35 + emit_partition
1.36 + reset_partition
1.37 + fi
1.38 +}
1.39 +
1.40 +
1.41 +
1.42 +# Emit the help message if requested.
1.43 +
1.44 +if [ "$1" = '--help' ] ; then
1.45 + cat 1>&2 <<EOF
1.46 +Usage: $PROGNAME ( -f <type> | -p <start> | -s <size> )...
1.47 +
1.48 +Produce partition descriptions, indicating partition type, start position and
1.49 +size for each partition. Each new occurrence of an active option starts a new
1.50 +partition description.
1.51 +
1.52 +Each line of the produced description is tab-separated with '-' indicating an
1.53 +empty field.
1.54 +EOF
1.55 + exit 0
1.56 +fi
1.57 +
1.58 +# Process the arguments, building a partition description.
1.59 +
1.60 +reset_partition
1.61 +
1.62 +while [ "$1" ] ; do
1.63 + case "$1" in
1.64 + -f )
1.65 + if [ "$TYPE" ] ; then next_partition ; fi
1.66 + TYPE="$2"
1.67 + shift 2
1.68 + ;;
1.69 + -p )
1.70 + if [ "$START" ] ; then next_partition ; fi
1.71 + START="$2"
1.72 + shift 2
1.73 + ;;
1.74 + -s )
1.75 + if [ "$SIZE" ] ; then next_partition ; fi
1.76 + SIZE="$2"
1.77 + shift 2
1.78 + ;;
1.79 + * )
1.80 + shift 1
1.81 + ;;
1.82 + esac
1.83 +done
1.84 +
1.85 +# Terminate any unfinished partition.
1.86 +
1.87 +next_partition
2.1 --- a/makesd-partition-table Fri May 24 18:27:02 2019 +0200
2.2 +++ b/makesd-partition-table Fri May 24 20:24:34 2019 +0200
2.3 @@ -75,7 +75,7 @@
2.4 # Alternatively, use previous start and size information.
2.5 # Otherwise, the first partition is being defined.
2.6
2.7 - if [ "$START" ] ; then
2.8 + if [ "$START" ] && [ "$START" != '-' ] ; then
2.9 PREVSTART=`align_cylinder $START`
2.10 elif [ "$PREVSTART" ] && [ "$PREVSIZE" ] ; then
2.11 PREVSTART=`align_cylinder $(($PREVSTART + $PREVSIZE))`
2.12 @@ -92,7 +92,7 @@
2.13 # Calculate and align the stated size.
2.14 # Otherwise, defer the calculation until emitting the details.
2.15
2.16 - if [ "$SIZE" ] ; then
2.17 + if [ "$SIZE" ] && [ "$SIZE" != '-' ] ; then
2.18 PREVSIZE=$(($SIZE * $DEVSIZE / 100))
2.19 PREVSIZE=`align_cylinder $PREVSIZE`
2.20
2.21 @@ -106,24 +106,12 @@
2.22 PREVTYPE=$TYPE
2.23 }
2.24
2.25 -# Reset the current partition details.
2.26 -
2.27 -reset_partition()
2.28 -{
2.29 - START=
2.30 - SIZE=
2.31 - TYPE=
2.32 -}
2.33 -
2.34 # Emit the current partition details and proceed to the next partition.
2.35
2.36 next_partition()
2.37 {
2.38 - if [ "$START" ] || [ "$SIZE" ] || [ "$TYPE" ] ; then
2.39 - emit_partition
2.40 - store_partition
2.41 - reset_partition
2.42 - fi
2.43 + emit_partition
2.44 + store_partition
2.45 }
2.46
2.47 # Convert the partition type to an sdisk-compatible identifier.
2.48 @@ -187,6 +175,19 @@
2.49
2.50
2.51
2.52 +# Process the arguments, building a partition description.
2.53 +
2.54 +read_fields()
2.55 +{
2.56 + OLDIFS=$IFS
2.57 + IFS=`echo -n '\t'` read START SIZE TYPE
2.58 + STATUS=$?
2.59 + IFS=$OLDIFS
2.60 + return $STATUS
2.61 +}
2.62 +
2.63 +
2.64 +
2.65 # Emit the help message if requested.
2.66
2.67 if [ "$1" = '--help' ] ; then
2.68 @@ -241,37 +242,10 @@
2.69
2.70 init_sfdisk "$DEV"
2.71
2.72 -# Process the arguments, building a partition description.
2.73 -
2.74 -reset_partition
2.75 -
2.76 -while [ "$1" ] ; do
2.77 - case "$1" in
2.78 - -f )
2.79 - if [ "$TYPE" ] ; then next_partition ; fi
2.80 - TYPE="$2"
2.81 - shift 2
2.82 - ;;
2.83 - -p )
2.84 - if [ "$START" ] ; then next_partition ; fi
2.85 - START="$2"
2.86 - shift 2
2.87 - ;;
2.88 - -s )
2.89 - if [ "$SIZE" ] ; then next_partition ; fi
2.90 - SIZE="$2"
2.91 - shift 2
2.92 - ;;
2.93 - * )
2.94 - shift 1
2.95 - ;;
2.96 - esac
2.97 +while read_fields ; do
2.98 + next_partition
2.99 done
2.100
2.101 -# Terminate any unfinished partition, emitting the previous partition.
2.102 -
2.103 -next_partition
2.104 -
2.105 # Emit the last partition.
2.106
2.107 emit_partition