static int vmdk_parent_open(BlockDriverState *bs, const char * filename)

{

    BDRVVmdkState *s = bs->opaque;

    char *p_name; 

    char desc[DESC_SIZE];

    char parent_img_name[1024];



    /* the descriptor offset = 0x200 */

    if (bdrv_pread(s->hd, 0x200, desc, DESC_SIZE) != DESC_SIZE)

        return -1;



    if ((p_name = strstr(desc,"parentFileNameHint")) != 0) {

        char *end_name;

        struct stat file_buf;



        p_name += sizeof("parentFileNameHint") + 1;

        if ((end_name = strchr(p_name,'\"')) == 0)

            return -1;

                

        strncpy(s->hd->backing_file, p_name, end_name - p_name);

        if (stat(s->hd->backing_file, &file_buf) != 0) {

            path_combine(parent_img_name, sizeof(parent_img_name),

                         filename, s->hd->backing_file);

        } else {

            strcpy(parent_img_name, s->hd->backing_file);

        }



        s->hd->backing_hd = bdrv_new("");

        if (!s->hd->backing_hd) {

            failure:

            bdrv_close(s->hd);

            return -1;

        }

        if (bdrv_open(s->hd->backing_hd, parent_img_name, 0) < 0)

            goto failure;

    }



    return 0;

}

static int vmdk_parent_open(BlockDriverState *bs, const char * filename)

{

    BDRVVmdkState *s = bs->opaque;

    char *p_name; 

    char desc[DESC_SIZE];

    char parent_img_name[1024];



    

    if (bdrv_pread(s->hd, 0x200, desc, DESC_SIZE) != DESC_SIZE)

        return -1;



    if ((p_name = strstr(desc,"parentFileNameHint")) != 0) {

        char *end_name;

        struct stat file_buf;



        p_name += sizeof("parentFileNameHint") + 1;

        if ((end_name = strchr(p_name,'\"')) == 0)

            return -1;

                

        strncpy(s->hd->backing_file, p_name, end_name - p_name);

        if (stat(s->hd->backing_file, &file_buf) != 0) {

            path_combine(parent_img_name, sizeof(parent_img_name),

                         filename, s->hd->backing_file);

        } else {

            strcpy(parent_img_name, s->hd->backing_file);

        }



        s->hd->backing_hd = bdrv_new("");

        if (!s->hd->backing_hd) {

            failure:

            bdrv_close(s->hd);

            return -1;

        }

        if (bdrv_open(s->hd->backing_hd, parent_img_name, 0) < 0)

            goto failure;

    }



    return 0;

}

        if (bdrv_open(s->hd->backing_hd, parent_img_name, 0) < 0)             return -1;
static int FUNC_0(BlockDriverState *VAR_0, const char * VAR_1)

{

    BDRVVmdkState *s = VAR_0->opaque;

    char *VAR_2; 

    char VAR_3[DESC_SIZE];

    char VAR_4[1024];



    

    if (bdrv_pread(s->hd, 0x200, VAR_3, DESC_SIZE) != DESC_SIZE)

        return -1;



    if ((VAR_2 = strstr(VAR_3,"parentFileNameHint")) != 0) {

        char *VAR_5;

        struct stat VAR_6;



        VAR_2 += sizeof("parentFileNameHint") + 1;

        if ((VAR_5 = strchr(VAR_2,'\"')) == 0)

            return -1;

                

        strncpy(s->hd->backing_file, VAR_2, VAR_5 - VAR_2);

        if (stat(s->hd->backing_file, &VAR_6) != 0) {

            path_combine(VAR_4, sizeof(VAR_4),

                         VAR_1, s->hd->backing_file);

        } else {

            strcpy(VAR_4, s->hd->backing_file);

        }



        s->hd->backing_hd = bdrv_new("");

        if (!s->hd->backing_hd) {

            failure:

            bdrv_close(s->hd);

            return -1;

        }

        if (bdrv_open(s->hd->backing_hd, VAR_4, 0) < 0)

            goto failure;

    }



    return 0;

}

static int FUNC_0(BlockDriverState *VAR_0, const char * VAR_1)
{ BDRVVmdkState *s = VAR_0->opaque; char *VAR_2; char VAR_3[DESC_SIZE]; char VAR_4[1024]; if (bdrv_pread(s->hd, 0x200, VAR_3, DESC_SIZE) != DESC_SIZE)
return -1; if ((VAR_2 = strstr(VAR_3,"parentFileNameHint")) != 0) { char *VAR_5; struct stat VAR_6; VAR_2 += sizeof("parentFileNameHint") + 1; if ((VAR_5 = strchr(VAR_2,'\"')) == 0)
return -1; strncpy(s->hd->backing_file, VAR_2, VAR_5 - VAR_2); if (stat(s->hd->backing_file, &VAR_6) != 0) { path_combine(VAR_4, sizeof(VAR_4),
VAR_1, s->hd->backing_file); } else { strcpy(VAR_4, s->hd->backing_file); } s->hd->backing_hd = bdrv_new(""); if (!s->hd->backing_hd) { failure:
bdrv_close(s->hd); return -1; } if (bdrv_open(s->hd->backing_hd, VAR_4, 0) < 0)
goto failure; } return 0; }