static int read_f(BlockBackend *blk, int argc, char **argv)

{

    struct timeval t1, t2;

    int Cflag = 0, pflag = 0, qflag = 0, vflag = 0;

    int Pflag = 0, sflag = 0, lflag = 0, bflag = 0;

    int c, cnt;

    char *buf;

    int64_t offset;

    int count;

    /* Some compilers get confused and warn if this is not initialized.  */

    int total = 0;

    int pattern = 0, pattern_offset = 0, pattern_count = 0;



    while ((c = getopt(argc, argv, "bCl:pP:qs:v")) != EOF) {

        switch (c) {

        case 'b':

            bflag = 1;

            break;

        case 'C':

            Cflag = 1;

            break;

        case 'l':

            lflag = 1;

            pattern_count = cvtnum(optarg);

            if (pattern_count < 0) {

                printf("non-numeric length argument -- %s\n", optarg);

                return 0;

            }

            break;

        case 'p':

            pflag = 1;

            break;

        case 'P':

            Pflag = 1;

            pattern = parse_pattern(optarg);

            if (pattern < 0) {

                return 0;

            }

            break;

        case 'q':

            qflag = 1;

            break;

        case 's':

            sflag = 1;

            pattern_offset = cvtnum(optarg);

            if (pattern_offset < 0) {

                printf("non-numeric length argument -- %s\n", optarg);

                return 0;

            }

            break;

        case 'v':

            vflag = 1;

            break;

        default:

            return qemuio_command_usage(&read_cmd);

        }

    }



    if (optind != argc - 2) {

        return qemuio_command_usage(&read_cmd);

    }



    if (bflag && pflag) {

        printf("-b and -p cannot be specified at the same time\n");

        return 0;

    }



    offset = cvtnum(argv[optind]);

    if (offset < 0) {

        printf("non-numeric length argument -- %s\n", argv[optind]);

        return 0;

    }



    optind++;

    count = cvtnum(argv[optind]);

    if (count < 0) {

        printf("non-numeric length argument -- %s\n", argv[optind]);

        return 0;

    }



    if (!Pflag && (lflag || sflag)) {

        return qemuio_command_usage(&read_cmd);

    }



    if (!lflag) {

        pattern_count = count - pattern_offset;

    }



    if ((pattern_count < 0) || (pattern_count + pattern_offset > count))  {

        printf("pattern verification range exceeds end of read data\n");

        return 0;

    }



    if (!pflag) {

        if (offset & 0x1ff) {

            printf("offset %" PRId64 " is not sector aligned\n",

                   offset);

            return 0;

        }

        if (count & 0x1ff) {

            printf("count %d is not sector aligned\n",

                   count);

            return 0;

        }

    }



    buf = qemu_io_alloc(blk, count, 0xab);



    gettimeofday(&t1, NULL);

    if (pflag) {

        cnt = do_pread(blk, buf, offset, count, &total);

    } else if (bflag) {

        cnt = do_load_vmstate(blk, buf, offset, count, &total);

    } else {

        cnt = do_read(blk, buf, offset, count, &total);

    }

    gettimeofday(&t2, NULL);



    if (cnt < 0) {

        printf("read failed: %s\n", strerror(-cnt));

        goto out;

    }



    if (Pflag) {

        void *cmp_buf = g_malloc(pattern_count);

        memset(cmp_buf, pattern, pattern_count);

        if (memcmp(buf + pattern_offset, cmp_buf, pattern_count)) {

            printf("Pattern verification failed at offset %"

                   PRId64 ", %d bytes\n",

                   offset + pattern_offset, pattern_count);

        }

        g_free(cmp_buf);

    }



    if (qflag) {

        goto out;

    }



    if (vflag) {

        dump_buffer(buf, offset, count);

    }



    /* Finally, report back -- -C gives a parsable format */

    t2 = tsub(t2, t1);

    print_report("read", &t2, offset, count, total, cnt, Cflag);



out:

    qemu_io_free(buf);



    return 0;

}

static int read_f(BlockBackend *blk, int argc, char **argv)

{

    struct timeval t1, t2;

    int Cflag = 0, pflag = 0, qflag = 0, vflag = 0;

    int Pflag = 0, sflag = 0, lflag = 0, bflag = 0;

    int c, cnt;

    char *buf;

    int64_t offset;

    int count;

    

    int total = 0;

    int pattern = 0, pattern_offset = 0, pattern_count = 0;



    while ((c = getopt(argc, argv, "bCl:pP:qs:v")) != EOF) {

        switch (c) {

        case 'b':

            bflag = 1;

            break;

        case 'C':

            Cflag = 1;

            break;

        case 'l':

            lflag = 1;

            pattern_count = cvtnum(optarg);

            if (pattern_count < 0) {

                printf("non-numeric length argument -- %s\n", optarg);

                return 0;

            }

            break;

        case 'p':

            pflag = 1;

            break;

        case 'P':

            Pflag = 1;

            pattern = parse_pattern(optarg);

            if (pattern < 0) {

                return 0;

            }

            break;

        case 'q':

            qflag = 1;

            break;

        case 's':

            sflag = 1;

            pattern_offset = cvtnum(optarg);

            if (pattern_offset < 0) {

                printf("non-numeric length argument -- %s\n", optarg);

                return 0;

            }

            break;

        case 'v':

            vflag = 1;

            break;

        default:

            return qemuio_command_usage(&read_cmd);

        }

    }



    if (optind != argc - 2) {

        return qemuio_command_usage(&read_cmd);

    }



    if (bflag && pflag) {

        printf("-b and -p cannot be specified at the same time\n");

        return 0;

    }



    offset = cvtnum(argv[optind]);

    if (offset < 0) {

        printf("non-numeric length argument -- %s\n", argv[optind]);

        return 0;

    }



    optind++;

    count = cvtnum(argv[optind]);

    if (count < 0) {

        printf("non-numeric length argument -- %s\n", argv[optind]);

        return 0;

    }



    if (!Pflag && (lflag || sflag)) {

        return qemuio_command_usage(&read_cmd);

    }



    if (!lflag) {

        pattern_count = count - pattern_offset;

    }



    if ((pattern_count < 0) || (pattern_count + pattern_offset > count))  {

        printf("pattern verification range exceeds end of read data\n");

        return 0;

    }



    if (!pflag) {

        if (offset & 0x1ff) {

            printf("offset %" PRId64 " is not sector aligned\n",

                   offset);

            return 0;

        }

        if (count & 0x1ff) {

            printf("count %d is not sector aligned\n",

                   count);

            return 0;

        }

    }



    buf = qemu_io_alloc(blk, count, 0xab);



    gettimeofday(&t1, NULL);

    if (pflag) {

        cnt = do_pread(blk, buf, offset, count, &total);

    } else if (bflag) {

        cnt = do_load_vmstate(blk, buf, offset, count, &total);

    } else {

        cnt = do_read(blk, buf, offset, count, &total);

    }

    gettimeofday(&t2, NULL);



    if (cnt < 0) {

        printf("read failed: %s\n", strerror(-cnt));

        goto out;

    }



    if (Pflag) {

        void *cmp_buf = g_malloc(pattern_count);

        memset(cmp_buf, pattern, pattern_count);

        if (memcmp(buf + pattern_offset, cmp_buf, pattern_count)) {

            printf("Pattern verification failed at offset %"

                   PRId64 ", %d bytes\n",

                   offset + pattern_offset, pattern_count);

        }

        g_free(cmp_buf);

    }



    if (qflag) {

        goto out;

    }



    if (vflag) {

        dump_buffer(buf, offset, count);

    }



    

    t2 = tsub(t2, t1);

    print_report("read", &t2, offset, count, total, cnt, Cflag);



out:

    qemu_io_free(buf);



    return 0;

}

static int FUNC_0(BlockBackend *VAR_0, int VAR_1, char **VAR_2)

{

    struct timeval VAR_3, VAR_4;

    int VAR_5 = 0, VAR_6 = 0, VAR_7 = 0, VAR_8 = 0;

    int VAR_9 = 0, VAR_10 = 0, VAR_11 = 0, VAR_12 = 0;

    int VAR_13, VAR_14;

    char *VAR_15;

    int64_t offset;

    int VAR_16;

    

    int VAR_17 = 0;

    int VAR_18 = 0, VAR_19 = 0, VAR_20 = 0;



    while ((VAR_13 = getopt(VAR_1, VAR_2, "bCl:pP:qs:v")) != EOF) {

        switch (VAR_13) {

        case 'b':

            VAR_12 = 1;

            break;

        case 'C':

            VAR_5 = 1;

            break;

        case 'l':

            VAR_11 = 1;

            VAR_20 = cvtnum(optarg);

            if (VAR_20 < 0) {

                printf("non-numeric length argument -- %s\n", optarg);

                return 0;

            }

            break;

        case 'p':

            VAR_6 = 1;

            break;

        case 'P':

            VAR_9 = 1;

            VAR_18 = parse_pattern(optarg);

            if (VAR_18 < 0) {

                return 0;

            }

            break;

        case 'q':

            VAR_7 = 1;

            break;

        case 's':

            VAR_10 = 1;

            VAR_19 = cvtnum(optarg);

            if (VAR_19 < 0) {

                printf("non-numeric length argument -- %s\n", optarg);

                return 0;

            }

            break;

        case 'v':

            VAR_8 = 1;

            break;

        default:

            return qemuio_command_usage(&read_cmd);

        }

    }



    if (optind != VAR_1 - 2) {

        return qemuio_command_usage(&read_cmd);

    }



    if (VAR_12 && VAR_6) {

        printf("-b and -p cannot be specified at the same time\n");

        return 0;

    }



    offset = cvtnum(VAR_2[optind]);

    if (offset < 0) {

        printf("non-numeric length argument -- %s\n", VAR_2[optind]);

        return 0;

    }



    optind++;

    VAR_16 = cvtnum(VAR_2[optind]);

    if (VAR_16 < 0) {

        printf("non-numeric length argument -- %s\n", VAR_2[optind]);

        return 0;

    }



    if (!VAR_9 && (VAR_11 || VAR_10)) {

        return qemuio_command_usage(&read_cmd);

    }



    if (!VAR_11) {

        VAR_20 = VAR_16 - VAR_19;

    }



    if ((VAR_20 < 0) || (VAR_20 + VAR_19 > VAR_16))  {

        printf("VAR_18 verification range exceeds end of read data\n");

        return 0;

    }



    if (!VAR_6) {

        if (offset & 0x1ff) {

            printf("offset %" PRId64 " is not sector aligned\n",

                   offset);

            return 0;

        }

        if (VAR_16 & 0x1ff) {

            printf("VAR_16 %d is not sector aligned\n",

                   VAR_16);

            return 0;

        }

    }



    VAR_15 = qemu_io_alloc(VAR_0, VAR_16, 0xab);



    gettimeofday(&VAR_3, NULL);

    if (VAR_6) {

        VAR_14 = do_pread(VAR_0, VAR_15, offset, VAR_16, &VAR_17);

    } else if (VAR_12) {

        VAR_14 = do_load_vmstate(VAR_0, VAR_15, offset, VAR_16, &VAR_17);

    } else {

        VAR_14 = do_read(VAR_0, VAR_15, offset, VAR_16, &VAR_17);

    }

    gettimeofday(&VAR_4, NULL);



    if (VAR_14 < 0) {

        printf("read failed: %s\n", strerror(-VAR_14));

        goto out;

    }



    if (VAR_9) {

        void *VAR_21 = g_malloc(VAR_20);

        memset(VAR_21, VAR_18, VAR_20);

        if (memcmp(VAR_15 + VAR_19, VAR_21, VAR_20)) {

            printf("Pattern verification failed at offset %"

                   PRId64 ", %d bytes\n",

                   offset + VAR_19, VAR_20);

        }

        g_free(VAR_21);

    }



    if (VAR_7) {

        goto out;

    }



    if (VAR_8) {

        dump_buffer(VAR_15, offset, VAR_16);

    }



    

    VAR_4 = tsub(VAR_4, VAR_3);

    print_report("read", &VAR_4, offset, VAR_16, VAR_17, VAR_14, VAR_5);



out:

    qemu_io_free(VAR_15);



    return 0;

}

static int FUNC_0(BlockBackend *VAR_0, int VAR_1, char **VAR_2)
{ struct timeval VAR_3, VAR_4; int VAR_5 = 0, VAR_6 = 0, VAR_7 = 0, VAR_8 = 0; int VAR_9 = 0, VAR_10 = 0, VAR_11 = 0, VAR_12 = 0; int VAR_13, VAR_14; char *VAR_15; int64_t offset; int VAR_16; int VAR_17 = 0; int VAR_18 = 0, VAR_19 = 0, VAR_20 = 0; while ((VAR_13 = getopt(VAR_1, VAR_2, "bCl:pP:qs:v")) != EOF) { switch (VAR_13) { case 'b':
VAR_12 = 1; break; case 'C':
VAR_5 = 1; break; case 'l':
VAR_11 = 1; VAR_20 = cvtnum(optarg); if (VAR_20 < 0) { printf("non-numeric length argument -- %s\n", optarg); return 0; } break; case 'p':
VAR_6 = 1; break; case 'P':
VAR_9 = 1; VAR_18 = parse_pattern(optarg); if (VAR_18 < 0) { return 0; } break; case 'q':
VAR_7 = 1; break; case 's':
VAR_10 = 1; VAR_19 = cvtnum(optarg); if (VAR_19 < 0) { printf("non-numeric length argument -- %s\n", optarg); return 0; } break; case 'v':
VAR_8 = 1; break; default:
return qemuio_command_usage(&read_cmd); } } if (optind != VAR_1 - 2) { return qemuio_command_usage(&read_cmd); } if (VAR_12 && VAR_6) { printf("-b and -p cannot be specified at the same time\n"); return 0; } offset = cvtnum(VAR_2[optind]); if (offset < 0) { printf("non-numeric length argument -- %s\n", VAR_2[optind]); return 0; } optind++; VAR_16 = cvtnum(VAR_2[optind]); if (VAR_16 < 0) { printf("non-numeric length argument -- %s\n", VAR_2[optind]); return 0; } if (!VAR_9 && (VAR_11 || VAR_10)) { return qemuio_command_usage(&read_cmd); } if (!VAR_11) { VAR_20 = VAR_16 - VAR_19; } if ((VAR_20 < 0) || (VAR_20 + VAR_19 > VAR_16))  { printf("VAR_18 verification range exceeds end of read data\n"); return 0; } if (!VAR_6) { if (offset & 0x1ff) { printf("offset %" PRId64 " is not sector aligned\n",
offset); return 0; } if (VAR_16 & 0x1ff) { printf("VAR_16 %d is not sector aligned\n",
VAR_16); return 0; } } VAR_15 = qemu_io_alloc(VAR_0, VAR_16, 0xab); gettimeofday(&VAR_3, NULL); if (VAR_6) { VAR_14 = do_pread(VAR_0, VAR_15, offset, VAR_16, &VAR_17); } else if (VAR_12) { VAR_14 = do_load_vmstate(VAR_0, VAR_15, offset, VAR_16, &VAR_17); } else { VAR_14 = do_read(VAR_0, VAR_15, offset, VAR_16, &VAR_17); } gettimeofday(&VAR_4, NULL); if (VAR_14 < 0) { printf("read failed: %s\n", strerror(-VAR_14)); goto out; } if (VAR_9) { void *VAR_21 = g_malloc(VAR_20); memset(VAR_21, VAR_18, VAR_20); if (memcmp(VAR_15 + VAR_19, VAR_21, VAR_20)) { printf("Pattern verification failed at offset %"
PRId64 ", %d bytes\n",
offset + VAR_19, VAR_20); } g_free(VAR_21); } if (VAR_7) { goto out; } if (VAR_8) { dump_buffer(VAR_15, offset, VAR_16); } VAR_4 = tsub(VAR_4, VAR_3); print_report("read", &VAR_4, offset, VAR_16, VAR_17, VAR_14, VAR_5); out:
qemu_io_free(VAR_15); return 0; }