]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: support nested MBR
authorKarel Zak <kzak@redhat.com>
Thu, 10 Oct 2013 10:42:18 +0000 (12:42 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 23 Oct 2013 08:45:14 +0000 (10:45 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/context.c

index 9106e29b3ec088fe14be2980dcffd3bc34a18802..faf03af449d1bbe6964d102bd011347a07bfdf4e 100644 (file)
@@ -27,7 +27,6 @@ struct fdisk_context *fdisk_new_context(void)
        return cxt;
 }
 
-/* only BSD is supported now */
 struct fdisk_context *fdisk_new_nested_context(struct fdisk_context *parent,
                                const char *name)
 {
@@ -53,14 +52,19 @@ struct fdisk_context *fdisk_new_nested_context(struct fdisk_context *parent,
        cxt->grain =            parent->grain;
        cxt->first_lba =        parent->first_lba;
        cxt->total_sectors =    parent->total_sectors;
+       cxt->firstsector =      parent->firstsector;
 
        cxt->ask_cb =           parent->ask_cb;
        cxt->ask_data =         parent->ask_data;
 
        cxt->geom = parent->geom;
 
-       if (name && strcmp(name, "bsd") == 0)
-               lb = cxt->labels[ cxt->nlabels++ ] = fdisk_new_bsd_label(cxt);
+       if (name) {
+               if (strcmp(name, "bsd") == 0)
+                       lb = cxt->labels[ cxt->nlabels++ ] = fdisk_new_bsd_label(cxt);
+               else if (strcmp(name, "dos") == 0)
+                       lb = cxt->labels[ cxt->nlabels++ ] = fdisk_new_dos_label(cxt);
+       }
 
        if (lb) {
                DBG(LABEL, dbgprint("probing for nested %s", lb->name));
@@ -160,7 +164,9 @@ static void reset_context(struct fdisk_context *cxt)
        if (!cxt->parent && cxt->dev_fd > -1)
                close(cxt->dev_fd);
        free(cxt->dev_path);
-       free(cxt->firstsector);
+
+       if (cxt->parent == NULL || cxt->parent->firstsector != cxt->firstsector)
+               free(cxt->firstsector);
 
        /* initialize */
        cxt->dev_fd = -1;