2 * This file contains the ini and command liner parser main.
14 static unsigned long get_mult_time(char c)
31 static unsigned long get_mult_bytes(char c)
42 return 1024 * 1024 * 1024;
49 * convert string into decimal value, noting any size suffix
51 static int str_to_decimal(const char *str, unsigned long long *val, int kilo)
57 *val = strtoul(str, NULL, 10);
58 if (*val == ULONG_MAX && errno == ERANGE)
62 *val *= get_mult_bytes(str[len - 1]);
64 *val *= get_mult_time(str[len - 1]);
68 static int check_str_bytes(const char *p, unsigned long long *val)
70 return str_to_decimal(p, val, 1);
73 static int check_str_time(const char *p, unsigned long long *val)
75 return str_to_decimal(p, val, 0);
78 void strip_blank_front(char **p)
86 void strip_blank_end(char *p)
88 char *s = p + strlen(p) - 1;
90 while (isspace(*s) || iscntrl(*s))
96 static int check_range_bytes(const char *str, unsigned long *val)
100 if (sscanf(str, "%lu%c", val, &suffix) == 2) {
101 *val *= get_mult_bytes(suffix);
105 if (sscanf(str, "%lu", val) == 1)
111 static int check_int(const char *p, unsigned int *val)
113 if (sscanf(p, "%u", val) == 1)
119 static struct fio_option *find_option(struct fio_option *options,
122 struct fio_option *o = &options[0];
125 if (!strcmp(o->name, opt))
134 static int handle_option(struct fio_option *o, const char *ptr, void *data)
136 unsigned int il, *ilp;
137 unsigned long long ull, *ullp;
138 unsigned long ul1, ul2, *ulp1, *ulp2;
140 int ret = 0, is_time = 0;
144 fio_opt_str_fn *fn = o->cb;
149 case FIO_OPT_STR_VAL_TIME:
151 case FIO_OPT_STR_VAL: {
152 fio_opt_str_val_fn *fn = o->cb;
155 ret = check_str_time(ptr, &ull);
157 ret = check_str_bytes(ptr, &ull);
162 if (o->max_val && ull > o->max_val)
166 ret = fn(data, &ull);
168 ullp = td_var(data, o->off1);
173 case FIO_OPT_STR_STORE:
174 cp = td_var(data, o->off1);
177 case FIO_OPT_RANGE: {
183 p1 = strchr(tmp, '-');
194 if (!check_range_bytes(p1, &ul1) && !check_range_bytes(p2, &ul2)) {
196 ulp1 = td_var(data, o->off1);
197 ulp2 = td_var(data, o->off2);
210 fio_opt_int_fn *fn = o->cb;
212 ret = check_int(ptr, &il);
216 if (o->max_val && il > o->max_val)
222 ilp = td_var(data, o->off1);
227 case FIO_OPT_STR_SET: {
228 fio_opt_str_set_fn *fn = o->cb;
233 ilp = td_var(data, o->off1);
239 fprintf(stderr, "Bad option type %d\n", o->type);
244 fprintf(stderr, "fio: failed parsing %s=%s\n", o->name, ptr);
249 int parse_cmd_option(const char *opt, const char *val,
250 struct fio_option *options, void *data)
252 struct fio_option *o;
254 o = find_option(options, opt);
256 fprintf(stderr, "Bad option %s\n", opt);
260 return handle_option(o, val, data);
263 int parse_option(const char *opt, struct fio_option *options, void *data)
265 struct fio_option *o;
271 pre = strchr(tmp, '=');
277 o = find_option(options, pre);
279 o = find_option(options, tmp);
284 fprintf(stderr, "Bad option %s\n", tmp);
288 return handle_option(o, post, data);