]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: follow explicitly specified partition size
authorKarel Zak <kzak@redhat.com>
Thu, 9 Oct 2014 10:09:07 +0000 (12:09 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 9 Oct 2014 10:09:07 +0000 (12:09 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/cfdisk.c
disk-utils/fdisk.c
libfdisk/src/script.c

index 4101827f1e41b9454c54066c2cf01a0a36bb97aa..43a081cc0094a28cebc5b737672183f1bf96e2e5 100644 (file)
@@ -1448,7 +1448,7 @@ done:
 
 /* @res is default value as well as result in bytes */
 static int ui_get_size(struct cfdisk *cf, const char *prompt, uintmax_t *res,
-                      uintmax_t low, uintmax_t up)
+                      uintmax_t low, uintmax_t up, int *expsize)
 {
        char buf[128];
        uintmax_t user = 0;
@@ -1502,6 +1502,9 @@ static int ui_get_size(struct cfdisk *cf, const char *prompt, uintmax_t *res,
                                ui_warnx(_("Maximal size is %ju bytes."), up);
                                rc = -ERANGE;
                        }
+                       if (rc == 0 && insec && expsize)
+                               *expsize = 1;
+
                } else
                        ui_warnx(_("Failed to parse size."));
        } while (rc != 0);
@@ -1807,6 +1810,7 @@ static int main_menu_action(struct cfdisk *cf, int key)
        {
                uint64_t start, size, dflt_size;
                struct fdisk_partition *npa;    /* the new partition */
+               int expsize = 0;                /* size specified explicitly in sectors */
 
                if (!pa || !fdisk_partition_is_freespace(pa))
                        return -EINVAL;
@@ -1817,7 +1821,7 @@ static int main_menu_action(struct cfdisk *cf, int key)
                start = fdisk_partition_get_start(pa);
                size = dflt_size = fdisk_partition_get_size(pa) * fdisk_get_sector_size(cf->cxt);
 
-               if (ui_get_size(cf, _("Partition size: "), &size, 1, size)
+               if (ui_get_size(cf, _("Partition size: "), &size, 1, size, &expsize)
                                == -CFDISK_ERR_ESC)
                        break;
 
@@ -1826,8 +1830,11 @@ static int main_menu_action(struct cfdisk *cf, int key)
                else /* set relative size of the partition */
                        fdisk_partition_set_size(npa, size / fdisk_get_sector_size(cf->cxt));
 
+               if (expsize)
+                       fdisk_partition_size_explicit(pa, 1);
+
                fdisk_partition_set_start(npa, start);
-                               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, NULL);
                fdisk_unref_partition(npa);
index ee4dd6c615658011e93e2e88697a826804564b35..ee99dd3a8453406ecf373fe1bd4784a3145db323 100644 (file)
@@ -272,7 +272,7 @@ static int ask_offset(struct fdisk_context *cxt,
                                num, sig, pwr,
                                sig ? "relative" : "absolute"));
                if (num >= low && num <= high) {
-                       if (sig)
+                       if (sig && pwr)
                                fdisk_ask_number_set_relative(ask, 1);
                        return fdisk_ask_number_set_result(ask, num);
                }
index fc77d9e71554dc7c0d307dc35db919b84561bba4..1b0d2898f01214d4c19c3c05b8e07ee700f32e51 100644 (file)
@@ -608,8 +608,10 @@ static int parse_script_line(struct fdisk_script *dp, char *s)
                        p += 5;
                        rc = next_number(&p, &num, &pow);
                        if (!rc) {
-                               if (pow)
+                               if (pow)        /* specified as <num><suffix> */
                                        num /= dp->cxt->sector_size;
+                               else            /* specified as number of sectors */
+                                       fdisk_partition_size_explicit(pa, 1);
                                fdisk_partition_set_size(pa, num);
                                fdisk_partition_end_follow_default(pa, 0);
                        }
@@ -766,8 +768,10 @@ static int parse_commas_line(struct fdisk_script *dp, char *s)
                                int pow = 0;
                                rc = next_number(&p, &num, &pow);
                                if (!rc) {
-                                       if (pow)
+                                       if (pow) /* specified as <size><suffix> */
                                                num /= dp->cxt->sector_size;
+                                       else     /* specified as number of sectors */
+                                               fdisk_partition_size_explicit(pa, 1);
                                        fdisk_partition_set_size(pa, num);
                                }
                                fdisk_partition_end_follow_default(pa, 0);