+ 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;