21#define FUSE_USE_VERSION FUSE_MAKE_VERSION(3, 12)
32static const char *hello_str =
"Hello World!\n";
33static const char *hello_name =
"hello";
35static int hello_stat(
fuse_ino_t ino,
struct stat *stbuf)
40 stbuf->st_mode = S_IFDIR | 0755;
45 stbuf->st_mode = S_IFREG | 0444;
47 stbuf->st_size = strlen(hello_str);
56static void hello_ll_init(
void *userdata,
struct fuse_conn_info *conn)
65 conn->
want &= ~FUSE_CAP_ASYNC_READ;
75 memset(&stbuf, 0,
sizeof(stbuf));
76 if (hello_stat(ino, &stbuf) == -1)
86 if (parent != 1 || strcmp(name, hello_name) != 0)
89 memset(&e, 0,
sizeof(e));
92 e.entry_timeout = 1.0;
93 hello_stat(e.ino, &e.attr);
104static void dirbuf_add(
fuse_req_t req,
struct dirbuf *b,
const char *name,
108 size_t oldsize = b->size;
110 b->p = (
char *) realloc(b->p, b->size);
111 memset(&stbuf, 0,
sizeof(stbuf));
117#define min(x, y) ((x) < (y) ? (x) : (y))
119static int reply_buf_limited(
fuse_req_t req,
const char *buf,
size_t bufsize,
120 off_t off,
size_t maxsize)
124 min(bufsize - off, maxsize));
139 memset(&b, 0,
sizeof(b));
140 dirbuf_add(req, &b,
".", 1);
141 dirbuf_add(req, &b,
"..", 1);
142 dirbuf_add(req, &b, hello_name, 2);
143 reply_buf_limited(req, b.p, b.size, off, size);
153 else if ((fi->
flags & O_ACCMODE) != O_RDONLY)
165 reply_buf_limited(req, hello_str, strlen(hello_str), off, size);
172 assert(ino == 1 || ino == 2);
173 if (strcmp(name,
"hello_ll_getxattr_name") == 0)
175 const char *buf =
"hello_ll_getxattr_value";
185 const char *value,
size_t size,
int flags)
189 assert(ino == 1 || ino == 2);
190 const char* exp_val =
"hello_ll_setxattr_value";
191 if (strcmp(name,
"hello_ll_setxattr_name") == 0 &&
192 strlen(exp_val) == size &&
193 strncmp(value, exp_val, size) == 0)
205 assert(ino == 1 || ino == 2);
206 if (strcmp(name,
"hello_ll_removexattr_name") == 0)
217 .
init = hello_ll_init,
218 .lookup = hello_ll_lookup,
219 .getattr = hello_ll_getattr,
220 .readdir = hello_ll_readdir,
221 .open = hello_ll_open,
222 .read = hello_ll_read,
223 .setxattr = hello_ll_setxattr,
224 .getxattr = hello_ll_getxattr,
225 .removexattr = hello_ll_removexattr,
228int main(
int argc,
char *argv[])
231 struct fuse_session *se;
236 if (fuse_parse_cmdline(&args, &opts) != 0)
238 if (opts.show_help) {
239 printf(
"usage: %s [options] <mountpoint>\n\n", argv[0]);
244 }
else if (opts.show_version) {
251 if(opts.mountpoint == NULL) {
252 printf(
"usage: %s [options] <mountpoint>\n", argv[0]);
253 printf(
" %s --help\n", argv[0]);
258 se = fuse_session_new(&args, &hello_ll_oper,
259 sizeof(hello_ll_oper), NULL);
272 if (opts.singlethread)
275 config = fuse_loop_cfg_create();
276 fuse_loop_cfg_set_clone_fd(config, opts.clone_fd);
277 fuse_loop_cfg_set_max_threads(config, opts.max_threads);
278 ret = fuse_session_loop_mt(se, config);
279 fuse_loop_cfg_destroy(config);
289 free(opts.mountpoint);
int fuse_set_signal_handlers(struct fuse_session *se)
#define FUSE_CAP_ASYNC_READ
const char * fuse_pkgversion(void)
void fuse_remove_signal_handlers(struct fuse_session *se)
int fuse_daemonize(int foreground)
void fuse_session_destroy(struct fuse_session *se)
int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi)
int fuse_reply_err(fuse_req_t req, int err)
int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size)
struct fuse_req * fuse_req_t
int fuse_session_loop(struct fuse_session *se)
int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e)
void fuse_session_unmount(struct fuse_session *se)
void fuse_cmdline_help(void)
void fuse_lowlevel_help(void)
int fuse_session_mount(struct fuse_session *se, const char *mountpoint)
void fuse_lowlevel_version(void)
size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize, const char *name, const struct stat *stbuf, off_t off)
int fuse_reply_attr(fuse_req_t req, const struct stat *attr, double attr_timeout)
void fuse_opt_free_args(struct fuse_args *args)
#define FUSE_ARGS_INIT(argc, argv)
void(* init)(void *userdata, struct fuse_conn_info *conn)