static int vmdk_open(BlockDriverState *bs, int flags)

{

    int ret;

    BDRVVmdkState *s = bs->opaque;



    if (vmdk_open_sparse(bs, bs->file, flags) == 0) {

        s->desc_offset = 0x200;

    } else {

        ret = vmdk_open_desc_file(bs, flags, 0);

        if (ret) {

            goto fail;

        }

    }

    /* try to open parent images, if exist */

    ret = vmdk_parent_open(bs);

    if (ret) {

        goto fail;

    }

    s->parent_cid = vmdk_read_cid(bs, 1);

    qemu_co_mutex_init(&s->lock);

    return ret;



fail:

    vmdk_free_extents(bs);

    return ret;

}

static int vmdk_open(BlockDriverState *bs, int flags)

{

    int ret;

    BDRVVmdkState *s = bs->opaque;



    if (vmdk_open_sparse(bs, bs->file, flags) == 0) {

        s->desc_offset = 0x200;

    } else {

        ret = vmdk_open_desc_file(bs, flags, 0);

        if (ret) {

            goto fail;

        }

    }

    

    ret = vmdk_parent_open(bs);

    if (ret) {

        goto fail;

    }

    s->parent_cid = vmdk_read_cid(bs, 1);

    qemu_co_mutex_init(&s->lock);

    return ret;



fail:

    vmdk_free_extents(bs);

    return ret;

}

static int FUNC_0(BlockDriverState *VAR_0, int VAR_1)

{

    int VAR_2;

    BDRVVmdkState *s = VAR_0->opaque;



    if (vmdk_open_sparse(VAR_0, VAR_0->file, VAR_1) == 0) {

        s->desc_offset = 0x200;

    } else {

        VAR_2 = vmdk_open_desc_file(VAR_0, VAR_1, 0);

        if (VAR_2) {

            goto fail;

        }

    }

    

    VAR_2 = vmdk_parent_open(VAR_0);

    if (VAR_2) {

        goto fail;

    }

    s->parent_cid = vmdk_read_cid(VAR_0, 1);

    qemu_co_mutex_init(&s->lock);

    return VAR_2;



fail:

    vmdk_free_extents(VAR_0);

    return VAR_2;

}

static int FUNC_0(BlockDriverState *VAR_0, int VAR_1)
{ int VAR_2; BDRVVmdkState *s = VAR_0->opaque; if (vmdk_open_sparse(VAR_0, VAR_0->file, VAR_1) == 0) { s->desc_offset = 0x200; } else { VAR_2 = vmdk_open_desc_file(VAR_0, VAR_1, 0); if (VAR_2) { goto fail; } } VAR_2 = vmdk_parent_open(VAR_0); if (VAR_2) { goto fail; } s->parent_cid = vmdk_read_cid(VAR_0, 1); qemu_co_mutex_init(&s->lock); return VAR_2; fail:
vmdk_free_extents(VAR_0); return VAR_2; }