From: Karel Zak Date: Thu, 27 Jun 2013 08:52:34 +0000 (+0200) Subject: libfdisk: improve nested context initialization X-Git-Tag: v2.24-rc1~141 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8a9256f9fcc0a3fa209b3cbb53edc1d9c1ea20f6;p=thirdparty%2Futil-linux.git libfdisk: improve nested context initialization - all label prober() function in fdisk_new_nested_context() - don't reset device properties for nested contexts Signed-off-by: Karel Zak --- diff --git a/libfdisk/src/context.c b/libfdisk/src/context.c index f44505a5b3..dc79783c42 100644 --- a/libfdisk/src/context.c +++ b/libfdisk/src/context.c @@ -32,9 +32,9 @@ struct fdisk_context *fdisk_new_nested_context(struct fdisk_context *parent, const char *name) { struct fdisk_context *cxt; + struct fdisk_label *lb = NULL; assert(parent); - assert(name); cxt = calloc(1, sizeof(*cxt)); if (!cxt) @@ -59,8 +59,23 @@ struct fdisk_context *fdisk_new_nested_context(struct fdisk_context *parent, cxt->geom = parent->geom; - if (strcmp(name, "bsd") == 0) - cxt->label = cxt->labels[ cxt->nlabels++ ] = fdisk_new_bsd_label(cxt); + if (name && strcmp(name, "bsd") == 0) + lb = cxt->labels[ cxt->nlabels++ ] = fdisk_new_bsd_label(cxt); + + if (lb) { + DBG(LABEL, dbgprint("probing for nested %s", lb->name)); + + cxt->label = lb; + + if (lb->op->probe(cxt) == 1) + __fdisk_context_switch_label(cxt, lb); + else { + DBG(LABEL, dbgprint("not found %s label", lb->name)); + if (lb->op->deinit) + lb->op->deinit(lb); + cxt->label = NULL; + } + } return cxt; } diff --git a/libfdisk/src/label.c b/libfdisk/src/label.c index bae9684804..147918e032 100644 --- a/libfdisk/src/label.c +++ b/libfdisk/src/label.c @@ -212,6 +212,7 @@ int fdisk_delete_partition(struct fdisk_context *cxt, size_t partnum) int fdisk_create_disklabel(struct fdisk_context *cxt, const char *name) { int haslabel = 0; + struct fdisk_label *lb; if (!cxt) return -EINVAL; @@ -229,16 +230,18 @@ int fdisk_create_disklabel(struct fdisk_context *cxt, const char *name) haslabel = 1; } - cxt->label = fdisk_context_get_label(cxt, name); - if (!cxt->label) + lb = fdisk_context_get_label(cxt, name); + if (!lb) return -EINVAL; - - DBG(LABEL, dbgprint("changing to %s label\n", cxt->label->name)); - if (!cxt->label->op->create) + if (!lb->op->create) return -ENOSYS; - if (haslabel) + __fdisk_context_switch_label(cxt, lb); + + if (haslabel && !cxt->parent) fdisk_reset_device_properties(cxt); + + DBG(LABEL, dbgprint("create a new %s label", lb->name)); return cxt->label->op->create(cxt); }