Here's a man page for fuse_opt.h. It's far from perfect, I mostly tried
to document our existing behavior and avoid copying from libfuse. There
are definitely areas of improvement but I think this goes a long way to
helping debug our fuse implementation.

I'm new to fuse, so please, anyone with more fuse knowledge, feel free
to chime in!

Ray


.\"     $OpenBSD$
.\"
.\" Copyright (c) Ray Lai <r...@raylai.com>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate$
.Dt FUSE_OPT 3
.Os
.Sh NAME
.Nm FUSE_ARGS_INIT ,
.Nm FUSE_OPT_IS_OPT_KEY ,
.Nm FUSE_OPT_KEY ,
.Nm fuse_opt_add_arg ,
.Nm fuse_opt_insert_arg ,
.Nm fuse_opt_free_args ,
.Nm fuse_opt_add_opt ,
.Nm fuse_opt_add_opt_escaped ,
.Nm fuse_opt_match ,
.Nm fuse_opt_parse
.Nd FUSE options parser
.Sh SYNOPSIS
.In fuse_opt.h
.Ft struct fuse_args
.Fn FUSE_ARGS_INIT "int argc" "char argv**"
.Ft int
.Fn FUSE_OPT_IS_OPT_KEY "fuse_opt *t"
.Ft struct fuse_opt
.Fn FUSE_OPT_KEY "const char *templ" "int key"
.Ft int
.Fn fuse_opt_add_arg "struct fuse_args *args" "const char *arg"
.Ft int
.Fn fuse_opt_insert_arg "struct fuse_args *" "int" "const char *"
.Ft void
.Fn fuse_opt_free_args "struct fuse_args *args"
.Ft int
.Fn fuse_opt_add_opt "char **opts" "const char *opt"
.Ft int
.Fn fuse_opt_add_opt_escaped "char **opts" "const char *opt"
.Ft int
.Fn fuse_opt_match "const struct fuse_opt *opts" "const char *opt"
.Ft int
.Fo fuse_opt_parse
.Fa "struct fuse_args *args"
.Fa "void *data"
.Fa "const struct fuse_opt *opts"
.Fa "fuse_opt_proc_t proc"
.Fc
.Sh DESCRIPTION
.Ft struct fuse_args
holds string options in an array:
.Bd -literal -offset indent
struct fuse_args {
        int argc;       /* argument count */
        char **argv;    /* NULL-terminated array of arguments */
        int allocated;  /* allocated by malloc? */
};
.Ed
.Pp
.Fn FUSE_ARGS_INIT
initializes a
.Ft struct fuse_args
with
.Ar argc
and
.Ar argv ,
which can be from
.Fn main .
.Ar argv
is NULL-terminated, and is suitable for use with
.Xr execvp 3 .
.Ar allocated
is set to 0.
.Pp
.Fn fuse_opt_add_arg
adds a single option to the end of
.Ar args .
On
.Ox ,
if
.Ar args->allocated
is 0,
.Ar args->argv
is copied to the heap and
.Ar args->allocated
is set to a non-zero value.
.Pp
.Fn fuse_opt_insert_arg
inserts a single option at position
.Ar p
into
.Ar args ,
shifting
.Ar args->argv
as needed.
(Shifting is currently unimplemented.)
.Pp
.Fn fuse_opt_free_args
frees all allocated memory in
.Ar args
and initializes everything to 0.
.Pp
.Fn fuse_opt_add_opt
adds an option
.Ar opt
to a pointer to an comma-separated string of options
.Ar opts .
.Ar *opts
can be NULL for adding the first option.
.Fn fuse_opt_add_opt_escaped
escapes any
.Sq ","
and
.Sq "\\"
characters in
.Ar opt
before adding it to
.Ar opts .
.Pp
.Fn fuse_opt_match
checks
.Ar opts
for whether
.Ar opt
is set or not.
.Pp
.Fn fuse_opt_parse
parses options.
.Ar opts
is an array of
.Ft struct fuse_opt ,
each which describes actions for each option:
.Bd -literal -offset indent
struct fuse_opt {
        const char *templ;      /* template for option */
        unsigned long off;      /* data offset */
        int val;                /* key value */
};
.Ed
.Pp
.Fn FUSE_OPT_KEY
returns a
.Ft struct fuse_opt
that matches an option
.Ar templ
with option key
.Ar key .
This function is used as an element in
.Ft struct fuse_opt
arrays.
.Fn FUSE_OPT_IS_OPT_KEY
checks if
.Ar t
is an option key.
.Pp
The last element of the
.Ar opts
.Ft struct fuse_opt
option array must be
.Dv FUSE_OPT_END .
.Pp
.Ar proc
points to a function with the following signature:
.Ft int (*fuse_opt_proc_t)
.Fo proc
.Fa "void *data"
.Fa "const char *arg"
.Fa "int key"
.Fa "struct fuse_args *outargs"
.Fc
.Pp
Special key values:
.Bd -literal -offset indent
FUSE_OPT_KEY_OPT        /* no match */
FUSE_OPT_KEY_NONOPT     /* non-option */
FUSE_OPT_KEY_KEEP       /* don't process; return 1 */
FUSE_OPT_KEY_DISCARD    /* don't process; return 0 */
.Ed
.Sh RETURN VALUES
.Fn fuse_opt_add_arg ,
.Fn fuse_opt_insert_arg ,
.Fn fuse_opt_add_opt ,
.Fn fuse_opt_add_opt_escaped ,
and
.Fn fuse_opt_parse
return 0 on success, -1 on error.
.Pp
.Fn fuse_opt_match
returns non-zero on match, 0 if no match.
.Sh EXAMPLES
Generate an empty
.Ft struct fuse_args :
.Bd -literal -offset indent
struct fuse_args args = FUSE_ARGS_INIT(0, NULL);
.Ed
.Pp
Initialize a
.Ft struct fuse_args ,
for example from
.Fn main :
.Bd -literal -offset indent
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
.Ed
.Sh ERRORS
.Fn fuse_opt_add_arg ,
.Fn fuse_opt_insert_arg ,
.Fn fuse_opt_add_opt ,
and
.Fn fuse_opt_add_opt_escaped
can run out of memory and set
.Va errno .
.Sh SEE ALSO
.Xr fuse_main 3
.Xr fuse 4
.Xr fb_setup 9
.Sh STANDARDS
The original FUSE specification can be found at
.Lk http://libfuse.github.io/doxygen/ .
The original implementation can be found at
.Lk https://github.com/libfuse/libfuse/ .
.Sh HISTORY
The FUSE library first appeared in
.Ox 5.4 .
.Sh AUTHORS
This manual was written by 
.An Ray Lai Aq Mt r...@raylai.com .
.Sh CAVEATS
.Sh BUGS

Reply via email to