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

                             BlockDriver **pdrv, Error **errp)

{

    BlockDriver *drv;

    uint8_t buf[BLOCK_PROBE_BUF_SIZE];

    int ret = 0;



    /* Return the raw BlockDriver * to scsi-generic devices or empty drives */

    if (bs->sg || !bdrv_is_inserted(bs) || bdrv_getlength(bs) == 0) {

        *pdrv = &bdrv_raw;

        return ret;

    }



    ret = bdrv_pread(bs, 0, buf, sizeof(buf));

    if (ret < 0) {

        error_setg_errno(errp, -ret, "Could not read image for determining its "

                         "format");

        *pdrv = NULL;

        return ret;

    }



    drv = bdrv_probe_all(buf, ret, filename);

    if (!drv) {

        error_setg(errp, "Could not determine image format: No compatible "

                   "driver found");

        ret = -ENOENT;

    }

    *pdrv = drv;

    return ret;

}

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

                             BlockDriver **pdrv, Error **errp)

{

    BlockDriver *drv;

    uint8_t buf[BLOCK_PROBE_BUF_SIZE];

    int ret = 0;



    

    if (bs->sg || !bdrv_is_inserted(bs) || bdrv_getlength(bs) == 0) {

        *pdrv = &bdrv_raw;

        return ret;

    }



    ret = bdrv_pread(bs, 0, buf, sizeof(buf));

    if (ret < 0) {

        error_setg_errno(errp, -ret, "Could not read image for determining its "

                         "format");

        *pdrv = NULL;

        return ret;

    }



    drv = bdrv_probe_all(buf, ret, filename);

    if (!drv) {

        error_setg(errp, "Could not determine image format: No compatible "

                   "driver found");

        ret = -ENOENT;

    }

    *pdrv = drv;

    return ret;

}

static int FUNC_0(BlockDriverState *VAR_0, const char *VAR_1,

                             BlockDriver **VAR_2, Error **VAR_3)

{

    BlockDriver *drv;

    uint8_t buf[BLOCK_PROBE_BUF_SIZE];

    int VAR_4 = 0;



    

    if (VAR_0->sg || !bdrv_is_inserted(VAR_0) || bdrv_getlength(VAR_0) == 0) {

        *VAR_2 = &bdrv_raw;

        return VAR_4;

    }



    VAR_4 = bdrv_pread(VAR_0, 0, buf, sizeof(buf));

    if (VAR_4 < 0) {

        error_setg_errno(VAR_3, -VAR_4, "Could not read image for determining its "

                         "format");

        *VAR_2 = NULL;

        return VAR_4;

    }



    drv = bdrv_probe_all(buf, VAR_4, VAR_1);

    if (!drv) {

        error_setg(VAR_3, "Could not determine image format: No compatible "

                   "driver found");

        VAR_4 = -ENOENT;

    }

    *VAR_2 = drv;

    return VAR_4;

}

static int FUNC_0(BlockDriverState *VAR_0, const char *VAR_1,
BlockDriver **VAR_2, Error **VAR_3)
{ BlockDriver *drv; uint8_t buf[BLOCK_PROBE_BUF_SIZE]; int VAR_4 = 0; if (VAR_0->sg || !bdrv_is_inserted(VAR_0) || bdrv_getlength(VAR_0) == 0) { *VAR_2 = &bdrv_raw; return VAR_4; } VAR_4 = bdrv_pread(VAR_0, 0, buf, sizeof(buf)); if (VAR_4 < 0) { error_setg_errno(VAR_3, -VAR_4, "Could not read image for determining its "
"format"); *VAR_2 = NULL; return VAR_4; } drv = bdrv_probe_all(buf, VAR_4, VAR_1); if (!drv) { error_setg(VAR_3, "Could not determine image format: No compatible "
"driver found"); VAR_4 = -ENOENT; } *VAR_2 = drv; return VAR_4; }