static int convert_read(ImgConvertState *s, int64_t sector_num, int nb_sectors,

                        uint8_t *buf)

{

    int n;

    int ret;



    if (s->status == BLK_ZERO || s->status == BLK_BACKING_FILE) {

        return 0;

    }



    assert(nb_sectors <= s->buf_sectors);

    while (nb_sectors > 0) {

        BlockBackend *blk;

        int64_t bs_sectors;



        /* In the case of compression with multiple source files, we can get a

         * nb_sectors that spreads into the next part. So we must be able to

         * read across multiple BDSes for one convert_read() call. */

        convert_select_part(s, sector_num);

        blk = s->src[s->src_cur];

        bs_sectors = s->src_sectors[s->src_cur];



        n = MIN(nb_sectors, bs_sectors - (sector_num - s->src_cur_offset));

        ret = blk_read(blk, sector_num - s->src_cur_offset, buf, n);

        if (ret < 0) {

            return ret;

        }



        sector_num += n;

        nb_sectors -= n;

        buf += n * BDRV_SECTOR_SIZE;

    }



    return 0;

}

static int convert_read(ImgConvertState *s, int64_t sector_num, int nb_sectors,

                        uint8_t *buf)

{

    int n;

    int ret;



    if (s->status == BLK_ZERO || s->status == BLK_BACKING_FILE) {

        return 0;

    }



    assert(nb_sectors <= s->buf_sectors);

    while (nb_sectors > 0) {

        BlockBackend *blk;

        int64_t bs_sectors;



        





        convert_select_part(s, sector_num);

        blk = s->src[s->src_cur];

        bs_sectors = s->src_sectors[s->src_cur];



        n = MIN(nb_sectors, bs_sectors - (sector_num - s->src_cur_offset));

        ret = blk_read(blk, sector_num - s->src_cur_offset, buf, n);

        if (ret < 0) {

            return ret;

        }



        sector_num += n;

        nb_sectors -= n;

        buf += n * BDRV_SECTOR_SIZE;

    }



    return 0;

}

static int FUNC_0(ImgConvertState *VAR_0, int64_t VAR_1, int VAR_2,

                        uint8_t *VAR_3)

{

    int VAR_4;

    int VAR_5;



    if (VAR_0->status == BLK_ZERO || VAR_0->status == BLK_BACKING_FILE) {

        return 0;

    }



    assert(VAR_2 <= VAR_0->buf_sectors);

    while (VAR_2 > 0) {

        BlockBackend *blk;

        int64_t bs_sectors;



        





        convert_select_part(VAR_0, VAR_1);

        blk = VAR_0->src[VAR_0->src_cur];

        bs_sectors = VAR_0->src_sectors[VAR_0->src_cur];



        VAR_4 = MIN(VAR_2, bs_sectors - (VAR_1 - VAR_0->src_cur_offset));

        VAR_5 = blk_read(blk, VAR_1 - VAR_0->src_cur_offset, VAR_3, VAR_4);

        if (VAR_5 < 0) {

            return VAR_5;

        }



        VAR_1 += VAR_4;

        VAR_2 -= VAR_4;

        VAR_3 += VAR_4 * BDRV_SECTOR_SIZE;

    }



    return 0;

}

static int FUNC_0(ImgConvertState *VAR_0, int64_t VAR_1, int VAR_2,
uint8_t *VAR_3)
{ int VAR_4; int VAR_5; if (VAR_0->status == BLK_ZERO || VAR_0->status == BLK_BACKING_FILE) { return 0; } assert(VAR_2 <= VAR_0->buf_sectors); while (VAR_2 > 0) { BlockBackend *blk; int64_t bs_sectors; convert_select_part(VAR_0, VAR_1); blk = VAR_0->src[VAR_0->src_cur]; bs_sectors = VAR_0->src_sectors[VAR_0->src_cur]; VAR_4 = MIN(VAR_2, bs_sectors - (VAR_1 - VAR_0->src_cur_offset)); VAR_5 = blk_read(blk, VAR_1 - VAR_0->src_cur_offset, VAR_3, VAR_4); if (VAR_5 < 0) { return VAR_5; } VAR_1 += VAR_4; VAR_2 -= VAR_4; VAR_3 += VAR_4 * BDRV_SECTOR_SIZE; } return 0; }