From: Karel Zak Date: Wed, 10 Jun 2015 14:55:29 +0000 (+0200) Subject: libfdisk: (dos) fix cylinders calculation X-Git-Tag: v2.27-rc1~151 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=535748a6175a142901069724cb11b60d4a63b671;p=thirdparty%2Futil-linux.git libfdisk: (dos) fix cylinders calculation Signed-off-by: Karel Zak --- diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index 52836ebf11..de70728c2a 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -1030,7 +1030,6 @@ static int add_partition(struct fdisk_context *cxt, size_t n, struct pte *ext_pe = l->ext_offset ? self_pte(cxt, l->ext_index) : NULL; struct fdisk_ask *ask = NULL; - fdisk_sector_t start, stop = 0, limit, temp, first[cxt->label->nparts_max], last[cxt->label->nparts_max]; @@ -1172,7 +1171,6 @@ static int add_partition(struct fdisk_context *cxt, size_t n, fdisk_reset_ask(ask); if (!ask) return -ENOMEM; - fdisk_ask_set_type(ask, FDISK_ASKTYPE_OFFSET); if (fdisk_use_cylinders(cxt)) { @@ -1196,18 +1194,16 @@ static int add_partition(struct fdisk_context *cxt, size_t n, stop = fdisk_ask_number_get_result(ask); isrel = fdisk_ask_number_is_relative(ask); + if (fdisk_use_cylinders(cxt)) { + stop = stop * fdisk_get_units_per_sector(cxt) - 1; + if (stop >limit) + stop = limit; + } if (stop >= start && stop <= limit) break; - fdisk_warnx(cxt, _("Value out of range.")); } - - if (fdisk_use_cylinders(cxt)) { - stop = stop * fdisk_get_units_per_sector(cxt) - 1; - if (stop >limit) - stop = limit; - } } DBG(LABEL, ul_debug("DOS: raw stop: %ju", (uintmax_t) stop)); @@ -1266,7 +1262,6 @@ static int add_partition(struct fdisk_context *cxt, size_t n, fdisk_label_set_changed(cxt->label, 1); rc = 0; - done: fdisk_unref_ask(ask); return rc;