static int bdrv_open_driver(BlockDriverState *bs, BlockDriver *drv,

                            const char *node_name, QDict *options,

                            int open_flags, Error **errp)

{

    Error *local_err = NULL;

    int ret;



    bdrv_assign_node_name(bs, node_name, &local_err);

    if (local_err) {

        error_propagate(errp, local_err);

        return -EINVAL;

    }



    bs->drv = drv;

    bs->read_only = !(bs->open_flags & BDRV_O_RDWR);

    bs->opaque = g_malloc0(drv->instance_size);



    if (drv->bdrv_file_open) {

        assert(!drv->bdrv_needs_filename || bs->filename[0]);

        ret = drv->bdrv_file_open(bs, options, open_flags, &local_err);

    } else if (drv->bdrv_open) {

        ret = drv->bdrv_open(bs, options, open_flags, &local_err);

    } else {

        ret = 0;

    }



    if (ret < 0) {

        if (local_err) {

            error_propagate(errp, local_err);

        } else if (bs->filename[0]) {

            error_setg_errno(errp, -ret, "Could not open '%s'", bs->filename);

        } else {

            error_setg_errno(errp, -ret, "Could not open image");

        }

        goto free_and_fail;

    }



    ret = refresh_total_sectors(bs, bs->total_sectors);

    if (ret < 0) {

        error_setg_errno(errp, -ret, "Could not refresh total sector count");

        goto free_and_fail;

    }



    bdrv_refresh_limits(bs, &local_err);

    if (local_err) {

        error_propagate(errp, local_err);

        ret = -EINVAL;

        goto free_and_fail;

    }



    assert(bdrv_opt_mem_align(bs) != 0);

    assert(bdrv_min_mem_align(bs) != 0);

    assert(is_power_of_2(bs->bl.request_alignment));



    return 0;



free_and_fail:

    /* FIXME Close bs first if already opened*/

    g_free(bs->opaque);

    bs->opaque = NULL;

    bs->drv = NULL;

    return ret;

}

static int bdrv_open_driver(BlockDriverState *bs, BlockDriver *drv,

                            const char *node_name, QDict *options,

                            int open_flags, Error **errp)

{

    Error *local_err = NULL;

    int ret;



    bdrv_assign_node_name(bs, node_name, &local_err);

    if (local_err) {

        error_propagate(errp, local_err);

        return -EINVAL;

    }



    bs->drv = drv;

    bs->read_only = !(bs->open_flags & BDRV_O_RDWR);

    bs->opaque = g_malloc0(drv->instance_size);



    if (drv->bdrv_file_open) {

        assert(!drv->bdrv_needs_filename || bs->filename[0]);

        ret = drv->bdrv_file_open(bs, options, open_flags, &local_err);

    } else if (drv->bdrv_open) {

        ret = drv->bdrv_open(bs, options, open_flags, &local_err);

    } else {

        ret = 0;

    }



    if (ret < 0) {

        if (local_err) {

            error_propagate(errp, local_err);

        } else if (bs->filename[0]) {

            error_setg_errno(errp, -ret, "Could not open '%s'", bs->filename);

        } else {

            error_setg_errno(errp, -ret, "Could not open image");

        }

        goto free_and_fail;

    }



    ret = refresh_total_sectors(bs, bs->total_sectors);

    if (ret < 0) {

        error_setg_errno(errp, -ret, "Could not refresh total sector count");

        goto free_and_fail;

    }



    bdrv_refresh_limits(bs, &local_err);

    if (local_err) {

        error_propagate(errp, local_err);

        ret = -EINVAL;

        goto free_and_fail;

    }



    assert(bdrv_opt_mem_align(bs) != 0);

    assert(bdrv_min_mem_align(bs) != 0);

    assert(is_power_of_2(bs->bl.request_alignment));



    return 0;



free_and_fail:

    

    g_free(bs->opaque);

    bs->opaque = NULL;

    bs->drv = NULL;

    return ret;

}

        goto free_and_fail;         goto free_and_fail;         ret = -EINVAL;         goto free_and_fail; free_and_fail:     bs->drv = NULL;
static int FUNC_0(BlockDriverState *VAR_0, BlockDriver *VAR_1,

                            const char *VAR_2, QDict *VAR_3,

                            int VAR_4, Error **VAR_5)

{

    Error *local_err = NULL;

    int VAR_6;



    bdrv_assign_node_name(VAR_0, VAR_2, &local_err);

    if (local_err) {

        error_propagate(VAR_5, local_err);

        return -EINVAL;

    }



    VAR_0->VAR_1 = VAR_1;

    VAR_0->read_only = !(VAR_0->VAR_4 & BDRV_O_RDWR);

    VAR_0->opaque = g_malloc0(VAR_1->instance_size);



    if (VAR_1->bdrv_file_open) {

        assert(!VAR_1->bdrv_needs_filename || VAR_0->filename[0]);

        VAR_6 = VAR_1->bdrv_file_open(VAR_0, VAR_3, VAR_4, &local_err);

    } else if (VAR_1->bdrv_open) {

        VAR_6 = VAR_1->bdrv_open(VAR_0, VAR_3, VAR_4, &local_err);

    } else {

        VAR_6 = 0;

    }



    if (VAR_6 < 0) {

        if (local_err) {

            error_propagate(VAR_5, local_err);

        } else if (VAR_0->filename[0]) {

            error_setg_errno(VAR_5, -VAR_6, "Could not open '%s'", VAR_0->filename);

        } else {

            error_setg_errno(VAR_5, -VAR_6, "Could not open image");

        }

        goto free_and_fail;

    }



    VAR_6 = refresh_total_sectors(VAR_0, VAR_0->total_sectors);

    if (VAR_6 < 0) {

        error_setg_errno(VAR_5, -VAR_6, "Could not refresh total sector count");

        goto free_and_fail;

    }



    bdrv_refresh_limits(VAR_0, &local_err);

    if (local_err) {

        error_propagate(VAR_5, local_err);

        VAR_6 = -EINVAL;

        goto free_and_fail;

    }



    assert(bdrv_opt_mem_align(VAR_0) != 0);

    assert(bdrv_min_mem_align(VAR_0) != 0);

    assert(is_power_of_2(VAR_0->bl.request_alignment));



    return 0;



free_and_fail:

    

    g_free(VAR_0->opaque);

    VAR_0->opaque = NULL;

    VAR_0->VAR_1 = NULL;

    return VAR_6;

}

static int FUNC_0(BlockDriverState *VAR_0, BlockDriver *VAR_1,
const char *VAR_2, QDict *VAR_3,
int VAR_4, Error **VAR_5)
{ Error *local_err = NULL; int VAR_6; bdrv_assign_node_name(VAR_0, VAR_2, &local_err); if (local_err) { error_propagate(VAR_5, local_err); return -EINVAL; } VAR_0->VAR_1 = VAR_1; VAR_0->read_only = !(VAR_0->VAR_4 & BDRV_O_RDWR); VAR_0->opaque = g_malloc0(VAR_1->instance_size); if (VAR_1->bdrv_file_open) { assert(!VAR_1->bdrv_needs_filename || VAR_0->filename[0]); VAR_6 = VAR_1->bdrv_file_open(VAR_0, VAR_3, VAR_4, &local_err); } else if (VAR_1->bdrv_open) { VAR_6 = VAR_1->bdrv_open(VAR_0, VAR_3, VAR_4, &local_err); } else { VAR_6 = 0; } if (VAR_6 < 0) { if (local_err) { error_propagate(VAR_5, local_err); } else if (VAR_0->filename[0]) { error_setg_errno(VAR_5, -VAR_6, "Could not open '%s'", VAR_0->filename); } else { error_setg_errno(VAR_5, -VAR_6, "Could not open image"); } goto free_and_fail; } VAR_6 = refresh_total_sectors(VAR_0, VAR_0->total_sectors); if (VAR_6 < 0) { error_setg_errno(VAR_5, -VAR_6, "Could not refresh total sector count"); goto free_and_fail; } bdrv_refresh_limits(VAR_0, &local_err); if (local_err) { error_propagate(VAR_5, local_err); VAR_6 = -EINVAL; goto free_and_fail; } assert(bdrv_opt_mem_align(VAR_0) != 0); assert(bdrv_min_mem_align(VAR_0) != 0); assert(is_power_of_2(VAR_0->bl.request_alignment)); return 0; free_and_fail:
g_free(VAR_0->opaque); VAR_0->opaque = NULL; VAR_0->VAR_1 = NULL; return VAR_6; }