void qmp_change_blockdev(const char *device, const char *filename,

                         const char *format, Error **errp)

{

    BlockBackend *blk;

    BlockDriverState *bs;

    BlockDriver *drv = NULL;

    int bdrv_flags;

    Error *err = NULL;



    blk = blk_by_name(device);

    if (!blk) {

        error_set(errp, QERR_DEVICE_NOT_FOUND, device);

        return;

    }

    bs = blk_bs(blk);



    if (format) {

        drv = bdrv_find_whitelisted_format(format, bs->read_only);

        if (!drv) {

            error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);

            return;

        }

    }



    eject_device(blk, 0, &err);

    if (err) {

        error_propagate(errp, err);

        return;

    }



    bdrv_flags = bdrv_is_read_only(bs) ? 0 : BDRV_O_RDWR;

    bdrv_flags |= bdrv_is_snapshot(bs) ? BDRV_O_SNAPSHOT : 0;



    qmp_bdrv_open_encrypted(bs, filename, bdrv_flags, drv, NULL, errp);

}

void qmp_change_blockdev(const char *device, const char *filename,

                         const char *format, Error **errp)

{

    BlockBackend *blk;

    BlockDriverState *bs;

    BlockDriver *drv = NULL;

    int bdrv_flags;

    Error *err = NULL;



    blk = blk_by_name(device);

    if (!blk) {

        error_set(errp, QERR_DEVICE_NOT_FOUND, device);

        return;

    }

    bs = blk_bs(blk);



    if (format) {

        drv = bdrv_find_whitelisted_format(format, bs->read_only);

        if (!drv) {

            error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);

            return;

        }

    }



    eject_device(blk, 0, &err);

    if (err) {

        error_propagate(errp, err);

        return;

    }



    bdrv_flags = bdrv_is_read_only(bs) ? 0 : BDRV_O_RDWR;

    bdrv_flags |= bdrv_is_snapshot(bs) ? BDRV_O_SNAPSHOT : 0;



    qmp_bdrv_open_encrypted(bs, filename, bdrv_flags, drv, NULL, errp);

}

void FUNC_0(const char *VAR_0, const char *VAR_1,

                         const char *VAR_2, Error **VAR_3)

{

    BlockBackend *blk;

    BlockDriverState *bs;

    BlockDriver *drv = NULL;

    int VAR_4;

    Error *err = NULL;



    blk = blk_by_name(VAR_0);

    if (!blk) {

        error_set(VAR_3, QERR_DEVICE_NOT_FOUND, VAR_0);

        return;

    }

    bs = blk_bs(blk);



    if (VAR_2) {

        drv = bdrv_find_whitelisted_format(VAR_2, bs->read_only);

        if (!drv) {

            error_set(VAR_3, QERR_INVALID_BLOCK_FORMAT, VAR_2);

            return;

        }

    }



    eject_device(blk, 0, &err);

    if (err) {

        error_propagate(VAR_3, err);

        return;

    }



    VAR_4 = bdrv_is_read_only(bs) ? 0 : BDRV_O_RDWR;

    VAR_4 |= bdrv_is_snapshot(bs) ? BDRV_O_SNAPSHOT : 0;



    qmp_bdrv_open_encrypted(bs, VAR_1, VAR_4, drv, NULL, VAR_3);

}

void FUNC_0(const char *VAR_0, const char *VAR_1,
const char *VAR_2, Error **VAR_3)
{ BlockBackend *blk; BlockDriverState *bs; BlockDriver *drv = NULL; int VAR_4; Error *err = NULL; blk = blk_by_name(VAR_0); if (!blk) { error_set(VAR_3, QERR_DEVICE_NOT_FOUND, VAR_0); return; } bs = blk_bs(blk); if (VAR_2) { drv = bdrv_find_whitelisted_format(VAR_2, bs->read_only); if (!drv) { error_set(VAR_3, QERR_INVALID_BLOCK_FORMAT, VAR_2); return; } } eject_device(blk, 0, &err); if (err) { error_propagate(VAR_3, err); return; } VAR_4 = bdrv_is_read_only(bs) ? 0 : BDRV_O_RDWR; VAR_4 |= bdrv_is_snapshot(bs) ? BDRV_O_SNAPSHOT : 0; qmp_bdrv_open_encrypted(bs, VAR_1, VAR_4, drv, NULL, VAR_3); }