1.\" $OpenBSD: fuse_main.3,v 1.6 2018/11/28 21:19:11 mpi Exp $ 2.\" 3.\" Copyright (c) 2013 Sylvestre Gallon <ccna.syl@gmail.com> 4.\" Copyright (c) 2018 Helg Bredow <helg@openbsd.org> 5.\" 6.\" Permission to use, copy, modify, and distribute this software for any 7.\" purpose with or without fee is hereby granted, provided that the above 8.\" copyright notice and this permission notice appear in all copies. 9.\" 10.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17.\" 18.Dd $Mdocdate: November 28 2018 $ 19.Dt FUSE_MAIN 3 20.Os 21.Sh NAME 22.Nm fuse_main 23.Nd FUSE helper function 24.Sh SYNOPSIS 25.In fuse.h 26.Ft int 27.Fn fuse_main "int argc" "char **argv" "const struct fuse_operations *ops" \ 28 "void *data" 29.Sh DESCRIPTION 30There are two ways of implementing a FUSE filesystem: 31by calling only 32.Fn fuse_main 33and passing this function the 34.Em ops 35argument containing all the callbacks of the filesystem, 36or by using the other functions, 37as detailed in 38.Xr fuse_loop 3 39.Pp 40.Fa argv 41is the list of arguments supplied to the program's main method and 42must at a minimum specify the directory on which the file system is to 43be mounted. 44The other arguments can be custom arguments specific to the 45file system or those supported by 46.Xr fuse_parse_cmdline 3 , 47.Xr fuse_new 3 48and 49.Xr fuse_mount 3 . 50.Sh EXAMPLES 51Here is a simple example of a FUSE implementation: 52.Bd -literal 53#include <errno.h> 54#include <fuse.h> 55#include <string.h> 56 57static int 58fs_readdir(const char *path, void *data, fuse_fill_dir_t filler, 59 off_t off, struct fuse_file_info *ffi) 60{ 61 if (strcmp(path, "/") != 0) 62 return (-ENOENT); 63 64 filler(data, ".", NULL, 0); 65 filler(data, "..", NULL, 0); 66 filler(data, "file", NULL, 0); 67 return (0); 68} 69 70static int 71fs_read(const char *path, char *buf, size_t size, off_t off, 72 struct fuse_file_info *ffi) 73{ 74 if (off >= 5) 75 return (0); 76 77 size = 5 - off; 78 memcpy(buf, "data." + off, size); 79 return (size); 80} 81 82static int 83fs_open(const char *path, struct fuse_file_info *ffi) 84{ 85 if (strncmp(path, "/file", 10) != 0) 86 return (-ENOENT); 87 88 if ((ffi->flags & 3) != O_RDONLY) 89 return (-EACCES); 90 91 return (0); 92} 93 94static int 95fs_getattr(const char *path, struct stat *st) 96{ 97 if (strcmp(path, "/") == 0) { 98 st->st_blksize = 512; 99 st->st_mode = 0755; 100 st->st_nlink = 2; 101 } else if (strcmp(path, "/file") == 0) { 102 st->st_mode = 0644; 103 st->st_blksize = 512; 104 st->st_nlink = 1; 105 st->st_size = 5; 106 } else { 107 return (-ENOENT); 108 } 109 110 return (0); 111} 112 113struct fuse_operations fsops = { 114 .readdir = fs_readdir, 115 .read = fs_read, 116 .open = fs_open, 117 .getattr = fs_getattr, 118}; 119 120int 121main(int ac, char **av) 122{ 123 return (fuse_main(ac, av, &fsops, NULL)); 124} 125.Ed 126.Sh SEE ALSO 127.Xr fuse_loop 3 , 128.Xr fuse_mount 3 , 129.Xr fuse_new 3 , 130.Xr fuse_parse_cmdline 3 , 131.Xr fuse_setup 3 , 132.Xr fuse 4 133.Sh STANDARDS 134The 135.Fn fuse_main 136function conforms to FUSE 2.6. 137.Sh HISTORY 138The 139.Fn fuse_main 140function first appeared in 141.Ox 5.4 . 142.Sh AUTHORS 143.An Sylvestre Gallon Aq Mt ccna.syl@gmail.com 144.An Helg Bredow Aq Mt helg@openbsd.org 145