libfuse: lib/fuse_lowlevel.c Source File

libfuse

fuse_lowlevel.c
1 /*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
4
5 Implementation of (most of) the low-level FUSE API. The session loop
6 functions are implemented in separate files.
7
8 This program can be distributed under the terms of the GNU LGPLv2.
9 See the file COPYING.LIB
10 */
11
12 #define _GNU_SOURCE
13
14 #include "config.h"
15 #include "fuse_i.h"
16 #include "fuse_kernel.h"
17 #include "fuse_opt.h"
18 #include "fuse_misc.h"
19 #include "mount_util.h"
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <stddef.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <limits.h>
27 #include <errno.h>
28 #include <assert.h>
29 #include <sys/file.h>
30
31 #ifndef F_LINUX_SPECIFIC_BASE
32 #define F_LINUX_SPECIFIC_BASE 1024
33 #endif
34 #ifndef F_SETPIPE_SZ
35 #define F_SETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 7)
36 #endif
37
38
39 #define PARAM(inarg) (((char *)(inarg)) + sizeof(*(inarg)))
40 #define OFFSET_MAX 0x7fffffffffffffffLL
41
42 #define container_of(ptr, type, member) ({ \
43 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
44 (type *)( (char *)__mptr - offsetof(type,member) );})
45
46 struct fuse_pollhandle {
47 uint64_t kh;
48 struct fuse_session *se;
49 };
50
51 static size_t pagesize;
52
53 static __attribute__((constructor)) void fuse_ll_init_pagesize(void)
54 {
55 pagesize = getpagesize();
56 }
57
58 static void convert_stat(const struct stat *stbuf, struct fuse_attr *attr)
59 {
60 attr->ino = stbuf->st_ino;
61 attr->mode = stbuf->st_mode;
62 attr->nlink = stbuf->st_nlink;
63 attr->uid = stbuf->st_uid;
64 attr->gid = stbuf->st_gid;
65 attr->rdev = stbuf->st_rdev;
66 attr->size = stbuf->st_size;
67 attr->blksize = stbuf->st_blksize;
68 attr->blocks = stbuf->st_blocks;
69 attr->atime = stbuf->st_atime;
70 attr->mtime = stbuf->st_mtime;
71 attr->ctime = stbuf->st_ctime;
72 attr->atimensec = ST_ATIM_NSEC(stbuf);
73 attr->mtimensec = ST_MTIM_NSEC(stbuf);
74 attr->ctimensec = ST_CTIM_NSEC(stbuf);
75 }
76
77 static void convert_attr(const struct fuse_setattr_in *attr, struct stat *stbuf)
78 {
79 stbuf->st_mode = attr->mode;
80 stbuf->st_uid = attr->uid;
81 stbuf->st_gid = attr->gid;
82 stbuf->st_size = attr->size;
83 stbuf->st_atime = attr->atime;
84 stbuf->st_mtime = attr->mtime;
85 stbuf->st_ctime = attr->ctime;
86 ST_ATIM_NSEC_SET(stbuf, attr->atimensec);
87 ST_MTIM_NSEC_SET(stbuf, attr->mtimensec);
88 ST_CTIM_NSEC_SET(stbuf, attr->ctimensec);
89 }
90
91 static size_t iov_length(const struct iovec *iov, size_t count)
92 {
93 size_t seg;
94 size_t ret = 0;
95
96 for (seg = 0; seg < count; seg++)
97 ret += iov[seg].iov_len;
98 return ret;
99 }
100
101 static void list_init_req(struct fuse_req *req)
102 {
103 req->next = req;
104 req->prev = req;
105 }
106
107 static void list_del_req(struct fuse_req *req)
108 {
109 struct fuse_req *prev = req->prev;
110 struct fuse_req *next = req->next;
111 prev->next = next;
112 next->prev = prev;
113 }
114
115 static void list_add_req(struct fuse_req *req, struct fuse_req *next)
116 {
117 struct fuse_req *prev = next->prev;
118 req->next = next;
119 req->prev = prev;
120 prev->next = req;
121 next->prev = req;
122 }
123
124 static void destroy_req(fuse_req_t req)
125 {
126 pthread_mutex_destroy(&req->lock);
127 free(req);
128 }
129
130 void fuse_free_req(fuse_req_t req)
131 {
132 int ctr;
133 struct fuse_session *se = req->se;
134
135 pthread_mutex_lock(&se->lock);
136 req->u.ni.func = NULL;
137 req->u.ni.data = NULL;
138 list_del_req(req);
139 ctr = --req->ctr;
140 fuse_chan_put(req->ch);
141 req->ch = NULL;
142 pthread_mutex_unlock(&se->lock);
143 if (!ctr)
144 destroy_req(req);
145 }
146
147 static struct fuse_req *fuse_ll_alloc_req(struct fuse_session *se)
148 {
149 struct fuse_req *req;
150
151 req = (struct fuse_req *) calloc(1, sizeof(struct fuse_req));
152 if (req == NULL) {
153 fprintf(stderr, "fuse: failed to allocate request\n");
154 } else {
155 req->se = se;
156 req->ctr = 1;
157 list_init_req(req);
158 fuse_mutex_init(&req->lock);
159 }
160
161 return req;
162 }
163
164 /* Send data. If *ch* is NULL, send via session master fd */
165 static int fuse_send_msg(struct fuse_session *se, struct fuse_chan *ch,
166 struct iovec *iov, int count)
167 {
168 struct fuse_out_header *out = iov[0].iov_base;
169
170 out->len = iov_length(iov, count);
171 if (se->debug) {
172 if (out->unique == 0) {
173 fprintf(stderr, "NOTIFY: code=%d length=%u\n",
174 out->error, out->len);
175 } else if (out->error) {
176 fprintf(stderr,
177 " unique: %llu, error: %i (%s), outsize: %i\n",
178 (unsigned long long) out->unique, out->error,
179 strerror(-out->error), out->len);
180 } else {
181 fprintf(stderr,
182 " unique: %llu, success, outsize: %i\n",
183 (unsigned long long) out->unique, out->len);
184 }
185 }
186
187 ssize_t res = writev(ch ? ch->fd : se->fd,
188 iov, count);
189 int err = errno;
190
191 if (res == -1) {
192 assert(se != NULL);
193
194 /* ENOENT means the operation was interrupted */
195 if (!fuse_session_exited(se) && err != ENOENT)
196 perror("fuse: writing device");
197 return -err;
198 }
199
200 return 0;
201 }
202
203
204 int fuse_send_reply_iov_nofree(fuse_req_t req, int error, struct iovec *iov,
205 int count)
206 {
207 struct fuse_out_header out;
208
209 if (error <= -1000 || error > 0) {
210 fprintf(stderr, "fuse: bad error value: %i\n", error);
211 error = -ERANGE;
212 }
213
214 out.unique = req->unique;
215 out.error = error;
216
217 iov[0].iov_base = &out;
218 iov[0].iov_len = sizeof(struct fuse_out_header);
219
220 return fuse_send_msg(req->se, req->ch, iov, count);
221 }
222
223 static int send_reply_iov(fuse_req_t req, int error, struct iovec *iov,
224 int count)
225 {
226 int res;
227
228 res = fuse_send_reply_iov_nofree(req, error, iov, count);
229 fuse_free_req(req);
230 return res;
231 }
232
233 static int send_reply(fuse_req_t req, int error, const void *arg,
234 size_t argsize)
235 {
236 struct iovec iov[2];
237 int count = 1;
238 if (argsize) {
239 iov[1].iov_base = (void *) arg;
240 iov[1].iov_len = argsize;
241 count++;
242 }
243 return send_reply_iov(req, error, iov, count);
244 }
245
246 int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count)
247 {
248 int res;
249 struct iovec *padded_iov;
250
251 padded_iov = malloc((count + 1) * sizeof(struct iovec));
252 if (padded_iov == NULL)
253 return fuse_reply_err(req, ENOMEM);
254
255 memcpy(padded_iov + 1, iov, count * sizeof(struct iovec));
256 count++;
257
258 res = send_reply_iov(req, 0, padded_iov, count);
259 free(padded_iov);
260
261 return res;
262 }
263
264
265 /* `buf` is allowed to be empty so that the proper size may be
266 allocated by the caller */
267 size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize,
268 const char *name, const struct stat *stbuf, off_t off)
269 {
270 (void)req;
271 size_t namelen;
272 size_t entlen;
273 size_t entlen_padded;
274 struct fuse_dirent *dirent;
275
276 namelen = strlen(name);
277 entlen = FUSE_NAME_OFFSET + namelen;
278 entlen_padded = FUSE_DIRENT_ALIGN(entlen);
279
280 if ((buf == NULL) || (entlen_padded > bufsize))
281 return entlen_padded;
282
283 dirent = (struct fuse_dirent*) buf;
284 dirent->ino = stbuf->st_ino;
285 dirent->off = off;
286 dirent->namelen = namelen;
287 dirent->type = (stbuf->st_mode & 0170000) >> 12;
288 strncpy(dirent->name, name, namelen);
289 memset(dirent->name + namelen, 0, entlen_padded - entlen);
290
291 return entlen_padded;
292 }
293
294 static void convert_statfs(const struct statvfs *stbuf,
295 struct fuse_kstatfs *kstatfs)
296 {
297 kstatfs->bsize = stbuf->f_bsize;
298 kstatfs->frsize = stbuf->f_frsize;
299 kstatfs->blocks = stbuf->f_blocks;
300 kstatfs->bfree = stbuf->f_bfree;
301 kstatfs->bavail = stbuf->f_bavail;
302 kstatfs->files = stbuf->f_files;
303 kstatfs->ffree = stbuf->f_ffree;
304 kstatfs->namelen = stbuf->f_namemax;
305 }
306
307 static int send_reply_ok(fuse_req_t req, const void *arg, size_t argsize)
308 {
309 return send_reply(req, 0, arg, argsize);
310 }
311
312 int fuse_reply_err(fuse_req_t req, int err)
313 {
314 return send_reply(req, -err, NULL, 0);
315 }
316
317 void fuse_reply_none(fuse_req_t req)
318 {
319 fuse_free_req(req);
320 }
321
322 static unsigned long calc_timeout_sec(double t)
323 {
324 if (t > (double) ULONG_MAX)
325 return ULONG_MAX;
326 else if (t < 0.0)
327 return 0;
328 else
329 return (unsigned long) t;
330 }
331
332 static unsigned int calc_timeout_nsec(double t)
333 {
334 double f = t - (double) calc_timeout_sec(t);
335 if (f < 0.0)
336 return 0;
337 else if (f >= 0.999999999)
338 return 999999999;
339 else
340 return (unsigned int) (f * 1.0e9);
341 }
342
343 static void fill_entry(struct fuse_entry_out *arg,
344 const struct fuse_entry_param *e)
345 {
346 arg->nodeid = e->ino;
347 arg->generation = e->generation;
348 arg->entry_valid = calc_timeout_sec(e->entry_timeout);
349 arg->entry_valid_nsec = calc_timeout_nsec(e->entry_timeout);
350 arg->attr_valid = calc_timeout_sec(e->attr_timeout);
351 arg->attr_valid_nsec = calc_timeout_nsec(e->attr_timeout);
352 convert_stat(&e->attr, &arg->attr);
353 }
354
355 /* `buf` is allowed to be empty so that the proper size may be
356 allocated by the caller */
357 size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize,
358 const char *name,
359 const struct fuse_entry_param *e, off_t off)
360 {
361 (void)req;
362 size_t namelen;
363 size_t entlen;
364 size_t entlen_padded;
365
366 namelen = strlen(name);
367 entlen = FUSE_NAME_OFFSET_DIRENTPLUS + namelen;
368 entlen_padded = FUSE_DIRENT_ALIGN(entlen);
369 if ((buf == NULL) || (entlen_padded > bufsize))
370 return entlen_padded;
371
372 struct fuse_direntplus *dp = (struct fuse_direntplus *) buf;
373 memset(&dp->entry_out, 0, sizeof(dp->entry_out));
374 fill_entry(&dp->entry_out, e);
375
376 struct fuse_dirent *dirent = &dp->dirent;
377 dirent->ino = e->attr.st_ino;
378 dirent->off = off;
379 dirent->namelen = namelen;
380 dirent->type = (e->attr.st_mode & 0170000) >> 12;
381 strncpy(dirent->name, name, namelen);
382 memset(dirent->name + namelen, 0, entlen_padded - entlen);
383
384 return entlen_padded;
385 }
386
387 static void fill_open(struct fuse_open_out *arg,
388 const struct fuse_file_info *f)
389 {
390 arg->fh = f->fh;
391 if (f->direct_io)
392 arg->open_flags |= FOPEN_DIRECT_IO;
393 if (f->keep_cache)
394 arg->open_flags |= FOPEN_KEEP_CACHE;
395 if (f->nonseekable)
396 arg->open_flags |= FOPEN_NONSEEKABLE;
397 }
398
399 int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e)
400 {
401 struct fuse_entry_out arg;
402 size_t size = req->se->conn.proto_minor < 9 ?
403 FUSE_COMPAT_ENTRY_OUT_SIZE : sizeof(arg);
404
405 /* before ABI 7.4 e->ino == 0 was invalid, only ENOENT meant
406 negative entry */
407 if (!e->ino && req->se->conn.proto_minor < 4)
408 return fuse_reply_err(req, ENOENT);
409
410 memset(&arg, 0, sizeof(arg));
411 fill_entry(&arg, e);
412 return send_reply_ok(req, &arg, size);
413 }
414
415 int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
416 const struct fuse_file_info *f)
417 {
418 char buf[sizeof(struct fuse_entry_out) + sizeof(struct fuse_open_out)];
419 size_t entrysize = req->se->conn.proto_minor < 9 ?
420 FUSE_COMPAT_ENTRY_OUT_SIZE : sizeof(struct fuse_entry_out);
421 struct fuse_entry_out *earg = (struct fuse_entry_out *) buf;
422 struct fuse_open_out *oarg = (struct fuse_open_out *) (buf + entrysize);
423
424 memset(buf, 0, sizeof(buf));
425 fill_entry(earg, e);
426 fill_open(oarg, f);
427 return send_reply_ok(req, buf,
428 entrysize + sizeof(struct fuse_open_out));
429 }
430
431 int fuse_reply_attr(fuse_req_t req, const struct stat *attr,
432 double attr_timeout)
433 {
434 struct fuse_attr_out arg;
435 size_t size = req->se->conn.proto_minor < 9 ?
436 FUSE_COMPAT_ATTR_OUT_SIZE : sizeof(arg);
437
438 memset(&arg, 0, sizeof(arg));
439 arg.attr_valid = calc_timeout_sec(attr_timeout);
440 arg.attr_valid_nsec = calc_timeout_nsec(attr_timeout);
441 convert_stat(attr, &arg.attr);
442
443 return send_reply_ok(req, &arg, size);
444 }
445
446 int fuse_reply_readlink(fuse_req_t req, const char *linkname)
447 {
448 return send_reply_ok(req, linkname, strlen(linkname));
449 }
450
451 int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *f)
452 {
453 struct fuse_open_out arg;
454
455 memset(&arg, 0, sizeof(arg));
456 fill_open(&arg, f);
457 return send_reply_ok(req, &arg, sizeof(arg));
458 }
459
460 int fuse_reply_write(fuse_req_t req, size_t count)
461 {
462 struct fuse_write_out arg;
463
464 memset(&arg, 0, sizeof(arg));
465 arg.size = count;
466
467 return send_reply_ok(req, &arg, sizeof(arg));
468 }
469
470 int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size)
471 {
472 return send_reply_ok(req, buf, size);
473 }
474
475 static int fuse_send_data_iov_fallback(struct fuse_session *se,
476 struct fuse_chan *ch,
477 struct iovec *iov, int iov_count,
478 struct fuse_bufvec *buf,
479 size_t len)
480 {
481 struct fuse_bufvec mem_buf = FUSE_BUFVEC_INIT(len);
482 void *mbuf;
483 int res;
484
485 /* Optimize common case */
486 if (buf->count == 1 && buf->idx == 0 && buf->off == 0 &&
487 !(buf->buf[0].flags & FUSE_BUF_IS_FD)) {
488 /* FIXME: also avoid memory copy if there are multiple buffers
489 but none of them contain an fd */
490
491 iov[iov_count].iov_base = buf->buf[0].mem;
492 iov[iov_count].iov_len = len;
493 iov_count++;
494 return fuse_send_msg(se, ch, iov, iov_count);
495 }
496
497 res = posix_memalign(&mbuf, pagesize, len);
498 if (res != 0)
499 return res;
500
501 mem_buf.buf[0].mem = mbuf;
502 res = fuse_buf_copy(&mem_buf, buf, 0);
503 if (res < 0) {
504 free(mbuf);
505 return -res;
506 }
507 len = res;
508
509 iov[iov_count].iov_base = mbuf;
510 iov[iov_count].iov_len = len;
511 iov_count++;
512 res = fuse_send_msg(se, ch, iov, iov_count);
513 free(mbuf);
514
515 return res;
516 }
517
518 struct fuse_ll_pipe {
519 size_t size;
520 int can_grow;
521 int pipe[2];
522 };
523
524 static void fuse_ll_pipe_free(struct fuse_ll_pipe *llp)
525 {
526 close(llp->pipe[0]);
527 close(llp->pipe[1]);
528 free(llp);
529 }
530
531 #ifdef HAVE_SPLICE
532 #if !defined(HAVE_PIPE2) || !defined(O_CLOEXEC)
533 static int fuse_pipe(int fds[2])
534 {
535 int rv = pipe(fds);
536
537 if (rv == -1)
538 return rv;
539
540 if (fcntl(fds[0], F_SETFL, O_NONBLOCK) == -1 ||
541 fcntl(fds[1], F_SETFL, O_NONBLOCK) == -1 ||
542 fcntl(fds[0], F_SETFD, FD_CLOEXEC) == -1 ||
543 fcntl(fds[1], F_SETFD, FD_CLOEXEC) == -1) {
544 close(fds[0]);
545 close(fds[1]);
546 rv = -1;
547 }
548 return rv;
549 }
550 #else
551 static int fuse_pipe(int fds[2])
552 {
553 return pipe2(fds, O_CLOEXEC | O_NONBLOCK);
554 }
555 #endif
556
557 static struct fuse_ll_pipe *fuse_ll_get_pipe(struct fuse_session *se)
558 {
559 struct fuse_ll_pipe *llp = pthread_getspecific(se->pipe_key);
560 if (llp == NULL) {
561 int res;
562
563 llp = malloc(sizeof(struct fuse_ll_pipe));
564 if (llp == NULL)
565 return NULL;
566
567 res = fuse_pipe(llp->pipe);
568 if (res == -1) {
569 free(llp);
570 return NULL;
571 }
572
573 /*
574 *the default size is 16 pages on linux
575 */
576 llp->size = pagesize * 16;
577 llp->can_grow = 1;
578
579 pthread_setspecific(se->pipe_key, llp);
580 }
581
582 return llp;
583 }
584 #endif
585
586 static void fuse_ll_clear_pipe(struct fuse_session *se)
587 {
588 struct fuse_ll_pipe *llp = pthread_getspecific(se->pipe_key);
589 if (llp) {
590 pthread_setspecific(se->pipe_key, NULL);
591 fuse_ll_pipe_free(llp);
592 }
593 }
594
595 #if defined(HAVE_SPLICE) && defined(HAVE_VMSPLICE)
596 static int read_back(int fd, char *buf, size_t len)
597 {
598 int res;
599
600 res = read(fd, buf, len);
601 if (res == -1) {
602 fprintf(stderr, "fuse: internal error: failed to read back from pipe: %s\n", strerror(errno));
603 return -EIO;
604 }
605 if (res != len) {
606 fprintf(stderr, "fuse: internal error: short read back from pipe: %i from %zi\n", res, len);
607 return -EIO;
608 }
609 return 0;
610 }
611
612 static int fuse_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
613 struct iovec *iov, int iov_count,
614 struct fuse_bufvec *buf, unsigned int flags)
615 {
616 int res;
617 size_t len = fuse_buf_size(buf);
618 struct fuse_out_header *out = iov[0].iov_base;
619 struct fuse_ll_pipe *llp;
620 int splice_flags;
621 size_t pipesize;
622 size_t total_fd_size;
623 size_t idx;
624 size_t headerlen;
625 struct fuse_bufvec pipe_buf = FUSE_BUFVEC_INIT(len);
626
627 if (se->broken_splice_nonblock)
628 goto fallback;
629
630 if (flags & FUSE_BUF_NO_SPLICE)
631 goto fallback;
632
633 total_fd_size = 0;
634 for (idx = buf->idx; idx < buf->count; idx++) {
635 if (buf->buf[idx].flags & FUSE_BUF_IS_FD) {
636 total_fd_size = buf->buf[idx].size;
637 if (idx == buf->idx)
638 total_fd_size -= buf->off;
639 }
640 }
641 if (total_fd_size < 2 * pagesize)
642 goto fallback;
643
644 if (se->conn.proto_minor < 14 ||
645 !(se->conn.want & FUSE_CAP_SPLICE_WRITE))
646 goto fallback;
647
648 llp = fuse_ll_get_pipe(se);
649 if (llp == NULL)
650 goto fallback;
651
652
653 headerlen = iov_length(iov, iov_count);
654
655 out->len = headerlen + len;
656
657 /*
658 * Heuristic for the required pipe size, does not work if the
659 * source contains less than page size fragments
660 */
661 pipesize = pagesize * (iov_count + buf->count + 1) + out->len;
662
663 if (llp->size < pipesize) {
664 if (llp->can_grow) {
665 res = fcntl(llp->pipe[0], F_SETPIPE_SZ, pipesize);
666 if (res == -1) {
667 llp->can_grow = 0;
668 goto fallback;
669 }
670 llp->size = res;
671 }
672 if (llp->size < pipesize)
673 goto fallback;
674 }
675
676
677 res = vmsplice(llp->pipe[1], iov, iov_count, SPLICE_F_NONBLOCK);
678 if (res == -1)
679 goto fallback;
680
681 if (res != headerlen) {
682 res = -EIO;
683 fprintf(stderr, "fuse: short vmsplice to pipe: %u/%zu\n", res,
684 headerlen);
685 goto clear_pipe;
686 }
687
688 pipe_buf.buf[0].flags = FUSE_BUF_IS_FD;
689 pipe_buf.buf[0].fd = llp->pipe[1];
690
691 res = fuse_buf_copy(&pipe_buf, buf,
692 FUSE_BUF_FORCE_SPLICE | FUSE_BUF_SPLICE_NONBLOCK);
693 if (res < 0) {
694 if (res == -EAGAIN || res == -EINVAL) {
695 /*
696 * Should only get EAGAIN on kernels with
697 * broken SPLICE_F_NONBLOCK support (<=
698 * 2.6.35) where this error or a short read is
699 * returned even if the pipe itself is not
700 * full
701 *
702 * EINVAL might mean that splice can't handle
703 * this combination of input and output.
704 */
705 if (res == -EAGAIN)
706 se->broken_splice_nonblock = 1;
707
708 pthread_setspecific(se->pipe_key, NULL);
709 fuse_ll_pipe_free(llp);
710 goto fallback;
711 }
712 res = -res;
713 goto clear_pipe;
714 }
715
716 if (res != 0 && res < len) {
717 struct fuse_bufvec mem_buf = FUSE_BUFVEC_INIT(len);
718 void *mbuf;
719 size_t now_len = res;
720 /*
721 * For regular files a short count is either
722 * 1) due to EOF, or
723 * 2) because of broken SPLICE_F_NONBLOCK (see above)
724 *
725 * For other inputs it's possible that we overflowed
726 * the pipe because of small buffer fragments.
727 */
728
729 res = posix_memalign(&mbuf, pagesize, len);
730 if (res != 0)
731 goto clear_pipe;
732
733 mem_buf.buf[0].mem = mbuf;
734 mem_buf.off = now_len;
735 res = fuse_buf_copy(&mem_buf, buf, 0);
736 if (res > 0) {
737 char *tmpbuf;
738 size_t extra_len = res;
739 /*
740 * Trickiest case: got more data. Need to get
741 * back the data from the pipe and then fall
742 * back to regular write.
743 */
744 tmpbuf = malloc(headerlen);
745 if (tmpbuf == NULL) {
746 free(mbuf);
747 res = ENOMEM;
748 goto clear_pipe;
749 }
750 res = read_back(llp->pipe[0], tmpbuf, headerlen);
751 free(tmpbuf);
752 if (res != 0) {
753 free(mbuf);
754 goto clear_pipe;
755 }
756 res = read_back(llp->pipe[0], mbuf, now_len);
757 if (res != 0) {
758 free(mbuf);
759 goto clear_pipe;
760 }
761 len = now_len + extra_len;
762 iov[iov_count].iov_base = mbuf;
763 iov[iov_count].iov_len = len;
764 iov_count++;
765 res = fuse_send_msg(se, ch, iov, iov_count);
766 free(mbuf);
767 return res;
768 }
769 free(mbuf);
770 res = now_len;
771 }
772 len = res;
773 out->len = headerlen + len;
774
775 if (se->debug) {
776 fprintf(stderr,
777 " unique: %llu, success, outsize: %i (splice)\n",
778 (unsigned long long) out->unique, out->len);
779 }
780
781 splice_flags = 0;
782 if ((flags & FUSE_BUF_SPLICE_MOVE) &&
783 (se->conn.want & FUSE_CAP_SPLICE_MOVE))
784 splice_flags |= SPLICE_F_MOVE;
785
786 res = splice(llp->pipe[0], NULL, ch ? ch->fd : se->fd,
787 NULL, out->len, splice_flags);
788 if (res == -1) {
789 res = -errno;
790 perror("fuse: splice from pipe");
791 goto clear_pipe;
792 }
793 if (res != out->len) {
794 res = -EIO;
795 fprintf(stderr, "fuse: short splice from pipe: %u/%u\n",
796 res, out->len);
797 goto clear_pipe;
798 }
799 return 0;
800
801 clear_pipe:
802 fuse_ll_clear_pipe(se);
803 return res;
804
805 fallback:
806 return fuse_send_data_iov_fallback(se, ch, iov, iov_count, buf, len);
807 }
808 #else
809 static int fuse_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
810 struct iovec *iov, int iov_count,
811 struct fuse_bufvec *buf, unsigned int flags)
812 {
813 size_t len = fuse_buf_size(buf);
814 (void) flags;
815
816 return fuse_send_data_iov_fallback(se, ch, iov, iov_count, buf, len);
817 }
818 #endif
819
820 int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv,
821 enum fuse_buf_copy_flags flags)
822 {
823 struct iovec iov[2];
824 struct fuse_out_header out;
825 int res;
826
827 iov[0].iov_base = &out;
828 iov[0].iov_len = sizeof(struct fuse_out_header);
829
830 out.unique = req->unique;
831 out.error = 0;
832
833 res = fuse_send_data_iov(req->se, req->ch, iov, 1, bufv, flags);
834 if (res <= 0) {
835 fuse_free_req(req);
836 return res;
837 } else {
838 return fuse_reply_err(req, res);
839 }
840 }
841
842 int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf)
843 {
844 struct fuse_statfs_out arg;
845 size_t size = req->se->conn.proto_minor < 4 ?
846 FUSE_COMPAT_STATFS_SIZE : sizeof(arg);
847
848 memset(&arg, 0, sizeof(arg));
849 convert_statfs(stbuf, &arg.st);
850
851 return send_reply_ok(req, &arg, size);
852 }
853
854 int fuse_reply_xattr(fuse_req_t req, size_t count)
855 {
856 struct fuse_getxattr_out arg;
857
858 memset(&arg, 0, sizeof(arg));
859 arg.size = count;
860
861 return send_reply_ok(req, &arg, sizeof(arg));
862 }
863
864 int fuse_reply_lock(fuse_req_t req, const struct flock *lock)
865 {
866 struct fuse_lk_out arg;
867
868 memset(&arg, 0, sizeof(arg));
869 arg.lk.type = lock->l_type;
870 if (lock->l_type != F_UNLCK) {
871 arg.lk.start = lock->l_start;
872 if (lock->l_len == 0)
873 arg.lk.end = OFFSET_MAX;
874 else
875 arg.lk.end = lock->l_start + lock->l_len - 1;
876 }
877 arg.lk.pid = lock->l_pid;
878 return send_reply_ok(req, &arg, sizeof(arg));
879 }
880
881 int fuse_reply_bmap(fuse_req_t req, uint64_t idx)
882 {
883 struct fuse_bmap_out arg;
884
885 memset(&arg, 0, sizeof(arg));
886 arg.block = idx;
887
888 return send_reply_ok(req, &arg, sizeof(arg));
889 }
890
891 static struct fuse_ioctl_iovec *fuse_ioctl_iovec_copy(const struct iovec *iov,
892 size_t count)
893 {
894 struct fuse_ioctl_iovec *fiov;
895 size_t i;
896
897 fiov = malloc(sizeof(fiov[0]) * count);
898 if (!fiov)
899 return NULL;
900
901 for (i = 0; i < count; i++) {
902 fiov[i].base = (uintptr_t) iov[i].iov_base;
903 fiov[i].len = iov[i].iov_len;
904 }
905
906 return fiov;
907 }
908
909 int fuse_reply_ioctl_retry(fuse_req_t req,
910 const struct iovec *in_iov, size_t in_count,
911 const struct iovec *out_iov, size_t out_count)
912 {
913 struct fuse_ioctl_out arg;
914 struct fuse_ioctl_iovec *in_fiov = NULL;
915 struct fuse_ioctl_iovec *out_fiov = NULL;
916 struct iovec iov[4];
917 size_t count = 1;
918 int res;
919
920 memset(&arg, 0, sizeof(arg));
921 arg.flags |= FUSE_IOCTL_RETRY;
922 arg.in_iovs = in_count;
923 arg.out_iovs = out_count;
924 iov[count].iov_base = &arg;
925 iov[count].iov_len = sizeof(arg);
926 count++;
927
928 if (req->se->conn.proto_minor < 16) {
929 if (in_count) {
930 iov[count].iov_base = (void *)in_iov;
931 iov[count].iov_len = sizeof(in_iov[0]) * in_count;
932 count++;
933 }
934
935 if (out_count) {
936 iov[count].iov_base = (void *)out_iov;
937 iov[count].iov_len = sizeof(out_iov[0]) * out_count;
938 count++;
939 }
940 } else {
941 /* Can't handle non-compat 64bit ioctls on 32bit */
942 if (sizeof(void *) == 4 && req->ioctl_64bit) {
943 res = fuse_reply_err(req, EINVAL);
944 goto out;
945 }
946
947 if (in_count) {
948 in_fiov = fuse_ioctl_iovec_copy(in_iov, in_count);
949 if (!in_fiov)
950 goto enomem;
951
952 iov[count].iov_base = (void *)in_fiov;
953 iov[count].iov_len = sizeof(in_fiov[0]) * in_count;
954 count++;
955 }
956 if (out_count) {
957 out_fiov = fuse_ioctl_iovec_copy(out_iov, out_count);
958 if (!out_fiov)
959 goto enomem;
960
961 iov[count].iov_base = (void *)out_fiov;
962 iov[count].iov_len = sizeof(out_fiov[0]) * out_count;
963 count++;
964 }
965 }
966
967 res = send_reply_iov(req, 0, iov, count);
968 out:
969 free(in_fiov);
970 free(out_fiov);
971
972 return res;
973
974 enomem:
975 res = fuse_reply_err(req, ENOMEM);
976 goto out;
977 }
978
979 int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size)
980 {
981 struct fuse_ioctl_out arg;
982 struct iovec iov[3];
983 size_t count = 1;
984
985 memset(&arg, 0, sizeof(arg));
986 arg.result = result;
987 iov[count].iov_base = &arg;
988 iov[count].iov_len = sizeof(arg);
989 count++;
990
991 if (size) {
992 iov[count].iov_base = (char *) buf;
993 iov[count].iov_len = size;
994 count++;
995 }
996
997 return send_reply_iov(req, 0, iov, count);
998 }
999
1000 int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov,
1001 int count)
1002 {
1003 struct iovec *padded_iov;
1004 struct fuse_ioctl_out arg;
1005 int res;
1006
1007 padded_iov = malloc((count + 2) * sizeof(struct iovec));
1008 if (padded_iov == NULL)
1009 return fuse_reply_err(req, ENOMEM);
1010
1011 memset(&arg, 0, sizeof(arg));
1012 arg.result = result;
1013 padded_iov[1].iov_base = &arg;
1014 padded_iov[1].iov_len = sizeof(arg);
1015
1016 memcpy(&padded_iov[2], iov, count * sizeof(struct iovec));
1017
1018 res = send_reply_iov(req, 0, padded_iov, count + 2);
1019 free(padded_iov);
1020
1021 return res;
1022 }
1023
1024 int fuse_reply_poll(fuse_req_t req, unsigned revents)
1025 {
1026 struct fuse_poll_out arg;
1027
1028 memset(&arg, 0, sizeof(arg));
1029 arg.revents = revents;
1030
1031 return send_reply_ok(req, &arg, sizeof(arg));
1032 }
1033
1034 static void do_lookup(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1035 {
1036 char *name = (char *) inarg;
1037
1038 if (req->se->op.lookup)
1039 req->se->op.lookup(req, nodeid, name);
1040 else
1041 fuse_reply_err(req, ENOSYS);
1042 }
1043
1044 static void do_forget(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1045 {
1046 struct fuse_forget_in *arg = (struct fuse_forget_in *) inarg;
1047
1048 if (req->se->op.forget)
1049 req->se->op.forget(req, nodeid, arg->nlookup);
1050 else
1051 fuse_reply_none(req);
1052 }
1053
1054 static void do_batch_forget(fuse_req_t req, fuse_ino_t nodeid,
1055 const void *inarg)
1056 {
1057 struct fuse_batch_forget_in *arg = (void *) inarg;
1058 struct fuse_forget_one *param = (void *) PARAM(arg);
1059 unsigned int i;
1060
1061 (void) nodeid;
1062
1063 if (req->se->op.forget_multi) {
1064 req->se->op.forget_multi(req, arg->count,
1065 (struct fuse_forget_data *) param);
1066 } else if (req->se->op.forget) {
1067 for (i = 0; i < arg->count; i++) {
1068 struct fuse_forget_one *forget = &param[i];
1069 struct fuse_req *dummy_req;
1070
1071 dummy_req = fuse_ll_alloc_req(req->se);
1072 if (dummy_req == NULL)
1073 break;
1074
1075 dummy_req->unique = req->unique;
1076 dummy_req->ctx = req->ctx;
1077 dummy_req->ch = NULL;
1078
1079 req->se->op.forget(dummy_req, forget->nodeid,
1080 forget->nlookup);
1081 }
1082 fuse_reply_none(req);
1083 } else {
1084 fuse_reply_none(req);
1085 }
1086 }
1087
1088 static void do_getattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1089 {
1090 struct fuse_file_info *fip = NULL;
1091 struct fuse_file_info fi;
1092
1093 if (req->se->conn.proto_minor >= 9) {
1094 struct fuse_getattr_in *arg = (struct fuse_getattr_in *) inarg;
1095
1096 if (arg->getattr_flags & FUSE_GETATTR_FH) {
1097 memset(&fi, 0, sizeof(fi));
1098 fi.fh = arg->fh;
1099 fip = &fi;
1100 }
1101 }
1102
1103 if (req->se->op.getattr)
1104 req->se->op.getattr(req, nodeid, fip);
1105 else
1106 fuse_reply_err(req, ENOSYS);
1107 }
1108
1109 static void do_setattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1110 {
1111 struct fuse_setattr_in *arg = (struct fuse_setattr_in *) inarg;
1112
1113 if (req->se->op.setattr) {
1114 struct fuse_file_info *fi = NULL;
1115 struct fuse_file_info fi_store;
1116 struct stat stbuf;
1117 memset(&stbuf, 0, sizeof(stbuf));
1118 convert_attr(arg, &stbuf);
1119 if (arg->valid & FATTR_FH) {
1120 arg->valid &= ~FATTR_FH;
1121 memset(&fi_store, 0, sizeof(fi_store));
1122 fi = &fi_store;
1123 fi->fh = arg->fh;
1124 }
1125 arg->valid &=
1126 FUSE_SET_ATTR_MODE |
1127 FUSE_SET_ATTR_UID |
1128 FUSE_SET_ATTR_GID |
1129 FUSE_SET_ATTR_SIZE |
1130 FUSE_SET_ATTR_ATIME |
1131 FUSE_SET_ATTR_MTIME |
1132 FUSE_SET_ATTR_ATIME_NOW |
1133 FUSE_SET_ATTR_MTIME_NOW |
1134 FUSE_SET_ATTR_CTIME;
1135
1136 req->se->op.setattr(req, nodeid, &stbuf, arg->valid, fi);
1137 } else
1138 fuse_reply_err(req, ENOSYS);
1139 }
1140
1141 static void do_access(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1142 {
1143 struct fuse_access_in *arg = (struct fuse_access_in *) inarg;
1144
1145 if (req->se->op.access)
1146 req->se->op.access(req, nodeid, arg->mask);
1147 else
1148 fuse_reply_err(req, ENOSYS);
1149 }
1150
1151 static void do_readlink(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1152 {
1153 (void) inarg;
1154
1155 if (req->se->op.readlink)
1156 req->se->op.readlink(req, nodeid);
1157 else
1158 fuse_reply_err(req, ENOSYS);
1159 }
1160
1161 static void do_mknod(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1162 {
1163 struct fuse_mknod_in *arg = (struct fuse_mknod_in *) inarg;
1164 char *name = PARAM(arg);
1165
1166 if (req->se->conn.proto_minor >= 12)
1167 req->ctx.umask = arg->umask;
1168 else
1169 name = (char *) inarg + FUSE_COMPAT_MKNOD_IN_SIZE;
1170
1171 if (req->se->op.mknod)
1172 req->se->op.mknod(req, nodeid, name, arg->mode, arg->rdev);
1173 else
1174 fuse_reply_err(req, ENOSYS);
1175 }
1176
1177 static void do_mkdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1178 {
1179 struct fuse_mkdir_in *arg = (struct fuse_mkdir_in *) inarg;
1180
1181 if (req->se->conn.proto_minor >= 12)
1182 req->ctx.umask = arg->umask;
1183
1184 if (req->se->op.mkdir)
1185 req->se->op.mkdir(req, nodeid, PARAM(arg), arg->mode);
1186 else
1187 fuse_reply_err(req, ENOSYS);
1188 }
1189
1190 static void do_unlink(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1191 {
1192 char *name = (char *) inarg;
1193
1194 if (req->se->op.unlink)
1195 req->se->op.unlink(req, nodeid, name);
1196 else
1197 fuse_reply_err(req, ENOSYS);
1198 }
1199
1200 static void do_rmdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1201 {
1202 char *name = (char *) inarg;
1203
1204 if (req->se->op.rmdir)
1205 req->se->op.rmdir(req, nodeid, name);
1206 else
1207 fuse_reply_err(req, ENOSYS);
1208 }
1209
1210 static void do_symlink(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1211 {
1212 char *name = (char *) inarg;
1213 char *linkname = ((char *) inarg) + strlen((char *) inarg) + 1;
1214
1215 if (req->se->op.symlink)
1216 req->se->op.symlink(req, linkname, nodeid, name);
1217 else
1218 fuse_reply_err(req, ENOSYS);
1219 }
1220
1221 static void do_rename(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1222 {
1223 struct fuse_rename_in *arg = (struct fuse_rename_in *) inarg;
1224 char *oldname = PARAM(arg);
1225 char *newname = oldname + strlen(oldname) + 1;
1226
1227 if (req->se->op.rename)
1228 req->se->op.rename(req, nodeid, oldname, arg->newdir, newname,
1229 0);
1230 else
1231 fuse_reply_err(req, ENOSYS);
1232 }
1233
1234 static void do_rename2(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1235 {
1236 struct fuse_rename2_in *arg = (struct fuse_rename2_in *) inarg;
1237 char *oldname = PARAM(arg);
1238 char *newname = oldname + strlen(oldname) + 1;
1239
1240 if (req->se->op.rename)
1241 req->se->op.rename(req, nodeid, oldname, arg->newdir, newname,
1242 arg->flags);
1243 else
1244 fuse_reply_err(req, ENOSYS);
1245 }
1246
1247 static void do_link(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1248 {
1249 struct fuse_link_in *arg = (struct fuse_link_in *) inarg;
1250
1251 if (req->se->op.link)
1252 req->se->op.link(req, arg->oldnodeid, nodeid, PARAM(arg));
1253 else
1254 fuse_reply_err(req, ENOSYS);
1255 }
1256
1257 static void do_create(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1258 {
1259 struct fuse_create_in *arg = (struct fuse_create_in *) inarg;
1260
1261 if (req->se->op.create) {
1262 struct fuse_file_info fi;
1263 char *name = PARAM(arg);
1264
1265 memset(&fi, 0, sizeof(fi));
1266 fi.flags = arg->flags;
1267
1268 if (req->se->conn.proto_minor >= 12)
1269 req->ctx.umask = arg->umask;
1270 else
1271 name = (char *) inarg + sizeof(struct fuse_open_in);
1272
1273 req->se->op.create(req, nodeid, name, arg->mode, &fi);
1274 } else
1275 fuse_reply_err(req, ENOSYS);
1276 }
1277
1278 static void do_open(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1279 {
1280 struct fuse_open_in *arg = (struct fuse_open_in *) inarg;
1281 struct fuse_file_info fi;
1282
1283 memset(&fi, 0, sizeof(fi));
1284 fi.flags = arg->flags;
1285
1286 if (req->se->op.open)
1287 req->se->op.open(req, nodeid, &fi);
1288 else
1289 fuse_reply_open(req, &fi);
1290 }
1291
1292 static void do_read(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1293 {
1294 struct fuse_read_in *arg = (struct fuse_read_in *) inarg;
1295
1296 if (req->se->op.read) {
1297 struct fuse_file_info fi;
1298
1299 memset(&fi, 0, sizeof(fi));
1300 fi.fh = arg->fh;
1301 if (req->se->conn.proto_minor >= 9) {
1302 fi.lock_owner = arg->lock_owner;
1303 fi.flags = arg->flags;
1304 }
1305 req->se->op.read(req, nodeid, arg->size, arg->offset, &fi);
1306 } else
1307 fuse_reply_err(req, ENOSYS);
1308 }
1309
1310 static void do_write(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1311 {
1312 struct fuse_write_in *arg = (struct fuse_write_in *) inarg;
1313 struct fuse_file_info fi;
1314 char *param;
1315
1316 memset(&fi, 0, sizeof(fi));
1317 fi.fh = arg->fh;
1318 fi.writepage = (arg->write_flags & 1) != 0;
1319
1320 if (req->se->conn.proto_minor < 9) {
1321 param = ((char *) arg) + FUSE_COMPAT_WRITE_IN_SIZE;
1322 } else {
1323 fi.lock_owner = arg->lock_owner;
1324 fi.flags = arg->flags;
1325 param = PARAM(arg);
1326 }
1327
1328 if (req->se->op.write)
1329 req->se->op.write(req, nodeid, param, arg->size,
1330 arg->offset, &fi);
1331 else
1332 fuse_reply_err(req, ENOSYS);
1333 }
1334
1335 static void do_write_buf(fuse_req_t req, fuse_ino_t nodeid, const void *inarg,
1336 const struct fuse_buf *ibuf)
1337 {
1338 struct fuse_session *se = req->se;
1339 struct fuse_bufvec bufv = {
1340 .buf[0] = *ibuf,
1341 .count = 1,
1342 };
1343 struct fuse_write_in *arg = (struct fuse_write_in *) inarg;
1344 struct fuse_file_info fi;
1345
1346 memset(&fi, 0, sizeof(fi));
1347 fi.fh = arg->fh;
1348 fi.writepage = arg->write_flags & 1;
1349
1350 if (se->conn.proto_minor < 9) {
1351 bufv.buf[0].mem = ((char *) arg) + FUSE_COMPAT_WRITE_IN_SIZE;
1352 bufv.buf[0].size -= sizeof(struct fuse_in_header) +
1353 FUSE_COMPAT_WRITE_IN_SIZE;
1354 assert(!(bufv.buf[0].flags & FUSE_BUF_IS_FD));
1355 } else {
1356 fi.lock_owner = arg->lock_owner;
1357 fi.flags = arg->flags;
1358 if (!(bufv.buf[0].flags & FUSE_BUF_IS_FD))
1359 bufv.buf[0].mem = PARAM(arg);
1360
1361 bufv.buf[0].size -= sizeof(struct fuse_in_header) +
1362 sizeof(struct fuse_write_in);
1363 }
1364 if (bufv.buf[0].size < arg->size) {
1365 fprintf(stderr, "fuse: do_write_buf: buffer size too small\n");
1366 fuse_reply_err(req, EIO);
1367 goto out;
1368 }
1369 bufv.buf[0].size = arg->size;
1370
1371 se->op.write_buf(req, nodeid, &bufv, arg->offset, &fi);
1372
1373 out:
1374 /* Need to reset the pipe if ->write_buf() didn't consume all data */
1375 if ((ibuf->flags & FUSE_BUF_IS_FD) && bufv.idx < bufv.count)
1376 fuse_ll_clear_pipe(se);
1377 }
1378
1379 static void do_flush(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1380 {
1381 struct fuse_flush_in *arg = (struct fuse_flush_in *) inarg;
1382 struct fuse_file_info fi;
1383
1384 memset(&fi, 0, sizeof(fi));
1385 fi.fh = arg->fh;
1386 fi.flush = 1;
1387 if (req->se->conn.proto_minor >= 7)
1388 fi.lock_owner = arg->lock_owner;
1389
1390 if (req->se->op.flush)
1391 req->se->op.flush(req, nodeid, &fi);
1392 else
1393 fuse_reply_err(req, ENOSYS);
1394 }
1395
1396 static void do_release(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1397 {
1398 struct fuse_release_in *arg = (struct fuse_release_in *) inarg;
1399 struct fuse_file_info fi;
1400
1401 memset(&fi, 0, sizeof(fi));
1402 fi.flags = arg->flags;
1403 fi.fh = arg->fh;
1404 if (req->se->conn.proto_minor >= 8) {
1405 fi.flush = (arg->release_flags & FUSE_RELEASE_FLUSH) ? 1 : 0;
1406 fi.lock_owner = arg->lock_owner;
1407 }
1408 if (arg->release_flags & FUSE_RELEASE_FLOCK_UNLOCK) {
1409 fi.flock_release = 1;
1410 fi.lock_owner = arg->lock_owner;
1411 }
1412
1413 if (req->se->op.release)
1414 req->se->op.release(req, nodeid, &fi);
1415 else
1416 fuse_reply_err(req, 0);
1417 }
1418
1419 static void do_fsync(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1420 {
1421 struct fuse_fsync_in *arg = (struct fuse_fsync_in *) inarg;
1422 struct fuse_file_info fi;
1423
1424 memset(&fi, 0, sizeof(fi));
1425 fi.fh = arg->fh;
1426
1427 if (req->se->op.fsync)
1428 req->se->op.fsync(req, nodeid, arg->fsync_flags & 1, &fi);
1429 else
1430 fuse_reply_err(req, ENOSYS);
1431 }
1432
1433 static void do_opendir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1434 {
1435 struct fuse_open_in *arg = (struct fuse_open_in *) inarg;
1436 struct fuse_file_info fi;
1437
1438 memset(&fi, 0, sizeof(fi));
1439 fi.flags = arg->flags;
1440
1441 if (req->se->op.opendir)
1442 req->se->op.opendir(req, nodeid, &fi);
1443 else
1444 fuse_reply_open(req, &fi);
1445 }
1446
1447 static void do_readdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1448 {
1449 struct fuse_read_in *arg = (struct fuse_read_in *) inarg;
1450 struct fuse_file_info fi;
1451
1452 memset(&fi, 0, sizeof(fi));
1453 fi.fh = arg->fh;
1454
1455 if (req->se->op.readdir)
1456 req->se->op.readdir(req, nodeid, arg->size, arg->offset, &fi);
1457 else
1458 fuse_reply_err(req, ENOSYS);
1459 }
1460
1461 static void do_readdirplus(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1462 {
1463 struct fuse_read_in *arg = (struct fuse_read_in *) inarg;
1464 struct fuse_file_info fi;
1465
1466 memset(&fi, 0, sizeof(fi));
1467 fi.fh = arg->fh;
1468
1469 if (req->se->op.readdirplus)
1470 req->se->op.readdirplus(req, nodeid, arg->size, arg->offset, &fi);
1471 else
1472 fuse_reply_err(req, ENOSYS);
1473 }
1474
1475 static void do_releasedir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1476 {
1477 struct fuse_release_in *arg = (struct fuse_release_in *) inarg;
1478 struct fuse_file_info fi;
1479
1480 memset(&fi, 0, sizeof(fi));
1481 fi.flags = arg->flags;
1482 fi.fh = arg->fh;
1483
1484 if (req->se->op.releasedir)
1485 req->se->op.releasedir(req, nodeid, &fi);
1486 else
1487 fuse_reply_err(req, 0);
1488 }
1489
1490 static void do_fsyncdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1491 {
1492 struct fuse_fsync_in *arg = (struct fuse_fsync_in *) inarg;
1493 struct fuse_file_info fi;
1494
1495 memset(&fi, 0, sizeof(fi));
1496 fi.fh = arg->fh;
1497
1498 if (req->se->op.fsyncdir)
1499 req->se->op.fsyncdir(req, nodeid, arg->fsync_flags & 1, &fi);
1500 else
1501 fuse_reply_err(req, ENOSYS);
1502 }
1503
1504 static void do_statfs(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1505 {
1506 (void) nodeid;
1507 (void) inarg;
1508
1509 if (req->se->op.statfs)
1510 req->se->op.statfs(req, nodeid);
1511 else {
1512 struct statvfs buf = {
1513 .f_namemax = 255,
1514 .f_bsize = 512,
1515 };
1516 fuse_reply_statfs(req, &buf);
1517 }
1518 }
1519
1520 static void do_setxattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1521 {
1522 struct fuse_setxattr_in *arg = (struct fuse_setxattr_in *) inarg;
1523 char *name = PARAM(arg);
1524 char *value = name + strlen(name) + 1;
1525
1526 if (req->se->op.setxattr)
1527 req->se->op.setxattr(req, nodeid, name, value, arg->size,
1528 arg->flags);
1529 else
1530 fuse_reply_err(req, ENOSYS);
1531 }
1532
1533 static void do_getxattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1534 {
1535 struct fuse_getxattr_in *arg = (struct fuse_getxattr_in *) inarg;
1536
1537 if (req->se->op.getxattr)
1538 req->se->op.getxattr(req, nodeid, PARAM(arg), arg->size);
1539 else
1540 fuse_reply_err(req, ENOSYS);
1541 }
1542
1543 static void do_listxattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1544 {
1545 struct fuse_getxattr_in *arg = (struct fuse_getxattr_in *) inarg;
1546
1547 if (req->se->op.listxattr)
1548 req->se->op.listxattr(req, nodeid, arg->size);
1549 else
1550 fuse_reply_err(req, ENOSYS);
1551 }
1552
1553 static void do_removexattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1554 {
1555 char *name = (char *) inarg;
1556
1557 if (req->se->op.removexattr)
1558 req->se->op.removexattr(req, nodeid, name);
1559 else
1560 fuse_reply_err(req, ENOSYS);
1561 }
1562
1563 static void convert_fuse_file_lock(struct fuse_file_lock *fl,
1564 struct flock *flock)
1565 {
1566 memset(flock, 0, sizeof(struct flock));
1567 flock->l_type = fl->type;
1568 flock->l_whence = SEEK_SET;
1569 flock->l_start = fl->start;
1570 if (fl->end == OFFSET_MAX)
1571 flock->l_len = 0;
1572 else
1573 flock->l_len = fl->end - fl->start + 1;
1574 flock->l_pid = fl->pid;
1575 }
1576
1577 static void do_getlk(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1578 {
1579 struct fuse_lk_in *arg = (struct fuse_lk_in *) inarg;
1580 struct fuse_file_info fi;
1581 struct flock flock;
1582
1583 memset(&fi, 0, sizeof(fi));
1584 fi.fh = arg->fh;
1585 fi.lock_owner = arg->owner;
1586
1587 convert_fuse_file_lock(&arg->lk, &flock);
1588 if (req->se->op.getlk)
1589 req->se->op.getlk(req, nodeid, &fi, &flock);
1590 else
1591 fuse_reply_err(req, ENOSYS);
1592 }
1593
1594 static void do_setlk_common(fuse_req_t req, fuse_ino_t nodeid,
1595 const void *inarg, int sleep)
1596 {
1597 struct fuse_lk_in *arg = (struct fuse_lk_in *) inarg;
1598 struct fuse_file_info fi;
1599 struct flock flock;
1600
1601 memset(&fi, 0, sizeof(fi));
1602 fi.fh = arg->fh;
1603 fi.lock_owner = arg->owner;
1604
1605 if (arg->lk_flags & FUSE_LK_FLOCK) {
1606 int op = 0;
1607
1608 switch (arg->lk.type) {
1609 case F_RDLCK:
1610 op = LOCK_SH;
1611 break;
1612 case F_WRLCK:
1613 op = LOCK_EX;
1614 break;
1615 case F_UNLCK:
1616 op = LOCK_UN;
1617 break;
1618 }
1619 if (!sleep)
1620 op |= LOCK_NB;
1621
1622 if (req->se->op.flock)
1623 req->se->op.flock(req, nodeid, &fi, op);
1624 else
1625 fuse_reply_err(req, ENOSYS);
1626 } else {
1627 convert_fuse_file_lock(&arg->lk, &flock);
1628 if (req->se->op.setlk)
1629 req->se->op.setlk(req, nodeid, &fi, &flock, sleep);
1630 else
1631 fuse_reply_err(req, ENOSYS);
1632 }
1633 }
1634
1635 static void do_setlk(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1636 {
1637 do_setlk_common(req, nodeid, inarg, 0);
1638 }
1639
1640 static void do_setlkw(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1641 {
1642 do_setlk_common(req, nodeid, inarg, 1);
1643 }
1644
1645 static int find_interrupted(struct fuse_session *se, struct fuse_req *req)
1646 {
1647 struct fuse_req *curr;
1648
1649 for (curr = se->list.next; curr != &se->list; curr = curr->next) {
1650 if (curr->unique == req->u.i.unique) {
1651 fuse_interrupt_func_t func;
1652 void *data;
1653
1654 curr->ctr++;
1655 pthread_mutex_unlock(&se->lock);
1656
1657 /* Ugh, ugly locking */
1658 pthread_mutex_lock(&curr->lock);
1659 pthread_mutex_lock(&se->lock);
1660 curr->interrupted = 1;
1661 func = curr->u.ni.func;
1662 data = curr->u.ni.data;
1663 pthread_mutex_unlock(&se->lock);
1664 if (func)
1665 func(curr, data);
1666 pthread_mutex_unlock(&curr->lock);
1667
1668 pthread_mutex_lock(&se->lock);
1669 curr->ctr--;
1670 if (!curr->ctr)
1671 destroy_req(curr);
1672
1673 return 1;
1674 }
1675 }
1676 for (curr = se->interrupts.next; curr != &se->interrupts;
1677 curr = curr->next) {
1678 if (curr->u.i.unique == req->u.i.unique)
1679 return 1;
1680 }
1681 return 0;
1682 }
1683
1684 static void do_interrupt(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1685 {
1686 struct fuse_interrupt_in *arg = (struct fuse_interrupt_in *) inarg;
1687 struct fuse_session *se = req->se;
1688
1689 (void) nodeid;
1690 if (se->debug)
1691 fprintf(stderr, "INTERRUPT: %llu\n",
1692 (unsigned long long) arg->unique);
1693
1694 req->u.i.unique = arg->unique;
1695
1696 pthread_mutex_lock(&se->lock);
1697 if (find_interrupted(se, req))
1698 destroy_req(req);
1699 else
1700 list_add_req(req, &se->interrupts);
1701 pthread_mutex_unlock(&se->lock);
1702 }
1703
1704 static struct fuse_req *check_interrupt(struct fuse_session *se,
1705 struct fuse_req *req)
1706 {
1707 struct fuse_req *curr;
1708
1709 for (curr = se->interrupts.next; curr != &se->interrupts;
1710 curr = curr->next) {
1711 if (curr->u.i.unique == req->unique) {
1712 req->interrupted = 1;
1713 list_del_req(curr);
1714 free(curr);
1715 return NULL;
1716 }
1717 }
1718 curr = se->interrupts.next;
1719 if (curr != &se->interrupts) {
1720 list_del_req(curr);
1721 list_init_req(curr);
1722 return curr;
1723 } else
1724 return NULL;
1725 }
1726
1727 static void do_bmap(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1728 {
1729 struct fuse_bmap_in *arg = (struct fuse_bmap_in *) inarg;
1730
1731 if (req->se->op.bmap)
1732 req->se->op.bmap(req, nodeid, arg->blocksize, arg->block);
1733 else
1734 fuse_reply_err(req, ENOSYS);
1735 }
1736
1737 static void do_ioctl(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1738 {
1739 struct fuse_ioctl_in *arg = (struct fuse_ioctl_in *) inarg;
1740 unsigned int flags = arg->flags;
1741 void *in_buf = arg->in_size ? PARAM(arg) : NULL;
1742 struct fuse_file_info fi;
1743
1744 if (flags & FUSE_IOCTL_DIR &&
1745 !(req->se->conn.want & FUSE_CAP_IOCTL_DIR)) {
1746 fuse_reply_err(req, ENOTTY);
1747 return;
1748 }
1749
1750 memset(&fi, 0, sizeof(fi));
1751 fi.fh = arg->fh;
1752
1753 if (sizeof(void *) == 4 && req->se->conn.proto_minor >= 16 &&
1754 !(flags & FUSE_IOCTL_32BIT)) {
1755 req->ioctl_64bit = 1;
1756 }
1757
1758 if (req->se->op.ioctl)
1759 req->se->op.ioctl(req, nodeid, arg->cmd,
1760 (void *)(uintptr_t)arg->arg, &fi, flags,
1761 in_buf, arg->in_size, arg->out_size);
1762 else
1763 fuse_reply_err(req, ENOSYS);
1764 }
1765
1766 void fuse_pollhandle_destroy(struct fuse_pollhandle *ph)
1767 {
1768 free(ph);
1769 }
1770
1771 static void do_poll(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1772 {
1773 struct fuse_poll_in *arg = (struct fuse_poll_in *) inarg;
1774 struct fuse_file_info fi;
1775
1776 memset(&fi, 0, sizeof(fi));
1777 fi.fh = arg->fh;
1778 fi.poll_events = arg->events;
1779
1780 if (req->se->op.poll) {
1781 struct fuse_pollhandle *ph = NULL;
1782
1783 if (arg->flags & FUSE_POLL_SCHEDULE_NOTIFY) {
1784 ph = malloc(sizeof(struct fuse_pollhandle));
1785 if (ph == NULL) {
1786 fuse_reply_err(req, ENOMEM);
1787 return;
1788 }
1789 ph->kh = arg->kh;
1790 ph->se = req->se;
1791 }
1792
1793 req->se->op.poll(req, nodeid, &fi, ph);
1794 } else {
1795 fuse_reply_err(req, ENOSYS);
1796 }
1797 }
1798
1799 static void do_fallocate(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1800 {
1801 struct fuse_fallocate_in *arg = (struct fuse_fallocate_in *) inarg;
1802 struct fuse_file_info fi;
1803
1804 memset(&fi, 0, sizeof(fi));
1805 fi.fh = arg->fh;
1806
1807 if (req->se->op.fallocate)
1808 req->se->op.fallocate(req, nodeid, arg->mode, arg->offset, arg->length, &fi);
1809 else
1810 fuse_reply_err(req, ENOSYS);
1811 }
1812
1813 static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1814 {
1815 struct fuse_init_in *arg = (struct fuse_init_in *) inarg;
1816 struct fuse_init_out outarg;
1817 struct fuse_session *se = req->se;
1818 size_t bufsize = se->bufsize;
1819 size_t outargsize = sizeof(outarg);
1820
1821 (void) nodeid;
1822 if (se->debug) {
1823 fprintf(stderr, "INIT: %u.%u\n", arg->major, arg->minor);
1824 if (arg->major == 7 && arg->minor >= 6) {
1825 fprintf(stderr, "flags=0x%08x\n", arg->flags);
1826 fprintf(stderr, "max_readahead=0x%08x\n",
1827 arg->max_readahead);
1828 }
1829 }
1830 se->conn.proto_major = arg->major;
1831 se->conn.proto_minor = arg->minor;
1832 se->conn.capable = 0;
1833 se->conn.want = 0;
1834
1835 memset(&outarg, 0, sizeof(outarg));
1836 outarg.major = FUSE_KERNEL_VERSION;
1837 outarg.minor = FUSE_KERNEL_MINOR_VERSION;
1838
1839 if (arg->major < 7) {
1840 fprintf(stderr, "fuse: unsupported protocol version: %u.%u\n",
1841 arg->major, arg->minor);
1842 fuse_reply_err(req, EPROTO);
1843 return;
1844 }
1845
1846 if (arg->major > 7) {
1847 /* Wait for a second INIT request with a 7.X version */
1848 send_reply_ok(req, &outarg, sizeof(outarg));
1849 return;
1850 }
1851
1852 if (arg->minor >= 6) {
1853 if (arg->max_readahead < se->conn.max_readahead)
1854 se->conn.max_readahead = arg->max_readahead;
1855 if (arg->flags & FUSE_ASYNC_READ)
1856 se->conn.capable |= FUSE_CAP_ASYNC_READ;
1857 if (arg->flags & FUSE_POSIX_LOCKS)
1858 se->conn.capable |= FUSE_CAP_POSIX_LOCKS;
1859 if (arg->flags & FUSE_ATOMIC_O_TRUNC)
1860 se->conn.capable |= FUSE_CAP_ATOMIC_O_TRUNC;
1861 if (arg->flags & FUSE_EXPORT_SUPPORT)
1862 se->conn.capable |= FUSE_CAP_EXPORT_SUPPORT;
1863 if (arg->flags & FUSE_DONT_MASK)
1864 se->conn.capable |= FUSE_CAP_DONT_MASK;
1865 if (arg->flags & FUSE_FLOCK_LOCKS)
1866 se->conn.capable |= FUSE_CAP_FLOCK_LOCKS;
1867 if (arg->flags & FUSE_AUTO_INVAL_DATA)
1868 se->conn.capable |= FUSE_CAP_AUTO_INVAL_DATA;
1869 if (arg->flags & FUSE_DO_READDIRPLUS)
1870 se->conn.capable |= FUSE_CAP_READDIRPLUS;
1871 if (arg->flags & FUSE_READDIRPLUS_AUTO)
1872 se->conn.capable |= FUSE_CAP_READDIRPLUS_AUTO;
1873 if (arg->flags & FUSE_ASYNC_DIO)
1874 se->conn.capable |= FUSE_CAP_ASYNC_DIO;
1875 if (arg->flags & FUSE_WRITEBACK_CACHE)
1876 se->conn.capable |= FUSE_CAP_WRITEBACK_CACHE;
1877 if (arg->flags & FUSE_NO_OPEN_SUPPORT)
1878 se->conn.capable |= FUSE_CAP_NO_OPEN_SUPPORT;
1879 if (arg->flags & FUSE_PARALLEL_DIROPS)
1880 se->conn.capable |= FUSE_CAP_PARALLEL_DIROPS;
1881 if (arg->flags & FUSE_POSIX_ACL)
1882 se->conn.capable |= FUSE_CAP_POSIX_ACL;
1883 if (arg->flags & FUSE_HANDLE_KILLPRIV)
1884 se->conn.capable |= FUSE_CAP_HANDLE_KILLPRIV;
1885 } else {
1886 se->conn.max_readahead = 0;
1887 }
1888
1889 if (se->conn.proto_minor >= 14) {
1890 #ifdef HAVE_SPLICE
1891 #ifdef HAVE_VMSPLICE
1892 se->conn.capable |= FUSE_CAP_SPLICE_WRITE | FUSE_CAP_SPLICE_MOVE;
1893 #endif
1894 se->conn.capable |= FUSE_CAP_SPLICE_READ;
1895 #endif
1896 }
1897 if (se->conn.proto_minor >= 18)
1898 se->conn.capable |= FUSE_CAP_IOCTL_DIR;
1899
1900 /* Default settings for modern filesystems.
1901 *
1902 * Most of these capabilities were disabled by default in
1903 * libfuse2 for backwards compatibility reasons. In libfuse3,
1904 * we can finally enable them by default (as long as they're
1905 * supported by the kernel).
1906 */
1907 #define LL_SET_DEFAULT(cond, cap) \
1908 if ((cond) && (se->conn.capable & (cap))) \
1909 se->conn.want |= (cap)
1910 LL_SET_DEFAULT(1, FUSE_CAP_ASYNC_READ);
1911 LL_SET_DEFAULT(1, FUSE_CAP_PARALLEL_DIROPS);
1912 LL_SET_DEFAULT(1, FUSE_CAP_AUTO_INVAL_DATA);
1913 LL_SET_DEFAULT(1, FUSE_CAP_HANDLE_KILLPRIV);
1914 LL_SET_DEFAULT(1, FUSE_CAP_ASYNC_DIO);
1915 LL_SET_DEFAULT(1, FUSE_CAP_IOCTL_DIR);
1916 LL_SET_DEFAULT(1, FUSE_CAP_ATOMIC_O_TRUNC);
1917 LL_SET_DEFAULT(se->op.write_buf, FUSE_CAP_SPLICE_READ);
1918 LL_SET_DEFAULT(se->op.getlk && se->op.setlk,
1919 FUSE_CAP_POSIX_LOCKS);
1920 LL_SET_DEFAULT(se->op.flock, FUSE_CAP_FLOCK_LOCKS);
1921 LL_SET_DEFAULT(se->op.readdirplus, FUSE_CAP_READDIRPLUS);
1922 LL_SET_DEFAULT(se->op.readdirplus && se->op.readdir,
1923 FUSE_CAP_READDIRPLUS_AUTO);
1924 se->conn.time_gran = 1;
1925
1926 if (bufsize < FUSE_MIN_READ_BUFFER) {
1927 fprintf(stderr, "fuse: warning: buffer size too small: %zu\n",
1928 bufsize);
1929 bufsize = FUSE_MIN_READ_BUFFER;
1930 }
1931
1932 bufsize -= 4096;
1933 if (bufsize < se->conn.max_write)
1934 se->conn.max_write = bufsize;
1935
1936 se->got_init = 1;
1937 if (se->op.init)
1938 se->op.init(se->userdata, &se->conn);
1939
1940 if (se->conn.want & (~se->conn.capable)) {
1941 fprintf(stderr, "fuse: error: filesystem requested capabilities "
1942 "0x%x that are not supported by kernel, aborting.\n",
1943 se->conn.want & (~se->conn.capable));
1944 fuse_reply_err(req, EPROTO);
1945 se->error = -EPROTO;
1946 fuse_session_exit(se);
1947 return;
1948 }
1949
1950 unsigned max_read_mo = get_max_read(se->mo);
1951 if (se->conn.max_read != max_read_mo) {
1952 fprintf(stderr, "fuse: error: init() and fuse_session_new() "
1953 "requested different maximum read size (%u vs %u)\n",
1954 se->conn.max_read, max_read_mo);
1955 fuse_reply_err(req, EPROTO);
1956 se->error = -EPROTO;
1957 fuse_session_exit(se);
1958 return;
1959 }
1960
1961 /* Always enable big writes, this is superseded
1962 by the max_write option */
1963 outarg.flags |= FUSE_BIG_WRITES;
1964
1965 if (se->conn.want & FUSE_CAP_ASYNC_READ)
1966 outarg.flags |= FUSE_ASYNC_READ;
1967 if (se->conn.want & FUSE_CAP_POSIX_LOCKS)
1968 outarg.flags |= FUSE_POSIX_LOCKS;
1969 if (se->conn.want & FUSE_CAP_ATOMIC_O_TRUNC)
1970 outarg.flags |= FUSE_ATOMIC_O_TRUNC;
1971 if (se->conn.want & FUSE_CAP_EXPORT_SUPPORT)
1972 outarg.flags |= FUSE_EXPORT_SUPPORT;
1973 if (se->conn.want & FUSE_CAP_DONT_MASK)
1974 outarg.flags |= FUSE_DONT_MASK;
1975 if (se->conn.want & FUSE_CAP_FLOCK_LOCKS)
1976 outarg.flags |= FUSE_FLOCK_LOCKS;
1977 if (se->conn.want & FUSE_CAP_AUTO_INVAL_DATA)
1978 outarg.flags |= FUSE_AUTO_INVAL_DATA;
1979 if (se->conn.want & FUSE_CAP_READDIRPLUS)
1980 outarg.flags |= FUSE_DO_READDIRPLUS;
1981 if (se->conn.want & FUSE_CAP_READDIRPLUS_AUTO)
1982 outarg.flags |= FUSE_READDIRPLUS_AUTO;
1983 if (se->conn.want & FUSE_CAP_ASYNC_DIO)
1984 outarg.flags |= FUSE_ASYNC_DIO;
1985 if (se->conn.want & FUSE_CAP_WRITEBACK_CACHE)
1986 outarg.flags |= FUSE_WRITEBACK_CACHE;
1987 if (se->conn.want & FUSE_CAP_POSIX_ACL)
1988 outarg.flags |= FUSE_POSIX_ACL;
1989 outarg.max_readahead = se->conn.max_readahead;
1990 outarg.max_write = se->conn.max_write;
1991 if (se->conn.proto_minor >= 13) {
1992 if (se->conn.max_background >= (1 << 16))
1993 se->conn.max_background = (1 << 16) - 1;
1994 if (se->conn.congestion_threshold > se->conn.max_background)
1995 se->conn.congestion_threshold = se->conn.max_background;
1996 if (!se->conn.congestion_threshold) {
1997 se->conn.congestion_threshold =
1998 se->conn.max_background * 3 / 4;
1999 }
2000
2001 outarg.max_background = se->conn.max_background;
2002 outarg.congestion_threshold = se->conn.congestion_threshold;
2003 }
2004 if (se->conn.proto_minor >= 23)
2005 outarg.time_gran = se->conn.time_gran;
2006
2007 if (se->debug) {
2008 fprintf(stderr, " INIT: %u.%u\n", outarg.major, outarg.minor);
2009 fprintf(stderr, " flags=0x%08x\n", outarg.flags);
2010 fprintf(stderr, " max_readahead=0x%08x\n",
2011 outarg.max_readahead);
2012 fprintf(stderr, " max_write=0x%08x\n", outarg.max_write);
2013 fprintf(stderr, " max_background=%i\n",
2014 outarg.max_background);
2015 fprintf(stderr, " congestion_threshold=%i\n",
2016 outarg.congestion_threshold);
2017 fprintf(stderr, " time_gran=%u\n",
2018 outarg.time_gran);
2019 }
2020 if (arg->minor < 5)
2021 outargsize = FUSE_COMPAT_INIT_OUT_SIZE;
2022 else if (arg->minor < 23)
2023 outargsize = FUSE_COMPAT_22_INIT_OUT_SIZE;
2024
2025 send_reply_ok(req, &outarg, outargsize);
2026 }
2027
2028 static void do_destroy(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
2029 {
2030 struct fuse_session *se = req->se;
2031
2032 (void) nodeid;
2033 (void) inarg;
2034
2035 se->got_destroy = 1;
2036 if (se->op.destroy)
2037 se->op.destroy(se->userdata);
2038
2039 send_reply_ok(req, NULL, 0);
2040 }
2041
2042 static void list_del_nreq(struct fuse_notify_req *nreq)
2043 {
2044 struct fuse_notify_req *prev = nreq->prev;
2045 struct fuse_notify_req *next = nreq->next;
2046 prev->next = next;
2047 next->prev = prev;
2048 }
2049
2050 static void list_add_nreq(struct fuse_notify_req *nreq,
2051 struct fuse_notify_req *next)
2052 {
2053 struct fuse_notify_req *prev = next->prev;
2054 nreq->next = next;
2055 nreq->prev = prev;
2056 prev->next = nreq;
2057 next->prev = nreq;
2058 }
2059
2060 static void list_init_nreq(struct fuse_notify_req *nreq)
2061 {
2062 nreq->next = nreq;
2063 nreq->prev = nreq;
2064 }
2065
2066 static void do_notify_reply(fuse_req_t req, fuse_ino_t nodeid,
2067 const void *inarg, const struct fuse_buf *buf)
2068 {
2069 struct fuse_session *se = req->se;
2070 struct fuse_notify_req *nreq;
2071 struct fuse_notify_req *head;
2072
2073 pthread_mutex_lock(&se->lock);
2074 head = &se->notify_list;
2075 for (nreq = head->next; nreq != head; nreq = nreq->next) {
2076 if (nreq->unique == req->unique) {
2077 list_del_nreq(nreq);
2078 break;
2079 }
2080 }
2081 pthread_mutex_unlock(&se->lock);
2082
2083 if (nreq != head)
2084 nreq->reply(nreq, req, nodeid, inarg, buf);
2085 }
2086
2087 static int send_notify_iov(struct fuse_session *se, int notify_code,
2088 struct iovec *iov, int count)
2089 {
2090 struct fuse_out_header out;
2091
2092 if (!se->got_init)
2093 return -ENOTCONN;
2094
2095 out.unique = 0;
2096 out.error = notify_code;
2097 iov[0].iov_base = &out;
2098 iov[0].iov_len = sizeof(struct fuse_out_header);
2099
2100 return fuse_send_msg(se, NULL, iov, count);
2101 }
2102
2103 int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph)
2104 {
2105 if (ph != NULL) {
2106 struct fuse_notify_poll_wakeup_out outarg;
2107 struct iovec iov[2];
2108
2109 outarg.kh = ph->kh;
2110
2111 iov[1].iov_base = &outarg;
2112 iov[1].iov_len = sizeof(outarg);
2113
2114 return send_notify_iov(ph->se, FUSE_NOTIFY_POLL, iov, 2);
2115 } else {
2116 return 0;
2117 }
2118 }
2119
2120 int fuse_lowlevel_notify_inval_inode(struct fuse_session *se, fuse_ino_t ino,
2121 off_t off, off_t len)
2122 {
2123 struct fuse_notify_inval_inode_out outarg;
2124 struct iovec iov[2];
2125
2126 if (!se)
2127 return -EINVAL;
2128
2129 if (se->conn.proto_major < 6 || se->conn.proto_minor < 12)
2130 return -ENOSYS;
2131
2132 outarg.ino = ino;
2133 outarg.off = off;
2134 outarg.len = len;
2135
2136 iov[1].iov_base = &outarg;
2137 iov[1].iov_len = sizeof(outarg);
2138
2139 return send_notify_iov(se, FUSE_NOTIFY_INVAL_INODE, iov, 2);
2140 }
2141
2142 int fuse_lowlevel_notify_inval_entry(struct fuse_session *se, fuse_ino_t parent,
2143 const char *name, size_t namelen)
2144 {
2145 struct fuse_notify_inval_entry_out outarg;
2146 struct iovec iov[3];
2147
2148 if (!se)
2149 return -EINVAL;
2150
2151 if (se->conn.proto_major < 6 || se->conn.proto_minor < 12)
2152 return -ENOSYS;
2153
2154 outarg.parent = parent;
2155 outarg.namelen = namelen;
2156 outarg.padding = 0;
2157
2158 iov[1].iov_base = &outarg;
2159 iov[1].iov_len = sizeof(outarg);
2160 iov[2].iov_base = (void *)name;
2161 iov[2].iov_len = namelen + 1;
2162
2163 return send_notify_iov(se, FUSE_NOTIFY_INVAL_ENTRY, iov, 3);
2164 }
2165
2166 int fuse_lowlevel_notify_delete(struct fuse_session *se,
2167 fuse_ino_t parent, fuse_ino_t child,
2168 const char *name, size_t namelen)
2169 {
2170 struct fuse_notify_delete_out outarg;
2171 struct iovec iov[3];
2172
2173 if (!se)
2174 return -EINVAL;
2175
2176 if (se->conn.proto_major < 6 || se->conn.proto_minor < 18)
2177 return -ENOSYS;
2178
2179 outarg.parent = parent;
2180 outarg.child = child;
2181 outarg.namelen = namelen;
2182 outarg.padding = 0;
2183
2184 iov[1].iov_base = &outarg;
2185 iov[1].iov_len = sizeof(outarg);
2186 iov[2].iov_base = (void *)name;
2187 iov[2].iov_len = namelen + 1;
2188
2189 return send_notify_iov(se, FUSE_NOTIFY_DELETE, iov, 3);
2190 }
2191
2192 int fuse_lowlevel_notify_store(struct fuse_session *se, fuse_ino_t ino,
2193 off_t offset, struct fuse_bufvec *bufv,
2194 enum fuse_buf_copy_flags flags)
2195 {
2196 struct fuse_out_header out;
2197 struct fuse_notify_store_out outarg;
2198 struct iovec iov[3];
2199 size_t size = fuse_buf_size(bufv);
2200 int res;
2201
2202 if (!se)
2203 return -EINVAL;
2204
2205 if (se->conn.proto_major < 6 || se->conn.proto_minor < 15)
2206 return -ENOSYS;
2207
2208 out.unique = 0;
2209 out.error = FUSE_NOTIFY_STORE;
2210
2211 outarg.nodeid = ino;
2212 outarg.offset = offset;
2213 outarg.size = size;
2214 outarg.padding = 0;
2215
2216 iov[0].iov_base = &out;
2217 iov[0].iov_len = sizeof(out);
2218 iov[1].iov_base = &outarg;
2219 iov[1].iov_len = sizeof(outarg);
2220
2221 res = fuse_send_data_iov(se, NULL, iov, 2, bufv, flags);
2222 if (res > 0)
2223 res = -res;
2224
2225 return res;
2226 }
2227
2228 struct fuse_retrieve_req {
2229 struct fuse_notify_req nreq;
2230 void *cookie;
2231 };
2232
2233 static void fuse_ll_retrieve_reply(struct fuse_notify_req *nreq,
2234 fuse_req_t req, fuse_ino_t ino,
2235 const void *inarg,
2236 const struct fuse_buf *ibuf)
2237 {
2238 struct fuse_session *se = req->se;
2239 struct fuse_retrieve_req *rreq =
2240 container_of(nreq, struct fuse_retrieve_req, nreq);
2241 const struct fuse_notify_retrieve_in *arg = inarg;
2242 struct fuse_bufvec bufv = {
2243 .buf[0] = *ibuf,
2244 .count = 1,
2245 };
2246
2247 if (!(bufv.buf[0].flags & FUSE_BUF_IS_FD))
2248 bufv.buf[0].mem = PARAM(arg);
2249
2250 bufv.buf[0].size -= sizeof(struct fuse_in_header) +
2251 sizeof(struct fuse_notify_retrieve_in);
2252
2253 if (bufv.buf[0].size < arg->size) {
2254 fprintf(stderr, "fuse: retrieve reply: buffer size too small\n");
2255 fuse_reply_none(req);
2256 goto out;
2257 }
2258 bufv.buf[0].size = arg->size;
2259
2260 if (se->op.retrieve_reply) {
2261 se->op.retrieve_reply(req, rreq->cookie, ino,
2262 arg->offset, &bufv);
2263 } else {
2264 fuse_reply_none(req);
2265 }
2266 out:
2267 free(rreq);
2268 if ((ibuf->flags & FUSE_BUF_IS_FD) && bufv.idx < bufv.count)
2269 fuse_ll_clear_pipe(se);
2270 }
2271
2272 int fuse_lowlevel_notify_retrieve(struct fuse_session *se, fuse_ino_t ino,
2273 size_t size, off_t offset, void *cookie)
2274 {
2275 struct fuse_notify_retrieve_out outarg;
2276 struct iovec iov[2];
2277 struct fuse_retrieve_req *rreq;
2278 int err;
2279
2280 if (!se)
2281 return -EINVAL;
2282
2283 if (se->conn.proto_major < 6 || se->conn.proto_minor < 15)
2284 return -ENOSYS;
2285
2286 rreq = malloc(sizeof(*rreq));
2287 if (rreq == NULL)
2288 return -ENOMEM;
2289
2290 pthread_mutex_lock(&se->lock);
2291 rreq->cookie = cookie;
2292 rreq->nreq.unique = se->notify_ctr++;
2293 rreq->nreq.reply = fuse_ll_retrieve_reply;
2294 list_add_nreq(&rreq->nreq, &se->notify_list);
2295 pthread_mutex_unlock(&se->lock);
2296
2297 outarg.notify_unique = rreq->nreq.unique;
2298 outarg.nodeid = ino;
2299 outarg.offset = offset;
2300 outarg.size = size;
2301 outarg.padding = 0;
2302
2303 iov[1].iov_base = &outarg;
2304 iov[1].iov_len = sizeof(outarg);
2305
2306 err = send_notify_iov(se, FUSE_NOTIFY_RETRIEVE, iov, 2);
2307 if (err) {
2308 pthread_mutex_lock(&se->lock);
2309 list_del_nreq(&rreq->nreq);
2310 pthread_mutex_unlock(&se->lock);
2311 free(rreq);
2312 }
2313
2314 return err;
2315 }
2316
2317 void *fuse_req_userdata(fuse_req_t req)
2318 {
2319 return req->se->userdata;
2320 }
2321
2322 const struct fuse_ctx *fuse_req_ctx(fuse_req_t req)
2323 {
2324 return &req->ctx;
2325 }
2326
2327 void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func,
2328 void *data)
2329 {
2330 pthread_mutex_lock(&req->lock);
2331 pthread_mutex_lock(&req->se->lock);
2332 req->u.ni.func = func;
2333 req->u.ni.data = data;
2334 pthread_mutex_unlock(&req->se->lock);
2335 if (req->interrupted && func)
2336 func(req, data);
2337 pthread_mutex_unlock(&req->lock);
2338 }
2339
2340 int fuse_req_interrupted(fuse_req_t req)
2341 {
2342 int interrupted;
2343
2344 pthread_mutex_lock(&req->se->lock);
2345 interrupted = req->interrupted;
2346 pthread_mutex_unlock(&req->se->lock);
2347
2348 return interrupted;
2349 }
2350
2351 static struct {
2352 void (*func)(fuse_req_t, fuse_ino_t, const void *);
2353 const char *name;
2354 } fuse_ll_ops[] = {
2355 [FUSE_LOOKUP] = { do_lookup, "LOOKUP" },
2356 [FUSE_FORGET] = { do_forget, "FORGET" },
2357 [FUSE_GETATTR] = { do_getattr, "GETATTR" },
2358 [FUSE_SETATTR] = { do_setattr, "SETATTR" },
2359 [FUSE_READLINK] = { do_readlink, "READLINK" },
2360 [FUSE_SYMLINK] = { do_symlink, "SYMLINK" },
2361 [FUSE_MKNOD] = { do_mknod, "MKNOD" },
2362 [FUSE_MKDIR] = { do_mkdir, "MKDIR" },
2363 [FUSE_UNLINK] = { do_unlink, "UNLINK" },
2364 [FUSE_RMDIR] = { do_rmdir, "RMDIR" },
2365 [FUSE_RENAME] = { do_rename, "RENAME" },
2366 [FUSE_LINK] = { do_link, "LINK" },
2367 [FUSE_OPEN] = { do_open, "OPEN" },
2368 [FUSE_READ] = { do_read, "READ" },
2369 [FUSE_WRITE] = { do_write, "WRITE" },
2370 [FUSE_STATFS] = { do_statfs, "STATFS" },
2371 [FUSE_RELEASE] = { do_release, "RELEASE" },
2372 [FUSE_FSYNC] = { do_fsync, "FSYNC" },
2373 [FUSE_SETXATTR] = { do_setxattr, "SETXATTR" },
2374 [FUSE_GETXATTR] = { do_getxattr, "GETXATTR" },
2375 [FUSE_LISTXATTR] = { do_listxattr, "LISTXATTR" },
2376 [FUSE_REMOVEXATTR] = { do_removexattr, "REMOVEXATTR" },
2377 [FUSE_FLUSH] = { do_flush, "FLUSH" },
2378 [FUSE_INIT] = { do_init, "INIT" },
2379 [FUSE_OPENDIR] = { do_opendir, "OPENDIR" },
2380 [FUSE_READDIR] = { do_readdir, "READDIR" },
2381 [FUSE_RELEASEDIR] = { do_releasedir, "RELEASEDIR" },
2382 [FUSE_FSYNCDIR] = { do_fsyncdir, "FSYNCDIR" },
2383 [FUSE_GETLK] = { do_getlk, "GETLK" },
2384 [FUSE_SETLK] = { do_setlk, "SETLK" },
2385 [FUSE_SETLKW] = { do_setlkw, "SETLKW" },
2386 [FUSE_ACCESS] = { do_access, "ACCESS" },
2387 [FUSE_CREATE] = { do_create, "CREATE" },
2388 [FUSE_INTERRUPT] = { do_interrupt, "INTERRUPT" },
2389 [FUSE_BMAP] = { do_bmap, "BMAP" },
2390 [FUSE_IOCTL] = { do_ioctl, "IOCTL" },
2391 [FUSE_POLL] = { do_poll, "POLL" },
2392 [FUSE_FALLOCATE] = { do_fallocate, "FALLOCATE" },
2393 [FUSE_DESTROY] = { do_destroy, "DESTROY" },
2394 [FUSE_NOTIFY_REPLY] = { (void *) 1, "NOTIFY_REPLY" },
2395 [FUSE_BATCH_FORGET] = { do_batch_forget, "BATCH_FORGET" },
2396 [FUSE_READDIRPLUS] = { do_readdirplus, "READDIRPLUS"},
2397 [FUSE_RENAME2] = { do_rename2, "RENAME2" },
2398 [CUSE_INIT] = { cuse_lowlevel_init, "CUSE_INIT" },
2399 };
2400
2401 #define FUSE_MAXOP (sizeof(fuse_ll_ops) / sizeof(fuse_ll_ops[0]))
2402
2403 static const char *opname(enum fuse_opcode opcode)
2404 {
2405 if (opcode >= FUSE_MAXOP || !fuse_ll_ops[opcode].name)
2406 return "???";
2407 else
2408 return fuse_ll_ops[opcode].name;
2409 }
2410
2411 static int fuse_ll_copy_from_pipe(struct fuse_bufvec *dst,
2412 struct fuse_bufvec *src)
2413 {
2414 ssize_t res = fuse_buf_copy(dst, src, 0);
2415 if (res < 0) {
2416 fprintf(stderr, "fuse: copy from pipe: %s\n", strerror(-res));
2417 return res;
2418 }
2419 if ((size_t)res < fuse_buf_size(dst)) {
2420 fprintf(stderr, "fuse: copy from pipe: short read\n");
2421 return -1;
2422 }
2423 return 0;
2424 }
2425
2426 void fuse_session_process_buf(struct fuse_session *se,
2427 const struct fuse_buf *buf)
2428 {
2429 fuse_session_process_buf_int(se, buf, NULL);
2430 }
2431
2432 void fuse_session_process_buf_int(struct fuse_session *se,
2433 const struct fuse_buf *buf, struct fuse_chan *ch)
2434 {
2435 const size_t write_header_size = sizeof(struct fuse_in_header) +
2436 sizeof(struct fuse_write_in);
2437 struct fuse_bufvec bufv = { .buf[0] = *buf, .count = 1 };
2438 struct fuse_bufvec tmpbuf = FUSE_BUFVEC_INIT(write_header_size);
2439 struct fuse_in_header *in;
2440 const void *inarg;
2441 struct fuse_req *req;
2442 void *mbuf = NULL;
2443 int err;
2444 int res;
2445
2446 if (buf->flags & FUSE_BUF_IS_FD) {
2447 if (buf->size < tmpbuf.buf[0].size)
2448 tmpbuf.buf[0].size = buf->size;
2449
2450 mbuf = malloc(tmpbuf.buf[0].size);
2451 if (mbuf == NULL) {
2452 fprintf(stderr, "fuse: failed to allocate header\n");
2453 goto clear_pipe;
2454 }
2455 tmpbuf.buf[0].mem = mbuf;
2456
2457 res = fuse_ll_copy_from_pipe(&tmpbuf, &bufv);
2458 if (res < 0)
2459 goto clear_pipe;
2460
2461 in = mbuf;
2462 } else {
2463 in = buf->mem;
2464 }
2465
2466 if (se->debug) {
2467 fprintf(stderr,
2468 "unique: %llu, opcode: %s (%i), nodeid: %llu, insize: %zu, pid: %u\n",
2469 (unsigned long long) in->unique,
2470 opname((enum fuse_opcode) in->opcode), in->opcode,
2471 (unsigned long long) in->nodeid, buf->size, in->pid);
2472 }
2473
2474 req = fuse_ll_alloc_req(se);
2475 if (req == NULL) {
2476 struct fuse_out_header out = {
2477 .unique = in->unique,
2478 .error = -ENOMEM,
2479 };
2480 struct iovec iov = {
2481 .iov_base = &out,
2482 .iov_len = sizeof(struct fuse_out_header),
2483 };
2484
2485 fuse_send_msg(se, ch, &iov, 1);
2486 goto clear_pipe;
2487 }
2488
2489 req->unique = in->unique;
2490 req->ctx.uid = in->uid;
2491 req->ctx.gid = in->gid;
2492 req->ctx.pid = in->pid;
2493 req->ch = ch ? fuse_chan_get(ch) : NULL;
2494
2495 err = EIO;
2496 if (!se->got_init) {
2497 enum fuse_opcode expected;
2498
2499 expected = se->cuse_data ? CUSE_INIT : FUSE_INIT;
2500 if (in->opcode != expected)
2501 goto reply_err;
2502 } else if (in->opcode == FUSE_INIT || in->opcode == CUSE_INIT)
2503 goto reply_err;
2504
2505 err = EACCES;
2506 /* Implement -o allow_root */
2507 if (se->deny_others && in->uid != se->owner && in->uid != 0 &&
2508 in->opcode != FUSE_INIT && in->opcode != FUSE_READ &&
2509 in->opcode != FUSE_WRITE && in->opcode != FUSE_FSYNC &&
2510 in->opcode != FUSE_RELEASE && in->opcode != FUSE_READDIR &&
2511 in->opcode != FUSE_FSYNCDIR && in->opcode != FUSE_RELEASEDIR &&
2512 in->opcode != FUSE_NOTIFY_REPLY &&
2513 in->opcode != FUSE_READDIRPLUS)
2514 goto reply_err;
2515
2516 err = ENOSYS;
2517 if (in->opcode >= FUSE_MAXOP || !fuse_ll_ops[in->opcode].func)
2518 goto reply_err;
2519 if (in->opcode != FUSE_INTERRUPT) {
2520 struct fuse_req *intr;
2521 pthread_mutex_lock(&se->lock);
2522 intr = check_interrupt(se, req);
2523 list_add_req(req, &se->list);
2524 pthread_mutex_unlock(&se->lock);
2525 if (intr)
2526 fuse_reply_err(intr, EAGAIN);
2527 }
2528
2529 if ((buf->flags & FUSE_BUF_IS_FD) && write_header_size < buf->size &&
2530 (in->opcode != FUSE_WRITE || !se->op.write_buf) &&
2531 in->opcode != FUSE_NOTIFY_REPLY) {
2532 void *newmbuf;
2533
2534 err = ENOMEM;
2535 newmbuf = realloc(mbuf, buf->size);
2536 if (newmbuf == NULL)
2537 goto reply_err;
2538 mbuf = newmbuf;
2539
2540 tmpbuf = FUSE_BUFVEC_INIT(buf->size - write_header_size);
2541 tmpbuf.buf[0].mem = mbuf + write_header_size;
2542
2543 res = fuse_ll_copy_from_pipe(&tmpbuf, &bufv);
2544 err = -res;
2545 if (res < 0)
2546 goto reply_err;
2547
2548 in = mbuf;
2549 }
2550
2551 inarg = (void *) &in[1];
2552 if (in->opcode == FUSE_WRITE && se->op.write_buf)
2553 do_write_buf(req, in->nodeid, inarg, buf);
2554 else if (in->opcode == FUSE_NOTIFY_REPLY)
2555 do_notify_reply(req, in->nodeid, inarg, buf);
2556 else
2557 fuse_ll_ops[in->opcode].func(req, in->nodeid, inarg);
2558
2559 out_free:
2560 free(mbuf);
2561 return;
2562
2563 reply_err:
2564 fuse_reply_err(req, err);
2565 clear_pipe:
2566 if (buf->flags & FUSE_BUF_IS_FD)
2567 fuse_ll_clear_pipe(se);
2568 goto out_free;
2569 }
2570
2571 #define LL_OPTION(n,o,v) \
2572 { n, offsetof(struct fuse_session, o), v }
2573
2574 static const struct fuse_opt fuse_ll_opts[] = {
2575 LL_OPTION("debug", debug, 1),
2576 LL_OPTION("-d", debug, 1),
2577 LL_OPTION("--debug", debug, 1),
2578 LL_OPTION("allow_root", deny_others, 1),
2579 FUSE_OPT_END
2580 };
2581
2582 void fuse_lowlevel_version(void)
2583 {
2584 printf("using FUSE kernel interface version %i.%i\n",
2585 FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION);
2586 fuse_mount_version();
2587 }
2588
2589 void fuse_lowlevel_help(void)
2590 {
2591 /* These are not all options, but the ones that are
2592 potentially of interest to an end-user */
2593 printf(
2594 " -o allow_other allow access by all users\n"
2595 " -o allow_root allow access by root\n"
2596 " -o auto_unmount auto unmount on process termination\n");
2597 }
2598
2599 void fuse_session_destroy(struct fuse_session *se)
2600 {
2601 struct fuse_ll_pipe *llp;
2602
2603 if (se->got_init && !se->got_destroy) {
2604 if (se->op.destroy)
2605 se->op.destroy(se->userdata);
2606 }
2607 llp = pthread_getspecific(se->pipe_key);
2608 if (llp != NULL)
2609 fuse_ll_pipe_free(llp);
2610 pthread_key_delete(se->pipe_key);
2611 pthread_mutex_destroy(&se->lock);
2612 free(se->cuse_data);
2613 if (se->fd != -1)
2614 close(se->fd);
2615 destroy_mount_opts(se->mo);
2616 free(se);
2617 }
2618
2619
2620 static void fuse_ll_pipe_destructor(void *data)
2621 {
2622 struct fuse_ll_pipe *llp = data;
2623 fuse_ll_pipe_free(llp);
2624 }
2625
2626 int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf)
2627 {
2628 return fuse_session_receive_buf_int(se, buf, NULL);
2629 }
2630
2631 int fuse_session_receive_buf_int(struct fuse_session *se, struct fuse_buf *buf,
2632 struct fuse_chan *ch)
2633 {
2634 int err;
2635 ssize_t res;
2636 #ifdef HAVE_SPLICE
2637 size_t bufsize = se->bufsize;
2638 struct fuse_ll_pipe *llp;
2639 struct fuse_buf tmpbuf;
2640
2641 if (se->conn.proto_minor < 14 || !(se->conn.want & FUSE_CAP_SPLICE_READ))
2642 goto fallback;
2643
2644 llp = fuse_ll_get_pipe(se);
2645 if (llp == NULL)
2646 goto fallback;
2647
2648 if (llp->size < bufsize) {
2649 if (llp->can_grow) {
2650 res = fcntl(llp->pipe[0], F_SETPIPE_SZ, bufsize);
2651 if (res == -1) {
2652 llp->can_grow = 0;
2653 goto fallback;
2654 }
2655 llp->size = res;
2656 }
2657 if (llp->size < bufsize)
2658 goto fallback;
2659 }
2660
2661 res = splice(ch ? ch->fd : se->fd,
2662 NULL, llp->pipe[1], NULL, bufsize, 0);
2663 err = errno;
2664
2665 if (fuse_session_exited(se))
2666 return 0;
2667
2668 if (res == -1) {
2669 if (err == ENODEV) {
2670 /* Filesystem was unmounted, or connection was aborted
2671 via /sys/fs/fuse/connections */
2672 fuse_session_exit(se);
2673 return 0;
2674 }
2675 if (err != EINTR && err != EAGAIN)
2676 perror("fuse: splice from device");
2677 return -err;
2678 }
2679
2680 if (res < sizeof(struct fuse_in_header)) {
2681 fprintf(stderr, "short splice from fuse device\n");
2682 return -EIO;
2683 }
2684
2685 tmpbuf = (struct fuse_buf) {
2686 .size = res,
2687 .flags = FUSE_BUF_IS_FD,
2688 .fd = llp->pipe[0],
2689 };
2690
2691 /*
2692 * Don't bother with zero copy for small requests.
2693 * fuse_loop_mt() needs to check for FORGET so this more than
2694 * just an optimization.
2695 */
2696 if (res < sizeof(struct fuse_in_header) +
2697 sizeof(struct fuse_write_in) + pagesize) {
2698 struct fuse_bufvec src = { .buf[0] = tmpbuf, .count = 1 };
2699 struct fuse_bufvec dst = { .count = 1 };
2700
2701 if (!buf->mem) {
2702 buf->mem = malloc(se->bufsize);
2703 if (!buf->mem) {
2704 fprintf(stderr,
2705 "fuse: failed to allocate read buffer\n");
2706 return -ENOMEM;
2707 }
2708 }
2709 buf->size = se->bufsize;
2710 buf->flags = 0;
2711 dst.buf[0] = *buf;
2712
2713 res = fuse_buf_copy(&dst, &src, 0);
2714 if (res < 0) {
2715 fprintf(stderr, "fuse: copy from pipe: %s\n",
2716 strerror(-res));
2717 fuse_ll_clear_pipe(se);
2718 return res;
2719 }
2720 if (res < tmpbuf.size) {
2721 fprintf(stderr, "fuse: copy from pipe: short read\n");
2722 fuse_ll_clear_pipe(se);
2723 return -EIO;
2724 }
2725 assert(res == tmpbuf.size);
2726
2727 } else {
2728 /* Don't overwrite buf->mem, as that would cause a leak */
2729 buf->fd = tmpbuf.fd;
2730 buf->flags = tmpbuf.flags;
2731 }
2732 buf->size = tmpbuf.size;
2733
2734 return res;
2735
2736 fallback:
2737 #endif
2738 if (!buf->mem) {
2739 buf->mem = malloc(se->bufsize);
2740 if (!buf->mem) {
2741 fprintf(stderr,
2742 "fuse: failed to allocate read buffer\n");
2743 return -ENOMEM;
2744 }
2745 }
2746
2747 restart:
2748 res = read(ch ? ch->fd : se->fd, buf->mem, se->bufsize);
2749 err = errno;
2750
2751 if (fuse_session_exited(se))
2752 return 0;
2753 if (res == -1) {
2754 /* ENOENT means the operation was interrupted, it's safe
2755 to restart */
2756 if (err == ENOENT)
2757 goto restart;
2758
2759 if (err == ENODEV) {
2760 /* Filesystem was unmounted, or connection was aborted
2761 via /sys/fs/fuse/connections */
2762 fuse_session_exit(se);
2763 return 0;
2764 }
2765 /* Errors occurring during normal operation: EINTR (read
2766 interrupted), EAGAIN (nonblocking I/O), ENODEV (filesystem
2767 umounted) */
2768 if (err != EINTR && err != EAGAIN)
2769 perror("fuse: reading device");
2770 return -err;
2771 }
2772 if ((size_t) res < sizeof(struct fuse_in_header)) {
2773 fprintf(stderr, "short read on fuse device\n");
2774 return -EIO;
2775 }
2776
2777 buf->size = res;
2778
2779 return res;
2780 }
2781
2782 #define KERNEL_BUF_PAGES 32
2783
2784 /* room needed in buffer to accommodate header */
2785 #define HEADER_SIZE 0x1000
2786
2787 struct fuse_session *fuse_session_new(struct fuse_args *args,
2788 const struct fuse_lowlevel_ops *op,
2789 size_t op_size, void *userdata)
2790 {
2791 int err;
2792 struct fuse_session *se;
2793 struct mount_opts *mo;
2794
2795 if (sizeof(struct fuse_lowlevel_ops) < op_size) {
2796 fprintf(stderr, "fuse: warning: library too old, some operations may not work\n");
2797 op_size = sizeof(struct fuse_lowlevel_ops);
2798 }
2799
2800 if (args->argc == 0) {
2801 fprintf(stderr, "fuse: empty argv passed to fuse_session_new().\n");
2802 return NULL;
2803 }
2804
2805 se = (struct fuse_session *) calloc(1, sizeof(struct fuse_session));
2806 if (se == NULL) {
2807 fprintf(stderr, "fuse: failed to allocate fuse object\n");
2808 goto out1;
2809 }
2810 se->fd = -1;
2811 se->conn.max_write = UINT_MAX;
2812 se->conn.max_readahead = UINT_MAX;
2813
2814 /* Parse options */
2815 if(fuse_opt_parse(args, se, fuse_ll_opts, NULL) == -1)
2816 goto out2;
2817 if(se->deny_others) {
2818 /* Allowing access only by root is done by instructing
2819 * kernel to allow access by everyone, and then restricting
2820 * access to root and mountpoint owner in libfuse.
2821 */
2822 // We may be adding the option a second time, but
2823 // that doesn't hurt.
2824 if(fuse_opt_add_arg(args, "-oallow_other") == -1)
2825 goto out2;
2826 }
2827 mo = parse_mount_opts(args);
2828 if (mo == NULL)
2829 goto out3;
2830
2831 if(args->argc == 1 &&
2832 args->argv[0][0] == '-') {
2833 fprintf(stderr, "fuse: warning: argv[0] looks like an option, but "
2834 "will be ignored\n");
2835 } else if (args->argc != 1) {
2836 int i;
2837 fprintf(stderr, "fuse: unknown option(s): `");
2838 for(i = 1; i < args->argc-1; i++)
2839 fprintf(stderr, "%s ", args->argv[i]);
2840 fprintf(stderr, "%s'\n", args->argv[i]);
2841 goto out4;
2842 }
2843
2844 if (se->debug)
2845 fprintf(stderr, "FUSE library version: %s\n", PACKAGE_VERSION);
2846
2847 se->bufsize = KERNEL_BUF_PAGES * getpagesize() + HEADER_SIZE;
2848
2849 list_init_req(&se->list);
2850 list_init_req(&se->interrupts);
2851 list_init_nreq(&se->notify_list);
2852 se->notify_ctr = 1;
2853 fuse_mutex_init(&se->lock);
2854
2855 err = pthread_key_create(&se->pipe_key, fuse_ll_pipe_destructor);
2856 if (err) {
2857 fprintf(stderr, "fuse: failed to create thread specific key: %s\n",
2858 strerror(err));
2859 goto out5;
2860 }
2861
2862 memcpy(&se->op, op, op_size);
2863 se->owner = getuid();
2864 se->userdata = userdata;
2865
2866 se->mo = mo;
2867 return se;
2868
2869 out5:
2870 pthread_mutex_destroy(&se->lock);
2871 out4:
2872 fuse_opt_free_args(args);
2873 out3:
2874 free(mo);
2875 out2:
2876 free(se);
2877 out1:
2878 return NULL;
2879 }
2880
2881 int fuse_session_mount(struct fuse_session *se, const char *mountpoint)
2882 {
2883 int fd;
2884
2885 /*
2886 * Make sure file descriptors 0, 1 and 2 are open, otherwise chaos
2887 * would ensue.
2888 */
2889 do {
2890 fd = open("/dev/null", O_RDWR);
2891 if (fd > 2)
2892 close(fd);
2893 } while (fd >= 0 && fd <= 2);
2894
2895 /*
2896 * To allow FUSE daemons to run without privileges, the caller may open
2897 * /dev/fuse before launching the file system and pass on the file
2898 * descriptor by specifying /dev/fd/N as the mount point. Note that the
2899 * parent process takes care of performing the mount in this case.
2900 */
2901 fd = fuse_mnt_parse_fuse_fd(mountpoint);
2902 if (fd != -1) {
2903 if (fcntl(fd, F_GETFD) == -1) {
2904 fprintf(stderr,
2905 "fuse: Invalid file descriptor /dev/fd/%u\n",
2906 fd);
2907 return -1;
2908 }
2909 se->fd = fd;
2910 return 0;
2911 }
2912
2913 /* Open channel */
2914 fd = fuse_kern_mount(mountpoint, se->mo);
2915 if (fd == -1)
2916 return -1;
2917 se->fd = fd;
2918
2919 /* Save mountpoint */
2920 se->mountpoint = strdup(mountpoint);
2921 if (se->mountpoint == NULL)
2922 goto error_out;
2923
2924 return 0;
2925
2926 error_out:
2927 fuse_kern_unmount(mountpoint, fd);
2928 return -1;
2929 }
2930
2931 int fuse_session_fd(struct fuse_session *se)
2932 {
2933 return se->fd;
2934 }
2935
2936 void fuse_session_unmount(struct fuse_session *se)
2937 {
2938 if (se->mountpoint != NULL) {
2939 fuse_kern_unmount(se->mountpoint, se->fd);
2940 free(se->mountpoint);
2941 se->mountpoint = NULL;
2942 }
2943 }
2944
2945 #ifdef linux
2946 int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[])
2947 {
2948 char *buf;
2949 size_t bufsize = 1024;
2950 char path[128];
2951 int ret;
2952 int fd;
2953 unsigned long pid = req->ctx.pid;
2954 char *s;
2955
2956 sprintf(path, "/proc/%lu/task/%lu/status", pid, pid);
2957
2958 retry:
2959 buf = malloc(bufsize);
2960 if (buf == NULL)
2961 return -ENOMEM;
2962
2963 ret = -EIO;
2964 fd = open(path, O_RDONLY);
2965 if (fd == -1)
2966 goto out_free;
2967
2968 ret = read(fd, buf, bufsize);
2969 close(fd);
2970 if (ret < 0) {
2971 ret = -EIO;
2972 goto out_free;
2973 }
2974
2975 if ((size_t)ret == bufsize) {
2976 free(buf);
2977 bufsize *= 4;
2978 goto retry;
2979 }
2980
2981 ret = -EIO;
2982 s = strstr(buf, "\nGroups:");
2983 if (s == NULL)
2984 goto out_free;
2985
2986 s += 8;
2987 ret = 0;
2988 while (1) {
2989 char *end;
2990 unsigned long val = strtoul(s, &end, 0);
2991 if (end == s)
2992 break;
2993
2994 s = end;
2995 if (ret < size)
2996 list[ret] = val;
2997 ret++;
2998 }
2999
3000 out_free:
3001 free(buf);
3002 return ret;
3003 }
3004 #else /* linux */
3005 /*
3006 * This is currently not implemented on other than Linux...
3007 */
3008 int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[])
3009 {
3010 (void) req; (void) size; (void) list;
3011 return -ENOSYS;
3012 }
3013 #endif
3014
3015 void fuse_session_exit(struct fuse_session *se)
3016 {
3017 se->exited = 1;
3018 }
3019
3020 void fuse_session_reset(struct fuse_session *se)
3021 {
3022 se->exited = 0;
3023 se->error = 0;
3024 }
3025
3026 int fuse_session_exited(struct fuse_session *se)
3027 {
3028 return se->exited;
3029 }
fuse_session_destroy
void fuse_session_destroy(struct fuse_session *se)
Definition: fuse_lowlevel.c:2599
fuse_reply_err
int fuse_reply_err(fuse_req_t req, int err)
Definition: fuse_lowlevel.c:312
fuse_bufvec::off
size_t off
Definition: fuse_common.h:679
FUSE_CAP_IOCTL_DIR
#define FUSE_CAP_IOCTL_DIR
Definition: fuse_common.h:197
fuse_session_receive_buf
int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf)
Definition: fuse_lowlevel.c:2626
fuse_session_new
struct fuse_session * fuse_session_new(struct fuse_args *args, const struct fuse_lowlevel_ops *op, size_t op_size, void *userdata)
Definition: fuse_lowlevel.c:2787
fuse_session_exit
void fuse_session_exit(struct fuse_session *se)
Definition: fuse_lowlevel.c:3015
fuse_file_info::fh
uint64_t fh
Definition: fuse_common.h:72
fuse_lowlevel_notify_retrieve
int fuse_lowlevel_notify_retrieve(struct fuse_session *se, fuse_ino_t ino, size_t size, off_t offset, void *cookie)
Definition: fuse_lowlevel.c:2272
fuse_lowlevel_notify_delete
int fuse_lowlevel_notify_delete(struct fuse_session *se, fuse_ino_t parent, fuse_ino_t child, const char *name, size_t namelen)
Definition: fuse_lowlevel.c:2166
fuse_file_info::writepage
unsigned int writepage
Definition: fuse_common.h:43
fuse_reply_ioctl
int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size)
Definition: fuse_lowlevel.c:979
fuse_lowlevel_help
void fuse_lowlevel_help(void)
Definition: fuse_lowlevel.c:2589
fuse_args::argc
int argc
Definition: fuse_opt.h:111
fuse_file_info::direct_io
unsigned int direct_io
Definition: fuse_common.h:46
FUSE_BUF_IS_FD
Definition: fuse_common.h:555
FUSE_CAP_HANDLE_KILLPRIV
#define FUSE_CAP_HANDLE_KILLPRIV
Definition: fuse_common.h:317
fuse_add_direntry_plus
size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize, const char *name, const struct fuse_entry_param *e, off_t off)
Definition: fuse_lowlevel.c:357
fuse_reply_data
int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv, enum fuse_buf_copy_flags flags)
Definition: fuse_lowlevel.c:820
fuse_file_info::poll_events
uint32_t poll_events
Definition: fuse_common.h:79
fuse_session_fd
int fuse_session_fd(struct fuse_session *se)
Definition: fuse_lowlevel.c:2931
fuse_req_ctx
const struct fuse_ctx * fuse_req_ctx(fuse_req_t req)
Definition: fuse_lowlevel.c:2322
FUSE_BUF_FORCE_SPLICE
Definition: fuse_common.h:597
fuse_session_mount
int fuse_session_mount(struct fuse_session *se, const char *mountpoint)
Definition: fuse_lowlevel.c:2881
FUSE_CAP_ASYNC_READ
#define FUSE_CAP_ASYNC_READ
Definition: fuse_common.h:120
fuse_reply_ioctl_retry
int fuse_reply_ioctl_retry(fuse_req_t req, const struct iovec *in_iov, size_t in_count, const struct iovec *out_iov, size_t out_count)
Definition: fuse_lowlevel.c:909
fuse_opt_parse
int fuse_opt_parse(struct fuse_args *args, void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc)
Definition: fuse_opt.c:397
fuse_interrupt_func_t
void(* fuse_interrupt_func_t)(fuse_req_t req, void *data)
Definition: fuse_lowlevel.h:1724
fuse_lowlevel_notify_poll
int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph)
Definition: fuse_lowlevel.c:2103
fuse_req_t
struct fuse_req * fuse_req_t
Definition: fuse_lowlevel.h:49
fuse_entry_param::attr
struct stat attr
Definition: fuse_lowlevel.h:91
fuse_add_direntry
size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize, const char *name, const struct stat *stbuf, off_t off)
Definition: fuse_lowlevel.c:267
fuse_req_userdata
void * fuse_req_userdata(fuse_req_t req)
Definition: fuse_lowlevel.c:2317
FUSE_BUF_SPLICE_MOVE
Definition: fuse_common.h:606
fuse_lowlevel_notify_inval_inode
int fuse_lowlevel_notify_inval_inode(struct fuse_session *se, fuse_ino_t ino, off_t off, off_t len)
Definition: fuse_lowlevel.c:2120
fuse_reply_bmap
int fuse_reply_bmap(fuse_req_t req, uint64_t idx)
Definition: fuse_lowlevel.c:881
fuse_file_info::keep_cache
unsigned int keep_cache
Definition: fuse_common.h:51
fuse_entry_param
Definition: fuse_lowlevel.h:59
FUSE_CAP_EXPORT_SUPPORT
#define FUSE_CAP_EXPORT_SUPPORT
Definition: fuse_common.h:144
fuse_entry_param::ino
fuse_ino_t ino
Definition: fuse_lowlevel.h:67
fuse_file_info::lock_owner
uint64_t lock_owner
Definition: fuse_common.h:75
fuse_reply_xattr
int fuse_reply_xattr(fuse_req_t req, size_t count)
Definition: fuse_lowlevel.c:854
fuse_session_exited
int fuse_session_exited(struct fuse_session *se)
Definition: fuse_lowlevel.c:3026
fuse_reply_entry
int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e)
Definition: fuse_lowlevel.c:399
FUSE_CAP_READDIRPLUS_AUTO
#define FUSE_CAP_READDIRPLUS_AUTO
Definition: fuse_common.h:246
FUSE_CAP_SPLICE_WRITE
#define FUSE_CAP_SPLICE_WRITE
Definition: fuse_common.h:160
fuse_opt_add_arg
int fuse_opt_add_arg(struct fuse_args *args, const char *arg)
Definition: fuse_opt.c:54
fuse_lowlevel_notify_store
int fuse_lowlevel_notify_store(struct fuse_session *se, fuse_ino_t ino, off_t offset, struct fuse_bufvec *bufv, enum fuse_buf_copy_flags flags)
Definition: fuse_lowlevel.c:2192
fuse_file_info
Definition: fuse_common.h:37
fuse_reply_lock
int fuse_reply_lock(fuse_req_t req, const struct flock *lock)
Definition: fuse_lowlevel.c:864
FUSE_CAP_NO_OPEN_SUPPORT
#define FUSE_CAP_NO_OPEN_SUPPORT
Definition: fuse_common.h:279
fuse_req_interrupted
int fuse_req_interrupted(fuse_req_t req)
Definition: fuse_lowlevel.c:2340
fuse_session_reset
void fuse_session_reset(struct fuse_session *se)
Definition: fuse_lowlevel.c:3020
fuse_lowlevel_version
void fuse_lowlevel_version(void)
Definition: fuse_lowlevel.c:2582
fuse_reply_ioctl_iov
int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov, int count)
Definition: fuse_lowlevel.c:1000
fuse_reply_none
void fuse_reply_none(fuse_req_t req)
Definition: fuse_lowlevel.c:317
fuse_req_getgroups
int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[])
Definition: fuse_lowlevel.c:3008
fuse_file_info::flags
int flags
Definition: fuse_common.h:39
fuse_bufvec
Definition: fuse_common.h:665
fuse_opt_free_args
void fuse_opt_free_args(struct fuse_args *args)
Definition: fuse_opt.c:33
FUSE_CAP_SPLICE_MOVE
#define FUSE_CAP_SPLICE_MOVE
Definition: fuse_common.h:168
fuse_bufvec::idx
size_t idx
Definition: fuse_common.h:674
fuse_ctx
Definition: fuse_lowlevel.h:114
fuse_bufvec::count
size_t count
Definition: fuse_common.h:669
FUSE_CAP_AUTO_INVAL_DATA
#define FUSE_CAP_AUTO_INVAL_DATA
Definition: fuse_common.h:219
fuse_lowlevel_notify_inval_entry
int fuse_lowlevel_notify_inval_entry(struct fuse_session *se, fuse_ino_t parent, const char *name, size_t namelen)
Definition: fuse_lowlevel.c:2142
fuse_opt.h
fuse_reply_attr
int fuse_reply_attr(fuse_req_t req, const struct stat *attr, double attr_timeout)
Definition: fuse_lowlevel.c:431
FUSE_CAP_SPLICE_READ
#define FUSE_CAP_SPLICE_READ
Definition: fuse_common.h:177
fuse_session_unmount
void fuse_session_unmount(struct fuse_session *se)
Definition: fuse_lowlevel.c:2936
fuse_file_info::nonseekable
unsigned int nonseekable
Definition: fuse_common.h:60
FUSE_OPT_END
#define FUSE_OPT_END
Definition: fuse_opt.h:104
fuse_buf::flags
enum fuse_buf_flags flags
Definition: fuse_common.h:633
fuse_reply_statfs
int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf)
Definition: fuse_lowlevel.c:842
fuse_pollhandle_destroy
void fuse_pollhandle_destroy(struct fuse_pollhandle *ph)
Definition: fuse_lowlevel.c:1766
fuse_file_info::flush
unsigned int flush
Definition: fuse_common.h:56
FUSE_BUF_NO_SPLICE
Definition: fuse_common.h:589
FUSE_CAP_FLOCK_LOCKS
#define FUSE_CAP_FLOCK_LOCKS
Definition: fuse_common.h:190
fuse_ino_t
uint64_t fuse_ino_t
Definition: fuse_lowlevel.h:46
fuse_args::argv
char ** argv
Definition: fuse_opt.h:114
FUSE_CAP_ASYNC_DIO
#define FUSE_CAP_ASYNC_DIO
Definition: fuse_common.h:257
fuse_req_interrupt_func
void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func, void *data)
Definition: fuse_lowlevel.c:2327
fuse_entry_param::generation
uint64_t generation
Definition: fuse_lowlevel.h:82
fuse_reply_create
int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e, const struct fuse_file_info *fi)
Definition: fuse_lowlevel.c:415
fuse_reply_write
int fuse_reply_write(fuse_req_t req, size_t count)
Definition: fuse_lowlevel.c:460
fuse_buf::mem
void * mem
Definition: fuse_common.h:640
FUSE_CAP_WRITEBACK_CACHE
#define FUSE_CAP_WRITEBACK_CACHE
Definition: fuse_common.h:266
FUSE_CAP_POSIX_LOCKS
#define FUSE_CAP_POSIX_LOCKS
Definition: fuse_common.h:128
FUSE_CAP_POSIX_ACL
#define FUSE_CAP_POSIX_ACL
Definition: fuse_common.h:308
fuse_reply_open
int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi)
Definition: fuse_lowlevel.c:451
FUSE_BUF_SPLICE_NONBLOCK
Definition: fuse_common.h:615
fuse_lowlevel_ops
Definition: fuse_lowlevel.h:175
fuse_bufvec::buf
struct fuse_buf buf[1]
Definition: fuse_common.h:684
fuse_opt
Definition: fuse_opt.h:77
FUSE_CAP_ATOMIC_O_TRUNC
#define FUSE_CAP_ATOMIC_O_TRUNC
Definition: fuse_common.h:137
fuse_args
Definition: fuse_opt.h:109
FUSE_CAP_READDIRPLUS
#define FUSE_CAP_READDIRPLUS
Definition: fuse_common.h:227
FUSE_CAP_PARALLEL_DIROPS
#define FUSE_CAP_PARALLEL_DIROPS
Definition: fuse_common.h:289
fuse_buf_size
size_t fuse_buf_size(const struct fuse_bufvec *bufv)
Definition: buffer.c:22
fuse_buf_copy
ssize_t fuse_buf_copy(struct fuse_bufvec *dst, struct fuse_bufvec *src, enum fuse_buf_copy_flags flags)
Definition: buffer.c:281
fuse_buf::size
size_t size
Definition: fuse_common.h:628
fuse_entry_param::entry_timeout
double entry_timeout
Definition: fuse_lowlevel.h:103
fuse_buf_copy_flags
fuse_buf_copy_flags
Definition: fuse_common.h:579
fuse_buf::fd
int fd
Definition: fuse_common.h:647
fuse_entry_param::attr_timeout
double attr_timeout
Definition: fuse_lowlevel.h:97
fuse_reply_iov
int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count)
Definition: fuse_lowlevel.c:246
fuse_buf
Definition: fuse_common.h:624
fuse_reply_readlink
int fuse_reply_readlink(fuse_req_t req, const char *link)
Definition: fuse_lowlevel.c:446
fuse_reply_buf
int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size)
Definition: fuse_lowlevel.c:470
fuse_reply_poll
int fuse_reply_poll(fuse_req_t req, unsigned revents)
Definition: fuse_lowlevel.c:1024
fuse_session_process_buf
void fuse_session_process_buf(struct fuse_session *se, const struct fuse_buf *buf)
Definition: fuse_lowlevel.c:2426
FUSE_CAP_DONT_MASK
#define FUSE_CAP_DONT_MASK
Definition: fuse_common.h:152