static int bdrv_open_common(BlockDriverState *bs, const char *filename,

    int flags, BlockDriver *drv)

{

    int ret, open_flags;



    assert(drv != NULL);



    bs->file = NULL;

    bs->total_sectors = 0;

    bs->is_temporary = 0;

    bs->encrypted = 0;

    bs->valid_key = 0;

    bs->open_flags = flags;

    /* buffer_alignment defaulted to 512, drivers can change this value */

    bs->buffer_alignment = 512;



    pstrcpy(bs->filename, sizeof(bs->filename), filename);



    if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv)) {

        return -ENOTSUP;

    }



    bs->drv = drv;

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



    /*

     * Yes, BDRV_O_NOCACHE aka O_DIRECT means we have to present a

     * write cache to the guest.  We do need the fdatasync to flush

     * out transactions for block allocations, and we maybe have a

     * volatile write cache in our backing device to deal with.

     */

    if (flags & (BDRV_O_CACHE_WB|BDRV_O_NOCACHE))

        bs->enable_write_cache = 1;



    /*

     * Clear flags that are internal to the block layer before opening the

     * image.

     */

    open_flags = flags & ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);



    /*

     * Snapshots should be writeable.

     */

    if (bs->is_temporary) {

        open_flags |= BDRV_O_RDWR;

    }



    /* Open the image, either directly or using a protocol */

    if (drv->bdrv_file_open) {

        ret = drv->bdrv_file_open(bs, filename, open_flags);

    } else {

        ret = bdrv_file_open(&bs->file, filename, open_flags);

        if (ret >= 0) {

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

        }

    }



    if (ret < 0) {

        goto free_and_fail;

    }



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



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

    if (ret < 0) {

        goto free_and_fail;

    }



#ifndef _WIN32

    if (bs->is_temporary) {

        unlink(filename);

    }

#endif

    return 0;



free_and_fail:

    if (bs->file) {

        bdrv_delete(bs->file);

        bs->file = NULL;

    }

    qemu_free(bs->opaque);

    bs->opaque = NULL;

    bs->drv = NULL;

    return ret;

}

static int bdrv_open_common(BlockDriverState *bs, const char *filename,

    int flags, BlockDriver *drv)

{

    int ret, open_flags;



    assert(drv != NULL);



    bs->file = NULL;

    bs->total_sectors = 0;

    bs->is_temporary = 0;

    bs->encrypted = 0;

    bs->valid_key = 0;

    bs->open_flags = flags;

    

    bs->buffer_alignment = 512;



    pstrcpy(bs->filename, sizeof(bs->filename), filename);



    if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv)) {

        return -ENOTSUP;

    }



    bs->drv = drv;

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



    











    if (flags & (BDRV_O_CACHE_WB|BDRV_O_NOCACHE))

        bs->enable_write_cache = 1;



    







    open_flags = flags & ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);



    





    if (bs->is_temporary) {

        open_flags |= BDRV_O_RDWR;

    }



    

    if (drv->bdrv_file_open) {

        ret = drv->bdrv_file_open(bs, filename, open_flags);

    } else {

        ret = bdrv_file_open(&bs->file, filename, open_flags);

        if (ret >= 0) {

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

        }

    }



    if (ret < 0) {

        goto free_and_fail;

    }



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



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

    if (ret < 0) {

        goto free_and_fail;

    }



#ifndef _WIN32

    if (bs->is_temporary) {

        unlink(filename);

    }

#endif

    return 0;



free_and_fail:

    if (bs->file) {

        bdrv_delete(bs->file);

        bs->file = NULL;

    }

    qemu_free(bs->opaque);

    bs->opaque = NULL;

    bs->drv = NULL;

    return ret;

}

    bs->is_temporary = 0;
static int FUNC_0(BlockDriverState *VAR_0, const char *VAR_1,

    int VAR_2, BlockDriver *VAR_3)

{

    int VAR_4, VAR_5;



    assert(VAR_3 != NULL);



    VAR_0->file = NULL;

    VAR_0->total_sectors = 0;

    VAR_0->is_temporary = 0;

    VAR_0->encrypted = 0;

    VAR_0->valid_key = 0;

    VAR_0->VAR_5 = VAR_2;

    

    VAR_0->buffer_alignment = 512;



    pstrcpy(VAR_0->VAR_1, sizeof(VAR_0->VAR_1), VAR_1);



    if (use_bdrv_whitelist && !bdrv_is_whitelisted(VAR_3)) {

        return -ENOTSUP;

    }



    VAR_0->VAR_3 = VAR_3;

    VAR_0->opaque = qemu_mallocz(VAR_3->instance_size);



    











    if (VAR_2 & (BDRV_O_CACHE_WB|BDRV_O_NOCACHE))

        VAR_0->enable_write_cache = 1;



    







    VAR_5 = VAR_2 & ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);



    





    if (VAR_0->is_temporary) {

        VAR_5 |= BDRV_O_RDWR;

    }



    

    if (VAR_3->bdrv_file_open) {

        VAR_4 = VAR_3->bdrv_file_open(VAR_0, VAR_1, VAR_5);

    } else {

        VAR_4 = bdrv_file_open(&VAR_0->file, VAR_1, VAR_5);

        if (VAR_4 >= 0) {

            VAR_4 = VAR_3->bdrv_open(VAR_0, VAR_5);

        }

    }



    if (VAR_4 < 0) {

        goto free_and_fail;

    }



    VAR_0->keep_read_only = VAR_0->read_only = !(VAR_5 & BDRV_O_RDWR);



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

    if (VAR_4 < 0) {

        goto free_and_fail;

    }



#ifndef _WIN32

    if (VAR_0->is_temporary) {

        unlink(VAR_1);

    }

#endif

    return 0;



free_and_fail:

    if (VAR_0->file) {

        bdrv_delete(VAR_0->file);

        VAR_0->file = NULL;

    }

    qemu_free(VAR_0->opaque);

    VAR_0->opaque = NULL;

    VAR_0->VAR_3 = NULL;

    return VAR_4;

}

static int FUNC_0(BlockDriverState *VAR_0, const char *VAR_1,
int VAR_2, BlockDriver *VAR_3)
{ int VAR_4, VAR_5; assert(VAR_3 != NULL); VAR_0->file = NULL; VAR_0->total_sectors = 0; VAR_0->is_temporary = 0; VAR_0->encrypted = 0; VAR_0->valid_key = 0; VAR_0->VAR_5 = VAR_2; VAR_0->buffer_alignment = 512; pstrcpy(VAR_0->VAR_1, sizeof(VAR_0->VAR_1), VAR_1); if (use_bdrv_whitelist && !bdrv_is_whitelisted(VAR_3)) { return -ENOTSUP; } VAR_0->VAR_3 = VAR_3; VAR_0->opaque = qemu_mallocz(VAR_3->instance_size); if (VAR_2 & (BDRV_O_CACHE_WB|BDRV_O_NOCACHE))
VAR_0->enable_write_cache = 1; VAR_5 = VAR_2 & ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING); if (VAR_0->is_temporary) { VAR_5 |= BDRV_O_RDWR; } if (VAR_3->bdrv_file_open) { VAR_4 = VAR_3->bdrv_file_open(VAR_0, VAR_1, VAR_5); } else { VAR_4 = bdrv_file_open(&VAR_0->file, VAR_1, VAR_5); if (VAR_4 >= 0) { VAR_4 = VAR_3->bdrv_open(VAR_0, VAR_5); } } if (VAR_4 < 0) { goto free_and_fail; } VAR_0->keep_read_only = VAR_0->read_only = !(VAR_5 & BDRV_O_RDWR); VAR_4 = refresh_total_sectors(VAR_0, VAR_0->total_sectors); if (VAR_4 < 0) { goto free_and_fail; } #ifndef _WIN32
if (VAR_0->is_temporary) { unlink(VAR_1); } #endif
return 0; free_and_fail:
if (VAR_0->file) { bdrv_delete(VAR_0->file); VAR_0->file = NULL; } qemu_free(VAR_0->opaque); VAR_0->opaque = NULL; VAR_0->VAR_3 = NULL; return VAR_4; }