openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/util-linux/2.33.2-r0/util-linux-2.33.2/libfdisk/src/context.c
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);

    cxt = calloc(1, sizeof(*cxt));
    if (!cxt)
        return NULL;

    DBG(CXT, ul_debugobj(parent, "alloc nested [%p] [name=%s]", cxt, name));
    cxt->refcount = 1;

    fdisk_ref_context(parent);
    cxt->parent = parent;

    if (init_nested_from_parent(cxt, 1) != 0)
    {
        cxt->parent = NULL;
        fdisk_unref_context(cxt);
        return NULL;
    }

    if (name)
    {
        if (strcasecmp(name, "bsd") == 0)
            lb = cxt->labels[cxt->nlabels++] = fdisk_new_bsd_label(cxt);
        else if (strcasecmp(name, "dos") == 0 || strcasecmp(name, "mbr") == 0)
            lb = cxt->labels[cxt->nlabels++] = fdisk_new_dos_label(cxt);
    }

    if (lb && parent->dev_fd >= 0)
    {
        DBG(CXT, ul_debugobj(cxt, "probing for nested %s", lb->name));

        cxt->label = lb;

        if (lb->op->probe(cxt) == 1)
            __fdisk_switch_label(cxt, lb);
        else
        {
            DBG(CXT, ul_debugobj(cxt, "not found %s label", lb->name));
            if (lb->op->deinit)
                lb->op->deinit(lb);
            cxt->label = NULL;
        }
    }

    return cxt;
}
/**
 * fdisk_new_nested_context:
 * @parent: parental context
 * @name: optional label name (e.g. "bsd")
 *
 * Create a new nested fdisk context for nested disk labels (e.g. BSD or PMBR).
 * The function also probes for the nested label on the device if device is
 * already assigned to parent.
 *
 * The new context is initialized according to @parent and both context shares
 * some settings and file descriptor to the device. The child propagate some
 * changes (like fdisk_assign_device()) to parent, but it does not work
 * vice-versa. The behavior is undefined if you assign another device to
 * parent.
 *
 * Returns: new context for nested partition table.
 */
@parent: parental context
@name: optional label name

Create a new nested fdisk context for nested disk labels .
The function also probes for the nested label on the device if device is
already assigned to parent.

The new context is initialized according to @parent and both context shares
some settings and file descriptor to the device. The child propagate some
changes (like fdisk_assign_device()) to parent, but it does not work
vice-versa. The behavior is undefined if you assign another device to
parent.

new context for nested partition table.
@parent : parental context @name : optional label name Create a new nested fdisk context for nested disk labels . The function also probes for the nested label on the device if device is already assigned to parent . The new context is initialized according to @parent and both context shares some settings and file descriptor to the device . The child propagate some changes ( like fdisk_assign_device () ) to parent but it does not work vice - versa . The behavior is undefined if you assign another device to parent . new context for nested partition table .
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);
    cxt = calloc(1, sizeof(*cxt));
    if (!cxt)
        return NULL;
    DBG(CXT, ul_debugobj(parent, "alloc nested [%p] [name=%s]", cxt, name));
    cxt->refcount = 1;
    fdisk_ref_context(parent);
    cxt->parent = parent;
    if (init_nested_from_parent(cxt, 1) != 0)
    {
        cxt->parent = NULL;
        fdisk_unref_context(cxt);
        return NULL;
    }
    if (name)
    {
        if (strcasecmp(name, "bsd") == 0)
            lb = cxt->labels[cxt->nlabels++] = fdisk_new_bsd_label(cxt);
        else if (strcasecmp(name, "dos") == 0 || strcasecmp(name, "mbr") == 0)
            lb = cxt->labels[cxt->nlabels++] = fdisk_new_dos_label(cxt);
    }
    if (lb && parent->dev_fd >= 0)
    {
        DBG(CXT, ul_debugobj(cxt, "probing for nested %s", lb->name));
        cxt->label = lb;
        if (lb->op->probe(cxt) == 1)
            __fdisk_switch_label(cxt, lb);
        else
        {
            DBG(CXT, ul_debugobj(cxt, "not found %s label", lb->name));
            if (lb->op->deinit)
                lb->op->deinit(lb);
            cxt->label = NULL;
        }
    }
    return cxt;
}
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 ) ; cxt = calloc ( 1 , sizeof ( * cxt ) ) ; if ( ! cxt ) return NULL ; DBG ( CXT , ul_debugobj ( parent , " " , cxt , name ) ) ; cxt -> refcount = 1 ; fdisk_ref_context ( parent ) ; cxt -> parent = parent ; if ( init_nested_from_parent ( cxt , 1 ) != 0 ) { cxt -> parent = NULL ; fdisk_unref_context ( cxt ) ; return NULL ; } if ( name ) { if ( strcasecmp ( name , " " ) == 0 ) lb = cxt -> labels [ cxt -> nlabels ++ ] = fdisk_new_bsd_label ( cxt ) ; else if ( strcasecmp ( name , " " ) == 0 || strcasecmp ( name , " " ) == 0 ) lb = cxt -> labels [ cxt -> nlabels ++ ] = fdisk_new_dos_label ( cxt ) ; } if ( lb && parent -> dev_fd >= 0 ) { DBG ( CXT , ul_debugobj ( cxt , " " , lb -> name ) ) ; cxt -> label = lb ; if ( lb -> op -> probe ( cxt ) == 1 ) __fdisk_switch_label ( cxt , lb ) ; else { DBG ( CXT , ul_debugobj ( cxt , " " , lb -> name ) ) ; if ( lb -> op -> deinit ) lb -> op -> deinit ( lb ) ; cxt -> label = NULL ; } } return cxt ; }
fdisk_new_nested_context:
 @parent: parental context
 @name: optional label name (e.g.
fdisk_new_nested_context : @parent : parental context @name : optional label name ( e . g .