write_f(int argc, char **argv)

{

	struct timeval t1, t2;

	int Cflag = 0, pflag = 0, qflag = 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 = 0xcd;



	while ((c = getopt(argc, argv, "bCpP:q")) != EOF) {

		switch (c) {

		case 'b':

			bflag = 1;

			break;

		case 'C':

			Cflag = 1;

			break;

		case 'p':

			pflag = 1;

			break;

		case 'P':

			pattern = atoi(optarg);

			break;

		case 'q':

			qflag = 1;

			break;

		default:

			return command_usage(&write_cmd);

		}

	}



	if (optind != argc - 2)

		return command_usage(&write_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) {

		if (offset & 0x1ff) {

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

				(long long)offset);

			return 0;

		}



		if (count & 0x1ff) {

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

				count);

			return 0;

		}

	}



	buf = qemu_io_alloc(count, pattern);



	gettimeofday(&t1, NULL);

	if (pflag)

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

	else if (bflag)

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

	else

		cnt = do_write(buf, offset, count, &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:

	qemu_io_free(buf);



	return 0;

}

write_f(int argc, char **argv)

{

	struct timeval t1, t2;

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

	int c, cnt;

	char *buf;

	int64_t offset;

	int count;

        

        int total = 0;

	int pattern = 0xcd;



	while ((c = getopt(argc, argv, "bCpP:q")) != EOF) {

		switch (c) {

		case 'b':

			bflag = 1;

			break;

		case 'C':

			Cflag = 1;

			break;

		case 'p':

			pflag = 1;

			break;

		case 'P':

			pattern = atoi(optarg);

			break;

		case 'q':

			qflag = 1;

			break;

		default:

			return command_usage(&write_cmd);

		}

	}



	if (optind != argc - 2)

		return command_usage(&write_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) {

		if (offset & 0x1ff) {

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

				(long long)offset);

			return 0;

		}



		if (count & 0x1ff) {

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

				count);

			return 0;

		}

	}



	buf = qemu_io_alloc(count, pattern);



	gettimeofday(&t1, NULL);

	if (pflag)

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

	else if (bflag)

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

	else

		cnt = do_write(buf, offset, count, &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:

	qemu_io_free(buf);



	return 0;

}

FUNC_0(int VAR_0, char **VAR_1)

{

	struct timeval VAR_2, VAR_3;

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

	int VAR_8, VAR_9;

	char *VAR_10;

	int64_t offset;

	int VAR_11;

        

        int VAR_12 = 0;

	int VAR_13 = 0xcd;



	while ((VAR_8 = getopt(VAR_0, VAR_1, "bCpP:q")) != EOF) {

		switch (VAR_8) {

		case 'b':

			VAR_7 = 1;

			break;

		case 'C':

			VAR_4 = 1;

			break;

		case 'p':

			VAR_5 = 1;

			break;

		case 'P':

			VAR_13 = atoi(optarg);

			break;

		case 'q':

			VAR_6 = 1;

			break;

		default:

			return command_usage(&write_cmd);

		}

	}



	if (optind != VAR_0 - 2)

		return command_usage(&write_cmd);



	if (VAR_7 && VAR_5) {

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

		return 0;

	}



	offset = cvtnum(VAR_1[optind]);

	if (offset < 0) {

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

		return 0;

	}



	optind++;

	VAR_11 = cvtnum(VAR_1[optind]);

	if (VAR_11 < 0) {

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

		return 0;

	}



	if (!VAR_5) {

		if (offset & 0x1ff) {

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

				(long long)offset);

			return 0;

		}



		if (VAR_11 & 0x1ff) {

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

				VAR_11);

			return 0;

		}

	}



	VAR_10 = qemu_io_alloc(VAR_11, VAR_13);



	gettimeofday(&VAR_2, NULL);

	if (VAR_5)

		VAR_9 = do_pwrite(VAR_10, offset, VAR_11, &VAR_12);

	else if (VAR_7)

		VAR_9 = do_save_vmstate(VAR_10, offset, VAR_11, &VAR_12);

	else

		VAR_9 = do_write(VAR_10, offset, VAR_11, &VAR_12);

	gettimeofday(&VAR_3, NULL);



	if (VAR_9 < 0) {

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

		goto out;

	}



	if (VAR_6)

		goto out;



	

	VAR_3 = tsub(VAR_3, VAR_2);

	print_report("wrote", &VAR_3, offset, VAR_11, VAR_12, VAR_9, VAR_4);



out:

	qemu_io_free(VAR_10);



	return 0;

}

FUNC_0(int VAR_0, char **VAR_1)
{ struct timeval VAR_2, VAR_3; int VAR_4 = 0, VAR_5 = 0, VAR_6 = 0, VAR_7 = 0; int VAR_8, VAR_9; char *VAR_10; int64_t offset; int VAR_11; int VAR_12 = 0; int VAR_13 = 0xcd; while ((VAR_8 = getopt(VAR_0, VAR_1, "bCpP:q")) != EOF) { switch (VAR_8) { case 'b':
VAR_7 = 1; break; case 'C':
VAR_4 = 1; break; case 'p':
VAR_5 = 1; break; case 'P':
VAR_13 = atoi(optarg); break; case 'q':
VAR_6 = 1; break; default:
return command_usage(&write_cmd); } } if (optind != VAR_0 - 2)
return command_usage(&write_cmd); if (VAR_7 && VAR_5) { printf("-b and -p cannot be specified at the same time\n"); return 0; } offset = cvtnum(VAR_1[optind]); if (offset < 0) { printf("non-numeric length argument -- %s\n", VAR_1[optind]); return 0; } optind++; VAR_11 = cvtnum(VAR_1[optind]); if (VAR_11 < 0) { printf("non-numeric length argument -- %s\n", VAR_1[optind]); return 0; } if (!VAR_5) { if (offset & 0x1ff) { printf("offset %lld is not sector aligned\n",
(long long)offset); return 0; } if (VAR_11 & 0x1ff) { printf("VAR_11 %d is not sector aligned\n",
VAR_11); return 0; } } VAR_10 = qemu_io_alloc(VAR_11, VAR_13); gettimeofday(&VAR_2, NULL); if (VAR_5)
VAR_9 = do_pwrite(VAR_10, offset, VAR_11, &VAR_12); else if (VAR_7)
VAR_9 = do_save_vmstate(VAR_10, offset, VAR_11, &VAR_12); else
VAR_9 = do_write(VAR_10, offset, VAR_11, &VAR_12); gettimeofday(&VAR_3, NULL); if (VAR_9 < 0) { printf("write failed: %s\n", strerror(-VAR_9)); goto out; } if (VAR_6)
goto out; VAR_3 = tsub(VAR_3, VAR_2); print_report("wrote", &VAR_3, offset, VAR_11, VAR_12, VAR_9, VAR_4); out:
qemu_io_free(VAR_10); return 0; }