summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2010-12-09 23:13:58 +0100
committerKarel Zak <kzak@redhat.com>2010-12-09 23:13:58 +0100
commitf30f2bbc81ad37cdd8f50485e41550dbbd82275d (patch)
tree97304a577f5b0d2dc93040c5777ac05b6f1a5fd3
parent8aa504664794150c2d64923e2a63341a2b56e065 (diff)
downloadutil-linux-old-f30f2bbc81ad37cdd8f50485e41550dbbd82275d.tar.gz
sfdisk: add option to use maximum partition size
Based on patch from Alex Bligh <alex@alex.org.uk>, 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 <kzak@redhat.com>
-rw-r--r--fdisk/sfdisk.84
-rw-r--r--fdisk/sfdisk.c2
2 files changed, 5 insertions, 1 deletions
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;