From: Karel Zak Date: Mon, 3 Feb 2014 11:22:31 +0000 (+0100) Subject: cfdisk: follow default end if possible X-Git-Tag: v2.25-rc1~486 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=872d23897c5a6e5bba99791ceeffe8122caf89b2;p=thirdparty%2Futil-linux.git cfdisk: follow default end if possible Signed-off-by: Karel Zak --- diff --git a/fdisks/cfdisk.c b/fdisks/cfdisk.c index adc6c3c965..c904f5e47b 100644 --- a/fdisks/cfdisk.c +++ b/fdisks/cfdisk.c @@ -646,7 +646,7 @@ static int menu_cb_main(struct cfdisk *cf, int key) break; case 'n': /* New */ { - uint64_t start, size; + uint64_t start, size, dflt_size; struct fdisk_partition *npa; /* the new partition */ if (!pa || !fdisk_partition_is_freespace(pa)) @@ -656,16 +656,19 @@ static int menu_cb_main(struct cfdisk *cf, int key) return -ENOMEM; /* free space range */ start = fdisk_partition_get_start(pa); - size = fdisk_partition_get_size(pa) * cf->cxt->sector_size; + size = dflt_size = fdisk_partition_get_size(pa) * cf->cxt->sector_size; if (ui_get_size(cf, _("Partition size: "), &size, 1, size) == -CFDISK_ERR_ESC) break; - size /= cf->cxt->sector_size; - /* properties of the new partition */ + + if (dflt_size == size) /* default is to fillin all free space */ + fdisk_partition_end_follow_default(npa, 1); + else /* set relative size of the partition */ + fdisk_partition_set_size(npa, size / cf->cxt->sector_size); + fdisk_partition_set_start(npa, start); - fdisk_partition_set_size(npa, size); - fdisk_partition_partno_follow_default(npa, 1); + fdisk_partition_partno_follow_default(npa, 1); /* add to disk label -- libfdisk will ask for missing details */ rc = fdisk_add_partition(cf->cxt, npa); fdisk_unref_partition(npa);