FUSE_MAIN(3)

NAME
fuse_main, fuse_version, fuse_new, fuse_parse_cmdline, fuse_mount, fuse_remove_signal_handlers, fuse_set_signal_handlers, fuse_get_session, fuse_get_context, fuse_is_lib_option, fuse_loop, fuse_loop_mt, fuse_chan_fd, fuse_unmount, fuse_daemonize, fuse_destroy, fuse_teardown - FUSE implementation routines

SYNOPSIS
#include <fuse.h>
int
fuse_main(int argc, char **argv, const struct fuse_operations *ops, void *data);
int
fuse_version(void);
struct fuse *
fuse_new(struct fuse_chan *fc, struct fuse_args *args, const struct fuse_operations *ops, size_t size, void *userdata);
int
fuse_parse_cmdline(struct fuse_args *args, char **mp, int *mt, int *fg);
struct fuse_chan *
fuse_mount(const char *dir, struct fuse_args *args);
void
fuse_remove_signal_handlers(struct fuse_session *se);
int
fuse_set_signal_handlers(struct fuse_session *se);
struct fuse_session *
fuse_get_session(struct fuse *f);
struct fuse_context *
fuse_get_context(void);
int
fuse_is_lib_option(const char *opt);
int
fuse_loop(struct fuse *fuse);
int
fuse_loop_mt(struct fuse *fuse);
int
fuse_chan_fd(struct fuse_chan *ch);
void
fuse_unmount(const char *dir, struct fuse_chan *ch);
int
fuse_daemonize(int foreground);
void
fuse_destroy(struct fuse *f);
void
fuse_teardown(struct fuse *f, char *mp);

DESCRIPTION
The FUSE library provides routines to implement a filesystem in userspace.

There are two ways of implementing a FUSE filesystem: by calling only fuse_main() and passing this function the ops argument containing all the callbacks of the filesystem, or by using the other functions, as detailed below.

fuse_version() returns the FUSE version number.

fuse_new() returns a struct fuse that will be needed by fuse_loop().

fuse_parse_cmdline() parses the struct fuse_args given by the user and will set mp with a char * containing the mountpoint directory.

fuse_mount() looks for an empty fuse(4) device to create a connection. If this function finds an available device it will open it for FUSE communication with the FUSE VFS driver and will mount the filesystem. This function will return a struct fuse_chan that will be needed by fuse_new().

fuse_remove_signal_handlers() is currently undocumented.

fuse_set_signal_handlers() is currently undocumented.

fuse_get_session() returns a pointer to the structure fuse_session contained in a struct fuse.

fuse_get_context() returns a pointer to the structure fuse_context. The returned fuse_context is only available during the lifetime of a FUSE operation.

fuse_is_lib_option() checks if the string opt is an option handled by libfuse or by the FUSE client. It returns 1 if it is handled by the lib and 0 otherwise.

fuse_loop_mt() is unsupported.

fuse_loop() is the main loop of a FUSE program. This function looks for FUSE requests from the kernel and responds to them using the struct fuse_operation present in the structure fuse. It will return only if something goes wrong or if the kernel sends a FUSE_DESTROY opcode to libfuse.

fuse_chan_fd() returns the filedescriptor used by the given fuse_chan structure.

fuse_unmount() unmounts the dir mountpoint.

fuse_daemonize() daemonises the FUSE library. It runs the FUSE program in the background, whilst continuing to handle kernel filesystem opcodes.

fuse_destroy() is currently undocumented.

fuse_teardown() calls fuse_unmount() and fuse_destroy().

EXAMPLES
Here is a simple example of a FUSE implementation:

    #include <errno.h>
    #include <fuse.h>
    #include <string.h>
    static int
    fs_readdir(const char *path, void *data, fuse_fill_dir_t filler,
        off_t off, struct fuse_file_info *ffi)
    {
    	if (strcmp(path, "/") != 0)
    		return (-ENOENT);
    	filler(data, ".", NULL, 0);
    	filler(data, "..", NULL, 0);
    	filler(data, "file", NULL, 0);
    	return (0);
    }
    static int
    fs_read(const char *path, char *buf, size_t size, off_t off,
        struct fuse_file_info *ffi)
    {
    	if (off >= 5)
    		return (0);
    	size = 5 - off;
    	memcpy(buf, "data." + off, size);
    	return (size);
    }
    static int
    fs_open(const char *path, struct fuse_file_info *ffi)
    {
    	if (strncmp(path, "/file", 10) != 0)
    		return (-ENOENT);
    	if ((ffi->flags & 3) != O_RDONLY)
    		return (-EACCES);
    	return (0);
    }
    static int
    fs_getattr(const char *path, struct stat *st)
    {
    	if (strcmp(path, "/") == 0) {
    		st->st_blksize = 512;
    		st->st_mode = 0755;
    		st->st_nlink = 2;
    	} else if (strcmp(path, "/file") == 0) {
    		st->st_mode = 0644;
    		st->st_blksize = 512;
    		st->st_nlink = 1;
    		st->st_size = 5;
    	} else {
    		return (-ENOENT);
    	}
    	return (0);
    }
    struct fuse_operations fsops = {
    	.readdir = fs_readdir,
    	.read = fs_read,
    	.open = fs_open,
    	.getattr = fs_getattr,
    };
    int
    main(int ac, char **av)
    {
    	return (fuse_main(ac, av, &fsops, NULL));
    }

SEE ALSO
fuse(4)

STANDARDS
The original FUSE specification can be found at http://libfuse.github.io/doxygen/. The original implementation can be found at https://github.com/libfuse/libfuse/.

HISTORY
The FUSE library first appeared in OpenBSD 5.4.

BUGS
This man page is woefully incomplete.