OpenBSD manual page server

Manual Page Search Parameters

FUSE_MAIN(3) Library Functions Manual FUSE_MAIN(3)

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_teardownFUSE implementation routines

#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);

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

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

() returns the FUSE version number.

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

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

() 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().

() is currently undocumented.

() is currently undocumented.

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

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

() 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.

() is unsupported.

() 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.

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

() unmounts the dir mountpoint.

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

() is currently undocumented.

() calls fuse_unmount() and fuse_destroy().

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));
}

The FUSE specifications and orignal implementation can be found at: http://fuse.sourceforge.net/

fuse(4)

The FUSE library first appeared in OpenBSD 5.4.

This man page is woefully incomplete.

August 8, 2013 OpenBSD-5.9