+ void *p = io_u_verify_off(hdr, io_u, header_num);
+ struct vhdr_crc7 *vh = hdr_priv(hdr);
+ unsigned char c;
+
+ dprint(FD_VERIFY, "crc7 verify io_u %p, len %u\n", io_u, hdr->len);
+
+ c = crc7(p, hdr->len - hdr_size(hdr));
+
+ if (c != vh->crc7) {
+ log_err("crc7: verify failed at %llu/%u\n",
+ io_u->offset + header_num * hdr->len, hdr->len);
+ log_err("crc7: wanted %x, got %x\n", vh->crc7, c);
+ return EIO;
+ }
+
+ return 0;
+}
+
+static int verify_io_u_crc16(struct verify_header *hdr, struct io_u *io_u,
+ unsigned int header_num)
+{
+ void *p = io_u_verify_off(hdr, io_u, header_num);
+ struct vhdr_crc16 *vh = hdr_priv(hdr);
+ unsigned short c;
+
+ dprint(FD_VERIFY, "crc16 verify io_u %p, len %u\n", io_u, hdr->len);
+
+ c = crc16(p, hdr->len - hdr_size(hdr));
+
+ if (c != vh->crc16) {
+ log_err("crc16: verify failed at %llu/%u\n",
+ io_u->offset + header_num * hdr->len, hdr->len);
+ log_err("crc16: wanted %x, got %x\n", vh->crc16, c);
+ return EIO;
+ }
+
+ return 0;
+}
+
+static int verify_io_u_crc64(struct verify_header *hdr, struct io_u *io_u,
+ unsigned int header_num)
+{
+ void *p = io_u_verify_off(hdr, io_u, header_num);
+ struct vhdr_crc64 *vh = hdr_priv(hdr);
+ unsigned long long c;
+
+ dprint(FD_VERIFY, "crc64 verify io_u %p, len %u\n", io_u, hdr->len);
+
+ c = crc64(p, hdr->len - hdr_size(hdr));
+
+ if (c != vh->crc64) {
+ log_err("crc64: verify failed at %llu/%u\n",
+ io_u->offset + header_num * hdr->len,
+ hdr->len);
+ log_err("crc64: wanted %llx, got %llx\n",
+ (unsigned long long) vh->crc64, c);
+ return EIO;
+ }
+
+ return 0;
+}
+
+static int verify_io_u_crc32(struct verify_header *hdr, struct io_u *io_u,
+ unsigned int header_num)
+{
+ void *p = io_u_verify_off(hdr, io_u, header_num);
+ struct vhdr_crc32 *vh = hdr_priv(hdr);
+ uint32_t c;
+
+ dprint(FD_VERIFY, "crc32 verify io_u %p, len %u\n", io_u, hdr->len);
+
+ c = crc32(p, hdr->len - hdr_size(hdr));
+
+ if (c != vh->crc32) {
+ log_err("crc32: verify failed at %llu/%u\n",
+ io_u->offset + header_num * hdr->len, hdr->len);
+ log_err("crc32: wanted %x, got %x\n", vh->crc32, c);
+ return EIO;
+ }
+
+ return 0;
+}
+
+static int verify_io_u_md5(struct verify_header *hdr, struct io_u *io_u,
+ unsigned int header_num)
+{
+ void *p = io_u_verify_off(hdr, io_u, header_num);
+ struct vhdr_md5 *vh = hdr_priv(hdr);
+ uint32_t hash[MD5_HASH_WORDS];
+ struct md5_ctx md5_ctx = {
+ .hash = hash,
+ };
+
+ dprint(FD_VERIFY, "md5 verify io_u %p, len %u\n", io_u, hdr->len);
+
+ md5_init(&md5_ctx);
+ md5_update(&md5_ctx, p, hdr->len - hdr_size(hdr));
+
+ if (memcmp(vh->md5_digest, md5_ctx.hash, sizeof(hash))) {
+ log_err("md5: verify failed at %llu/%u\n",
+ io_u->offset + header_num * hdr->len, hdr->len);
+ hexdump(vh->md5_digest, sizeof(vh->md5_digest));
+ hexdump(md5_ctx.hash, sizeof(hash));
+ return EIO;
+ }
+
+ return 0;
+}
+
+static unsigned int hweight8(unsigned int w)
+{
+ unsigned int res = w - ((w >> 1) & 0x55);
+
+ res = (res & 0x33) + ((res >> 2) & 0x33);
+ return (res + (res >> 4)) & 0x0F;
+}
+
+int verify_io_u_pattern(unsigned long pattern, unsigned long pattern_size,
+ char *buf, unsigned int len, unsigned int mod)
+{
+ unsigned int i;
+ char split_pattern[4];
+
+ for (i = 0; i < 4; i++) {
+ split_pattern[i] = pattern & 0xff;
+ pattern >>= 8;
+ }
+
+ for (i = 0; i < len; i++) {
+ if (buf[i] != split_pattern[mod]) {
+ unsigned int bits;
+
+ bits = hweight8(buf[i] ^ split_pattern[mod]);
+ log_err("fio: got pattern %x, wanted %x. Bad bits %d\n",
+ buf[i], split_pattern[mod], bits);
+ log_err("fio: bad pattern block offset %u\n", i);
+ return EIO;
+ }
+ mod++;
+ if (mod == pattern_size)
+ mod = 0;
+ }
+
+ return 0;
+}
+
+int verify_io_u(struct thread_data *td, struct io_u *io_u)
+{
+ struct verify_header *hdr;
+ unsigned int hdr_size, hdr_inc, hdr_num = 0;
+ void *p;