init: fix memory leak in error handling
[fio.git] / parse.h
... / ...
CommitLineData
1#ifndef FIO_PARSE_H
2#define FIO_PARSE_H
3
4#include <inttypes.h>
5#include "flist.h"
6
7/*
8 * Option types
9 */
10enum fio_opt_type {
11 FIO_OPT_INVALID = 0,
12 FIO_OPT_STR,
13 FIO_OPT_STR_MULTI,
14 FIO_OPT_STR_VAL,
15 FIO_OPT_STR_VAL_TIME,
16 FIO_OPT_STR_STORE,
17 FIO_OPT_RANGE,
18 FIO_OPT_INT,
19 FIO_OPT_BOOL,
20 FIO_OPT_FLOAT_LIST,
21 FIO_OPT_STR_SET,
22 FIO_OPT_DEPRECATED,
23 FIO_OPT_UNSUPPORTED, /* keep this last */
24};
25
26/*
27 * Match a possible value string with the integer option.
28 */
29struct value_pair {
30 const char *ival; /* string option */
31 unsigned int oval; /* output value */
32 const char *help; /* help text for sub option */
33 int orval; /* OR value */
34 void *cb; /* sub-option callback */
35};
36
37#define OPT_LEN_MAX 4096
38#define PARSE_MAX_VP 24
39
40/*
41 * Option define
42 */
43struct fio_option {
44 const char *name; /* option name */
45 const char *lname; /* long option name */
46 const char *alias; /* possible old allowed name */
47 enum fio_opt_type type; /* option type */
48 unsigned int off1; /* potential parameters */
49 unsigned int off2;
50 unsigned int off3;
51 unsigned int off4;
52 unsigned int off5;
53 unsigned int off6;
54 unsigned int maxval; /* max and min value */
55 int minval;
56 double maxfp; /* max and min floating value */
57 double minfp;
58 unsigned int interval; /* client hint for suitable interval */
59 unsigned int maxlen; /* max length */
60 int neg; /* negate value stored */
61 int prio;
62 void *cb; /* callback */
63 const char *help; /* help text for option */
64 const char *def; /* default setting */
65 struct value_pair posval[PARSE_MAX_VP];/* possible values */
66 const char *parent; /* parent option */
67 int hide; /* hide if parent isn't set */
68 int hide_on_set; /* hide on set, not on unset */
69 const char *inverse; /* if set, apply opposite action to this option */
70 struct fio_option *inv_opt; /* cached lookup */
71 int (*verify)(const struct fio_option *, void *);
72 const char *prof_name; /* only valid for specific profile */
73 void *prof_opts;
74 uint64_t category; /* what type of option */
75 uint64_t group; /* who to group with */
76 void *gui_data;
77 int is_seconds; /* time value with seconds base */
78 int is_time; /* time based value */
79 int no_warn_def;
80 int pow2; /* must be a power-of-2 */
81 int no_free;
82};
83
84extern int parse_option(char *, const char *, const struct fio_option *,
85 const struct fio_option **, void *,
86 struct flist_head *);
87extern void sort_options(char **, const struct fio_option *, int);
88extern int parse_cmd_option(const char *t, const char *l,
89 const struct fio_option *, void *,
90 struct flist_head *);
91extern int show_cmd_help(const struct fio_option *, const char *);
92extern void fill_default_options(void *, const struct fio_option *);
93extern void options_init(struct fio_option *);
94extern void options_mem_dupe(const struct fio_option *, void *);
95extern void options_free(const struct fio_option *, void *);
96
97extern void strip_blank_front(char **);
98extern void strip_blank_end(char *);
99extern int str_to_decimal(const char *, long long *, int, void *, int, int);
100extern int check_str_bytes(const char *p, long long *val, void *data);
101extern int check_str_time(const char *p, long long *val, int);
102extern int str_to_float(const char *str, double *val, int is_time);
103
104extern int string_distance(const char *s1, const char *s2);
105extern int string_distance_ok(const char *s1, int dist);
106
107/*
108 * Handlers for the options
109 */
110typedef int (fio_opt_str_fn)(void *, const char *);
111typedef int (fio_opt_str_val_fn)(void *, long long *);
112typedef int (fio_opt_int_fn)(void *, int *);
113
114struct thread_options;
115static inline void *td_var(void *to, const struct fio_option *o,
116 unsigned int offset)
117{
118 void *ret;
119
120 if (o->prof_opts)
121 ret = o->prof_opts;
122 else
123 ret = to;
124
125 return ret + offset;
126}
127
128static inline int parse_is_percent(unsigned long long val)
129{
130 return val <= -1ULL && val >= (-1ULL - 100ULL);
131}
132
133struct print_option {
134 struct flist_head list;
135 char *name;
136 char *value;
137};
138
139#endif