| FUSE_MAIN(3) | Library Functions Manual | FUSE_MAIN(3) |
fuse_main — FUSE
helper function
#include
<fuse.h>
int
fuse_main(int
argc, char **argv,
const struct fuse_operations
*ops, void
*data);
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 in
fuse_loop(3)
argv is the list of arguments supplied to the program's main method and must at a minimum specify the directory on which the file system is to be mounted. The other arguments can be custom arguments specific to the file system or those supported by fuse_parse_cmdline(3), fuse_new(3) and fuse_mount(3).
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)
{
size_t len;
const char *file_contents = "fuse filesystem example\n";
len = strlen(file_contents);
if (off < len) {
if (off + size > len)
size = len - off;
memcpy(buf, file_contents + off, size);
} else
size = 0;
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 argc, char **argv)
{
return (fuse_main(argc, argv, &fsops, NULL));
}
fuse_loop(3), fuse_mount(3), fuse_new(3), fuse_parse_cmdline(3), fuse_setup(3), fuse(4)
The fuse_main() function conforms to FUSE
2.6.
The fuse_main() function first appeared in
OpenBSD 5.4.
Sylvestre Gallon
<ccna.syl@gmail.com>
Helg Bredow
<helg@openbsd.org>
| May 25, 2020 | openbsd |