From: Karel Zak Date: Tue, 14 Oct 2014 17:46:17 +0000 (+0200) Subject: libfdisk: (dos) set partition start/size only when requested X-Git-Tag: v2.26-rc1~307 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=150d98ee3f24bfdc5b181b195e865657d8c6245c;p=thirdparty%2Futil-linux.git libfdisk: (dos) set partition start/size only when requested --- diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index 0ce032867d..0ae0615a24 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -1808,7 +1808,6 @@ static int dos_set_partition(struct fdisk_context *cxt, size_t n, { struct dos_partition *p; struct pte *pe; - sector_t start, size; assert(cxt); assert(pa); @@ -1827,16 +1826,28 @@ static int dos_set_partition(struct fdisk_context *cxt, size_t n, if (pa->type && !pa->type->code) fdisk_warnx(cxt, _("Type 0 means free space to many systems. " "Having partitions of type 0 is probably unwise.")); - pe = self_pte(cxt, n); + p = self_partition(cxt, n); - start = pa->start ? pa->start : get_abs_partition_start(pe); - size = pa->size ? pa->size : dos_partition_get_size(p); + if (pa->start || pa->size) { + sector_t start, size; + + pe = self_pte(cxt, n); + + start = pa->start ? pa->start : get_abs_partition_start(pe); + size = pa->size ? pa->size : dos_partition_get_size(p); - set_partition(cxt, n, 0, start, start + size - 1, + set_partition(cxt, n, 0, start, start + size - 1, pa->type ? pa->type->code : p->sys_ind, pa->boot); + } else { + if (pa->type) + p->sys_ind = pa->type->code; + if (pa->boot != FDISK_EMPTY_BOOTFLAG) + p->boot_ind = pa->boot == 1 ? ACTIVE_FLAG : 0; + } + partition_set_changed(cxt, n, 1); return 0; } diff --git a/libfdisk/src/fdiskP.h b/libfdisk/src/fdiskP.h index e1b4636213..253c515f8b 100644 --- a/libfdisk/src/fdiskP.h +++ b/libfdisk/src/fdiskP.h @@ -139,6 +139,8 @@ struct fdisk_partition { char *start_addr; /* start C/H/S in string */ char *end_addr; /* end C/H/S in string */ + int boot; /* MBR only: 1 = yes, 0 = no, -1 undefined */ + unsigned int partno_follow_default : 1, /* use default partno */ start_follow_default : 1, /* use default start */ end_follow_default : 1, /* use default end */ @@ -146,12 +148,12 @@ struct fdisk_partition { freespace : 1, /* this is free space */ container : 1, /* container partition (e.g. extended partition) */ wholedisk : 1, /* special system partition */ - boot : 1, /* bootable (MBR only) */ used : 1; /* partition already used */ }; #define FDISK_EMPTY_PARTNO ((size_t) -1) #define FDISK_EMPTY_PARTITION { .partno = FDISK_EMPTY_PARTNO } +#define FDISK_EMPTY_BOOTFLAG (-1) struct fdisk_table { struct list_head parts; /* partitions */ diff --git a/libfdisk/src/partition.c b/libfdisk/src/partition.c index c6142900e8..cad4214edf 100644 --- a/libfdisk/src/partition.c +++ b/libfdisk/src/partition.c @@ -17,6 +17,7 @@ struct fdisk_partition *fdisk_new_partition(void) INIT_LIST_HEAD(&pa->parts); pa->partno = FDISK_EMPTY_PARTNO; pa->parent_partno = FDISK_EMPTY_PARTNO; + pa->boot = FDISK_EMPTY_BOOTFLAG; DBG(PART, ul_debugobj(pa, "alloc")); return pa; } @@ -43,6 +44,7 @@ void fdisk_reset_partition(struct fdisk_partition *pa) memset(pa, 0, sizeof(*pa)); pa->partno = FDISK_EMPTY_PARTNO; pa->parent_partno = FDISK_EMPTY_PARTNO; + pa->boot = FDISK_EMPTY_BOOTFLAG; pa->refcount = ref; INIT_LIST_HEAD(&pa->parts); } @@ -408,7 +410,7 @@ int fdisk_partition_is_used(struct fdisk_partition *pa) int fdisk_partition_is_bootable(struct fdisk_partition *pa) { - return pa && pa->boot; + return pa && pa->boot == 1; } int fdisk_partition_is_freespace(struct fdisk_partition *pa)