On 11/28/25 16:35, Alyssa Ross wrote: > On Fri, Nov 28, 2025 at 04:31:21PM -0500, Demi Marie Obenour wrote: >> On 11/28/25 16:26, Alyssa Ross wrote: >>> Demi Marie Obenour writes: >>> >>>> On 11/28/25 16:14, Alyssa Ross wrote: >>>>> Demi Marie Obenour writes: >>>>> >>>>>> On 11/28/25 08:22, Alyssa Ross wrote: >>>>>>> We want non-minimally-sized partitions to leave space for updates. >>>>>>> All such partitions will also be labelled, so we can just add another >>>>>>> optional field at the end. >>>>>>> >>>>>>> Since we don't parse partition specifications in sh, we can't keep a >>>>>>> running total any more, so instead we just go through the table at the >>>>>>> end and add up all the sizes, taking advantage of our knowledge that >>>>>>> the size will always be the last thing in each line in our tables. >>>>>>> >>>>>>> Signed-off-by: Alyssa Ross >>>>>>> Message-ID: <20251127174054.2056835-2-hi@alyssa.is> >> >> (snip) >> >>>>>>> # Keep 1MiB free at the start, and 1MiB free at the end. >>>>>>> -gptBytes=$((ONE_MiB * 2)) >>>>>>> -for partition; do >>>>>>> - sizeMiB="$(sizeMiB "${partition%%:*}")" >>>>>>> - table="$table${nl}size=${sizeMiB}MiB,$(awk -f "$scriptsDir/sfdisk-field.awk" -v partition="$partition")" >>>>>>> - gptBytes="$((gptBytes + sizeMiB * ONE_MiB))" >>>>>>> -done >>>>>>> +gptMiB=2 >>>>>>> +while read -r partition; do >>>>>>> + # Here we rely on sfdisk-field.awk always putting size last. >>>>>>> + : $((gptMiB += ${partition##*=})) >>>>>>> +done <>>>>>> +$table >>>>>>> +EOF >>>>>> >>>>>> Nit: should ${partition##*=} be in double quotes? >>>>> >>>>> I tried changing it, but it is apparently an "arithmetic syntax error" >>>>> to use double quotes here. >>>> >>>> I'd use a separate variable then. >>> >>> Doesn't seem to make a difference. As an experiment: >>> >>> partition="size=2 + 3" >>> size=${partition##*=} >>> printf "%s\n" $(($size)) >>> >>> This prints 5 even though a separate variable is used. It doesn't seem >>> to be possible to get $(( … )) *not* to interpret arithmetic in >>> variables. >>> >>> In bash, but not busybox ash as used in Nix builds, it is possible to >>> use double quotes like you suggested, but $(("$size")) is /still/ 5. >> >> That's actually required by POSIX. What about: >> >> size=${partition##*=} >> : $((gptMiB += size)) > > How's that better? Arithmetic will still be expanded inside size — > or do you have some other concern with the parameter expansion inside > the arithmetic expansion? Nevermind. The only way it would be better is if the input was explicitly validated, which might not be worthwile. In bash, bad $size even allows code execution in at least the default mode. -- Sincerely, Demi Marie Obenour (she/her/hers)