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, *ilp1, *ilp2;
137 unsigned long long ull, *ullp;
138 unsigned long ul1, ul2;
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 case FIO_OPT_STR_VAL_INT: {
153 fio_opt_str_val_fn *fn = o->cb;
156 ret = check_str_time(ptr, &ull);
158 ret = check_str_bytes(ptr, &ull);
163 if (o->max_val && ull > o->max_val)
167 ret = fn(data, &ull);
169 if (o->type == FIO_OPT_STR_VAL_INT) {
170 ilp1 = td_var(data, o->off1);
173 ullp = td_var(data, o->off1);
179 case FIO_OPT_STR_STORE:
180 cp = td_var(data, o->off1);
183 case FIO_OPT_RANGE: {
187 strncpy(tmp, ptr, sizeof(tmp) - 1);
189 p1 = strchr(tmp, '-');
200 if (!check_range_bytes(p1, &ul1) && !check_range_bytes(p2, &ul2)) {
202 ilp1 = td_var(data, o->off1);
203 ilp2 = td_var(data, o->off2);
216 fio_opt_int_fn *fn = o->cb;
218 ret = check_int(ptr, &il);
222 if (o->max_val && il > o->max_val)
228 ilp1 = td_var(data, o->off1);
233 case FIO_OPT_STR_SET: {
234 fio_opt_str_set_fn *fn = o->cb;
239 ilp1 = td_var(data, o->off1);
245 fprintf(stderr, "Bad option type %d\n", o->type);
252 int parse_cmd_option(const char *opt, const char *val,
253 struct fio_option *options, void *data)
255 struct fio_option *o;
257 o = find_option(options, opt);
259 fprintf(stderr, "Bad option %s\n", opt);
263 if (!handle_option(o, val, data))
266 fprintf(stderr, "fio: failed parsing %s=%s\n", opt, val);
270 int parse_option(const char *opt, struct fio_option *options, void *data)
272 struct fio_option *o;
276 strncpy(tmp, opt, sizeof(tmp) - 1);
278 pre = strchr(tmp, '=');
284 o = find_option(options, pre);
286 o = find_option(options, tmp);
291 fprintf(stderr, "Bad option %s\n", tmp);
295 if (!handle_option(o, post, data))
298 fprintf(stderr, "fio: failed parsing %s\n", opt);