]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: add support for nested contexts
authorKarel Zak <kzak@redhat.com>
Tue, 5 Mar 2013 14:13:26 +0000 (15:13 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 11 Mar 2013 12:00:57 +0000 (13:00 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/context.c
libfdisk/src/fdiskP.h
libfdisk/src/libfdisk.h

index 352f03ac35a7b83f6c8f24e5ed80fd313f9d7458..139932620b3989e6c7492e2602d42a89e5b01154 100644 (file)
@@ -21,7 +21,6 @@ struct fdisk_context *fdisk_new_context(void)
        cxt->labels[ cxt->nlabels++ ] = fdisk_new_gpt_label(cxt);
        cxt->labels[ cxt->nlabels++ ] = fdisk_new_dos_label(cxt);
        cxt->labels[ cxt->nlabels++ ] = fdisk_new_aix_label(cxt);
-       cxt->labels[ cxt->nlabels++ ] = fdisk_new_bsd_label(cxt);
        cxt->labels[ cxt->nlabels++ ] = fdisk_new_mac_label(cxt);
        cxt->labels[ cxt->nlabels++ ] = fdisk_new_sgi_label(cxt);
        cxt->labels[ cxt->nlabels++ ] = fdisk_new_sun_label(cxt);
@@ -29,6 +28,42 @@ 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)
+{
+       struct fdisk_context *cxt;
+
+       assert(parent);
+       assert(name);
+
+       cxt = calloc(1, sizeof(*cxt));
+       if (!cxt)
+               return NULL;
+
+       DBG(LABEL, dbgprint("new context %p allocated", cxt));
+       cxt->dev_fd = parent->dev_fd;
+       cxt->parent = parent;
+
+       cxt->io_size =          parent->io_size;
+       cxt->optimal_io_size =  parent->optimal_io_size;
+       cxt->min_io_size =      parent->min_io_size;
+       cxt->phy_sector_size =  parent->phy_sector_size;
+       cxt->sector_size =      parent->sector_size;
+       cxt->alignment_offset = parent->alignment_offset;
+       cxt->grain =            parent->grain;
+       cxt->first_lba =        parent->first_lba;
+       cxt->total_sectors =    parent->total_sectors;
+
+       cxt->geom = parent->geom;
+
+       if (strcmp(name, "bsd") == 0)
+               cxt->label = cxt->labels[ cxt->nlabels++ ] = fdisk_new_bsd_label(cxt);
+
+       return cxt;
+}
+
+
 /*
  * Returns the current label if no name specified.
  */
@@ -77,7 +112,7 @@ static void reset_context(struct fdisk_context *cxt)
                fdisk_deinit_label(cxt->labels[i]);
 
        /* free device specific stuff */
-       if (cxt->dev_fd > -1)
+       if (!cxt->parent && cxt->dev_fd > -1)
                close(cxt->dev_fd);
        free(cxt->dev_path);
        free(cxt->firstsector);
index 7a528eb57bd03bbf61597db14fe5b170c9fd65bb..89a96d964779616dbdd847e5f94ba45ae82e67ac 100644 (file)
@@ -274,6 +274,8 @@ struct fdisk_context {
 
        int     (*ask_cb)(struct fdisk_context *, struct fdisk_ask *, void *);  /* fdisk dialogs callback */
        void    *ask_data;              /* ask_cb() data */
+
+       struct fdisk_context    *parent;        /* for nested PT */
 };
 
 /* context.c */
index 92c03b69325a89bcb31bc45ba57d67c83f30e7d3..a08a2afa55cb9fee2e8ed7923e0701b50342b9ae 100644 (file)
@@ -69,6 +69,8 @@ extern void fdisk_init_debug(int mask);
 
 /* context.h */
 extern struct fdisk_context *fdisk_new_context(void);
+extern struct fdisk_context *fdisk_new_nested_context(
+                       struct fdisk_context *parent, const char *name);
 extern void fdisk_free_context(struct fdisk_context *cxt);
 
 extern int fdisk_context_set_ask(struct fdisk_context *cxt,