]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (dos) set partition start/size only when requested
authorKarel Zak <kzak@redhat.com>
Tue, 14 Oct 2014 17:46:17 +0000 (19:46 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 14 Oct 2014 17:46:17 +0000 (19:46 +0200)
libfdisk/src/dos.c
libfdisk/src/fdiskP.h
libfdisk/src/partition.c

index 0ce032867d47f3e414b63e45765f26125ff5d4cc..0ae0615a24847913b1dc94ce4c6506001626c619 100644 (file)
@@ -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;
 }
index e1b4636213eb2a4f7c56a43232b2c66a88de2626..253c515f8b00d47637fa690c56042bd37a278641 100644 (file)
@@ -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 */
index c6142900e8fc5c546740d15e8100da9ad4c1dc32..cad4214edf2e0e9fb4a7af81122688bc2d5d7eee 100644 (file)
@@ -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)