From: Karel Zak Date: Thu, 9 Dec 2010 22:13:58 +0000 (+0100) Subject: sfdisk: add option to use maximum partition size X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f30f2bbc81ad37cdd8f50485e41550dbbd82275d;p=util-linux sfdisk: add option to use maximum partition size Based on patch from Alex Bligh , Alex wrote: By default, omitting a size parameter means that the maximum sized partition is used. However, this option is not available in conjunction with the -N flag, as under such circumstances the default is the current size of the partition. This patch allows a size to be specified as "+" in which case the maximum sized partition is used, irrespective of the setting of the -N flag. This allows partitions to be programatically resized to their maximum size, by (for instance): echo ",+," | sfdisk -N1 /dev/sda This is non-trivial to do without the patch, as -N makes the default size the existing size. As there is (without this patch) no way of reading the maximum size, the only option is to delete the partition and recreate it. This is undesirable for a number of reasons (e.g. errors between delete and recreate). Addresses: https://bugs.launchpad.net/ubuntu/+source/util-linux/+bug/686124 Signed-off-by: Karel Zak --- diff --git a/fdisk/sfdisk.8 b/fdisk/sfdisk.8 index 7e2dca93..f6e98c17 100644 --- a/fdisk/sfdisk.8 +++ b/fdisk/sfdisk.8 @@ -428,7 +428,9 @@ the defaults are: Linux partition, Extended partition, Empty, Empty. .LP But when the \-N option (change a single partition only) is given, the default for each field is its previous value. - +.LP +A '+' can be specified instead of a number for size, which means +as much as possible. This is useful with the \-N option. .SH EXAMPLE The command .RS diff --git a/fdisk/sfdisk.c b/fdisk/sfdisk.c index fd2f27eb..958faaeb 100644 --- a/fdisk/sfdisk.c +++ b/fdisk/sfdisk.c @@ -2100,6 +2100,8 @@ read_line(int pno, struct part_desc *ep, char *dev, int interactive, def = orig ? orig->size : (pno > 4 && pct > 1) ? 0 : ml1; if (fno < 2 || !*(fields[1])) p.size = def; + else if (!strcmp(fields[1], "+")) + p.size = ml1; else { if (get_ul(fields[1], &ul, def / unitsize(0), 0)) return 0;