Add check for OPT_LEN_MAX being too small
[fio.git] / parse.h
1 #ifndef FIO_PARSE_H
2 #define FIO_PARSE_H
3
4 /*
5  * Option types
6  */
7 enum fio_opt_type {
8         FIO_OPT_STR = 0,
9         FIO_OPT_STR_VAL,
10         FIO_OPT_STR_VAL_TIME,
11         FIO_OPT_STR_STORE,
12         FIO_OPT_RANGE,
13         FIO_OPT_INT,
14         FIO_OPT_BOOL,
15         FIO_OPT_STR_SET,
16         FIO_OPT_DEPRECATED,
17 };
18
19 /*
20  * Match a possible value string with the integer option.
21  */
22 struct value_pair {
23         const char *ival;               /* string option */
24         unsigned int oval;              /* output value */
25         const char *help;               /* help text for sub option */
26 };
27
28 #define OPT_LEN_MAX     4096
29 #define PARSE_MAX_VP    16
30
31 /*
32  * Option define
33  */
34 struct fio_option {
35         const char *name;               /* option name */
36         const char *alias;              /* possible old allowed name */
37         enum fio_opt_type type;         /* option type */
38         unsigned int off1;              /* potential parameters */
39         unsigned int off2;
40         unsigned int off3;
41         unsigned int off4;
42         unsigned int maxval;            /* max and min value */
43         int minval;
44         int neg;                        /* negate value stored */
45         int prio;
46         void *cb;                       /* callback */
47         const char *help;               /* help text for option */
48         const char *def;                /* default setting */
49         const struct value_pair posval[PARSE_MAX_VP];/* possible values */
50         const char *parent;             /* parent option */
51         int (*verify)(struct fio_option *, void *);
52 };
53
54 typedef int (str_cb_fn)(void *, char *);
55
56 extern int parse_option(const char *, struct fio_option *, void *);
57 extern void sort_options(char **, struct fio_option *, int);
58 extern int parse_cmd_option(const char *t, const char *l, struct fio_option *, void *);
59 extern int show_cmd_help(struct fio_option *, const char *);
60 extern void fill_default_options(void *, struct fio_option *);
61 extern void options_init(struct fio_option *);
62
63 extern void strip_blank_front(char **);
64 extern void strip_blank_end(char *);
65 extern int str_to_decimal(const char *, long long *, int, void *);
66
67 /*
68  * Handlers for the options
69  */
70 typedef int (fio_opt_str_fn)(void *, const char *);
71 typedef int (fio_opt_str_val_fn)(void *, long long *);
72 typedef int (fio_opt_int_fn)(void *, int *);
73 typedef int (fio_opt_str_set_fn)(void *);
74
75 #define td_var(start, offset)   ((void *) start + (offset))
76
77 #ifndef min
78 #define min(a, b)       ((a) < (b) ? (a) : (b))
79 #endif
80 #ifndef max
81 #define max(a, b)       ((a) > (b) ? (a) : (b))
82 #endif
83
84 #endif