From: Karel Zak Date: Mon, 3 Feb 2014 11:23:18 +0000 (+0100) Subject: libfdisk: don't ask for pri/log if wanted start within extended partition X-Git-Tag: v2.25-rc1~485 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a3e37fa7af93622e2217b7f020f41104b005b848;p=thirdparty%2Futil-linux.git libfdisk: don't ask for pri/log if wanted start within extended partition Signed-off-by: Karel Zak --- diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index 01e2032683..cb34be8aba 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -830,7 +830,8 @@ static int get_start_from_user( struct fdisk_context *cxt, (uintmax_t) pa->start, (uintmax_t) low, (uintmax_t) limit)); *start = pa->start; if (*start < low || *start > limit) { - fdisk_warnx(cxt, _("Start sector out of range.")); + fdisk_warnx(cxt, _("Start sector %ju out of range."), + (uintmax_t) *start); return -ERANGE; } } else { @@ -1293,12 +1294,32 @@ static int dos_add_partition(struct fdisk_context *cxt, size_t i, free_primary = 0; int rc = 0; struct fdisk_dos_label *l = self_label(cxt); + struct dos_partition *ext = l->ext_offset ? + self_partition(cxt, l->ext_index) : NULL; assert(cxt); assert(cxt->label); assert(fdisk_is_disklabel(cxt, DOS)); - /* TODO: use pa->type */ + + /* pa specifies start within extended partition, add logical */ + if (pa && pa->start + && pa->start >= l->ext_offset + && pa->start <= l->ext_offset + dos_partition_get_size(ext)) { + rc = add_logical(cxt, pa); + goto done; + + /* pa specifies start, but outside extended partition */ + } else if (pa && pa->start && l->ext_offset) { + int j; + + j = get_partition_unused_primary(cxt, pa); + if (j >= 0) { + rc = add_partition(cxt, j, pa); + goto done; + } + + } for (i = 0; i < 4; i++) { struct dos_partition *p = self_partition(cxt, i); @@ -1611,7 +1632,6 @@ static int dos_get_partition(struct fdisk_context *cxt, size_t n, return 0; } - /* * Fix the chain of logicals. * ext_offset is unchanged, the set of sectors used is unchanged