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 <kzak@redhat.com>
This commit is contained in:
Karel Zak 2013-06-27 10:52:34 +02:00
parent 60c1b03620
commit 8a9256f9fc
2 changed files with 27 additions and 9 deletions

View File

@ -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;
}

View File

@ -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);
}