]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
cfdisk: follow default end if possible
authorKarel Zak <kzak@redhat.com>
Mon, 3 Feb 2014 11:22:31 +0000 (12:22 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 11 Mar 2014 10:35:14 +0000 (11:35 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/cfdisk.c

index adc6c3c9658c5e7929f9297338472be8a1698c07..c904f5e47bf98cd858003dc159558a186cdd517f 100644 (file)
@@ -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);