blob: 45462596ca4246dd6a7b4eac7600a2936c241b81 [file] [log] [blame]
Jens Axboee1f36502006-10-27 10:54:08 +02001#ifndef FIO_PARSE_H
2#define FIO_PARSE_H
3
4/*
5 * Option types
6 */
7enum fio_opt_type {
8 FIO_OPT_STR = 0,
9 FIO_OPT_STR_VAL,
Jens Axboe75e6f362006-11-03 08:17:09 +010010 FIO_OPT_STR_VAL_INT,
Jens Axboee1f36502006-10-27 10:54:08 +020011 FIO_OPT_STR_VAL_TIME,
12 FIO_OPT_STR_STORE,
13 FIO_OPT_RANGE,
14 FIO_OPT_INT,
Jens Axboe13335dd2007-01-10 13:14:02 +010015 FIO_OPT_BOOL,
Jens Axboee1f36502006-10-27 10:54:08 +020016 FIO_OPT_STR_SET,
Jens Axboe15ca1502008-04-07 09:26:02 +020017 FIO_OPT_DEPRECATED,
Jens Axboee1f36502006-10-27 10:54:08 +020018};
19
20/*
Jens Axboeb1ec1da2007-02-23 10:29:16 +010021 * Match a possible value string with the integer option.
22 */
23struct value_pair {
24 const char *ival; /* string option */
25 unsigned int oval; /* output value */
Jens Axboe78372132007-03-14 13:24:07 +010026 const char *help; /* help text for sub option */
Jens Axboeb1ec1da2007-02-23 10:29:16 +010027};
28
Aaron Carroll88b5a392008-10-07 11:25:20 +020029#define OPT_LEN_MAX 1024
Jens Axboeb1ec1da2007-02-23 10:29:16 +010030#define PARSE_MAX_VP 16
31
32/*
Jens Axboee1f36502006-10-27 10:54:08 +020033 * Option define
34 */
35struct fio_option {
Jens Axboeee738492007-01-10 11:23:16 +010036 const char *name; /* option name */
Jens Axboe03b74b32007-01-11 11:04:31 +010037 const char *alias; /* possible old allowed name */
Jens Axboeee738492007-01-10 11:23:16 +010038 enum fio_opt_type type; /* option type */
39 unsigned int off1; /* potential parameters */
Jens Axboee1f36502006-10-27 10:54:08 +020040 unsigned int off2;
Jens Axboef90eff52006-11-06 11:08:21 +010041 unsigned int off3;
42 unsigned int off4;
Jens Axboeee738492007-01-10 11:23:16 +010043 unsigned int maxval; /* max and min value */
Jens Axboe63f29372007-01-10 13:20:09 +010044 int minval;
Jens Axboe76a43db2007-01-11 13:24:44 +010045 int neg; /* negate value stored */
Jens Axboe3b8b7132008-06-10 19:46:23 +020046 int prio;
Jens Axboeee738492007-01-10 11:23:16 +010047 void *cb; /* callback */
48 const char *help; /* help text for option */
49 const char *def; /* default setting */
Jens Axboeb1ec1da2007-02-23 10:29:16 +010050 const struct value_pair posval[PARSE_MAX_VP];/* possible values */
Jens Axboeafdf9352007-07-31 16:14:34 +020051 const char *parent; /* parent option */
Jens Axboee1f36502006-10-27 10:54:08 +020052};
53
54typedef int (str_cb_fn)(void *, char *);
55
56extern int parse_option(const char *, struct fio_option *, void *);
Jens Axboe3b8b7132008-06-10 19:46:23 +020057extern void sort_options(char **, struct fio_option *, int);
Jens Axboeb4692822006-10-27 13:43:22 +020058extern int parse_cmd_option(const char *t, const char *l, struct fio_option *, void *);
Jens Axboefd28ca42007-01-09 21:20:13 +010059extern int show_cmd_help(struct fio_option *, const char *);
Jens Axboeee738492007-01-10 11:23:16 +010060extern void fill_default_options(void *, struct fio_option *);
Jens Axboe13335dd2007-01-10 13:14:02 +010061extern void options_init(struct fio_option *);
Jens Axboee1f36502006-10-27 10:54:08 +020062
63extern void strip_blank_front(char **);
64extern void strip_blank_end(char *);
Jens Axboe564ca972007-12-14 12:21:19 +010065extern int str_to_decimal(const char *, long long *, int);
Jens Axboee1f36502006-10-27 10:54:08 +020066
67/*
68 * Handlers for the options
69 */
Jens Axboeb4692822006-10-27 13:43:22 +020070typedef int (fio_opt_str_fn)(void *, const char *);
Jens Axboe63f29372007-01-10 13:20:09 +010071typedef int (fio_opt_str_val_fn)(void *, long long *);
72typedef int (fio_opt_int_fn)(void *, int *);
Jens Axboee1f36502006-10-27 10:54:08 +020073typedef int (fio_opt_str_set_fn)(void *);
74
75#define td_var(start, offset) ((void *) start + (offset))
76
Jens Axboe0e9f7fa2007-03-01 14:05:30 +010077#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
Jens Axboee1f36502006-10-27 10:54:08 +020084#endif