static int sd_truncate(BlockDriverState *bs, int64_t offset)

{

    BDRVSheepdogState *s = bs->opaque;

    int ret, fd;

    unsigned int datalen;



    if (offset < s->inode.vdi_size) {

        error_report("shrinking is not supported");

        return -EINVAL;

    } else if (offset > SD_MAX_VDI_SIZE) {

        error_report("too big image size");

        return -EINVAL;

    }



    fd = connect_to_sdog(s->addr, s->port);

    if (fd < 0) {

        return fd;

    }



    /* we don't need to update entire object */

    datalen = SD_INODE_SIZE - sizeof(s->inode.data_vdi_id);

    s->inode.vdi_size = offset;

    ret = write_object(fd, (char *)&s->inode, vid_to_vdi_oid(s->inode.vdi_id),

                       s->inode.nr_copies, datalen, 0, false, s->cache_enabled);

    close(fd);



    if (ret < 0) {

        error_report("failed to update an inode.");

    }



    return ret;

}

static int sd_truncate(BlockDriverState *bs, int64_t offset)

{

    BDRVSheepdogState *s = bs->opaque;

    int ret, fd;

    unsigned int datalen;



    if (offset < s->inode.vdi_size) {

        error_report("shrinking is not supported");

        return -EINVAL;

    } else if (offset > SD_MAX_VDI_SIZE) {

        error_report("too big image size");

        return -EINVAL;

    }



    fd = connect_to_sdog(s->addr, s->port);

    if (fd < 0) {

        return fd;

    }



    

    datalen = SD_INODE_SIZE - sizeof(s->inode.data_vdi_id);

    s->inode.vdi_size = offset;

    ret = write_object(fd, (char *)&s->inode, vid_to_vdi_oid(s->inode.vdi_id),

                       s->inode.nr_copies, datalen, 0, false, s->cache_enabled);

    close(fd);



    if (ret < 0) {

        error_report("failed to update an inode.");

    }



    return ret;

}

static int FUNC_0(BlockDriverState *VAR_0, int64_t VAR_1)

{

    BDRVSheepdogState *s = VAR_0->opaque;

    int VAR_2, VAR_3;

    unsigned int VAR_4;



    if (VAR_1 < s->inode.vdi_size) {

        error_report("shrinking is not supported");

        return -EINVAL;

    } else if (VAR_1 > SD_MAX_VDI_SIZE) {

        error_report("too big image size");

        return -EINVAL;

    }



    VAR_3 = connect_to_sdog(s->addr, s->port);

    if (VAR_3 < 0) {

        return VAR_3;

    }



    

    VAR_4 = SD_INODE_SIZE - sizeof(s->inode.data_vdi_id);

    s->inode.vdi_size = VAR_1;

    VAR_2 = write_object(VAR_3, (char *)&s->inode, vid_to_vdi_oid(s->inode.vdi_id),

                       s->inode.nr_copies, VAR_4, 0, false, s->cache_enabled);

    close(VAR_3);



    if (VAR_2 < 0) {

        error_report("failed to update an inode.");

    }



    return VAR_2;

}

static int FUNC_0(BlockDriverState *VAR_0, int64_t VAR_1)
{ BDRVSheepdogState *s = VAR_0->opaque; int VAR_2, VAR_3; unsigned int VAR_4; if (VAR_1 < s->inode.vdi_size) { error_report("shrinking is not supported"); return -EINVAL; } else if (VAR_1 > SD_MAX_VDI_SIZE) { error_report("too big image size"); return -EINVAL; } VAR_3 = connect_to_sdog(s->addr, s->port); if (VAR_3 < 0) { return VAR_3; } VAR_4 = SD_INODE_SIZE - sizeof(s->inode.data_vdi_id); s->inode.vdi_size = VAR_1; VAR_2 = write_object(VAR_3, (char *)&s->inode, vid_to_vdi_oid(s->inode.vdi_id),
s->inode.nr_copies, VAR_4, 0, false, s->cache_enabled); close(VAR_3); if (VAR_2 < 0) { error_report("failed to update an inode."); } return VAR_2; }