2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu>
5 This program can be distributed under the terms of the GNU GPL.
12 /* This file defines the option parsing interface of FUSE */
21 * This structure describes a single option, and and action associated
22 * with it, in case it matches.
24 * More than one such match may occur, in which case the action for
25 * each match is executed.
27 * There are three possible actions in case of a match:
29 * i) An integer (int or unsigned) variable determined by 'offset' is
32 * ii) The processing function is called, with 'value' as the key
34 * iii) An integer (any) or string (char *) variable determined by
35 * 'offset' is set to the value of an option parameter
37 * 'offset' should normally be either set to
39 * - 'offsetof(struct foo, member)' actions i) and iii)
43 * The 'offsetof()' macro is defined in the <stddef.h> header.
45 * The template determines which options match, and also have an
46 * effect on the action. Normally the action is either i) or ii), but
47 * if a format is present in the template, then action iii) is
50 * The types of templates are:
52 * 1) "-x", "-foo", "--foo", "--foo-bar", etc. These match only
53 * themselves. Invalid values are "--" and anything beginning
56 * 2) "foo", "foo-bar", etc. These match "-ofoo", "-ofoo-bar" or
57 * the relevant option in a comma separated option list
59 * 3) "bar=", "--foo=", etc. These are variations of 1) and 2)
60 * which have a parameter
62 * 4) "bar=%s", "--foo=%lu", etc. Same matching as above but perform
65 * 5) "-x ", etc. Matches either "-xparam" or "-x param" as
66 * two separate arguments
68 * 6) "-x %s", etc. Combination of 4) and 5)
70 * If the format is "%s", memory is allocated for the string unlike
74 /** Matching template and optional parameter formatting */
78 * Offset of variable within 'data' parameter of fuse_opt_parse()
84 * Value to set the variable to, or to be passed as 'key' to the
85 * processing function. Ignored if template has a format
91 * Key option. In case of a match, the processing function will be
92 * called with the specified key.
94 #define FUSE_OPT_KEY(templ, key) { templ, -1U, key }
97 * Last option. An array of 'struct fuse_opt' must end with a NULL
100 #define FUSE_OPT_END { .templ = NULL }
106 /** Argument count */
109 /** Argument vector. NULL terminated */
112 /** Is 'argv' allocated? */
117 * Initializer for 'struct fuse_args'
119 #define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 }
122 * Key value passed to the processing function if an option did not
125 #define FUSE_OPT_KEY_OPT -1
128 * Key value passed to the processing function for all non-options
130 * Non-options are the arguments beginning with a charater other than
131 * '-' or all arguments after the special '--' option
133 #define FUSE_OPT_KEY_NONOPT -2
136 * Special key value for options to keep
138 * Argument is not passed to processing function, but behave as if the
139 * processing function returned 1
141 #define FUSE_OPT_KEY_KEEP -3
144 * Special key value for options to discard
146 * Argument is not passed to processing function, but behave as if the
147 * processing function returned zero
149 #define FUSE_OPT_KEY_DISCARD -4
152 * Processing function
154 * This function is called if
155 * - option did not match any 'struct fuse_opt'
156 * - argument is a non-option
157 * - option did match and offset was set to -1
159 * The 'arg' parameter will always contain the whole argument or
160 * option including the parameter if exists. A two-argument option
161 * ("-x foo") is always converted to single arguemnt option of the
162 * form "-xfoo" before this function is called.
164 * Options of the form '-ofoo' are passed to this function without the
167 * The return value of this function determines whether this argument
168 * is to be inserted into the output argument vector, or discarded.
170 * @param data is the user data passed to the fuse_opt_parse() function
171 * @param arg is the whole argument or option
172 * @param key determines why the processing function was called
173 * @param outargs the current output argument list
174 * @return -1 on error, 0 if arg is to be discarded, 1 if arg should be kept
176 typedef int (*fuse_opt_proc_t)(void *data, const char *arg, int key,
177 struct fuse_args *outargs);
180 * Option parsing function
182 * If 'args' was returned from a previous call to fuse_opt_parse() or
183 * it was constructed from
185 * A NULL 'args' is equivalent to an empty argument vector
187 * A NULL 'opts' is equivalent to an 'opts' array containing a single
190 * A NULL 'proc' is equivalent to a processing function always
193 * @param args is the input and output argument list
194 * @param data is the user data
195 * @param opts is the option description array
196 * @param proc is the processing function
197 * @return -1 on error, 0 on success
199 int fuse_opt_parse(struct fuse_args *args, void *data,
200 const struct fuse_opt opts[], fuse_opt_proc_t proc);
203 * Add an option to a comma separated option list
205 * @param opts is a pointer to an option list, may point to a NULL value
206 * @param opt is the option to add
207 * @return -1 on allocation error, 0 on success
209 int fuse_opt_add_opt(char **opts, const char *opt);
212 * Add an argument to a NULL terminated argument vector
214 * @param args is the structure containing the current argument list
215 * @param arg is the new argument to add
216 * @return -1 on allocation error, 0 on success
218 int fuse_opt_add_arg(struct fuse_args *args, const char *arg);
221 * Add an argument at the specified position in a NULL terminated
224 * Adds the argument to the N-th position. This is useful for adding
225 * options at the beggining of the array which must not come after the
226 * special '--' option.
228 * @param args is the structure containing the current argument list
229 * @param pos is the position at which to add the argument
230 * @param arg is the new argument to add
231 * @return -1 on allocation error, 0 on success
233 int fuse_opt_insert_arg(struct fuse_args *args, int pos, const char *arg);
236 * Free the contents of argument list
238 * The structure itself is not freed
240 * @param args is the structure containing the argument list
242 void fuse_opt_free_args(struct fuse_args *args);
246 * Check if an option matches
248 * @param opts is the option description array
249 * @param opt is the option to match
250 * @return 1 if a match is found, 0 if not
252 int fuse_opt_match(const struct fuse_opt opts[], const char *opt);
258 #endif /* _FUSE_OPT_H_ */