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