blob: 085de1a5face6410696d4ecab6d8e464e1a10416 [file] [log] [blame]
Jens Axboee1f36502006-10-27 10:54:08 +02001#ifndef FIO_PARSE_H
2#define FIO_PARSE_H
3
Jens Axboe9f988e22010-03-04 10:42:38 +01004#include "flist.h"
5
Jens Axboee1f36502006-10-27 10:54:08 +02006/*
7 * Option types
8 */
9enum fio_opt_type {
10 FIO_OPT_STR = 0,
11 FIO_OPT_STR_VAL,
12 FIO_OPT_STR_VAL_TIME,
13 FIO_OPT_STR_STORE,
14 FIO_OPT_RANGE,
15 FIO_OPT_INT,
Jens Axboe13335dd2007-01-10 13:14:02 +010016 FIO_OPT_BOOL,
Jens Axboee1f36502006-10-27 10:54:08 +020017 FIO_OPT_STR_SET,
Jens Axboe15ca1502008-04-07 09:26:02 +020018 FIO_OPT_DEPRECATED,
Jens Axboee1f36502006-10-27 10:54:08 +020019};
20
21/*
Jens Axboeb1ec1da2007-02-23 10:29:16 +010022 * Match a possible value string with the integer option.
23 */
24struct value_pair {
25 const char *ival; /* string option */
26 unsigned int oval; /* output value */
Jens Axboe78372132007-03-14 13:24:07 +010027 const char *help; /* help text for sub option */
Jens Axboeb1ec1da2007-02-23 10:29:16 +010028};
29
Zhang, Yanminc06c78c2010-03-03 08:26:30 +010030#define OPT_LEN_MAX 4096
Jens Axboeb1ec1da2007-02-23 10:29:16 +010031#define PARSE_MAX_VP 16
32
33/*
Jens Axboee1f36502006-10-27 10:54:08 +020034 * Option define
35 */
36struct fio_option {
Jens Axboeee738492007-01-10 11:23:16 +010037 const char *name; /* option name */
Jens Axboe03b74b32007-01-11 11:04:31 +010038 const char *alias; /* possible old allowed name */
Jens Axboeee738492007-01-10 11:23:16 +010039 enum fio_opt_type type; /* option type */
40 unsigned int off1; /* potential parameters */
Jens Axboee1f36502006-10-27 10:54:08 +020041 unsigned int off2;
Jens Axboef90eff52006-11-06 11:08:21 +010042 unsigned int off3;
43 unsigned int off4;
Jens Axboeee738492007-01-10 11:23:16 +010044 unsigned int maxval; /* max and min value */
Jens Axboe63f29372007-01-10 13:20:09 +010045 int minval;
Jens Axboe76a43db2007-01-11 13:24:44 +010046 int neg; /* negate value stored */
Jens Axboe3b8b7132008-06-10 19:46:23 +020047 int prio;
Jens Axboeee738492007-01-10 11:23:16 +010048 void *cb; /* callback */
49 const char *help; /* help text for option */
50 const char *def; /* default setting */
Jens Axboeb1ec1da2007-02-23 10:29:16 +010051 const struct value_pair posval[PARSE_MAX_VP];/* possible values */
Jens Axboeafdf9352007-07-31 16:14:34 +020052 const char *parent; /* parent option */
Jens Axboe70a4c0c2009-07-01 09:24:05 +020053 int (*verify)(struct fio_option *, void *);
Jens Axboee1f36502006-10-27 10:54:08 +020054};
55
56typedef int (str_cb_fn)(void *, char *);
57
Jens Axboe9f988e22010-03-04 10:42:38 +010058extern int parse_option(const char *, struct fio_option *, struct flist_head *, void *);
Jens Axboe3b8b7132008-06-10 19:46:23 +020059extern void sort_options(char **, struct fio_option *, int);
Jens Axboe9f988e22010-03-04 10:42:38 +010060extern int parse_cmd_option(const char *t, const char *l, struct fio_option *, struct flist_head *, void *);
Jens Axboefd28ca42007-01-09 21:20:13 +010061extern int show_cmd_help(struct fio_option *, const char *);
Jens Axboeee738492007-01-10 11:23:16 +010062extern void fill_default_options(void *, struct fio_option *);
Jens Axboe9f988e22010-03-04 10:42:38 +010063extern void option_init(struct fio_option *);
Jens Axboe13335dd2007-01-10 13:14:02 +010064extern void options_init(struct fio_option *);
Jens Axboee1f36502006-10-27 10:54:08 +020065
66extern void strip_blank_front(char **);
67extern void strip_blank_end(char *);
Jens Axboed6978a32009-07-18 21:04:09 +020068extern int str_to_decimal(const char *, long long *, int, void *);
Jens Axboee1f36502006-10-27 10:54:08 +020069
70/*
71 * Handlers for the options
72 */
Jens Axboeb4692822006-10-27 13:43:22 +020073typedef int (fio_opt_str_fn)(void *, const char *);
Jens Axboe63f29372007-01-10 13:20:09 +010074typedef int (fio_opt_str_val_fn)(void *, long long *);
75typedef int (fio_opt_int_fn)(void *, int *);
Jens Axboee1f36502006-10-27 10:54:08 +020076typedef int (fio_opt_str_set_fn)(void *);
77
78#define td_var(start, offset) ((void *) start + (offset))
79
Jens Axboe0e9f7fa2007-03-01 14:05:30 +010080#ifndef min
81#define min(a, b) ((a) < (b) ? (a) : (b))
82#endif
83#ifndef max
84#define max(a, b) ((a) > (b) ? (a) : (b))
85#endif
86
Jens Axboee1f36502006-10-27 10:54:08 +020087#endif