xref: /openbsd-src/lib/libfuse/fuse_opt.3 (revision 428182543471d6caab43990ede786ad0fae9d539)
1*42818254Smpi.\"	$OpenBSD: fuse_opt.3,v 1.3 2018/11/30 18:19:12 mpi Exp $
28e7147f2Shelg.\"
38e7147f2Shelg.\" Copyright (c) Ray Lai <ray@raylai.com>
48e7147f2Shelg.\" Copyright (c) Helg Bredow <helg@openbsd.org>
58e7147f2Shelg.\"
68e7147f2Shelg.\" Permission to use, copy, modify, and distribute this software for any
78e7147f2Shelg.\" purpose with or without fee is hereby granted, provided that the above
88e7147f2Shelg.\" copyright notice and this permission notice appear in all copies.
98e7147f2Shelg.\"
108e7147f2Shelg.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
118e7147f2Shelg.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
128e7147f2Shelg.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
138e7147f2Shelg.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
148e7147f2Shelg.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
158e7147f2Shelg.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
168e7147f2Shelg.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
178e7147f2Shelg.\"
18*42818254Smpi.Dd $Mdocdate: November 30 2018 $
198e7147f2Shelg.Dt FUSE_OPT 3
208e7147f2Shelg.Os
218e7147f2Shelg.Sh NAME
228e7147f2Shelg.Nm FUSE_ARGS_INIT ,
238e7147f2Shelg.Nm FUSE_OPT_IS_OPT_KEY ,
248e7147f2Shelg.Nm FUSE_OPT_KEY ,
258e7147f2Shelg.Nm fuse_opt_add_arg ,
268e7147f2Shelg.Nm fuse_opt_insert_arg ,
278e7147f2Shelg.Nm fuse_opt_add_opt ,
288e7147f2Shelg.Nm fuse_opt_add_opt_escaped ,
29477ebe4aSjmc.Nm fuse_opt_free_args ,
308e7147f2Shelg.Nm fuse_opt_match ,
318e7147f2Shelg.Nm fuse_opt_parse
328e7147f2Shelg.Nd FUSE argument and option parser
338e7147f2Shelg.Sh SYNOPSIS
348e7147f2Shelg.In fuse_opt.h
358e7147f2Shelg.Ft struct fuse_args
368e7147f2Shelg.Fo FUSE_ARGS_INIT
378e7147f2Shelg.Fa "int argc"
388e7147f2Shelg.Fa "char argv**"
398e7147f2Shelg.Fc
408e7147f2Shelg.Ft int
418e7147f2Shelg.Fo FUSE_OPT_IS_OPT_KEY
428e7147f2Shelg.Fa "fuse_opt *t"
438e7147f2Shelg.Fc
448e7147f2Shelg.Ft struct fuse_opt
458e7147f2Shelg.Fo FUSE_OPT_KEY
468e7147f2Shelg.Fa "const char *templ"
478e7147f2Shelg.Fa "int key"
488e7147f2Shelg.Fc
498e7147f2Shelg.Ft int
508e7147f2Shelg.Fo fuse_opt_add_arg
518e7147f2Shelg.Fa "struct fuse_args *args"
528e7147f2Shelg.Fa "const char *arg"
538e7147f2Shelg.Fc
548e7147f2Shelg.Ft int
558e7147f2Shelg.Fo fuse_opt_insert_arg
568e7147f2Shelg.Fa "struct fuse_args *args"
578e7147f2Shelg.Fa "int pos"
588e7147f2Shelg.Fa "const char *opt"
598e7147f2Shelg.Fc
608e7147f2Shelg.Ft int
618e7147f2Shelg.Fo fuse_opt_add_opt
628e7147f2Shelg.Fa "char **opts"
638e7147f2Shelg.Fa "const char *opt"
648e7147f2Shelg.Fc
658e7147f2Shelg.Ft int
668e7147f2Shelg.Fo fuse_opt_add_opt_escaped
678e7147f2Shelg.Fa "char **opts"
688e7147f2Shelg.Fa "const char *opt"
698e7147f2Shelg.Fc
708e7147f2Shelg.Ft void
718e7147f2Shelg.Fo fuse_opt_free_args
728e7147f2Shelg.Fa "struct fuse_args *args"
738e7147f2Shelg.Fc
748e7147f2Shelg.Ft int
758e7147f2Shelg.Fo fuse_opt_match
768e7147f2Shelg.Fa "const struct fuse_opt *opts"
778e7147f2Shelg.Fa "const char *opt"
788e7147f2Shelg.Fc
798e7147f2Shelg.Ft int
808e7147f2Shelg.Fo fuse_opt_parse
818e7147f2Shelg.Fa "struct fuse_args *args"
828e7147f2Shelg.Fa "void *data"
838e7147f2Shelg.Fa "const struct fuse_opt *opts"
848e7147f2Shelg.Fa "fuse_opt_proc_t proc"
858e7147f2Shelg.Fc
868e7147f2Shelg.Sh DESCRIPTION
878e7147f2ShelgThese FUSE library functions and macros provide support for complex
88477ebe4aSjmcargument and option parsing.
89477ebe4aSjmcThese are typically entered on the command line
90477ebe4aSjmcbut may also be passed by file systems to the
918e7147f2Shelg.Xr fuse_mount 3
928e7147f2Shelgand
938e7147f2Shelg.Xr fuse_new 3
948e7147f2Shelgfunctions.
958e7147f2Shelg.Ft struct fuse_args
968e7147f2Shelgholds string options in an array:
978e7147f2Shelg.Bd -literal -offset indent
988e7147f2Shelgstruct fuse_args {
998e7147f2Shelg        int argc;	/* argument count */
1008e7147f2Shelg        char **argv;	/* NULL-terminated array of arguments */
1018e7147f2Shelg        int allocated;	/* argv was allocated and must be freed */
1028e7147f2Shelg};
1038e7147f2Shelg.Ed
1048e7147f2Shelg.Pp
1058e7147f2Shelg.Bl -tag -width Ds -compact
1068e7147f2Shelg.It Fn FUSE_OPT_KEY templ key
1078e7147f2Shelgreturns a
1088e7147f2Shelg.Fa struct fuse_opt
1098e7147f2Shelgtemplate that matches an argument or option
1108e7147f2Shelg.Fa templ
1118e7147f2Shelgwith option key
1128e7147f2Shelg.Fa key .
1138e7147f2ShelgThis macro is used as an element in
1148e7147f2Shelg.Fa struct fuse_opt
115477ebe4aSjmcarrays to create a template that is processed by a fuse_opt_proc_t.
116477ebe4aSjmcThe special constants FUSE_OPT_KEEP and FUSE_OPT_DISCARD can be specified if
1178e7147f2Shelgproc does not need to handle this option or argument; proc is not called in
1188e7147f2Shelgthis case.
1198e7147f2Shelg.Pp
1208e7147f2Shelg.It Fn FUSE_OPT_IS_OPT_KEY templ
1218e7147f2Shelgchecks if
1228e7147f2Shelg.Fa templ
1238e7147f2Shelgis an option key.
1248e7147f2Shelg.Pp
1258e7147f2ShelgThe last element of the
1268e7147f2Shelg.Fa opts
1278e7147f2Shelg.Ft struct fuse_opt
1288e7147f2Shelgoption array must be
1298e7147f2Shelg.Dv FUSE_OPT_END .
1308e7147f2Shelg.Pp
1318e7147f2Shelg.Fa proc
1328e7147f2Shelgpoints to a function with the following signature:
1338e7147f2Shelg.Ft int (*fuse_opt_proc_t)
1348e7147f2Shelg.Fo proc
1358e7147f2Shelg.Fa "void *data"
1368e7147f2Shelg.Fa "const char *arg"
1378e7147f2Shelg.Fa "int key"
1388e7147f2Shelg.Fa "struct fuse_args *outargs"
1398e7147f2Shelg.Fc
1408e7147f2Shelg.Pp
1418e7147f2ShelgSpecial key values:
1428e7147f2Shelg.Bd -literal -offset indent
1438e7147f2ShelgFUSE_OPT_KEY_OPT	/* no match */
1448e7147f2ShelgFUSE_OPT_KEY_NONOPT	/* non-option */
1458e7147f2ShelgFUSE_OPT_KEY_KEEP	/* don't process; return 1 */
1468e7147f2ShelgFUSE_OPT_KEY_DISCARD	/* don't process; return 0 */
1478e7147f2Shelg.Ed
148477ebe4aSjmc.Pp
1498e7147f2Shelg.It Fn FUSE_ARGS_INIT
1508e7147f2Shelginitializes a
1518e7147f2Shelg.Ft struct fuse_args
1528e7147f2Shelgwith
1538e7147f2Shelg.Fa argc
1548e7147f2Shelgand
1558e7147f2Shelg.Fa argv ,
156477ebe4aSjmcwhich are usually obtained from
1578e7147f2Shelg.Fn main .
1588e7147f2Shelg.Fa argv
1598e7147f2Shelgis NULL-terminated, and is suitable for use with
1608e7147f2Shelg.Xr execvp 3 .
1618e7147f2Shelg.Fa argv
1628e7147f2Shelgis used directly and
1638e7147f2Shelg.Fa allocated
1648e7147f2Shelgis set to 0.
1658e7147f2Shelg.Pp
1668e7147f2Shelg.It Fn fuse_opt_add_arg
1678e7147f2Shelgadds a single option to the end of
1688e7147f2Shelg.Fa args .
1698e7147f2ShelgIf
1708e7147f2Shelg.Fa args->allocated
1718e7147f2Shelgis 0,
1728e7147f2Shelg.Fa args->argv
1738e7147f2Shelgis copied to the heap and
1748e7147f2Shelg.Fa args->allocated
1758e7147f2Shelgis set to a non-zero value.
1768e7147f2Shelg.Pp
1778e7147f2Shelg.It Fn fuse_opt_insert_arg
1788e7147f2Shelginserts a single argument at position
1798e7147f2Shelg.Fa pos
1808e7147f2Shelginto
1818e7147f2Shelg.Fa args ,
1828e7147f2Shelgshifting
1838e7147f2Shelg.Fa args->argv
1848e7147f2Shelgas needed.
1858e7147f2Shelg.Pp
1868e7147f2Shelg.It Fn fuse_opt_add_opt
1878e7147f2Shelgadds an option
1888e7147f2Shelg.Fa opt
1898e7147f2Shelgto a comma-separated string of options
1908e7147f2Shelg.Fa opts .
1918e7147f2Shelg.Fa *opts
1928e7147f2Shelgcan be NULL, which is typically used when adding the first option.
1938e7147f2Shelg.Pp
1948e7147f2Shelg.It Fn fuse_opt_add_opt_escaped
1958e7147f2Shelgescapes any
1968e7147f2Shelg.Sq ","
1978e7147f2Shelgand
1988e7147f2Shelg.Sq "\\"
1998e7147f2Shelgcharacters in
2008e7147f2Shelg.Fa opt
2018e7147f2Shelgbefore adding it to
2028e7147f2Shelg.Fa opts .
2038e7147f2Shelg.Pp
2048e7147f2Shelg.It Fn fuse_opt_free_args
2058e7147f2Shelgfrees
2068e7147f2Shelg.Fa args->argv
2078e7147f2Shelgif it was allocated
2088e7147f2Shelg.Fa args
2098e7147f2Shelgand initializes everything to 0.
2108e7147f2Shelg.Pp
2118e7147f2Shelg.It Fn fuse_opt_match
2128e7147f2Shelgtests if the argument or option
2138e7147f2Shelg.Fa opt
2148e7147f2Shelgappears in the list of templates
2158e7147f2Shelg.Fa opts .
2168e7147f2ShelgIf
2178e7147f2Shelg.Fa opt
2188e7147f2Shelgis an option then it must not include the -o prefix.
2198e7147f2Shelg.Pp
2208e7147f2Shelg.It Fn fuse_opt_parse
2218e7147f2Shelgparses options, setting any members of
2228e7147f2Shelg.Fa data
223477ebe4aSjmcautomatically depending on the format of the template.
224477ebe4aSjmcIf
2258e7147f2Shelg.Fa proc
2268e7147f2Shelgis not NULL, then this is called for any argument that matches a template
227*42818254Smpithat has
2288e7147f2Shelg.Fa val
2298e7147f2Shelg= FUSE_OPT_KEY.
2308e7147f2Shelg.Fa opts
2318e7147f2Shelgis an array of
2328e7147f2Shelg.Ft struct fuse_opt ,
2338e7147f2Shelgeach of which describes actions for each option:
2348e7147f2Shelg.Bd -literal -offset indent
2358e7147f2Shelgstruct fuse_opt {
2368e7147f2Shelg        const char *templ;	/* template for option */
2378e7147f2Shelg        unsigned long off;	/* data offset */
2388e7147f2Shelg        int val;		/* key value */
2398e7147f2Shelg};
2408e7147f2Shelg.Ed
2418e7147f2Shelg.Pp
2428e7147f2ShelgThe following templates are supported.
2438e7147f2Shelgfoo=
2448e7147f2Shelg.Pp
2458e7147f2Shelgfoo=%u %u can be any format that can be parsed by
246477ebe4aSjmc.Fn sscanf 3 .
247477ebe4aSjmcIf this is %s then a copy of the string is allocated.
248477ebe4aSjmcfoo=bar matches the option exactly (treated the same as if it didn't have an =).
2498e7147f2Shelg.Pp
2508e7147f2Shelgfoo matches exactly
2518e7147f2Shelg.Pp
2528e7147f2Shelg-b or --bar matches the argument
2538e7147f2Shelg"-b " or "--bar " (trailing space) argument expects a value, that is passed to
2548e7147f2Shelg.Fa proc
2558e7147f2Shelg.Pp
2568e7147f2Shelg-b %u or:w
2578e7147f2Shelg --bar %u Treated the same as foo=%u above
2588e7147f2Shelg.Pp
259477ebe4aSjmcEach argument or option is matched against every template.
260477ebe4aSjmcThis allows more than one member of
2618e7147f2Shelg.Fa data
262477ebe4aSjmcto be set by a single argument or option (see example for gid below).
2638e7147f2Shelg.El
2648e7147f2Shelg.Sh RETURN VALUES
2658e7147f2Shelg.Fn fuse_opt_add_arg ,
2668e7147f2Shelg.Fn fuse_opt_insert_arg ,
2678e7147f2Shelg.Fn fuse_opt_add_opt ,
2688e7147f2Shelg.Fn fuse_opt_add_opt_escaped ,
2698e7147f2Shelgand
2708e7147f2Shelg.Fn fuse_opt_parse
2718e7147f2Shelgreturn 0 on success, -1 on error.
2728e7147f2Shelg.Pp
2738e7147f2Shelg.Fn fuse_opt_match
2748e7147f2Shelgreturns 1 on match, 0 if no match.
2758e7147f2Shelg.Sh ERRORS
2768e7147f2Shelg.Fn fuse_opt_add_arg ,
2778e7147f2Shelg.Fn fuse_opt_insert_arg ,
2788e7147f2Shelg.Fn fuse_opt_add_opt ,
2798e7147f2Shelgand
2808e7147f2Shelg.Fn fuse_opt_add_opt_escaped
2818e7147f2Shelgcan run out of memory and set
2828e7147f2Shelg.Va errno .
2838e7147f2Shelg.Sh SEE ALSO
2848e7147f2Shelg.Xr fuse_main 3
2858e7147f2Shelg.Sh STANDARDS
2868e7147f2ShelgThese library functions conform to FUSE 2.6.
2878e7147f2Shelg.Sh HISTORY
2888e7147f2ShelgThese functions first appeared in
2898e7147f2Shelg.Ox 5.4 .
2908e7147f2Shelg.Sh AUTHORS
2918e7147f2Shelg.An Sylvestre Gallon Aq Mt ccna.syl@gmail.com
2928e7147f2Shelg.An Helg Bredow Aq Mt xx404@msn.com
2938e7147f2Shelg.Pp
2948e7147f2ShelgThis manual was written by
2958e7147f2Shelg.An Ray Lai Aq Mt ray@raylai.com
2968e7147f2Shelgand updated by
2978e7147f2Shelg.An Helg Bredow Aq Mt xx404@msn.com
298