sd_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors,

                       int *pnum)

{

    BDRVSheepdogState *s = bs->opaque;

    SheepdogInode *inode = &s->inode;

    uint32_t object_size = (UINT32_C(1) << inode->block_size_shift);

    uint64_t offset = sector_num * BDRV_SECTOR_SIZE;

    unsigned long start = offset / object_size,

                  end = DIV_ROUND_UP((sector_num + nb_sectors) *

                                     BDRV_SECTOR_SIZE, object_size);

    unsigned long idx;

    int64_t ret = BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | offset;



    for (idx = start; idx < end; idx++) {

        if (inode->data_vdi_id[idx] == 0) {

            break;

        }

    }

    if (idx == start) {

        /* Get the longest length of unallocated sectors */

        ret = 0;

        for (idx = start + 1; idx < end; idx++) {

            if (inode->data_vdi_id[idx] != 0) {

                break;

            }

        }

    }



    *pnum = (idx - start) * object_size / BDRV_SECTOR_SIZE;

    if (*pnum > nb_sectors) {

        *pnum = nb_sectors;

    }

    return ret;

}

sd_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors,

                       int *pnum)

{

    BDRVSheepdogState *s = bs->opaque;

    SheepdogInode *inode = &s->inode;

    uint32_t object_size = (UINT32_C(1) << inode->block_size_shift);

    uint64_t offset = sector_num * BDRV_SECTOR_SIZE;

    unsigned long start = offset / object_size,

                  end = DIV_ROUND_UP((sector_num + nb_sectors) *

                                     BDRV_SECTOR_SIZE, object_size);

    unsigned long idx;

    int64_t ret = BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | offset;



    for (idx = start; idx < end; idx++) {

        if (inode->data_vdi_id[idx] == 0) {

            break;

        }

    }

    if (idx == start) {

        

        ret = 0;

        for (idx = start + 1; idx < end; idx++) {

            if (inode->data_vdi_id[idx] != 0) {

                break;

            }

        }

    }



    *pnum = (idx - start) * object_size / BDRV_SECTOR_SIZE;

    if (*pnum > nb_sectors) {

        *pnum = nb_sectors;

    }

    return ret;

}

FUNC_0(BlockDriverState *VAR_0, int64_t VAR_1, int VAR_2,

                       int *VAR_3)

{

    BDRVSheepdogState *s = VAR_0->opaque;

    SheepdogInode *inode = &s->inode;

    uint32_t object_size = (UINT32_C(1) << inode->block_size_shift);

    uint64_t offset = VAR_1 * BDRV_SECTOR_SIZE;

    unsigned long VAR_4 = offset / object_size,

                  VAR_5 = DIV_ROUND_UP((VAR_1 + VAR_2) *

                                     BDRV_SECTOR_SIZE, object_size);

    unsigned long VAR_6;

    int64_t ret = BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | offset;



    for (VAR_6 = VAR_4; VAR_6 < VAR_5; VAR_6++) {

        if (inode->data_vdi_id[VAR_6] == 0) {

            break;

        }

    }

    if (VAR_6 == VAR_4) {

        

        ret = 0;

        for (VAR_6 = VAR_4 + 1; VAR_6 < VAR_5; VAR_6++) {

            if (inode->data_vdi_id[VAR_6] != 0) {

                break;

            }

        }

    }



    *VAR_3 = (VAR_6 - VAR_4) * object_size / BDRV_SECTOR_SIZE;

    if (*VAR_3 > VAR_2) {

        *VAR_3 = VAR_2;

    }

    return ret;

}

FUNC_0(BlockDriverState *VAR_0, int64_t VAR_1, int VAR_2,
int *VAR_3)
{ BDRVSheepdogState *s = VAR_0->opaque; SheepdogInode *inode = &s->inode; uint32_t object_size = (UINT32_C(1) << inode->block_size_shift); uint64_t offset = VAR_1 * BDRV_SECTOR_SIZE; unsigned long VAR_4 = offset / object_size,
VAR_5 = DIV_ROUND_UP((VAR_1 + VAR_2) *
BDRV_SECTOR_SIZE, object_size); unsigned long VAR_6; int64_t ret = BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | offset; for (VAR_6 = VAR_4; VAR_6 < VAR_5; VAR_6++) { if (inode->data_vdi_id[VAR_6] == 0) { break; } } if (VAR_6 == VAR_4) { ret = 0; for (VAR_6 = VAR_4 + 1; VAR_6 < VAR_5; VAR_6++) { if (inode->data_vdi_id[VAR_6] != 0) { break; } } } *VAR_3 = (VAR_6 - VAR_4) * object_size / BDRV_SECTOR_SIZE; if (*VAR_3 > VAR_2) { *VAR_3 = VAR_2; } return ret; }