]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (dos) reset logical partition stuff after error
authorKarel Zak <kzak@redhat.com>
Thu, 9 Oct 2014 12:03:45 +0000 (14:03 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 9 Oct 2014 12:03:45 +0000 (14:03 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/dos.c

index e350d08deb5fadec3ccdf02e30b9766fb02af8fa..f489fdf172adc5a85501ef8e68616da23ae92eeb 100644 (file)
@@ -1182,6 +1182,7 @@ static int add_logical(struct fdisk_context *cxt,
                       size_t *partno)
 {
        struct pte *pe;
+       int rc;
 
        assert(cxt);
        assert(partno);
@@ -1212,7 +1213,18 @@ static int add_logical(struct fdisk_context *cxt,
                fdisk_info(cxt, _("Adding logical partition %zu"),
                                cxt->label->nparts_max);
        *partno = cxt->label->nparts_max - 1;
-       return add_partition(cxt, *partno, pa);
+       rc = add_partition(cxt, *partno, pa);
+
+       if (rc) {
+               /* reset on error */
+               cxt->label->nparts_max--;
+               pe->pt_entry = NULL;
+               pe->ex_entry = NULL;
+               pe->offset = 0;
+               pe->changed = 0;
+       }
+
+       return rc;
 }
 
 static void check(struct fdisk_context *cxt, size_t n,
@@ -1653,12 +1665,9 @@ static int dos_write_disklabel(struct fdisk_context *cxt)
        for (i = 4; i < cxt->label->nparts_max; i++) {
                struct pte *pe = self_pte(cxt, i);
 
-               if (!pe->changed)
+               if (!pe->changed || !pe->offset || !pe->sectorbuffer)
                        continue;
 
-               assert(pe->sectorbuffer);
-               assert(pe->offset);
-
                mbr_set_magic(pe->sectorbuffer);
                rc = write_sector(cxt, pe->offset, pe->sectorbuffer);
                if (rc)