-static int pattern_cb(char *pattern, unsigned int max_size,
- const char *input, unsigned int *pattern_bytes)
-{
- long off;
- int i = 0, j = 0, len, k, base = 10;
- uint32_t pattern_length;
- char *loc1, *loc2;
-
- loc1 = strstr(input, "0x");
- loc2 = strstr(input, "0X");
- if (loc1 || loc2)
- base = 16;
- off = strtol(input, NULL, base);
- if (off != LONG_MAX || errno != ERANGE) {
- while (off) {
- pattern[i] = off & 0xff;
- off >>= 8;
- i++;
- }
- } else {
- len = strlen(input);
- k = len - 1;
- if (base == 16) {
- if (loc1)
- j = loc1 - input + 2;
- else
- j = loc2 - input + 2;
- } else
- return 1;
- if (len - j < max_size * 2) {
- while (k >= j) {
- off = converthexchartoint(input[k--]);
- if (k >= j)
- off += (converthexchartoint(input[k--])
- * 16);
- pattern[i++] = (char) off;
- }
- }
- }
-
- /*
- * Fill the pattern all the way to the end. This greatly reduces
- * the number of memcpy's we have to do when verifying the IO.
- */
- pattern_length = i;
- while (i > 1 && i * 2 <= max_size) {
- memcpy(&pattern[i], &pattern[0], i);
- i *= 2;
- }
-
- /*
- * Fill remainder, if the pattern multiple ends up not being
- * max_size.
- */
- while (i > 1 && i < max_size) {
- unsigned int b = min(pattern_length, max_size - i);
-
- memcpy(&pattern[i], &pattern[0], b);
- i += b;
- }
-
- if (i == 1) {
- /*
- * The code in verify_io_u_pattern assumes a single byte
- * pattern fills the whole verify pattern buffer.
- */
- memset(pattern, pattern[0], max_size);
- }
-
- *pattern_bytes = i;
- return 0;
-}
-