static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,

        const char *desc_file_path)

{

    int ret;

    char access[11];

    char type[11];

    char fname[512];

    const char *p = desc;

    int64_t sectors = 0;

    int64_t flat_offset;

    char extent_path[PATH_MAX];

    BlockDriverState *extent_file;

    Error *local_err = NULL;



    while (*p) {

        /* parse extent line:

         * RW [size in sectors] FLAT "file-name.vmdk" OFFSET

         * or

         * RW [size in sectors] SPARSE "file-name.vmdk"

         */

        flat_offset = -1;

        ret = sscanf(p, "%10s %" SCNd64 " %10s \"%511[^\n\r\"]\" %" SCNd64,

                access, &sectors, type, fname, &flat_offset);

        if (ret < 4 || strcmp(access, "RW")) {

            goto next_line;

        } else if (!strcmp(type, "FLAT")) {

            if (ret != 5 || flat_offset < 0) {

                return -EINVAL;

            }

        } else if (ret != 4) {

            return -EINVAL;

        }



        if (sectors <= 0 ||

            (strcmp(type, "FLAT") && strcmp(type, "SPARSE") &&

             strcmp(type, "VMFS") && strcmp(type, "VMFSSPARSE")) ||

            (strcmp(access, "RW"))) {

            goto next_line;

        }



        path_combine(extent_path, sizeof(extent_path),

                desc_file_path, fname);

        ret = bdrv_file_open(&extent_file, extent_path, NULL, bs->open_flags,

                             &local_err);

        if (ret) {

            qerror_report_err(local_err);

            error_free(local_err);

            return ret;

        }



        /* save to extents array */

        if (!strcmp(type, "FLAT") || !strcmp(type, "VMFS")) {

            /* FLAT extent */

            VmdkExtent *extent;



            ret = vmdk_add_extent(bs, extent_file, true, sectors,

                            0, 0, 0, 0, sectors, &extent);

            if (ret < 0) {

                return ret;

            }

            extent->flat_start_offset = flat_offset << 9;

        } else if (!strcmp(type, "SPARSE") || !strcmp(type, "VMFSSPARSE")) {

            /* SPARSE extent and VMFSSPARSE extent are both "COWD" sparse file*/

            ret = vmdk_open_sparse(bs, extent_file, bs->open_flags);

            if (ret) {

                bdrv_unref(extent_file);

                return ret;

            }

        } else {

            fprintf(stderr,

                "VMDK: Not supported extent type \"%s\""".\n", type);

            return -ENOTSUP;

        }

next_line:

        /* move to next line */

        while (*p && *p != '\n') {

            p++;

        }

        p++;

    }

    return 0;

}

static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,

        const char *desc_file_path)

{

    int ret;

    char access[11];

    char type[11];

    char fname[512];

    const char *p = desc;

    int64_t sectors = 0;

    int64_t flat_offset;

    char extent_path[PATH_MAX];

    BlockDriverState *extent_file;

    Error *local_err = NULL;



    while (*p) {

        









        flat_offset = -1;

        ret = sscanf(p, "%10s %" SCNd64 " %10s \"%511[^\n\r\"]\" %" SCNd64,

                access, &sectors, type, fname, &flat_offset);

        if (ret < 4 || strcmp(access, "RW")) {

            goto next_line;

        } else if (!strcmp(type, "FLAT")) {

            if (ret != 5 || flat_offset < 0) {

                return -EINVAL;

            }

        } else if (ret != 4) {

            return -EINVAL;

        }



        if (sectors <= 0 ||

            (strcmp(type, "FLAT") && strcmp(type, "SPARSE") &&

             strcmp(type, "VMFS") && strcmp(type, "VMFSSPARSE")) ||

            (strcmp(access, "RW"))) {

            goto next_line;

        }



        path_combine(extent_path, sizeof(extent_path),

                desc_file_path, fname);

        ret = bdrv_file_open(&extent_file, extent_path, NULL, bs->open_flags,

                             &local_err);

        if (ret) {

            qerror_report_err(local_err);

            error_free(local_err);

            return ret;

        }



        

        if (!strcmp(type, "FLAT") || !strcmp(type, "VMFS")) {

            

            VmdkExtent *extent;



            ret = vmdk_add_extent(bs, extent_file, true, sectors,

                            0, 0, 0, 0, sectors, &extent);

            if (ret < 0) {

                return ret;

            }

            extent->flat_start_offset = flat_offset << 9;

        } else if (!strcmp(type, "SPARSE") || !strcmp(type, "VMFSSPARSE")) {

            

            ret = vmdk_open_sparse(bs, extent_file, bs->open_flags);

            if (ret) {

                bdrv_unref(extent_file);

                return ret;

            }

        } else {

            fprintf(stderr,

                "VMDK: Not supported extent type \"%s\""".\n", type);

            return -ENOTSUP;

        }

next_line:

        

        while (*p && *p != '\n') {

            p++;

        }

        p++;

    }

    return 0;

}

                            0, 0, 0, 0, sectors, &extent);
static int FUNC_0(const char *VAR_0, BlockDriverState *VAR_1,

        const char *VAR_2)

{

    int VAR_3;

    char VAR_4[11];

    char VAR_5[11];

    char VAR_6[512];

    const char *VAR_7 = VAR_0;

    int64_t sectors = 0;

    int64_t flat_offset;

    char VAR_8[PATH_MAX];

    BlockDriverState *extent_file;

    Error *local_err = NULL;



    while (*VAR_7) {

        









        flat_offset = -1;

        VAR_3 = sscanf(VAR_7, "%10s %" SCNd64 " %10s \"%511[^\n\r\"]\" %" SCNd64,

                VAR_4, &sectors, VAR_5, VAR_6, &flat_offset);

        if (VAR_3 < 4 || strcmp(VAR_4, "RW")) {

            goto next_line;

        } else if (!strcmp(VAR_5, "FLAT")) {

            if (VAR_3 != 5 || flat_offset < 0) {

                return -EINVAL;

            }

        } else if (VAR_3 != 4) {

            return -EINVAL;

        }



        if (sectors <= 0 ||

            (strcmp(VAR_5, "FLAT") && strcmp(VAR_5, "SPARSE") &&

             strcmp(VAR_5, "VMFS") && strcmp(VAR_5, "VMFSSPARSE")) ||

            (strcmp(VAR_4, "RW"))) {

            goto next_line;

        }



        path_combine(VAR_8, sizeof(VAR_8),

                VAR_2, VAR_6);

        VAR_3 = bdrv_file_open(&extent_file, VAR_8, NULL, VAR_1->open_flags,

                             &local_err);

        if (VAR_3) {

            qerror_report_err(local_err);

            error_free(local_err);

            return VAR_3;

        }



        

        if (!strcmp(VAR_5, "FLAT") || !strcmp(VAR_5, "VMFS")) {

            

            VmdkExtent *extent;



            VAR_3 = vmdk_add_extent(VAR_1, extent_file, true, sectors,

                            0, 0, 0, 0, sectors, &extent);

            if (VAR_3 < 0) {

                return VAR_3;

            }

            extent->flat_start_offset = flat_offset << 9;

        } else if (!strcmp(VAR_5, "SPARSE") || !strcmp(VAR_5, "VMFSSPARSE")) {

            

            VAR_3 = vmdk_open_sparse(VAR_1, extent_file, VAR_1->open_flags);

            if (VAR_3) {

                bdrv_unref(extent_file);

                return VAR_3;

            }

        } else {

            fprintf(stderr,

                "VMDK: Not supported extent VAR_5 \"%s\""".\n", VAR_5);

            return -ENOTSUP;

        }

next_line:

        

        while (*VAR_7 && *VAR_7 != '\n') {

            VAR_7++;

        }

        VAR_7++;

    }

    return 0;

}

static int FUNC_0(const char *VAR_0, BlockDriverState *VAR_1,
const char *VAR_2)
{ int VAR_3; char VAR_4[11]; char VAR_5[11]; char VAR_6[512]; const char *VAR_7 = VAR_0; int64_t sectors = 0; int64_t flat_offset; char VAR_8[PATH_MAX]; BlockDriverState *extent_file; Error *local_err = NULL; while (*VAR_7) { flat_offset = -1; VAR_3 = sscanf(VAR_7, "%10s %" SCNd64 " %10s \"%511[^\n\r\"]\" %" SCNd64,
VAR_4, &sectors, VAR_5, VAR_6, &flat_offset); if (VAR_3 < 4 || strcmp(VAR_4, "RW")) { goto next_line; } else if (!strcmp(VAR_5, "FLAT")) { if (VAR_3 != 5 || flat_offset < 0) { return -EINVAL; } } else if (VAR_3 != 4) { return -EINVAL; } if (sectors <= 0 ||
(strcmp(VAR_5, "FLAT") && strcmp(VAR_5, "SPARSE") &&
strcmp(VAR_5, "VMFS") && strcmp(VAR_5, "VMFSSPARSE")) ||
(strcmp(VAR_4, "RW"))) { goto next_line; } path_combine(VAR_8, sizeof(VAR_8),
VAR_2, VAR_6); VAR_3 = bdrv_file_open(&extent_file, VAR_8, NULL, VAR_1->open_flags,
&local_err); if (VAR_3) { qerror_report_err(local_err); error_free(local_err); return VAR_3; } if (!strcmp(VAR_5, "FLAT") || !strcmp(VAR_5, "VMFS")) { VmdkExtent *extent; VAR_3 = vmdk_add_extent(VAR_1, extent_file, true, sectors,
0, 0, 0, 0, sectors, &extent); if (VAR_3 < 0) { return VAR_3; } extent->flat_start_offset = flat_offset << 9; } else if (!strcmp(VAR_5, "SPARSE") || !strcmp(VAR_5, "VMFSSPARSE")) { VAR_3 = vmdk_open_sparse(VAR_1, extent_file, VAR_1->open_flags); if (VAR_3) { bdrv_unref(extent_file); return VAR_3; } } else { fprintf(stderr,
"VMDK: Not supported extent VAR_5 \"%s\""".\n", VAR_5); return -ENOTSUP; } next_line:
while (*VAR_7 && *VAR_7 != '\n') { VAR_7++; } VAR_7++; } return 0; }