"\n"
" Reads a segment of the currently open file, optionally dumping it to the\n"
" standard output stream (with -v option) for subsequent inspection.\n"
-" -p, -- use bdrv_pread to read the file\n"
" -C, -- report statistics in a machine parsable format\n"
-" -v, -- dump buffer to standard output\n"
+" -l, -- length for pattern verification (only with -P)\n"
+" -p, -- use bdrv_pread to read the file\n"
+" -P, -- use a pattern to verify read data\n"
" -q, -- quite mode, do not show I/O statistics\n"
+" -s, -- start offset for pattern verification (only with -P)\n"
+" -v, -- dump buffer to standard output\n"
"\n");
}
{
struct timeval t1, t2;
int Cflag = 0, pflag = 0, qflag = 0, vflag = 0;
+ int Pflag = 0, sflag = 0, lflag = 0;
int c, cnt;
char *buf;
int64_t offset;
- int count, total;
+ 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, "Cpqv")) != EOF) {
+ while ((c = getopt(argc, argv, "Cl:pP:qs:v")) != EOF) {
switch (c) {
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 = atoi(optarg);
+ 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;
return 0;
}
+ if (!Pflag && (lflag || sflag)) {
+ return command_usage(&read_cmd);
+ }
+
+ if (!lflag) {
+ pattern_count = count - pattern_offset;
+ }
+
+ if ((pattern_count < 0) || (pattern_count + pattern_offset > count)) {
+ printf("pattern verfication range exceeds end of read data\n");
+ return 0;
+ }
+
if (!pflag)
if (offset & 0x1ff) {
printf("offset %lld is not sector aligned\n",
return 0;
}
+ if (Pflag) {
+ void* cmp_buf = malloc(pattern_count);
+ memset(cmp_buf, pattern, pattern_count);
+ if (memcmp(buf + pattern_offset, cmp_buf, pattern_count)) {
+ printf("Pattern verification failed at offset %lld, "
+ "%d bytes\n",
+ (long long) offset + pattern_offset, pattern_count);
+ }
+ free(cmp_buf);
+ }
+
if (qflag)
return 0;
.cfunc = read_f,
.argmin = 2,
.argmax = -1,
- .args = "[-aCpqv] off len",
+ .args = "[-aCpqv] [-P pattern [-s off] [-l len]] off len",
.oneline = "reads a number of bytes at a specified offset",
.help = read_help,
};
" standard output stream (with -v option) for subsequent inspection.\n"
" Uses multiple iovec buffers if more than one byte range is specified.\n"
" -C, -- report statistics in a machine parsable format\n"
+" -P, -- use a pattern to verify read data\n"
" -v, -- dump buffer to standard output\n"
" -q, -- quite mode, do not show I/O statistics\n"
"\n");
int count = 0, total;
int nr_iov, i;
QEMUIOVector qiov;
+ int pattern = 0;
+ int Pflag = 0;
- while ((c = getopt(argc, argv, "Cqv")) != EOF) {
+ while ((c = getopt(argc, argv, "CP:qv")) != EOF) {
switch (c) {
case 'C':
Cflag = 1;
break;
+ case 'P':
+ Pflag = 1;
+ pattern = atoi(optarg);
+ break;
case 'q':
qflag = 1;
break;
return 0;
}
+ if (Pflag) {
+ void* cmp_buf = malloc(count);
+ memset(cmp_buf, pattern, count);
+ if (memcmp(buf, cmp_buf, count)) {
+ printf("Pattern verification failed at offset %lld, "
+ "%d bytes\n",
+ (long long) offset, count);
+ }
+ free(cmp_buf);
+ }
+
if (qflag)
return 0;
.cfunc = readv_f,
.argmin = 2,
.argmax = -1,
- .args = "[-Cqv] off len [len..]",
+ .args = "[-Cqv] [-P pattern ] off len [len..]",
.oneline = "reads a number of bytes at a specified offset",
.help = readv_help,
};
int c, cnt;
char *buf;
int64_t offset;
- int count, total;
+ int count;
+ /* Some compilers get confused and warn if this is not initialized. */
+ int total = 0;
int pattern = 0xcd;
while ((c = getopt(argc, argv, "CpP:q")) != EOF) {
char s1[64];
int num;
int ret;
+ const char *retstr;
offset = cvtnum(argv[1]);
if (offset & 0x1ff) {
nb_sectors = 1;
ret = bdrv_is_allocated(bs, offset >> 9, nb_sectors, &num);
- if (ret) {
- printf("is_allocated: %s", strerror(ret));
- return 0;
- }
cvtstr(offset, s1, sizeof(s1));
+ retstr = ret ? "allocated" : "not allocated";
if (nb_sectors == 1)
- printf("sector allocated at offset %s\n", s1);
+ printf("sector %s at offset %s\n", retstr, s1);
else
- printf("%d/%d sectors allocated at offset %s\n",
- num, nb_sectors, s1);
+ printf("%d/%d sectors %s at offset %s\n",
+ num, nb_sectors, retstr, s1);
return 0;
}