/* Return values: 0 - success -EINVAL - backing format specified, but no file -ENOSPC - can't update the backing file because no space is left in the image file header -ENOTSUP - format driver doesn't support changing the backing file  */
int bdrv_change_backing_file(BlockDriverState *bs, const char *backing_file, const char *backing_fmt)
/* Return values: 0 - success -EINVAL - backing format specified, but no file -ENOSPC - can't update the backing file because no space is left in the image file header -ENOTSUP - format driver doesn't support changing the backing file  */
int bdrv_change_backing_file(BlockDriverState *bs, const char *backing_file, const char *backing_fmt)
{
    BlockDriver *drv = bs->drv;
    int ret;
    if (backing_fmt && !backing_file) {
        return -EINVAL;
    }
    if (drv->bdrv_change_backing_file != NULL) {
        ret = drv->bdrv_change_backing_file(bs, backing_file, backing_fmt);
    } else {
        ret = -ENOTSUP;
    }
    if (ret == 0) {
        pstrcpy(bs->backing_file, sizeof(bs->backing_file), backing_file ?: "");
        pstrcpy(bs->backing_format, sizeof(bs->backing_format), backing_fmt ?: "");
    }
    return ret;
}