const char *name)
{
struct fdisk_context *cxt;
+ struct fdisk_label *lb = NULL;
assert(parent);
- assert(name);
cxt = calloc(1, sizeof(*cxt));
if (!cxt)
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;
}
int fdisk_create_disklabel(struct fdisk_context *cxt, const char *name)
{
int haslabel = 0;
+ struct fdisk_label *lb;
if (!cxt)
return -EINVAL;
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);
}