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

{

    struct timeval t1, t2;

    bool Cflag = false, qflag = false, bflag = false;

    bool Pflag = false, zflag = false, cflag = false;

    int flags = 0;

    int c, cnt;

    char *buf = NULL;

    int64_t offset;

    int64_t count;

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

    int64_t total = 0;

    int pattern = 0xcd;



    while ((c = getopt(argc, argv, "bcCfpP:quz")) != -1) {

        switch (c) {

        case 'b':

            bflag = true;

            break;

        case 'c':

            cflag = true;

            break;

        case 'C':

            Cflag = true;

            break;

        case 'f':

            flags |= BDRV_REQ_FUA;

            break;

        case 'p':

            /* Ignored for backwards compatibility */

            break;

        case 'P':

            Pflag = true;

            pattern = parse_pattern(optarg);

            if (pattern < 0) {

                return 0;

            }

            break;

        case 'q':

            qflag = true;

            break;

        case 'u':

            flags |= BDRV_REQ_MAY_UNMAP;

            break;

        case 'z':

            zflag = true;

            break;

        default:

            return qemuio_command_usage(&write_cmd);

        }

    }



    if (optind != argc - 2) {

        return qemuio_command_usage(&write_cmd);

    }



    if (bflag && zflag) {

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

        return 0;

    }



    if ((flags & BDRV_REQ_FUA) && (bflag || cflag)) {

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

        return 0;

    }



    if ((flags & BDRV_REQ_MAY_UNMAP) && !zflag) {

        printf("-u requires -z to be specified\n");

        return 0;

    }



    if (zflag && Pflag) {

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

        return 0;

    }



    offset = cvtnum(argv[optind]);

    if (offset < 0) {

        print_cvtnum_err(offset, argv[optind]);

        return 0;

    }



    optind++;

    count = cvtnum(argv[optind]);

    if (count < 0) {

        print_cvtnum_err(count, argv[optind]);

        return 0;

    } else if (count > SIZE_MAX) {

        printf("length cannot exceed %" PRIu64 ", given %s\n",

               (uint64_t) SIZE_MAX, argv[optind]);

        return 0;

    }



    if (bflag || cflag) {

        if (offset & 0x1ff) {

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

                   offset);

            return 0;

        }



        if (count & 0x1ff) {

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

                   count);

            return 0;

        }

    }



    if (!zflag) {

        buf = qemu_io_alloc(blk, count, pattern);

    }



    gettimeofday(&t1, NULL);

    if (bflag) {

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

    } else if (zflag) {

        cnt = do_co_pwrite_zeroes(blk, offset, count, flags, &total);

    } else if (cflag) {

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

    } else {

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

    }

    gettimeofday(&t2, NULL);



    if (cnt < 0) {

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

        goto out;

    }



    if (qflag) {

        goto out;

    }



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

    t2 = tsub(t2, t1);

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



out:

    if (!zflag) {

        qemu_io_free(buf);

    }



    return 0;

}

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

{

    struct timeval t1, t2;

    bool Cflag = false, qflag = false, bflag = false;

    bool Pflag = false, zflag = false, cflag = false;

    int flags = 0;

    int c, cnt;

    char *buf = NULL;

    int64_t offset;

    int64_t count;

    

    int64_t total = 0;

    int pattern = 0xcd;



    while ((c = getopt(argc, argv, "bcCfpP:quz")) != -1) {

        switch (c) {

        case 'b':

            bflag = true;

            break;

        case 'c':

            cflag = true;

            break;

        case 'C':

            Cflag = true;

            break;

        case 'f':

            flags |= BDRV_REQ_FUA;

            break;

        case 'p':

            

            break;

        case 'P':

            Pflag = true;

            pattern = parse_pattern(optarg);

            if (pattern < 0) {

                return 0;

            }

            break;

        case 'q':

            qflag = true;

            break;

        case 'u':

            flags |= BDRV_REQ_MAY_UNMAP;

            break;

        case 'z':

            zflag = true;

            break;

        default:

            return qemuio_command_usage(&write_cmd);

        }

    }



    if (optind != argc - 2) {

        return qemuio_command_usage(&write_cmd);

    }



    if (bflag && zflag) {

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

        return 0;

    }



    if ((flags & BDRV_REQ_FUA) && (bflag || cflag)) {

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

        return 0;

    }



    if ((flags & BDRV_REQ_MAY_UNMAP) && !zflag) {

        printf("-u requires -z to be specified\n");

        return 0;

    }



    if (zflag && Pflag) {

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

        return 0;

    }



    offset = cvtnum(argv[optind]);

    if (offset < 0) {

        print_cvtnum_err(offset, argv[optind]);

        return 0;

    }



    optind++;

    count = cvtnum(argv[optind]);

    if (count < 0) {

        print_cvtnum_err(count, argv[optind]);

        return 0;

    } else if (count > SIZE_MAX) {

        printf("length cannot exceed %" PRIu64 ", given %s\n",

               (uint64_t) SIZE_MAX, argv[optind]);

        return 0;

    }



    if (bflag || cflag) {

        if (offset & 0x1ff) {

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

                   offset);

            return 0;

        }



        if (count & 0x1ff) {

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

                   count);

            return 0;

        }

    }



    if (!zflag) {

        buf = qemu_io_alloc(blk, count, pattern);

    }



    gettimeofday(&t1, NULL);

    if (bflag) {

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

    } else if (zflag) {

        cnt = do_co_pwrite_zeroes(blk, offset, count, flags, &total);

    } else if (cflag) {

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

    } else {

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

    }

    gettimeofday(&t2, NULL);



    if (cnt < 0) {

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

        goto out;

    }



    if (qflag) {

        goto out;

    }



    

    t2 = tsub(t2, t1);

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



out:

    if (!zflag) {

        qemu_io_free(buf);

    }



    return 0;

}

    } else if (count > SIZE_MAX) {                (uint64_t) SIZE_MAX, argv[optind]);     } else if (count > SIZE_MAX) {                (uint64_t) SIZE_MAX, argv[optind]);
static int FUNC_0(BlockBackend *VAR_0, int VAR_1, char **VAR_2)

{

    struct timeval VAR_3, VAR_4;

    bool Cflag = false, qflag = false, bflag = false;

    bool Pflag = false, zflag = false, cflag = false;

    int VAR_5 = 0;

    int VAR_6, VAR_7;

    char *VAR_8 = NULL;

    int64_t offset;

    int64_t count;

    

    int64_t total = 0;

    int VAR_9 = 0xcd;



    while ((VAR_6 = getopt(VAR_1, VAR_2, "bcCfpP:quz")) != -1) {

        switch (VAR_6) {

        case 'b':

            bflag = true;

            break;

        case 'VAR_6':

            cflag = true;

            break;

        case 'C':

            Cflag = true;

            break;

        case 'f':

            VAR_5 |= BDRV_REQ_FUA;

            break;

        case 'p':

            

            break;

        case 'P':

            Pflag = true;

            VAR_9 = parse_pattern(optarg);

            if (VAR_9 < 0) {

                return 0;

            }

            break;

        case 'q':

            qflag = true;

            break;

        case 'u':

            VAR_5 |= BDRV_REQ_MAY_UNMAP;

            break;

        case 'z':

            zflag = true;

            break;

        default:

            return qemuio_command_usage(&write_cmd);

        }

    }



    if (optind != VAR_1 - 2) {

        return qemuio_command_usage(&write_cmd);

    }



    if (bflag && zflag) {

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

        return 0;

    }



    if ((VAR_5 & BDRV_REQ_FUA) && (bflag || cflag)) {

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

        return 0;

    }



    if ((VAR_5 & BDRV_REQ_MAY_UNMAP) && !zflag) {

        printf("-u requires -z to be specified\n");

        return 0;

    }



    if (zflag && Pflag) {

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

        return 0;

    }



    offset = cvtnum(VAR_2[optind]);

    if (offset < 0) {

        print_cvtnum_err(offset, VAR_2[optind]);

        return 0;

    }



    optind++;

    count = cvtnum(VAR_2[optind]);

    if (count < 0) {

        print_cvtnum_err(count, VAR_2[optind]);

        return 0;

    } else if (count > SIZE_MAX) {

        printf("length cannot exceed %" PRIu64 ", given %s\n",

               (uint64_t) SIZE_MAX, VAR_2[optind]);

        return 0;

    }



    if (bflag || cflag) {

        if (offset & 0x1ff) {

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

                   offset);

            return 0;

        }



        if (count & 0x1ff) {

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

                   count);

            return 0;

        }

    }



    if (!zflag) {

        VAR_8 = qemu_io_alloc(VAR_0, count, VAR_9);

    }



    gettimeofday(&VAR_3, NULL);

    if (bflag) {

        VAR_7 = do_save_vmstate(VAR_0, VAR_8, offset, count, &total);

    } else if (zflag) {

        VAR_7 = do_co_pwrite_zeroes(VAR_0, offset, count, VAR_5, &total);

    } else if (cflag) {

        VAR_7 = do_write_compressed(VAR_0, VAR_8, offset, count, &total);

    } else {

        VAR_7 = do_pwrite(VAR_0, VAR_8, offset, count, VAR_5, &total);

    }

    gettimeofday(&VAR_4, NULL);



    if (VAR_7 < 0) {

        printf("write failed: %s\n", strerror(-VAR_7));

        goto out;

    }



    if (qflag) {

        goto out;

    }



    

    VAR_4 = tsub(VAR_4, VAR_3);

    print_report("wrote", &VAR_4, offset, count, total, VAR_7, Cflag);



out:

    if (!zflag) {

        qemu_io_free(VAR_8);

    }



    return 0;

}

static int FUNC_0(BlockBackend *VAR_0, int VAR_1, char **VAR_2)
{ struct timeval VAR_3, VAR_4; bool Cflag = false, qflag = false, bflag = false; bool Pflag = false, zflag = false, cflag = false; int VAR_5 = 0; int VAR_6, VAR_7; char *VAR_8 = NULL; int64_t offset; int64_t count; int64_t total = 0; int VAR_9 = 0xcd; while ((VAR_6 = getopt(VAR_1, VAR_2, "bcCfpP:quz")) != -1) { switch (VAR_6) { case 'b':
bflag = true; break; case 'VAR_6':
cflag = true; break; case 'C':
Cflag = true; break; case 'f':
VAR_5 |= BDRV_REQ_FUA; break; case 'p':
break; case 'P':
Pflag = true; VAR_9 = parse_pattern(optarg); if (VAR_9 < 0) { return 0; } break; case 'q':
qflag = true; break; case 'u':
VAR_5 |= BDRV_REQ_MAY_UNMAP; break; case 'z':
zflag = true; break; default:
return qemuio_command_usage(&write_cmd); } } if (optind != VAR_1 - 2) { return qemuio_command_usage(&write_cmd); } if (bflag && zflag) { printf("-b and -z cannot be specified at the same time\n"); return 0; } if ((VAR_5 & BDRV_REQ_FUA) && (bflag || cflag)) { printf("-f and -b or -VAR_6 cannot be specified at the same time\n"); return 0; } if ((VAR_5 & BDRV_REQ_MAY_UNMAP) && !zflag) { printf("-u requires -z to be specified\n"); return 0; } if (zflag && Pflag) { printf("-z and -P cannot be specified at the same time\n"); return 0; } offset = cvtnum(VAR_2[optind]); if (offset < 0) { print_cvtnum_err(offset, VAR_2[optind]); return 0; } optind++; count = cvtnum(VAR_2[optind]); if (count < 0) { print_cvtnum_err(count, VAR_2[optind]); return 0; } else if (count > SIZE_MAX) { printf("length cannot exceed %" PRIu64 ", given %s\n",
(uint64_t) SIZE_MAX, VAR_2[optind]); return 0; } if (bflag || cflag) { if (offset & 0x1ff) { printf("offset %" PRId64 " is not sector aligned\n",
offset); return 0; } if (count & 0x1ff) { printf("count %"PRId64" is not sector aligned\n",
count); return 0; } } if (!zflag) { VAR_8 = qemu_io_alloc(VAR_0, count, VAR_9); } gettimeofday(&VAR_3, NULL); if (bflag) { VAR_7 = do_save_vmstate(VAR_0, VAR_8, offset, count, &total); } else if (zflag) { VAR_7 = do_co_pwrite_zeroes(VAR_0, offset, count, VAR_5, &total); } else if (cflag) { VAR_7 = do_write_compressed(VAR_0, VAR_8, offset, count, &total); } else { VAR_7 = do_pwrite(VAR_0, VAR_8, offset, count, VAR_5, &total); } gettimeofday(&VAR_4, NULL); if (VAR_7 < 0) { printf("write failed: %s\n", strerror(-VAR_7)); goto out; } if (qflag) { goto out; } VAR_4 = tsub(VAR_4, VAR_3); print_report("wrote", &VAR_4, offset, count, total, VAR_7, Cflag); out:
if (!zflag) { qemu_io_free(VAR_8); } return 0; }