From: Karel Zak Date: Thu, 9 Oct 2014 10:09:07 +0000 (+0200) Subject: libfdisk: follow explicitly specified partition size X-Git-Tag: v2.26-rc1~333 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b0b9fb1bff7b4ddd6669a2a57fe4561df376f04;p=thirdparty%2Futil-linux.git libfdisk: follow explicitly specified partition size Signed-off-by: Karel Zak --- diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c index 4101827f1e..43a081cc00 100644 --- a/disk-utils/cfdisk.c +++ b/disk-utils/cfdisk.c @@ -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); diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c index ee4dd6c615..ee99dd3a84 100644 --- a/disk-utils/fdisk.c +++ b/disk-utils/fdisk.c @@ -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); } diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c index fc77d9e715..1b0d2898f0 100644 --- a/libfdisk/src/script.c +++ b/libfdisk/src/script.c @@ -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 /= 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 */ 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);