static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent,

                            Error **errp)

{

    int ret;

    int l1_size, i;



    /* read the L1 table */

    l1_size = extent->l1_size * sizeof(uint32_t);

    extent->l1_table = g_try_malloc(l1_size);

    if (l1_size && extent->l1_table == NULL) {

        return -ENOMEM;

    }



    ret = bdrv_pread(extent->file,

                     extent->l1_table_offset,

                     extent->l1_table,

                     l1_size);

    if (ret < 0) {

        error_setg_errno(errp, -ret,

                         "Could not read l1 table from extent '%s'",

                         extent->file->filename);

        goto fail_l1;

    }

    for (i = 0; i < extent->l1_size; i++) {

        le32_to_cpus(&extent->l1_table[i]);

    }



    if (extent->l1_backup_table_offset) {

        extent->l1_backup_table = g_try_malloc(l1_size);

        if (l1_size && extent->l1_backup_table == NULL) {

            ret = -ENOMEM;

            goto fail_l1;

        }

        ret = bdrv_pread(extent->file,

                         extent->l1_backup_table_offset,

                         extent->l1_backup_table,

                         l1_size);

        if (ret < 0) {

            error_setg_errno(errp, -ret,

                             "Could not read l1 backup table from extent '%s'",

                             extent->file->filename);

            goto fail_l1b;

        }

        for (i = 0; i < extent->l1_size; i++) {

            le32_to_cpus(&extent->l1_backup_table[i]);

        }

    }



    extent->l2_cache =

        g_new(uint32_t, extent->l2_size * L2_CACHE_SIZE);

    return 0;

 fail_l1b:

    g_free(extent->l1_backup_table);

 fail_l1:

    g_free(extent->l1_table);

    return ret;

}

static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent,

                            Error **errp)

{

    int ret;

    int l1_size, i;



    

    l1_size = extent->l1_size * sizeof(uint32_t);

    extent->l1_table = g_try_malloc(l1_size);

    if (l1_size && extent->l1_table == NULL) {

        return -ENOMEM;

    }



    ret = bdrv_pread(extent->file,

                     extent->l1_table_offset,

                     extent->l1_table,

                     l1_size);

    if (ret < 0) {

        error_setg_errno(errp, -ret,

                         "Could not read l1 table from extent '%s'",

                         extent->file->filename);

        goto fail_l1;

    }

    for (i = 0; i < extent->l1_size; i++) {

        le32_to_cpus(&extent->l1_table[i]);

    }



    if (extent->l1_backup_table_offset) {

        extent->l1_backup_table = g_try_malloc(l1_size);

        if (l1_size && extent->l1_backup_table == NULL) {

            ret = -ENOMEM;

            goto fail_l1;

        }

        ret = bdrv_pread(extent->file,

                         extent->l1_backup_table_offset,

                         extent->l1_backup_table,

                         l1_size);

        if (ret < 0) {

            error_setg_errno(errp, -ret,

                             "Could not read l1 backup table from extent '%s'",

                             extent->file->filename);

            goto fail_l1b;

        }

        for (i = 0; i < extent->l1_size; i++) {

            le32_to_cpus(&extent->l1_backup_table[i]);

        }

    }



    extent->l2_cache =

        g_new(uint32_t, extent->l2_size * L2_CACHE_SIZE);

    return 0;

 fail_l1b:

    g_free(extent->l1_backup_table);

 fail_l1:

    g_free(extent->l1_table);

    return ret;

}

    int l1_size, i;
static int FUNC_0(BlockDriverState *VAR_0, VmdkExtent *VAR_1,

                            Error **VAR_2)

{

    int VAR_3;

    int VAR_4, VAR_5;



    

    VAR_4 = VAR_1->VAR_4 * sizeof(uint32_t);

    VAR_1->l1_table = g_try_malloc(VAR_4);

    if (VAR_4 && VAR_1->l1_table == NULL) {

        return -ENOMEM;

    }



    VAR_3 = bdrv_pread(VAR_1->file,

                     VAR_1->l1_table_offset,

                     VAR_1->l1_table,

                     VAR_4);

    if (VAR_3 < 0) {

        error_setg_errno(VAR_2, -VAR_3,

                         "Could not read l1 table from VAR_1 '%s'",

                         VAR_1->file->filename);

        goto fail_l1;

    }

    for (VAR_5 = 0; VAR_5 < VAR_1->VAR_4; VAR_5++) {

        le32_to_cpus(&VAR_1->l1_table[VAR_5]);

    }



    if (VAR_1->l1_backup_table_offset) {

        VAR_1->l1_backup_table = g_try_malloc(VAR_4);

        if (VAR_4 && VAR_1->l1_backup_table == NULL) {

            VAR_3 = -ENOMEM;

            goto fail_l1;

        }

        VAR_3 = bdrv_pread(VAR_1->file,

                         VAR_1->l1_backup_table_offset,

                         VAR_1->l1_backup_table,

                         VAR_4);

        if (VAR_3 < 0) {

            error_setg_errno(VAR_2, -VAR_3,

                             "Could not read l1 backup table from VAR_1 '%s'",

                             VAR_1->file->filename);

            goto fail_l1b;

        }

        for (VAR_5 = 0; VAR_5 < VAR_1->VAR_4; VAR_5++) {

            le32_to_cpus(&VAR_1->l1_backup_table[VAR_5]);

        }

    }



    VAR_1->l2_cache =

        g_new(uint32_t, VAR_1->l2_size * L2_CACHE_SIZE);

    return 0;

 fail_l1b:

    g_free(VAR_1->l1_backup_table);

 fail_l1:

    g_free(VAR_1->l1_table);

    return VAR_3;

}

static int FUNC_0(BlockDriverState *VAR_0, VmdkExtent *VAR_1,
Error **VAR_2)
{ int VAR_3; int VAR_4, VAR_5; VAR_4 = VAR_1->VAR_4 * sizeof(uint32_t); VAR_1->l1_table = g_try_malloc(VAR_4); if (VAR_4 && VAR_1->l1_table == NULL) { return -ENOMEM; } VAR_3 = bdrv_pread(VAR_1->file,
VAR_1->l1_table_offset,
VAR_1->l1_table,
VAR_4); if (VAR_3 < 0) { error_setg_errno(VAR_2, -VAR_3,
"Could not read l1 table from VAR_1 '%s'",
VAR_1->file->filename); goto fail_l1; } for (VAR_5 = 0; VAR_5 < VAR_1->VAR_4; VAR_5++) { le32_to_cpus(&VAR_1->l1_table[VAR_5]); } if (VAR_1->l1_backup_table_offset) { VAR_1->l1_backup_table = g_try_malloc(VAR_4); if (VAR_4 && VAR_1->l1_backup_table == NULL) { VAR_3 = -ENOMEM; goto fail_l1; } VAR_3 = bdrv_pread(VAR_1->file,
VAR_1->l1_backup_table_offset,
VAR_1->l1_backup_table,
VAR_4); if (VAR_3 < 0) { error_setg_errno(VAR_2, -VAR_3,
"Could not read l1 backup table from VAR_1 '%s'",
VAR_1->file->filename); goto fail_l1b; } for (VAR_5 = 0; VAR_5 < VAR_1->VAR_4; VAR_5++) { le32_to_cpus(&VAR_1->l1_backup_table[VAR_5]); } } VAR_1->l2_cache =
g_new(uint32_t, VAR_1->l2_size * L2_CACHE_SIZE); return 0; fail_l1b:
g_free(VAR_1->l1_backup_table); fail_l1:
g_free(VAR_1->l1_table); return VAR_3; }