Document parser int taking hex input
[fio.git] / verify.c
index 41c2f77e7a3bfc027b0eb09316234f702776ba96..d98dfcf4c52b8bd5a43411bb2cf8397c6fd0952d 100644 (file)
--- a/verify.c
+++ b/verify.c
@@ -50,10 +50,20 @@ static void hexdump(void *buffer, int len)
        log_info("\n");
 }
 
+/*
+ * 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 + sizeof(*hdr) + header_num * hdr->len;
+}
+
 static int verify_io_u_crc7(struct verify_header *hdr, struct io_u *io_u,
                             unsigned char header_num)
 {
-       void *p = io_u->buf + header_num * hdr->len + sizeof(*hdr);
+       void *p = io_u_verify_off(hdr, io_u, header_num);
        unsigned char c;
 
        c = crc7(p, hdr->len - sizeof(*hdr));
@@ -72,7 +82,7 @@ static int verify_io_u_crc7(struct verify_header *hdr, struct io_u *io_u,
 static int verify_io_u_crc16(struct verify_header *hdr, struct io_u *io_u,
                              unsigned int header_num)
 {
-       void *p = io_u->buf + header_num * hdr->len + sizeof(*hdr);
+       void *p = io_u_verify_off(hdr, io_u, header_num);
        unsigned short c;
 
        c = crc16(p, hdr->len - sizeof(*hdr));
@@ -91,7 +101,7 @@ static int verify_io_u_crc16(struct verify_header *hdr, struct io_u *io_u,
 static int verify_io_u_crc64(struct verify_header *hdr, struct io_u *io_u,
                              unsigned int header_num)
 {
-       void *p = io_u->buf + header_num * hdr->len + sizeof(*hdr);
+       void *p = io_u_verify_off(hdr, io_u, header_num);
        unsigned long long c;
 
        c = crc64(p, hdr->len - sizeof(*hdr));
@@ -110,7 +120,7 @@ static int verify_io_u_crc64(struct verify_header *hdr, struct io_u *io_u,
 static int verify_io_u_crc32(struct verify_header *hdr, struct io_u *io_u,
                             unsigned int header_num)
 {
-       void *p = io_u->buf + header_num * hdr->len + sizeof(*hdr);
+       void *p = io_u_verify_off(hdr, io_u, header_num);
        unsigned long c;
 
        c = crc32(p, hdr->len - sizeof(*hdr));
@@ -129,15 +139,16 @@ static int verify_io_u_crc32(struct verify_header *hdr, struct io_u *io_u,
 static int verify_io_u_md5(struct verify_header *hdr, struct io_u *io_u,
                           unsigned int header_num)
 {
-       void *p = io_u->buf + header_num * hdr->len + sizeof(*hdr);
+       void *p = io_u_verify_off(hdr, io_u, header_num);
        uint32_t hash[MD5_HASH_WORDS];
        struct md5_ctx md5_ctx = {
                .hash = hash,
        };
 
+       memset(md5_ctx.hash, 0, sizeof(hdr->md5_digest));
        md5_update(&md5_ctx, p, hdr->len - sizeof(*hdr));
 
-       if (memcmp(hdr->md5_digest, md5_ctx.hash, sizeof(md5_ctx.hash))) {
+       if (memcmp(hdr->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);
@@ -160,12 +171,12 @@ int verify_io_u(struct thread_data *td, struct io_u *io_u)
                return 0;
 
        hdr_inc = io_u->buflen;
-       if (td->o.header_interval)
-               hdr_inc = td->o.header_interval;
+       if (td->o.verify_interval)
+               hdr_inc = td->o.verify_interval;
 
        for (p = io_u->buf; p < io_u->buf + io_u->buflen; p += hdr_inc) {
-               if (td->o.header_offset)
-                       memswp(p, p + td->o.header_offset, sizeof(*hdr));
+               if (td->o.verify_offset)
+                       memswp(p, p + td->o.verify_offset, sizeof(*hdr));
 
                hdr = p;
 
@@ -226,6 +237,7 @@ static void fill_md5(struct verify_header *hdr, void *p, unsigned int len)
                .hash = (uint32_t *) hdr->md5_digest,
        };
 
+       memset(md5_ctx.hash, 0, sizeof(hdr->md5_digest));
        md5_update(&md5_ctx, p, len);
 }
 
@@ -245,8 +257,8 @@ void populate_verify_io_u(struct thread_data *td, struct io_u *io_u)
        fill_random_bytes(td, p, io_u->buflen);
 
        hdr_inc = io_u->buflen;
-       if (td->o.header_interval)
-               hdr_inc = td->o.header_interval;
+       if (td->o.verify_interval)
+               hdr_inc = td->o.verify_interval;
        data_len = hdr_inc - sizeof(*hdr);
 
        for (;p < io_u->buf + io_u->buflen; p += hdr_inc) {
@@ -277,8 +289,8 @@ void populate_verify_io_u(struct thread_data *td, struct io_u *io_u)
                        log_err("fio: bad verify type: %d\n", td->o.verify);
                        assert(0);
                }
-               if (td->o.header_offset)
-                       memswp(p, p + td->o.header_offset, sizeof(*hdr));
+               if (td->o.verify_offset)
+                       memswp(p, p + td->o.verify_offset, sizeof(*hdr));
        }
 }