+ unsigned int kb_base = fio_get_kb_base(data);
+ unsigned long long ret = 1;
+ unsigned int i, pow = 0, mult = kb_base;
+ char *c;
+
+ if (!p)
+ return 1;
+
+ c = strdup(p);
+
+ for (i = 0; i < strlen(c); i++)
+ c[i] = tolower(c[i]);
+
+ if (!strcmp("pib", c)) {
+ pow = 5;
+ mult = 1000;
+ } else if (!strcmp("tib", c)) {
+ pow = 4;
+ mult = 1000;
+ } else if (!strcmp("gib", c)) {
+ pow = 3;
+ mult = 1000;
+ } else if (!strcmp("mib", c)) {
+ pow = 2;
+ mult = 1000;
+ } else if (!strcmp("kib", c)) {
+ pow = 1;
+ mult = 1000;
+ } else if (!strcmp("p", c) || !strcmp("pb", c))
+ pow = 5;
+ else if (!strcmp("t", c) || !strcmp("tb", c))
+ pow = 4;
+ else if (!strcmp("g", c) || !strcmp("gb", c))
+ pow = 3;
+ else if (!strcmp("m", c) || !strcmp("mb", c))
+ pow = 2;
+ else if (!strcmp("k", c) || !strcmp("kb", c))
+ pow = 1;
+
+ while (pow--)
+ ret *= (unsigned long long) mult;
+
+ free(c);
+ return ret;
+}
+
+static unsigned long long get_mult_bytes(const char *str, int len, void *data)
+{
+ const char *p;
+
+ if (len < 2)
+ return __get_mult_bytes(str, data);
+
+ /*
+ * if the last char is 'b' or 'B', the user likely used
+ * "1gb" instead of just "1g". If the second to last is also
+ * a letter, adjust.
+ */
+ p = str + len - 1;
+ while (isalpha(*(p - 1)))
+ p--;
+ if (!isalpha(*p))
+ p = NULL;
+
+ return __get_mult_bytes(p, data);