static int vmdk_open_vmfs_sparse(BlockDriverState *bs,

                                 BlockDriverState *file,

                                 int flags, Error **errp)

{

    int ret;

    uint32_t magic;

    VMDK3Header header;

    VmdkExtent *extent;



    ret = bdrv_pread(file, sizeof(magic), &header, sizeof(header));

    if (ret < 0) {

        error_setg_errno(errp, -ret,

                         "Could not read header from file '%s'",

                         file->filename);

        return ret;

    }

    ret = vmdk_add_extent(bs, file, false,

                          le32_to_cpu(header.disk_sectors),

                          le32_to_cpu(header.l1dir_offset) << 9,

                          0,

                          le32_to_cpu(header.l1dir_size),

                          4096,

                          le32_to_cpu(header.granularity),

                          &extent,

                          errp);

    if (ret < 0) {

        return ret;

    }

    ret = vmdk_init_tables(bs, extent, errp);

    if (ret) {

        /* free extent allocated by vmdk_add_extent */

        vmdk_free_last_extent(bs);

    }

    return ret;

}

static int vmdk_open_vmfs_sparse(BlockDriverState *bs,

                                 BlockDriverState *file,

                                 int flags, Error **errp)

{

    int ret;

    uint32_t magic;

    VMDK3Header header;

    VmdkExtent *extent;



    ret = bdrv_pread(file, sizeof(magic), &header, sizeof(header));

    if (ret < 0) {

        error_setg_errno(errp, -ret,

                         "Could not read header from file '%s'",

                         file->filename);

        return ret;

    }

    ret = vmdk_add_extent(bs, file, false,

                          le32_to_cpu(header.disk_sectors),

                          le32_to_cpu(header.l1dir_offset) << 9,

                          0,

                          le32_to_cpu(header.l1dir_size),

                          4096,

                          le32_to_cpu(header.granularity),

                          &extent,

                          errp);

    if (ret < 0) {

        return ret;

    }

    ret = vmdk_init_tables(bs, extent, errp);

    if (ret) {

        

        vmdk_free_last_extent(bs);

    }

    return ret;

}

                          le32_to_cpu(header.l1dir_offset) << 9,
static int FUNC_0(BlockDriverState *VAR_0,

                                 BlockDriverState *VAR_1,

                                 int VAR_2, Error **VAR_3)

{

    int VAR_4;

    uint32_t magic;

    VMDK3Header header;

    VmdkExtent *extent;



    VAR_4 = bdrv_pread(VAR_1, sizeof(magic), &header, sizeof(header));

    if (VAR_4 < 0) {

        error_setg_errno(VAR_3, -VAR_4,

                         "Could not read header from VAR_1 '%s'",

                         VAR_1->filename);

        return VAR_4;

    }

    VAR_4 = vmdk_add_extent(VAR_0, VAR_1, false,

                          le32_to_cpu(header.disk_sectors),

                          le32_to_cpu(header.l1dir_offset) << 9,

                          0,

                          le32_to_cpu(header.l1dir_size),

                          4096,

                          le32_to_cpu(header.granularity),

                          &extent,

                          VAR_3);

    if (VAR_4 < 0) {

        return VAR_4;

    }

    VAR_4 = vmdk_init_tables(VAR_0, extent, VAR_3);

    if (VAR_4) {

        

        vmdk_free_last_extent(VAR_0);

    }

    return VAR_4;

}

static int FUNC_0(BlockDriverState *VAR_0,
BlockDriverState *VAR_1,
int VAR_2, Error **VAR_3)
{ int VAR_4; uint32_t magic; VMDK3Header header; VmdkExtent *extent; VAR_4 = bdrv_pread(VAR_1, sizeof(magic), &header, sizeof(header)); if (VAR_4 < 0) { error_setg_errno(VAR_3, -VAR_4,
"Could not read header from VAR_1 '%s'",
VAR_1->filename); return VAR_4; } VAR_4 = vmdk_add_extent(VAR_0, VAR_1, false,
le32_to_cpu(header.disk_sectors),
le32_to_cpu(header.l1dir_offset) << 9,
0,
le32_to_cpu(header.l1dir_size),
4096,
le32_to_cpu(header.granularity),
&extent,
VAR_3); if (VAR_4 < 0) { return VAR_4; } VAR_4 = vmdk_init_tables(VAR_0, extent, VAR_3); if (VAR_4) { vmdk_free_last_extent(VAR_0); } return VAR_4; }