2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
5 This program can be distributed under the terms of the GNU LGPLv2.
6 See the file COPYING.LIB.
14 * This file defines the option parsing interface of FUSE
24 * This structure describes a single option, and and action associated
25 * with it, in case it matches.
27 * More than one such match may occur, in which case the action for
28 * each match is executed.
30 * There are three possible actions in case of a match:
32 * i) An integer (int or unsigned) variable determined by 'offset' is
35 * ii) The processing function is called, with 'value' as the key
37 * iii) An integer (any) or string (char *) variable determined by
38 * 'offset' is set to the value of an option parameter
40 * 'offset' should normally be either set to
42 * - 'offsetof(struct foo, member)' actions i) and iii)
46 * The 'offsetof()' macro is defined in the <stddef.h> header.
48 * The template determines which options match, and also have an
49 * effect on the action. Normally the action is either i) or ii), but
50 * if a format is present in the template, then action iii) is
53 * The types of templates are:
55 * 1) "-x", "-foo", "--foo", "--foo-bar", etc. These match only
56 * themselves. Invalid values are "--" and anything beginning
59 * 2) "foo", "foo-bar", etc. These match "-ofoo", "-ofoo-bar" or
60 * the relevant option in a comma separated option list
62 * 3) "bar=", "--foo=", etc. These are variations of 1) and 2)
63 * which have a parameter
65 * 4) "bar=%s", "--foo=%lu", etc. Same matching as above but perform
68 * 5) "-x ", etc. Matches either "-xparam" or "-x param" as
69 * two separate arguments
71 * 6) "-x %s", etc. Combination of 4) and 5)
73 * If the format is "%s", memory is allocated for the string unlike
77 /** Matching template and optional parameter formatting */
81 * Offset of variable within 'data' parameter of fuse_opt_parse()
87 * Value to set the variable to, or to be passed as 'key' to the
88 * processing function. Ignored if template has a format
94 * Key option. In case of a match, the processing function will be
95 * called with the specified key.
97 #define FUSE_OPT_KEY(templ, key) { templ, -1U, key }
100 * Last option. An array of 'struct fuse_opt' must end with a NULL
103 #define FUSE_OPT_END { .templ = NULL }
109 /** Argument count */
112 /** Argument vector. NULL terminated */
115 /** Is 'argv' allocated? */
120 * Initializer for 'struct fuse_args'
122 #define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 }
125 * Key value passed to the processing function if an option did not
128 #define FUSE_OPT_KEY_OPT -1
131 * Key value passed to the processing function for all non-options
133 * Non-options are the arguments beginning with a charater other than
134 * '-' or all arguments after the special '--' option
136 #define FUSE_OPT_KEY_NONOPT -2
139 * Special key value for options to keep
141 * Argument is not passed to processing function, but behave as if the
142 * processing function returned 1
144 #define FUSE_OPT_KEY_KEEP -3
147 * Special key value for options to discard
149 * Argument is not passed to processing function, but behave as if the
150 * processing function returned zero
152 #define FUSE_OPT_KEY_DISCARD -4
155 * Processing function
157 * This function is called if
158 * - option did not match any 'struct fuse_opt'
159 * - argument is a non-option
160 * - option did match and offset was set to -1
162 * The 'arg' parameter will always contain the whole argument or
163 * option including the parameter if exists. A two-argument option
164 * ("-x foo") is always converted to single arguemnt option of the
165 * form "-xfoo" before this function is called.
167 * Options of the form '-ofoo' are passed to this function without the
170 * The return value of this function determines whether this argument
171 * is to be inserted into the output argument vector, or discarded.
173 * @param data is the user data passed to the fuse_opt_parse() function
174 * @param arg is the whole argument or option
175 * @param key determines why the processing function was called
176 * @param outargs the current output argument list
177 * @return -1 on error, 0 if arg is to be discarded, 1 if arg should be kept
179 typedef int (*fuse_opt_proc_t
)(void *data
, const char *arg
, int key
,
180 struct fuse_args
*outargs
);
183 * Option parsing function
185 * If 'args' was returned from a previous call to fuse_opt_parse() or
186 * it was constructed from
188 * A NULL 'args' is equivalent to an empty argument vector
190 * A NULL 'opts' is equivalent to an 'opts' array containing a single
193 * A NULL 'proc' is equivalent to a processing function always
196 * @param args is the input and output argument list
197 * @param data is the user data
198 * @param opts is the option description array
199 * @param proc is the processing function
200 * @return -1 on error, 0 on success
202 int fuse_opt_parse(struct fuse_args
*args
, void *data
,
203 const struct fuse_opt opts
[], fuse_opt_proc_t proc
);
206 * Add an option to a comma separated option list
208 * @param opts is a pointer to an option list, may point to a NULL value
209 * @param opt is the option to add
210 * @return -1 on allocation error, 0 on success
212 int fuse_opt_add_opt(char **opts
, const char *opt
);
215 * Add an argument to a NULL terminated argument vector
217 * @param args is the structure containing the current argument list
218 * @param arg is the new argument to add
219 * @return -1 on allocation error, 0 on success
221 int fuse_opt_add_arg(struct fuse_args
*args
, const char *arg
);
224 * Add an argument at the specified position in a NULL terminated
227 * Adds the argument to the N-th position. This is useful for adding
228 * options at the beggining of the array which must not come after the
229 * special '--' option.
231 * @param args is the structure containing the current argument list
232 * @param pos is the position at which to add the argument
233 * @param arg is the new argument to add
234 * @return -1 on allocation error, 0 on success
236 int fuse_opt_insert_arg(struct fuse_args
*args
, int pos
, const char *arg
);
239 * Free the contents of argument list
241 * The structure itself is not freed
243 * @param args is the structure containing the argument list
245 void fuse_opt_free_args(struct fuse_args
*args
);
249 * Check if an option matches
251 * @param opts is the option description array
252 * @param opt is the option to match
253 * @return 1 if a match is found, 0 if not
255 int fuse_opt_match(const struct fuse_opt opts
[], const char *opt
);
261 #endif /* _FUSE_OPT_H_ */