+/*
+ * Prepare for seperation of verify_header and checksum header
+ */
+static inline unsigned int __hdr_size(int verify_type)
+{
+ unsigned int len = len;
+
+ switch (verify_type) {
+ case VERIFY_NONE:
+ case VERIFY_NULL:
+ len = 0;
+ break;
+ case VERIFY_MD5:
+ len = sizeof(struct vhdr_md5);
+ break;
+ case VERIFY_CRC64:
+ len = sizeof(struct vhdr_crc64);
+ break;
+ case VERIFY_CRC32C:
+ case VERIFY_CRC32:
+ case VERIFY_CRC32C_INTEL:
+ len = sizeof(struct vhdr_crc32);
+ break;
+ case VERIFY_CRC16:
+ len = sizeof(struct vhdr_crc16);
+ break;
+ case VERIFY_CRC7:
+ len = sizeof(struct vhdr_crc7);
+ break;
+ case VERIFY_SHA256:
+ len = sizeof(struct vhdr_sha256);
+ break;
+ case VERIFY_SHA512:
+ len = sizeof(struct vhdr_sha512);
+ break;
+ case VERIFY_META:
+ len = sizeof(struct vhdr_meta);
+ break;
+ default:
+ log_err("fio: unknown verify header!\n");
+ assert(0);
+ }
+
+ return len + sizeof(struct verify_header);
+}
+
+static inline unsigned int hdr_size(struct verify_header *hdr)
+{
+ return __hdr_size(hdr->verify_type);
+}
+
+static void *hdr_priv(struct verify_header *hdr)
+{
+ void *priv = hdr;
+
+ return priv + sizeof(struct verify_header);
+}
+
+/*
+ * Return data area 'header_num'
+ */
+static inline void *io_u_verify_off(struct verify_header *hdr,
+ struct io_u *io_u, unsigned char header_num)
+{
+ return io_u->buf + header_num * hdr->len + hdr_size(hdr);
+}
+
+static int verify_io_u_meta(struct verify_header *hdr, struct thread_data *td,
+ struct io_u *io_u, unsigned int header_num)
+{
+ struct vhdr_meta *vh = hdr_priv(hdr);
+
+ dprint(FD_VERIFY, "meta verify io_u %p, len %u\n", io_u, hdr->len);
+
+ if (vh->offset != io_u->offset + header_num * td->o.verify_interval) {
+ log_err("meta: verify failed at %llu/%u\n",
+ io_u->offset + header_num * hdr->len, hdr->len);
+ return EILSEQ;
+ }
+
+ return 0;
+}
+
+static int verify_io_u_sha512(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_sha512 *vh = hdr_priv(hdr);
+ uint8_t sha512[128];
+ struct sha512_ctx sha512_ctx = {
+ .buf = sha512,
+ };
+
+ dprint(FD_VERIFY, "sha512 verify io_u %p, len %u\n", io_u, hdr->len);
+
+ sha512_init(&sha512_ctx);
+ sha512_update(&sha512_ctx, p, hdr->len - hdr_size(hdr));
+
+ if (memcmp(vh->sha512, sha512_ctx.buf, sizeof(sha512))) {
+ log_err("sha512: verify failed at %llu/%u\n",
+ io_u->offset + header_num * hdr->len, hdr->len);
+ hexdump(vh->sha512, sizeof(vh->sha512));
+ hexdump(sha512_ctx.buf, sizeof(sha512));
+ return EILSEQ;
+ }
+
+ return 0;
+}
+
+static int verify_io_u_sha256(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_sha256 *vh = hdr_priv(hdr);
+ uint8_t sha256[128];
+ struct sha256_ctx sha256_ctx = {
+ .buf = sha256,
+ };
+
+ dprint(FD_VERIFY, "sha256 verify io_u %p, len %u\n", io_u, hdr->len);
+
+ sha256_init(&sha256_ctx);
+ sha256_update(&sha256_ctx, p, hdr->len - hdr_size(hdr));
+
+ if (memcmp(vh->sha256, sha256_ctx.buf, sizeof(sha256))) {
+ log_err("sha256: verify failed at %llu/%u\n",
+ io_u->offset + header_num * hdr->len, hdr->len);
+ hexdump(vh->sha256, sizeof(vh->sha256));
+ hexdump(sha256_ctx.buf, sizeof(sha256));
+ return EILSEQ;
+ }
+
+ return 0;
+}
+
+static int verify_io_u_crc7(struct verify_header *hdr, struct io_u *io_u,
+ unsigned char header_num)
+{
+ 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 EILSEQ;
+ }
+
+ 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 EILSEQ;
+ }
+
+ return 0;
+}
+
+static int verify_io_u_crc64(struct verify_header *hdr, struct io_u *io_u,
+ unsigned int header_num)