2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
5 This program can be distributed under the terms of the GNU LGPLv2.
6 See the file COPYING.LIB
13 #include "fuse_kernel.h"
15 #include "fuse_misc.h"
27 #ifndef F_LINUX_SPECIFIC_BASE
28 #define F_LINUX_SPECIFIC_BASE 1024
31 #define F_SETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 7)
35 #define PARAM(inarg) (((char *)(inarg)) + sizeof(*(inarg)))
36 #define OFFSET_MAX 0x7fffffffffffffffLL
38 #define container_of(ptr, type, member) ({ \
39 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
40 (type *)( (char *)__mptr - offsetof(type,member) );})
42 struct fuse_pollhandle
{
48 static size_t pagesize
;
50 static __attribute__((constructor
)) void fuse_ll_init_pagesize(void)
52 pagesize
= getpagesize();
55 static void convert_stat(const struct stat
*stbuf
, struct fuse_attr
*attr
)
57 attr
->ino
= stbuf
->st_ino
;
58 attr
->mode
= stbuf
->st_mode
;
59 attr
->nlink
= stbuf
->st_nlink
;
60 attr
->uid
= stbuf
->st_uid
;
61 attr
->gid
= stbuf
->st_gid
;
62 attr
->rdev
= stbuf
->st_rdev
;
63 attr
->size
= stbuf
->st_size
;
64 attr
->blksize
= stbuf
->st_blksize
;
65 attr
->blocks
= stbuf
->st_blocks
;
66 attr
->atime
= stbuf
->st_atime
;
67 attr
->mtime
= stbuf
->st_mtime
;
68 attr
->ctime
= stbuf
->st_ctime
;
69 attr
->atimensec
= ST_ATIM_NSEC(stbuf
);
70 attr
->mtimensec
= ST_MTIM_NSEC(stbuf
);
71 attr
->ctimensec
= ST_CTIM_NSEC(stbuf
);
74 static void convert_attr(const struct fuse_setattr_in
*attr
, struct stat
*stbuf
)
76 stbuf
->st_mode
= attr
->mode
;
77 stbuf
->st_uid
= attr
->uid
;
78 stbuf
->st_gid
= attr
->gid
;
79 stbuf
->st_size
= attr
->size
;
80 stbuf
->st_atime
= attr
->atime
;
81 stbuf
->st_mtime
= attr
->mtime
;
82 stbuf
->st_ctime
= attr
->ctime
;
83 ST_ATIM_NSEC_SET(stbuf
, attr
->atimensec
);
84 ST_MTIM_NSEC_SET(stbuf
, attr
->mtimensec
);
85 ST_CTIM_NSEC_SET(stbuf
, attr
->ctimensec
);
88 static size_t iov_length(const struct iovec
*iov
, size_t count
)
93 for (seg
= 0; seg
< count
; seg
++)
94 ret
+= iov
[seg
].iov_len
;
98 static void list_init_req(struct fuse_req
*req
)
104 static void list_del_req(struct fuse_req
*req
)
106 struct fuse_req
*prev
= req
->prev
;
107 struct fuse_req
*next
= req
->next
;
112 static void list_add_req(struct fuse_req
*req
, struct fuse_req
*next
)
114 struct fuse_req
*prev
= next
->prev
;
121 static void destroy_req(fuse_req_t req
)
123 pthread_mutex_destroy(&req
->lock
);
127 void fuse_free_req(fuse_req_t req
)
130 struct fuse_ll
*f
= req
->f
;
132 pthread_mutex_lock(&f
->lock
);
133 req
->u
.ni
.func
= NULL
;
134 req
->u
.ni
.data
= NULL
;
137 fuse_chan_put(req
->ch
);
139 pthread_mutex_unlock(&f
->lock
);
144 static struct fuse_req
*fuse_ll_alloc_req(struct fuse_ll
*f
)
146 struct fuse_req
*req
;
148 req
= (struct fuse_req
*) calloc(1, sizeof(struct fuse_req
));
150 fprintf(stderr
, "fuse: failed to allocate request\n");
155 fuse_mutex_init(&req
->lock
);
161 static int fuse_chan_recv(struct fuse_session
*se
, struct fuse_buf
*buf
,
162 struct fuse_chan
*ch
)
164 struct fuse_ll
*f
= se
->f
;
169 buf
->mem
= malloc(f
->bufsize
);
172 "fuse: failed to allocate read buffer\n");
178 res
= read(fuse_chan_fd(ch
), buf
->mem
, f
->bufsize
);
181 if (fuse_session_exited(se
))
184 /* ENOENT means the operation was interrupted, it's safe
190 fuse_session_exit(se
);
193 /* Errors occurring during normal operation: EINTR (read
194 interrupted), EAGAIN (nonblocking I/O), ENODEV (filesystem
196 if (err
!= EINTR
&& err
!= EAGAIN
)
197 perror("fuse: reading device");
200 if ((size_t) res
< sizeof(struct fuse_in_header
)) {
201 fprintf(stderr
, "short read on fuse device\n");
210 static int fuse_chan_send(struct fuse_chan
*ch
, const struct iovec iov
[],
213 ssize_t res
= writev(fuse_chan_fd(ch
), iov
, count
);
217 struct fuse_session
*se
= fuse_chan_session(ch
);
221 /* ENOENT means the operation was interrupted */
222 if (!fuse_session_exited(se
) && err
!= ENOENT
)
223 perror("fuse: writing device");
230 void fuse_chan_close(struct fuse_chan
*ch
)
232 int fd
= fuse_chan_fd(ch
);
238 static int fuse_send_msg(struct fuse_ll
*f
, struct fuse_chan
*ch
,
239 struct iovec
*iov
, int count
)
241 struct fuse_out_header
*out
= iov
[0].iov_base
;
243 out
->len
= iov_length(iov
, count
);
245 if (out
->unique
== 0) {
246 fprintf(stderr
, "NOTIFY: code=%d length=%u\n",
247 out
->error
, out
->len
);
248 } else if (out
->error
) {
250 " unique: %llu, error: %i (%s), outsize: %i\n",
251 (unsigned long long) out
->unique
, out
->error
,
252 strerror(-out
->error
), out
->len
);
255 " unique: %llu, success, outsize: %i\n",
256 (unsigned long long) out
->unique
, out
->len
);
260 return fuse_chan_send(ch
, iov
, count
);
263 int fuse_send_reply_iov_nofree(fuse_req_t req
, int error
, struct iovec
*iov
,
266 struct fuse_out_header out
;
268 if (error
<= -1000 || error
> 0) {
269 fprintf(stderr
, "fuse: bad error value: %i\n", error
);
273 out
.unique
= req
->unique
;
276 iov
[0].iov_base
= &out
;
277 iov
[0].iov_len
= sizeof(struct fuse_out_header
);
279 return fuse_send_msg(req
->f
, req
->ch
, iov
, count
);
282 static int send_reply_iov(fuse_req_t req
, int error
, struct iovec
*iov
,
287 res
= fuse_send_reply_iov_nofree(req
, error
, iov
, count
);
292 static int send_reply(fuse_req_t req
, int error
, const void *arg
,
298 iov
[1].iov_base
= (void *) arg
;
299 iov
[1].iov_len
= argsize
;
302 return send_reply_iov(req
, error
, iov
, count
);
305 int fuse_reply_iov(fuse_req_t req
, const struct iovec
*iov
, int count
)
308 struct iovec
*padded_iov
;
310 padded_iov
= malloc((count
+ 1) * sizeof(struct iovec
));
311 if (padded_iov
== NULL
)
312 return fuse_reply_err(req
, ENOMEM
);
314 memcpy(padded_iov
+ 1, iov
, count
* sizeof(struct iovec
));
317 res
= send_reply_iov(req
, 0, padded_iov
, count
);
323 static size_t fuse_dirent_size(size_t namelen
)
325 return FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET
+ namelen
);
328 static void fuse_add_dirent(struct fuse_dirent
*dirent
, const char *name
,
329 const struct stat
*stbuf
, off_t off
)
331 unsigned namelen
= strlen(name
);
332 unsigned entlen
= FUSE_NAME_OFFSET
+ namelen
;
333 unsigned entsize
= fuse_dirent_size(namelen
);
334 unsigned padlen
= entsize
- entlen
;
336 dirent
->ino
= stbuf
->st_ino
;
338 dirent
->namelen
= namelen
;
339 dirent
->type
= (stbuf
->st_mode
& 0170000) >> 12;
340 strncpy(dirent
->name
, name
, namelen
);
342 memset(dirent
->name
+ namelen
, 0, padlen
);
345 size_t fuse_add_direntry(fuse_req_t req
, char *buf
, size_t bufsize
,
346 const char *name
, const struct stat
*stbuf
, off_t off
)
351 entsize
= fuse_dirent_size(strlen(name
));
352 if (entsize
<= bufsize
&& buf
)
353 fuse_add_dirent((struct fuse_dirent
*) buf
, name
, stbuf
, off
);
357 static void convert_statfs(const struct statvfs
*stbuf
,
358 struct fuse_kstatfs
*kstatfs
)
360 kstatfs
->bsize
= stbuf
->f_bsize
;
361 kstatfs
->frsize
= stbuf
->f_frsize
;
362 kstatfs
->blocks
= stbuf
->f_blocks
;
363 kstatfs
->bfree
= stbuf
->f_bfree
;
364 kstatfs
->bavail
= stbuf
->f_bavail
;
365 kstatfs
->files
= stbuf
->f_files
;
366 kstatfs
->ffree
= stbuf
->f_ffree
;
367 kstatfs
->namelen
= stbuf
->f_namemax
;
370 static int send_reply_ok(fuse_req_t req
, const void *arg
, size_t argsize
)
372 return send_reply(req
, 0, arg
, argsize
);
375 int fuse_reply_err(fuse_req_t req
, int err
)
377 return send_reply(req
, -err
, NULL
, 0);
380 void fuse_reply_none(fuse_req_t req
)
385 static unsigned long calc_timeout_sec(double t
)
387 if (t
> (double) ULONG_MAX
)
392 return (unsigned long) t
;
395 static unsigned int calc_timeout_nsec(double t
)
397 double f
= t
- (double) calc_timeout_sec(t
);
400 else if (f
>= 0.999999999)
403 return (unsigned int) (f
* 1.0e9
);
406 static void fill_entry(struct fuse_entry_out
*arg
,
407 const struct fuse_entry_param
*e
)
409 arg
->nodeid
= e
->ino
;
410 arg
->generation
= e
->generation
;
411 arg
->entry_valid
= calc_timeout_sec(e
->entry_timeout
);
412 arg
->entry_valid_nsec
= calc_timeout_nsec(e
->entry_timeout
);
413 arg
->attr_valid
= calc_timeout_sec(e
->attr_timeout
);
414 arg
->attr_valid_nsec
= calc_timeout_nsec(e
->attr_timeout
);
415 convert_stat(&e
->attr
, &arg
->attr
);
418 size_t fuse_add_direntry_plus(fuse_req_t req
, char *buf
, size_t bufsize
,
420 const struct fuse_entry_param
*e
, off_t off
)
425 entsize
= FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET_DIRENTPLUS
+ strlen(name
));
426 if (entsize
<= bufsize
&& buf
) {
427 struct fuse_direntplus
*dp
= (struct fuse_direntplus
*) buf
;
428 memset(&dp
->entry_out
, 0, sizeof(dp
->entry_out
));
429 fill_entry(&dp
->entry_out
, e
);
430 fuse_add_dirent(&dp
->dirent
, name
, &e
->attr
, off
);
435 static void fill_open(struct fuse_open_out
*arg
,
436 const struct fuse_file_info
*f
)
440 arg
->open_flags
|= FOPEN_DIRECT_IO
;
442 arg
->open_flags
|= FOPEN_KEEP_CACHE
;
444 arg
->open_flags
|= FOPEN_NONSEEKABLE
;
447 int fuse_reply_entry(fuse_req_t req
, const struct fuse_entry_param
*e
)
449 struct fuse_entry_out arg
;
450 size_t size
= req
->f
->conn
.proto_minor
< 9 ?
451 FUSE_COMPAT_ENTRY_OUT_SIZE
: sizeof(arg
);
453 /* before ABI 7.4 e->ino == 0 was invalid, only ENOENT meant
455 if (!e
->ino
&& req
->f
->conn
.proto_minor
< 4)
456 return fuse_reply_err(req
, ENOENT
);
458 memset(&arg
, 0, sizeof(arg
));
460 return send_reply_ok(req
, &arg
, size
);
463 int fuse_reply_create(fuse_req_t req
, const struct fuse_entry_param
*e
,
464 const struct fuse_file_info
*f
)
466 char buf
[sizeof(struct fuse_entry_out
) + sizeof(struct fuse_open_out
)];
467 size_t entrysize
= req
->f
->conn
.proto_minor
< 9 ?
468 FUSE_COMPAT_ENTRY_OUT_SIZE
: sizeof(struct fuse_entry_out
);
469 struct fuse_entry_out
*earg
= (struct fuse_entry_out
*) buf
;
470 struct fuse_open_out
*oarg
= (struct fuse_open_out
*) (buf
+ entrysize
);
472 memset(buf
, 0, sizeof(buf
));
475 return send_reply_ok(req
, buf
,
476 entrysize
+ sizeof(struct fuse_open_out
));
479 int fuse_reply_attr(fuse_req_t req
, const struct stat
*attr
,
482 struct fuse_attr_out arg
;
483 size_t size
= req
->f
->conn
.proto_minor
< 9 ?
484 FUSE_COMPAT_ATTR_OUT_SIZE
: sizeof(arg
);
486 memset(&arg
, 0, sizeof(arg
));
487 arg
.attr_valid
= calc_timeout_sec(attr_timeout
);
488 arg
.attr_valid_nsec
= calc_timeout_nsec(attr_timeout
);
489 convert_stat(attr
, &arg
.attr
);
491 return send_reply_ok(req
, &arg
, size
);
494 int fuse_reply_readlink(fuse_req_t req
, const char *linkname
)
496 return send_reply_ok(req
, linkname
, strlen(linkname
));
499 int fuse_reply_open(fuse_req_t req
, const struct fuse_file_info
*f
)
501 struct fuse_open_out arg
;
503 memset(&arg
, 0, sizeof(arg
));
505 return send_reply_ok(req
, &arg
, sizeof(arg
));
508 int fuse_reply_write(fuse_req_t req
, size_t count
)
510 struct fuse_write_out arg
;
512 memset(&arg
, 0, sizeof(arg
));
515 return send_reply_ok(req
, &arg
, sizeof(arg
));
518 int fuse_reply_buf(fuse_req_t req
, const char *buf
, size_t size
)
520 return send_reply_ok(req
, buf
, size
);
523 static int fuse_send_data_iov_fallback(struct fuse_ll
*f
, struct fuse_chan
*ch
,
524 struct iovec
*iov
, int iov_count
,
525 struct fuse_bufvec
*buf
,
528 struct fuse_bufvec mem_buf
= FUSE_BUFVEC_INIT(len
);
532 /* Optimize common case */
533 if (buf
->count
== 1 && buf
->idx
== 0 && buf
->off
== 0 &&
534 !(buf
->buf
[0].flags
& FUSE_BUF_IS_FD
)) {
535 /* FIXME: also avoid memory copy if there are multiple buffers
536 but none of them contain an fd */
538 iov
[iov_count
].iov_base
= buf
->buf
[0].mem
;
539 iov
[iov_count
].iov_len
= len
;
541 return fuse_send_msg(f
, ch
, iov
, iov_count
);
544 res
= posix_memalign(&mbuf
, pagesize
, len
);
548 mem_buf
.buf
[0].mem
= mbuf
;
549 res
= fuse_buf_copy(&mem_buf
, buf
, 0);
556 iov
[iov_count
].iov_base
= mbuf
;
557 iov
[iov_count
].iov_len
= len
;
559 res
= fuse_send_msg(f
, ch
, iov
, iov_count
);
565 struct fuse_ll_pipe
{
571 static void fuse_ll_pipe_free(struct fuse_ll_pipe
*llp
)
579 #if !defined(HAVE_PIPE2) || !defined(O_CLOEXEC)
580 static int fuse_pipe(int fds
[2])
587 if (fcntl(fds
[0], F_SETFL
, O_NONBLOCK
) == -1 ||
588 fcntl(fds
[1], F_SETFL
, O_NONBLOCK
) == -1 ||
589 fcntl(fds
[0], F_SETFD
, FD_CLOEXEC
) == -1 ||
590 fcntl(fds
[1], F_SETFD
, FD_CLOEXEC
) == -1) {
598 static int fuse_pipe(int fds
[2])
600 return pipe2(fds
, O_CLOEXEC
| O_NONBLOCK
);
604 static struct fuse_ll_pipe
*fuse_ll_get_pipe(struct fuse_ll
*f
)
606 struct fuse_ll_pipe
*llp
= pthread_getspecific(f
->pipe_key
);
610 llp
= malloc(sizeof(struct fuse_ll_pipe
));
614 res
= fuse_pipe(llp
->pipe
);
621 *the default size is 16 pages on linux
623 llp
->size
= pagesize
* 16;
626 pthread_setspecific(f
->pipe_key
, llp
);
633 static void fuse_ll_clear_pipe(struct fuse_ll
*f
)
635 struct fuse_ll_pipe
*llp
= pthread_getspecific(f
->pipe_key
);
637 pthread_setspecific(f
->pipe_key
, NULL
);
638 fuse_ll_pipe_free(llp
);
642 #if defined(HAVE_SPLICE) && defined(HAVE_VMSPLICE)
643 static int read_back(int fd
, char *buf
, size_t len
)
647 res
= read(fd
, buf
, len
);
649 fprintf(stderr
, "fuse: internal error: failed to read back from pipe: %s\n", strerror(errno
));
653 fprintf(stderr
, "fuse: internal error: short read back from pipe: %i from %zi\n", res
, len
);
659 static int fuse_send_data_iov(struct fuse_ll
*f
, struct fuse_chan
*ch
,
660 struct iovec
*iov
, int iov_count
,
661 struct fuse_bufvec
*buf
, unsigned int flags
)
664 size_t len
= fuse_buf_size(buf
);
665 struct fuse_out_header
*out
= iov
[0].iov_base
;
666 struct fuse_ll_pipe
*llp
;
669 size_t total_fd_size
;
672 struct fuse_bufvec pipe_buf
= FUSE_BUFVEC_INIT(len
);
674 if (f
->broken_splice_nonblock
)
677 if (flags
& FUSE_BUF_NO_SPLICE
)
681 for (idx
= buf
->idx
; idx
< buf
->count
; idx
++) {
682 if (buf
->buf
[idx
].flags
& FUSE_BUF_IS_FD
) {
683 total_fd_size
= buf
->buf
[idx
].size
;
685 total_fd_size
-= buf
->off
;
688 if (total_fd_size
< 2 * pagesize
)
691 if (f
->conn
.proto_minor
< 14 ||
692 !(f
->conn
.want
& FUSE_CAP_SPLICE_WRITE
))
695 llp
= fuse_ll_get_pipe(f
);
700 headerlen
= iov_length(iov
, iov_count
);
702 out
->len
= headerlen
+ len
;
705 * Heuristic for the required pipe size, does not work if the
706 * source contains less than page size fragments
708 pipesize
= pagesize
* (iov_count
+ buf
->count
+ 1) + out
->len
;
710 if (llp
->size
< pipesize
) {
712 res
= fcntl(llp
->pipe
[0], F_SETPIPE_SZ
, pipesize
);
719 if (llp
->size
< pipesize
)
724 res
= vmsplice(llp
->pipe
[1], iov
, iov_count
, SPLICE_F_NONBLOCK
);
728 if (res
!= headerlen
) {
730 fprintf(stderr
, "fuse: short vmsplice to pipe: %u/%zu\n", res
,
735 pipe_buf
.buf
[0].flags
= FUSE_BUF_IS_FD
;
736 pipe_buf
.buf
[0].fd
= llp
->pipe
[1];
738 res
= fuse_buf_copy(&pipe_buf
, buf
,
739 FUSE_BUF_FORCE_SPLICE
| FUSE_BUF_SPLICE_NONBLOCK
);
741 if (res
== -EAGAIN
|| res
== -EINVAL
) {
743 * Should only get EAGAIN on kernels with
744 * broken SPLICE_F_NONBLOCK support (<=
745 * 2.6.35) where this error or a short read is
746 * returned even if the pipe itself is not
749 * EINVAL might mean that splice can't handle
750 * this combination of input and output.
753 f
->broken_splice_nonblock
= 1;
755 pthread_setspecific(f
->pipe_key
, NULL
);
756 fuse_ll_pipe_free(llp
);
763 if (res
!= 0 && res
< len
) {
764 struct fuse_bufvec mem_buf
= FUSE_BUFVEC_INIT(len
);
766 size_t now_len
= res
;
768 * For regular files a short count is either
770 * 2) because of broken SPLICE_F_NONBLOCK (see above)
772 * For other inputs it's possible that we overflowed
773 * the pipe because of small buffer fragments.
776 res
= posix_memalign(&mbuf
, pagesize
, len
);
780 mem_buf
.buf
[0].mem
= mbuf
;
781 mem_buf
.off
= now_len
;
782 res
= fuse_buf_copy(&mem_buf
, buf
, 0);
785 size_t extra_len
= res
;
787 * Trickiest case: got more data. Need to get
788 * back the data from the pipe and then fall
789 * back to regular write.
791 tmpbuf
= malloc(headerlen
);
792 if (tmpbuf
== NULL
) {
797 res
= read_back(llp
->pipe
[0], tmpbuf
, headerlen
);
803 res
= read_back(llp
->pipe
[0], mbuf
, now_len
);
808 len
= now_len
+ extra_len
;
809 iov
[iov_count
].iov_base
= mbuf
;
810 iov
[iov_count
].iov_len
= len
;
812 res
= fuse_send_msg(f
, ch
, iov
, iov_count
);
820 out
->len
= headerlen
+ len
;
824 " unique: %llu, success, outsize: %i (splice)\n",
825 (unsigned long long) out
->unique
, out
->len
);
829 if ((flags
& FUSE_BUF_SPLICE_MOVE
) &&
830 (f
->conn
.want
& FUSE_CAP_SPLICE_MOVE
))
831 splice_flags
|= SPLICE_F_MOVE
;
833 res
= splice(llp
->pipe
[0], NULL
,
834 fuse_chan_fd(ch
), NULL
, out
->len
, splice_flags
);
837 perror("fuse: splice from pipe");
840 if (res
!= out
->len
) {
842 fprintf(stderr
, "fuse: short splice from pipe: %u/%u\n",
849 fuse_ll_clear_pipe(f
);
853 return fuse_send_data_iov_fallback(f
, ch
, iov
, iov_count
, buf
, len
);
856 static int fuse_send_data_iov(struct fuse_ll
*f
, struct fuse_chan
*ch
,
857 struct iovec
*iov
, int iov_count
,
858 struct fuse_bufvec
*buf
, unsigned int flags
)
860 size_t len
= fuse_buf_size(buf
);
863 return fuse_send_data_iov_fallback(f
, ch
, iov
, iov_count
, buf
, len
);
867 int fuse_reply_data(fuse_req_t req
, struct fuse_bufvec
*bufv
,
868 enum fuse_buf_copy_flags flags
)
871 struct fuse_out_header out
;
874 iov
[0].iov_base
= &out
;
875 iov
[0].iov_len
= sizeof(struct fuse_out_header
);
877 out
.unique
= req
->unique
;
880 res
= fuse_send_data_iov(req
->f
, req
->ch
, iov
, 1, bufv
, flags
);
885 return fuse_reply_err(req
, res
);
889 int fuse_reply_statfs(fuse_req_t req
, const struct statvfs
*stbuf
)
891 struct fuse_statfs_out arg
;
892 size_t size
= req
->f
->conn
.proto_minor
< 4 ?
893 FUSE_COMPAT_STATFS_SIZE
: sizeof(arg
);
895 memset(&arg
, 0, sizeof(arg
));
896 convert_statfs(stbuf
, &arg
.st
);
898 return send_reply_ok(req
, &arg
, size
);
901 int fuse_reply_xattr(fuse_req_t req
, size_t count
)
903 struct fuse_getxattr_out arg
;
905 memset(&arg
, 0, sizeof(arg
));
908 return send_reply_ok(req
, &arg
, sizeof(arg
));
911 int fuse_reply_lock(fuse_req_t req
, const struct flock
*lock
)
913 struct fuse_lk_out arg
;
915 memset(&arg
, 0, sizeof(arg
));
916 arg
.lk
.type
= lock
->l_type
;
917 if (lock
->l_type
!= F_UNLCK
) {
918 arg
.lk
.start
= lock
->l_start
;
919 if (lock
->l_len
== 0)
920 arg
.lk
.end
= OFFSET_MAX
;
922 arg
.lk
.end
= lock
->l_start
+ lock
->l_len
- 1;
924 arg
.lk
.pid
= lock
->l_pid
;
925 return send_reply_ok(req
, &arg
, sizeof(arg
));
928 int fuse_reply_bmap(fuse_req_t req
, uint64_t idx
)
930 struct fuse_bmap_out arg
;
932 memset(&arg
, 0, sizeof(arg
));
935 return send_reply_ok(req
, &arg
, sizeof(arg
));
938 static struct fuse_ioctl_iovec
*fuse_ioctl_iovec_copy(const struct iovec
*iov
,
941 struct fuse_ioctl_iovec
*fiov
;
944 fiov
= malloc(sizeof(fiov
[0]) * count
);
948 for (i
= 0; i
< count
; i
++) {
949 fiov
[i
].base
= (uintptr_t) iov
[i
].iov_base
;
950 fiov
[i
].len
= iov
[i
].iov_len
;
956 int fuse_reply_ioctl_retry(fuse_req_t req
,
957 const struct iovec
*in_iov
, size_t in_count
,
958 const struct iovec
*out_iov
, size_t out_count
)
960 struct fuse_ioctl_out arg
;
961 struct fuse_ioctl_iovec
*in_fiov
= NULL
;
962 struct fuse_ioctl_iovec
*out_fiov
= NULL
;
967 memset(&arg
, 0, sizeof(arg
));
968 arg
.flags
|= FUSE_IOCTL_RETRY
;
969 arg
.in_iovs
= in_count
;
970 arg
.out_iovs
= out_count
;
971 iov
[count
].iov_base
= &arg
;
972 iov
[count
].iov_len
= sizeof(arg
);
975 if (req
->f
->conn
.proto_minor
< 16) {
977 iov
[count
].iov_base
= (void *)in_iov
;
978 iov
[count
].iov_len
= sizeof(in_iov
[0]) * in_count
;
983 iov
[count
].iov_base
= (void *)out_iov
;
984 iov
[count
].iov_len
= sizeof(out_iov
[0]) * out_count
;
988 /* Can't handle non-compat 64bit ioctls on 32bit */
989 if (sizeof(void *) == 4 && req
->ioctl_64bit
) {
990 res
= fuse_reply_err(req
, EINVAL
);
995 in_fiov
= fuse_ioctl_iovec_copy(in_iov
, in_count
);
999 iov
[count
].iov_base
= (void *)in_fiov
;
1000 iov
[count
].iov_len
= sizeof(in_fiov
[0]) * in_count
;
1004 out_fiov
= fuse_ioctl_iovec_copy(out_iov
, out_count
);
1008 iov
[count
].iov_base
= (void *)out_fiov
;
1009 iov
[count
].iov_len
= sizeof(out_fiov
[0]) * out_count
;
1014 res
= send_reply_iov(req
, 0, iov
, count
);
1022 res
= fuse_reply_err(req
, ENOMEM
);
1026 int fuse_reply_ioctl(fuse_req_t req
, int result
, const void *buf
, size_t size
)
1028 struct fuse_ioctl_out arg
;
1029 struct iovec iov
[3];
1032 memset(&arg
, 0, sizeof(arg
));
1033 arg
.result
= result
;
1034 iov
[count
].iov_base
= &arg
;
1035 iov
[count
].iov_len
= sizeof(arg
);
1039 iov
[count
].iov_base
= (char *) buf
;
1040 iov
[count
].iov_len
= size
;
1044 return send_reply_iov(req
, 0, iov
, count
);
1047 int fuse_reply_ioctl_iov(fuse_req_t req
, int result
, const struct iovec
*iov
,
1050 struct iovec
*padded_iov
;
1051 struct fuse_ioctl_out arg
;
1054 padded_iov
= malloc((count
+ 2) * sizeof(struct iovec
));
1055 if (padded_iov
== NULL
)
1056 return fuse_reply_err(req
, ENOMEM
);
1058 memset(&arg
, 0, sizeof(arg
));
1059 arg
.result
= result
;
1060 padded_iov
[1].iov_base
= &arg
;
1061 padded_iov
[1].iov_len
= sizeof(arg
);
1063 memcpy(&padded_iov
[2], iov
, count
* sizeof(struct iovec
));
1065 res
= send_reply_iov(req
, 0, padded_iov
, count
+ 2);
1071 int fuse_reply_poll(fuse_req_t req
, unsigned revents
)
1073 struct fuse_poll_out arg
;
1075 memset(&arg
, 0, sizeof(arg
));
1076 arg
.revents
= revents
;
1078 return send_reply_ok(req
, &arg
, sizeof(arg
));
1081 static void do_lookup(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1083 char *name
= (char *) inarg
;
1085 if (req
->f
->op
.lookup
)
1086 req
->f
->op
.lookup(req
, nodeid
, name
);
1088 fuse_reply_err(req
, ENOSYS
);
1091 static void do_forget(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1093 struct fuse_forget_in
*arg
= (struct fuse_forget_in
*) inarg
;
1095 if (req
->f
->op
.forget
)
1096 req
->f
->op
.forget(req
, nodeid
, arg
->nlookup
);
1098 fuse_reply_none(req
);
1101 static void do_batch_forget(fuse_req_t req
, fuse_ino_t nodeid
,
1104 struct fuse_batch_forget_in
*arg
= (void *) inarg
;
1105 struct fuse_forget_one
*param
= (void *) PARAM(arg
);
1110 if (req
->f
->op
.forget_multi
) {
1111 req
->f
->op
.forget_multi(req
, arg
->count
,
1112 (struct fuse_forget_data
*) param
);
1113 } else if (req
->f
->op
.forget
) {
1114 for (i
= 0; i
< arg
->count
; i
++) {
1115 struct fuse_forget_one
*forget
= ¶m
[i
];
1116 struct fuse_req
*dummy_req
;
1118 dummy_req
= fuse_ll_alloc_req(req
->f
);
1119 if (dummy_req
== NULL
)
1122 dummy_req
->unique
= req
->unique
;
1123 dummy_req
->ctx
= req
->ctx
;
1124 dummy_req
->ch
= NULL
;
1126 req
->f
->op
.forget(dummy_req
, forget
->nodeid
,
1129 fuse_reply_none(req
);
1131 fuse_reply_none(req
);
1135 static void do_getattr(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1137 struct fuse_file_info
*fip
= NULL
;
1138 struct fuse_file_info fi
;
1140 if (req
->f
->conn
.proto_minor
>= 9) {
1141 struct fuse_getattr_in
*arg
= (struct fuse_getattr_in
*) inarg
;
1143 if (arg
->getattr_flags
& FUSE_GETATTR_FH
) {
1144 memset(&fi
, 0, sizeof(fi
));
1150 if (req
->f
->op
.getattr
)
1151 req
->f
->op
.getattr(req
, nodeid
, fip
);
1153 fuse_reply_err(req
, ENOSYS
);
1156 static void do_setattr(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1158 struct fuse_setattr_in
*arg
= (struct fuse_setattr_in
*) inarg
;
1160 if (req
->f
->op
.setattr
) {
1161 struct fuse_file_info
*fi
= NULL
;
1162 struct fuse_file_info fi_store
;
1164 memset(&stbuf
, 0, sizeof(stbuf
));
1165 convert_attr(arg
, &stbuf
);
1166 if (arg
->valid
& FATTR_FH
) {
1167 arg
->valid
&= ~FATTR_FH
;
1168 memset(&fi_store
, 0, sizeof(fi_store
));
1173 FUSE_SET_ATTR_MODE
|
1176 FUSE_SET_ATTR_SIZE
|
1177 FUSE_SET_ATTR_ATIME
|
1178 FUSE_SET_ATTR_MTIME
|
1179 FUSE_SET_ATTR_ATIME_NOW
|
1180 FUSE_SET_ATTR_MTIME_NOW
|
1181 FUSE_SET_ATTR_CTIME
;
1183 req
->f
->op
.setattr(req
, nodeid
, &stbuf
, arg
->valid
, fi
);
1185 fuse_reply_err(req
, ENOSYS
);
1188 static void do_access(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1190 struct fuse_access_in
*arg
= (struct fuse_access_in
*) inarg
;
1192 if (req
->f
->op
.access
)
1193 req
->f
->op
.access(req
, nodeid
, arg
->mask
);
1195 fuse_reply_err(req
, ENOSYS
);
1198 static void do_readlink(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1202 if (req
->f
->op
.readlink
)
1203 req
->f
->op
.readlink(req
, nodeid
);
1205 fuse_reply_err(req
, ENOSYS
);
1208 static void do_mknod(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1210 struct fuse_mknod_in
*arg
= (struct fuse_mknod_in
*) inarg
;
1211 char *name
= PARAM(arg
);
1213 if (req
->f
->conn
.proto_minor
>= 12)
1214 req
->ctx
.umask
= arg
->umask
;
1216 name
= (char *) inarg
+ FUSE_COMPAT_MKNOD_IN_SIZE
;
1218 if (req
->f
->op
.mknod
)
1219 req
->f
->op
.mknod(req
, nodeid
, name
, arg
->mode
, arg
->rdev
);
1221 fuse_reply_err(req
, ENOSYS
);
1224 static void do_mkdir(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1226 struct fuse_mkdir_in
*arg
= (struct fuse_mkdir_in
*) inarg
;
1228 if (req
->f
->conn
.proto_minor
>= 12)
1229 req
->ctx
.umask
= arg
->umask
;
1231 if (req
->f
->op
.mkdir
)
1232 req
->f
->op
.mkdir(req
, nodeid
, PARAM(arg
), arg
->mode
);
1234 fuse_reply_err(req
, ENOSYS
);
1237 static void do_unlink(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1239 char *name
= (char *) inarg
;
1241 if (req
->f
->op
.unlink
)
1242 req
->f
->op
.unlink(req
, nodeid
, name
);
1244 fuse_reply_err(req
, ENOSYS
);
1247 static void do_rmdir(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1249 char *name
= (char *) inarg
;
1251 if (req
->f
->op
.rmdir
)
1252 req
->f
->op
.rmdir(req
, nodeid
, name
);
1254 fuse_reply_err(req
, ENOSYS
);
1257 static void do_symlink(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1259 char *name
= (char *) inarg
;
1260 char *linkname
= ((char *) inarg
) + strlen((char *) inarg
) + 1;
1262 if (req
->f
->op
.symlink
)
1263 req
->f
->op
.symlink(req
, linkname
, nodeid
, name
);
1265 fuse_reply_err(req
, ENOSYS
);
1268 static void do_rename(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1270 struct fuse_rename_in
*arg
= (struct fuse_rename_in
*) inarg
;
1271 char *oldname
= PARAM(arg
);
1272 char *newname
= oldname
+ strlen(oldname
) + 1;
1274 if (req
->f
->op
.rename
)
1275 req
->f
->op
.rename(req
, nodeid
, oldname
, arg
->newdir
, newname
,
1278 fuse_reply_err(req
, ENOSYS
);
1281 static void do_rename2(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1283 struct fuse_rename2_in
*arg
= (struct fuse_rename2_in
*) inarg
;
1284 char *oldname
= PARAM(arg
);
1285 char *newname
= oldname
+ strlen(oldname
) + 1;
1287 if (req
->f
->op
.rename
)
1288 req
->f
->op
.rename(req
, nodeid
, oldname
, arg
->newdir
, newname
,
1291 fuse_reply_err(req
, ENOSYS
);
1294 static void do_link(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1296 struct fuse_link_in
*arg
= (struct fuse_link_in
*) inarg
;
1298 if (req
->f
->op
.link
)
1299 req
->f
->op
.link(req
, arg
->oldnodeid
, nodeid
, PARAM(arg
));
1301 fuse_reply_err(req
, ENOSYS
);
1304 static void do_create(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1306 struct fuse_create_in
*arg
= (struct fuse_create_in
*) inarg
;
1308 if (req
->f
->op
.create
) {
1309 struct fuse_file_info fi
;
1310 char *name
= PARAM(arg
);
1312 memset(&fi
, 0, sizeof(fi
));
1313 fi
.flags
= arg
->flags
;
1315 if (req
->f
->conn
.proto_minor
>= 12)
1316 req
->ctx
.umask
= arg
->umask
;
1318 name
= (char *) inarg
+ sizeof(struct fuse_open_in
);
1320 req
->f
->op
.create(req
, nodeid
, name
, arg
->mode
, &fi
);
1322 fuse_reply_err(req
, ENOSYS
);
1325 static void do_open(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1327 struct fuse_open_in
*arg
= (struct fuse_open_in
*) inarg
;
1328 struct fuse_file_info fi
;
1330 memset(&fi
, 0, sizeof(fi
));
1331 fi
.flags
= arg
->flags
;
1333 if (req
->f
->op
.open
)
1334 req
->f
->op
.open(req
, nodeid
, &fi
);
1336 fuse_reply_open(req
, &fi
);
1339 static void do_read(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1341 struct fuse_read_in
*arg
= (struct fuse_read_in
*) inarg
;
1343 if (req
->f
->op
.read
) {
1344 struct fuse_file_info fi
;
1346 memset(&fi
, 0, sizeof(fi
));
1348 if (req
->f
->conn
.proto_minor
>= 9) {
1349 fi
.lock_owner
= arg
->lock_owner
;
1350 fi
.flags
= arg
->flags
;
1352 req
->f
->op
.read(req
, nodeid
, arg
->size
, arg
->offset
, &fi
);
1354 fuse_reply_err(req
, ENOSYS
);
1357 static void do_write(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1359 struct fuse_write_in
*arg
= (struct fuse_write_in
*) inarg
;
1360 struct fuse_file_info fi
;
1363 memset(&fi
, 0, sizeof(fi
));
1365 fi
.writepage
= (arg
->write_flags
& 1) != 0;
1367 if (req
->f
->conn
.proto_minor
< 9) {
1368 param
= ((char *) arg
) + FUSE_COMPAT_WRITE_IN_SIZE
;
1370 fi
.lock_owner
= arg
->lock_owner
;
1371 fi
.flags
= arg
->flags
;
1375 if (req
->f
->op
.write
)
1376 req
->f
->op
.write(req
, nodeid
, param
, arg
->size
,
1379 fuse_reply_err(req
, ENOSYS
);
1382 static void do_write_buf(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
,
1383 const struct fuse_buf
*ibuf
)
1385 struct fuse_ll
*f
= req
->f
;
1386 struct fuse_bufvec bufv
= {
1390 struct fuse_write_in
*arg
= (struct fuse_write_in
*) inarg
;
1391 struct fuse_file_info fi
;
1393 memset(&fi
, 0, sizeof(fi
));
1395 fi
.writepage
= arg
->write_flags
& 1;
1397 if (req
->f
->conn
.proto_minor
< 9) {
1398 bufv
.buf
[0].mem
= ((char *) arg
) + FUSE_COMPAT_WRITE_IN_SIZE
;
1399 bufv
.buf
[0].size
-= sizeof(struct fuse_in_header
) +
1400 FUSE_COMPAT_WRITE_IN_SIZE
;
1401 assert(!(bufv
.buf
[0].flags
& FUSE_BUF_IS_FD
));
1403 fi
.lock_owner
= arg
->lock_owner
;
1404 fi
.flags
= arg
->flags
;
1405 if (!(bufv
.buf
[0].flags
& FUSE_BUF_IS_FD
))
1406 bufv
.buf
[0].mem
= PARAM(arg
);
1408 bufv
.buf
[0].size
-= sizeof(struct fuse_in_header
) +
1409 sizeof(struct fuse_write_in
);
1411 if (bufv
.buf
[0].size
< arg
->size
) {
1412 fprintf(stderr
, "fuse: do_write_buf: buffer size too small\n");
1413 fuse_reply_err(req
, EIO
);
1416 bufv
.buf
[0].size
= arg
->size
;
1418 req
->f
->op
.write_buf(req
, nodeid
, &bufv
, arg
->offset
, &fi
);
1421 /* Need to reset the pipe if ->write_buf() didn't consume all data */
1422 if ((ibuf
->flags
& FUSE_BUF_IS_FD
) && bufv
.idx
< bufv
.count
)
1423 fuse_ll_clear_pipe(f
);
1426 static void do_flush(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1428 struct fuse_flush_in
*arg
= (struct fuse_flush_in
*) inarg
;
1429 struct fuse_file_info fi
;
1431 memset(&fi
, 0, sizeof(fi
));
1434 if (req
->f
->conn
.proto_minor
>= 7)
1435 fi
.lock_owner
= arg
->lock_owner
;
1437 if (req
->f
->op
.flush
)
1438 req
->f
->op
.flush(req
, nodeid
, &fi
);
1440 fuse_reply_err(req
, ENOSYS
);
1443 static void do_release(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1445 struct fuse_release_in
*arg
= (struct fuse_release_in
*) inarg
;
1446 struct fuse_file_info fi
;
1448 memset(&fi
, 0, sizeof(fi
));
1449 fi
.flags
= arg
->flags
;
1451 if (req
->f
->conn
.proto_minor
>= 8) {
1452 fi
.flush
= (arg
->release_flags
& FUSE_RELEASE_FLUSH
) ? 1 : 0;
1453 fi
.lock_owner
= arg
->lock_owner
;
1455 if (arg
->release_flags
& FUSE_RELEASE_FLOCK_UNLOCK
) {
1456 fi
.flock_release
= 1;
1457 fi
.lock_owner
= arg
->lock_owner
;
1460 if (req
->f
->op
.release
)
1461 req
->f
->op
.release(req
, nodeid
, &fi
);
1463 fuse_reply_err(req
, 0);
1466 static void do_fsync(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1468 struct fuse_fsync_in
*arg
= (struct fuse_fsync_in
*) inarg
;
1469 struct fuse_file_info fi
;
1471 memset(&fi
, 0, sizeof(fi
));
1474 if (req
->f
->op
.fsync
)
1475 req
->f
->op
.fsync(req
, nodeid
, arg
->fsync_flags
& 1, &fi
);
1477 fuse_reply_err(req
, ENOSYS
);
1480 static void do_opendir(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1482 struct fuse_open_in
*arg
= (struct fuse_open_in
*) inarg
;
1483 struct fuse_file_info fi
;
1485 memset(&fi
, 0, sizeof(fi
));
1486 fi
.flags
= arg
->flags
;
1488 if (req
->f
->op
.opendir
)
1489 req
->f
->op
.opendir(req
, nodeid
, &fi
);
1491 fuse_reply_open(req
, &fi
);
1494 static void do_readdir(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1496 struct fuse_read_in
*arg
= (struct fuse_read_in
*) inarg
;
1497 struct fuse_file_info fi
;
1499 memset(&fi
, 0, sizeof(fi
));
1502 if (req
->f
->op
.readdir
)
1503 req
->f
->op
.readdir(req
, nodeid
, arg
->size
, arg
->offset
, &fi
);
1505 fuse_reply_err(req
, ENOSYS
);
1508 static void do_readdirplus(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1510 struct fuse_read_in
*arg
= (struct fuse_read_in
*) inarg
;
1511 struct fuse_file_info fi
;
1513 memset(&fi
, 0, sizeof(fi
));
1516 if (req
->f
->op
.readdirplus
)
1517 req
->f
->op
.readdirplus(req
, nodeid
, arg
->size
, arg
->offset
, &fi
);
1519 fuse_reply_err(req
, ENOSYS
);
1522 static void do_releasedir(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1524 struct fuse_release_in
*arg
= (struct fuse_release_in
*) inarg
;
1525 struct fuse_file_info fi
;
1527 memset(&fi
, 0, sizeof(fi
));
1528 fi
.flags
= arg
->flags
;
1531 if (req
->f
->op
.releasedir
)
1532 req
->f
->op
.releasedir(req
, nodeid
, &fi
);
1534 fuse_reply_err(req
, 0);
1537 static void do_fsyncdir(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1539 struct fuse_fsync_in
*arg
= (struct fuse_fsync_in
*) inarg
;
1540 struct fuse_file_info fi
;
1542 memset(&fi
, 0, sizeof(fi
));
1545 if (req
->f
->op
.fsyncdir
)
1546 req
->f
->op
.fsyncdir(req
, nodeid
, arg
->fsync_flags
& 1, &fi
);
1548 fuse_reply_err(req
, ENOSYS
);
1551 static void do_statfs(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1556 if (req
->f
->op
.statfs
)
1557 req
->f
->op
.statfs(req
, nodeid
);
1559 struct statvfs buf
= {
1563 fuse_reply_statfs(req
, &buf
);
1567 static void do_setxattr(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1569 struct fuse_setxattr_in
*arg
= (struct fuse_setxattr_in
*) inarg
;
1570 char *name
= PARAM(arg
);
1571 char *value
= name
+ strlen(name
) + 1;
1573 if (req
->f
->op
.setxattr
)
1574 req
->f
->op
.setxattr(req
, nodeid
, name
, value
, arg
->size
,
1577 fuse_reply_err(req
, ENOSYS
);
1580 static void do_getxattr(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1582 struct fuse_getxattr_in
*arg
= (struct fuse_getxattr_in
*) inarg
;
1584 if (req
->f
->op
.getxattr
)
1585 req
->f
->op
.getxattr(req
, nodeid
, PARAM(arg
), arg
->size
);
1587 fuse_reply_err(req
, ENOSYS
);
1590 static void do_listxattr(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1592 struct fuse_getxattr_in
*arg
= (struct fuse_getxattr_in
*) inarg
;
1594 if (req
->f
->op
.listxattr
)
1595 req
->f
->op
.listxattr(req
, nodeid
, arg
->size
);
1597 fuse_reply_err(req
, ENOSYS
);
1600 static void do_removexattr(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1602 char *name
= (char *) inarg
;
1604 if (req
->f
->op
.removexattr
)
1605 req
->f
->op
.removexattr(req
, nodeid
, name
);
1607 fuse_reply_err(req
, ENOSYS
);
1610 static void convert_fuse_file_lock(struct fuse_file_lock
*fl
,
1611 struct flock
*flock
)
1613 memset(flock
, 0, sizeof(struct flock
));
1614 flock
->l_type
= fl
->type
;
1615 flock
->l_whence
= SEEK_SET
;
1616 flock
->l_start
= fl
->start
;
1617 if (fl
->end
== OFFSET_MAX
)
1620 flock
->l_len
= fl
->end
- fl
->start
+ 1;
1621 flock
->l_pid
= fl
->pid
;
1624 static void do_getlk(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1626 struct fuse_lk_in
*arg
= (struct fuse_lk_in
*) inarg
;
1627 struct fuse_file_info fi
;
1630 memset(&fi
, 0, sizeof(fi
));
1632 fi
.lock_owner
= arg
->owner
;
1634 convert_fuse_file_lock(&arg
->lk
, &flock
);
1635 if (req
->f
->op
.getlk
)
1636 req
->f
->op
.getlk(req
, nodeid
, &fi
, &flock
);
1638 fuse_reply_err(req
, ENOSYS
);
1641 static void do_setlk_common(fuse_req_t req
, fuse_ino_t nodeid
,
1642 const void *inarg
, int sleep
)
1644 struct fuse_lk_in
*arg
= (struct fuse_lk_in
*) inarg
;
1645 struct fuse_file_info fi
;
1648 memset(&fi
, 0, sizeof(fi
));
1650 fi
.lock_owner
= arg
->owner
;
1652 if (arg
->lk_flags
& FUSE_LK_FLOCK
) {
1655 switch (arg
->lk
.type
) {
1669 if (req
->f
->op
.flock
)
1670 req
->f
->op
.flock(req
, nodeid
, &fi
, op
);
1672 fuse_reply_err(req
, ENOSYS
);
1674 convert_fuse_file_lock(&arg
->lk
, &flock
);
1675 if (req
->f
->op
.setlk
)
1676 req
->f
->op
.setlk(req
, nodeid
, &fi
, &flock
, sleep
);
1678 fuse_reply_err(req
, ENOSYS
);
1682 static void do_setlk(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1684 do_setlk_common(req
, nodeid
, inarg
, 0);
1687 static void do_setlkw(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1689 do_setlk_common(req
, nodeid
, inarg
, 1);
1692 static int find_interrupted(struct fuse_ll
*f
, struct fuse_req
*req
)
1694 struct fuse_req
*curr
;
1696 for (curr
= f
->list
.next
; curr
!= &f
->list
; curr
= curr
->next
) {
1697 if (curr
->unique
== req
->u
.i
.unique
) {
1698 fuse_interrupt_func_t func
;
1702 pthread_mutex_unlock(&f
->lock
);
1704 /* Ugh, ugly locking */
1705 pthread_mutex_lock(&curr
->lock
);
1706 pthread_mutex_lock(&f
->lock
);
1707 curr
->interrupted
= 1;
1708 func
= curr
->u
.ni
.func
;
1709 data
= curr
->u
.ni
.data
;
1710 pthread_mutex_unlock(&f
->lock
);
1713 pthread_mutex_unlock(&curr
->lock
);
1715 pthread_mutex_lock(&f
->lock
);
1723 for (curr
= f
->interrupts
.next
; curr
!= &f
->interrupts
;
1724 curr
= curr
->next
) {
1725 if (curr
->u
.i
.unique
== req
->u
.i
.unique
)
1731 static void do_interrupt(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1733 struct fuse_interrupt_in
*arg
= (struct fuse_interrupt_in
*) inarg
;
1734 struct fuse_ll
*f
= req
->f
;
1738 fprintf(stderr
, "INTERRUPT: %llu\n",
1739 (unsigned long long) arg
->unique
);
1741 req
->u
.i
.unique
= arg
->unique
;
1743 pthread_mutex_lock(&f
->lock
);
1744 if (find_interrupted(f
, req
))
1747 list_add_req(req
, &f
->interrupts
);
1748 pthread_mutex_unlock(&f
->lock
);
1751 static struct fuse_req
*check_interrupt(struct fuse_ll
*f
, struct fuse_req
*req
)
1753 struct fuse_req
*curr
;
1755 for (curr
= f
->interrupts
.next
; curr
!= &f
->interrupts
;
1756 curr
= curr
->next
) {
1757 if (curr
->u
.i
.unique
== req
->unique
) {
1758 req
->interrupted
= 1;
1764 curr
= f
->interrupts
.next
;
1765 if (curr
!= &f
->interrupts
) {
1767 list_init_req(curr
);
1773 static void do_bmap(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1775 struct fuse_bmap_in
*arg
= (struct fuse_bmap_in
*) inarg
;
1777 if (req
->f
->op
.bmap
)
1778 req
->f
->op
.bmap(req
, nodeid
, arg
->blocksize
, arg
->block
);
1780 fuse_reply_err(req
, ENOSYS
);
1783 static void do_ioctl(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1785 struct fuse_ioctl_in
*arg
= (struct fuse_ioctl_in
*) inarg
;
1786 unsigned int flags
= arg
->flags
;
1787 void *in_buf
= arg
->in_size
? PARAM(arg
) : NULL
;
1788 struct fuse_file_info fi
;
1790 if (flags
& FUSE_IOCTL_DIR
&&
1791 !(req
->f
->conn
.want
& FUSE_CAP_IOCTL_DIR
)) {
1792 fuse_reply_err(req
, ENOTTY
);
1796 memset(&fi
, 0, sizeof(fi
));
1799 if (sizeof(void *) == 4 && req
->f
->conn
.proto_minor
>= 16 &&
1800 !(flags
& FUSE_IOCTL_32BIT
)) {
1801 req
->ioctl_64bit
= 1;
1804 if (req
->f
->op
.ioctl
)
1805 req
->f
->op
.ioctl(req
, nodeid
, arg
->cmd
,
1806 (void *)(uintptr_t)arg
->arg
, &fi
, flags
,
1807 in_buf
, arg
->in_size
, arg
->out_size
);
1809 fuse_reply_err(req
, ENOSYS
);
1812 void fuse_pollhandle_destroy(struct fuse_pollhandle
*ph
)
1817 static void do_poll(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1819 struct fuse_poll_in
*arg
= (struct fuse_poll_in
*) inarg
;
1820 struct fuse_file_info fi
;
1822 memset(&fi
, 0, sizeof(fi
));
1824 fi
.poll_events
= arg
->events
;
1826 if (req
->f
->op
.poll
) {
1827 struct fuse_pollhandle
*ph
= NULL
;
1829 if (arg
->flags
& FUSE_POLL_SCHEDULE_NOTIFY
) {
1830 ph
= malloc(sizeof(struct fuse_pollhandle
));
1832 fuse_reply_err(req
, ENOMEM
);
1840 req
->f
->op
.poll(req
, nodeid
, &fi
, ph
);
1842 fuse_reply_err(req
, ENOSYS
);
1846 static void do_fallocate(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1848 struct fuse_fallocate_in
*arg
= (struct fuse_fallocate_in
*) inarg
;
1849 struct fuse_file_info fi
;
1851 memset(&fi
, 0, sizeof(fi
));
1854 if (req
->f
->op
.fallocate
)
1855 req
->f
->op
.fallocate(req
, nodeid
, arg
->mode
, arg
->offset
, arg
->length
, &fi
);
1857 fuse_reply_err(req
, ENOSYS
);
1860 static void do_init(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
1862 struct fuse_init_in
*arg
= (struct fuse_init_in
*) inarg
;
1863 struct fuse_init_out outarg
;
1864 struct fuse_ll
*f
= req
->f
;
1865 size_t bufsize
= f
->bufsize
;
1866 size_t outargsize
= sizeof(outarg
);
1870 fprintf(stderr
, "INIT: %u.%u\n", arg
->major
, arg
->minor
);
1871 if (arg
->major
== 7 && arg
->minor
>= 6) {
1872 fprintf(stderr
, "flags=0x%08x\n", arg
->flags
);
1873 fprintf(stderr
, "max_readahead=0x%08x\n",
1874 arg
->max_readahead
);
1877 f
->conn
.proto_major
= arg
->major
;
1878 f
->conn
.proto_minor
= arg
->minor
;
1879 f
->conn
.capable
= 0;
1882 memset(&outarg
, 0, sizeof(outarg
));
1883 outarg
.major
= FUSE_KERNEL_VERSION
;
1884 outarg
.minor
= FUSE_KERNEL_MINOR_VERSION
;
1886 if (arg
->major
< 7) {
1887 fprintf(stderr
, "fuse: unsupported protocol version: %u.%u\n",
1888 arg
->major
, arg
->minor
);
1889 fuse_reply_err(req
, EPROTO
);
1893 if (arg
->major
> 7) {
1894 /* Wait for a second INIT request with a 7.X version */
1895 send_reply_ok(req
, &outarg
, sizeof(outarg
));
1899 if (arg
->minor
>= 6) {
1900 if (f
->conn
.async_read
)
1901 f
->conn
.async_read
= arg
->flags
& FUSE_ASYNC_READ
;
1902 if (arg
->max_readahead
< f
->conn
.max_readahead
)
1903 f
->conn
.max_readahead
= arg
->max_readahead
;
1904 if (arg
->flags
& FUSE_ASYNC_READ
)
1905 f
->conn
.capable
|= FUSE_CAP_ASYNC_READ
;
1906 if (arg
->flags
& FUSE_POSIX_LOCKS
)
1907 f
->conn
.capable
|= FUSE_CAP_POSIX_LOCKS
;
1908 if (arg
->flags
& FUSE_ATOMIC_O_TRUNC
)
1909 f
->conn
.capable
|= FUSE_CAP_ATOMIC_O_TRUNC
;
1910 if (arg
->flags
& FUSE_EXPORT_SUPPORT
)
1911 f
->conn
.capable
|= FUSE_CAP_EXPORT_SUPPORT
;
1912 if (arg
->flags
& FUSE_BIG_WRITES
)
1913 f
->conn
.capable
|= FUSE_CAP_BIG_WRITES
;
1914 if (arg
->flags
& FUSE_DONT_MASK
)
1915 f
->conn
.capable
|= FUSE_CAP_DONT_MASK
;
1916 if (arg
->flags
& FUSE_FLOCK_LOCKS
)
1917 f
->conn
.capable
|= FUSE_CAP_FLOCK_LOCKS
;
1918 if (arg
->flags
& FUSE_AUTO_INVAL_DATA
)
1919 f
->conn
.capable
|= FUSE_CAP_AUTO_INVAL_DATA
;
1920 if (arg
->flags
& FUSE_DO_READDIRPLUS
)
1921 f
->conn
.capable
|= FUSE_CAP_READDIRPLUS
;
1922 if (arg
->flags
& FUSE_READDIRPLUS_AUTO
)
1923 f
->conn
.capable
|= FUSE_CAP_READDIRPLUS_AUTO
;
1924 if (arg
->flags
& FUSE_ASYNC_DIO
)
1925 f
->conn
.capable
|= FUSE_CAP_ASYNC_DIO
;
1926 if (arg
->flags
& FUSE_WRITEBACK_CACHE
)
1927 f
->conn
.capable
|= FUSE_CAP_WRITEBACK_CACHE
;
1928 if (arg
->flags
& FUSE_NO_OPEN_SUPPORT
)
1929 f
->conn
.capable
|= FUSE_CAP_NO_OPEN_SUPPORT
;
1931 f
->conn
.async_read
= 0;
1932 f
->conn
.max_readahead
= 0;
1935 if (req
->f
->conn
.proto_minor
>= 14) {
1937 #ifdef HAVE_VMSPLICE
1938 f
->conn
.capable
|= FUSE_CAP_SPLICE_WRITE
| FUSE_CAP_SPLICE_MOVE
;
1939 if (f
->splice_write
)
1940 f
->conn
.want
|= FUSE_CAP_SPLICE_WRITE
;
1942 f
->conn
.want
|= FUSE_CAP_SPLICE_MOVE
;
1944 f
->conn
.capable
|= FUSE_CAP_SPLICE_READ
;
1946 f
->conn
.want
|= FUSE_CAP_SPLICE_READ
;
1949 if (req
->f
->conn
.proto_minor
>= 18)
1950 f
->conn
.capable
|= FUSE_CAP_IOCTL_DIR
;
1952 if (f
->atomic_o_trunc
)
1953 f
->conn
.want
|= FUSE_CAP_ATOMIC_O_TRUNC
;
1954 if (f
->op
.getlk
&& f
->op
.setlk
&& !f
->no_remote_posix_lock
)
1955 f
->conn
.want
|= FUSE_CAP_POSIX_LOCKS
;
1956 if (f
->op
.flock
&& !f
->no_remote_flock
)
1957 f
->conn
.want
|= FUSE_CAP_FLOCK_LOCKS
;
1959 f
->conn
.want
|= FUSE_CAP_BIG_WRITES
;
1960 if (f
->auto_inval_data
)
1961 f
->conn
.want
|= FUSE_CAP_AUTO_INVAL_DATA
;
1962 if (f
->op
.readdirplus
&& !f
->no_readdirplus
) {
1963 f
->conn
.want
|= FUSE_CAP_READDIRPLUS
;
1964 if (!f
->no_readdirplus_auto
)
1965 f
->conn
.want
|= FUSE_CAP_READDIRPLUS_AUTO
;
1968 f
->conn
.want
|= FUSE_CAP_ASYNC_DIO
;
1969 if (f
->writeback_cache
)
1970 f
->conn
.want
|= FUSE_CAP_WRITEBACK_CACHE
;
1972 if (bufsize
< FUSE_MIN_READ_BUFFER
) {
1973 fprintf(stderr
, "fuse: warning: buffer size too small: %zu\n",
1975 bufsize
= FUSE_MIN_READ_BUFFER
;
1979 if (bufsize
< f
->conn
.max_write
)
1980 f
->conn
.max_write
= bufsize
;
1984 f
->op
.init(f
->userdata
, &f
->conn
);
1986 if (f
->no_splice_read
)
1987 f
->conn
.want
&= ~FUSE_CAP_SPLICE_READ
;
1988 if (f
->no_splice_write
)
1989 f
->conn
.want
&= ~FUSE_CAP_SPLICE_WRITE
;
1990 if (f
->no_splice_move
)
1991 f
->conn
.want
&= ~FUSE_CAP_SPLICE_MOVE
;
1992 if (f
->no_auto_inval_data
)
1993 f
->conn
.want
&= ~FUSE_CAP_AUTO_INVAL_DATA
;
1994 if (f
->no_readdirplus
)
1995 f
->conn
.want
&= ~FUSE_CAP_READDIRPLUS
;
1996 if (f
->no_readdirplus_auto
)
1997 f
->conn
.want
&= ~FUSE_CAP_READDIRPLUS_AUTO
;
1998 if (f
->no_async_dio
)
1999 f
->conn
.want
&= ~FUSE_CAP_ASYNC_DIO
;
2000 if (f
->no_writeback_cache
)
2001 f
->conn
.want
&= ~FUSE_CAP_WRITEBACK_CACHE
;
2003 if (f
->conn
.async_read
|| (f
->conn
.want
& FUSE_CAP_ASYNC_READ
))
2004 outarg
.flags
|= FUSE_ASYNC_READ
;
2005 if (f
->conn
.want
& FUSE_CAP_POSIX_LOCKS
)
2006 outarg
.flags
|= FUSE_POSIX_LOCKS
;
2007 if (f
->conn
.want
& FUSE_CAP_ATOMIC_O_TRUNC
)
2008 outarg
.flags
|= FUSE_ATOMIC_O_TRUNC
;
2009 if (f
->conn
.want
& FUSE_CAP_EXPORT_SUPPORT
)
2010 outarg
.flags
|= FUSE_EXPORT_SUPPORT
;
2011 if (f
->conn
.want
& FUSE_CAP_BIG_WRITES
)
2012 outarg
.flags
|= FUSE_BIG_WRITES
;
2013 if (f
->conn
.want
& FUSE_CAP_DONT_MASK
)
2014 outarg
.flags
|= FUSE_DONT_MASK
;
2015 if (f
->conn
.want
& FUSE_CAP_FLOCK_LOCKS
)
2016 outarg
.flags
|= FUSE_FLOCK_LOCKS
;
2017 if (f
->conn
.want
& FUSE_CAP_AUTO_INVAL_DATA
)
2018 outarg
.flags
|= FUSE_AUTO_INVAL_DATA
;
2019 if (f
->conn
.want
& FUSE_CAP_READDIRPLUS
)
2020 outarg
.flags
|= FUSE_DO_READDIRPLUS
;
2021 if (f
->conn
.want
& FUSE_CAP_READDIRPLUS_AUTO
)
2022 outarg
.flags
|= FUSE_READDIRPLUS_AUTO
;
2023 if (f
->conn
.want
& FUSE_CAP_ASYNC_DIO
)
2024 outarg
.flags
|= FUSE_ASYNC_DIO
;
2025 if (f
->conn
.want
& FUSE_CAP_WRITEBACK_CACHE
)
2026 outarg
.flags
|= FUSE_WRITEBACK_CACHE
;
2027 outarg
.max_readahead
= f
->conn
.max_readahead
;
2028 outarg
.max_write
= f
->conn
.max_write
;
2029 if (f
->conn
.proto_minor
>= 13) {
2030 if (f
->conn
.max_background
>= (1 << 16))
2031 f
->conn
.max_background
= (1 << 16) - 1;
2032 if (f
->conn
.congestion_threshold
> f
->conn
.max_background
)
2033 f
->conn
.congestion_threshold
= f
->conn
.max_background
;
2034 if (!f
->conn
.congestion_threshold
) {
2035 f
->conn
.congestion_threshold
=
2036 f
->conn
.max_background
* 3 / 4;
2039 outarg
.max_background
= f
->conn
.max_background
;
2040 outarg
.congestion_threshold
= f
->conn
.congestion_threshold
;
2042 if (f
->conn
.proto_minor
>= 23)
2043 outarg
.time_gran
= f
->conn
.time_gran
;
2046 fprintf(stderr
, " INIT: %u.%u\n", outarg
.major
, outarg
.minor
);
2047 fprintf(stderr
, " flags=0x%08x\n", outarg
.flags
);
2048 fprintf(stderr
, " max_readahead=0x%08x\n",
2049 outarg
.max_readahead
);
2050 fprintf(stderr
, " max_write=0x%08x\n", outarg
.max_write
);
2051 fprintf(stderr
, " max_background=%i\n",
2052 outarg
.max_background
);
2053 fprintf(stderr
, " congestion_threshold=%i\n",
2054 outarg
.congestion_threshold
);
2055 fprintf(stderr
, " time_gran=%u\n",
2059 outargsize
= FUSE_COMPAT_INIT_OUT_SIZE
;
2060 else if (arg
->minor
< 23)
2061 outargsize
= FUSE_COMPAT_22_INIT_OUT_SIZE
;
2063 send_reply_ok(req
, &outarg
, outargsize
);
2066 static void do_destroy(fuse_req_t req
, fuse_ino_t nodeid
, const void *inarg
)
2068 struct fuse_ll
*f
= req
->f
;
2075 f
->op
.destroy(f
->userdata
);
2077 send_reply_ok(req
, NULL
, 0);
2080 static void list_del_nreq(struct fuse_notify_req
*nreq
)
2082 struct fuse_notify_req
*prev
= nreq
->prev
;
2083 struct fuse_notify_req
*next
= nreq
->next
;
2088 static void list_add_nreq(struct fuse_notify_req
*nreq
,
2089 struct fuse_notify_req
*next
)
2091 struct fuse_notify_req
*prev
= next
->prev
;
2098 static void list_init_nreq(struct fuse_notify_req
*nreq
)
2104 static void do_notify_reply(fuse_req_t req
, fuse_ino_t nodeid
,
2105 const void *inarg
, const struct fuse_buf
*buf
)
2107 struct fuse_ll
*f
= req
->f
;
2108 struct fuse_notify_req
*nreq
;
2109 struct fuse_notify_req
*head
;
2111 pthread_mutex_lock(&f
->lock
);
2112 head
= &f
->notify_list
;
2113 for (nreq
= head
->next
; nreq
!= head
; nreq
= nreq
->next
) {
2114 if (nreq
->unique
== req
->unique
) {
2115 list_del_nreq(nreq
);
2119 pthread_mutex_unlock(&f
->lock
);
2122 nreq
->reply(nreq
, req
, nodeid
, inarg
, buf
);
2125 static int send_notify_iov(struct fuse_ll
*f
, struct fuse_chan
*ch
,
2126 int notify_code
, struct iovec
*iov
, int count
)
2128 struct fuse_out_header out
;
2134 out
.error
= notify_code
;
2135 iov
[0].iov_base
= &out
;
2136 iov
[0].iov_len
= sizeof(struct fuse_out_header
);
2138 return fuse_send_msg(f
, ch
, iov
, count
);
2141 int fuse_lowlevel_notify_poll(struct fuse_pollhandle
*ph
)
2144 struct fuse_notify_poll_wakeup_out outarg
;
2145 struct iovec iov
[2];
2149 iov
[1].iov_base
= &outarg
;
2150 iov
[1].iov_len
= sizeof(outarg
);
2152 return send_notify_iov(ph
->f
, ph
->ch
, FUSE_NOTIFY_POLL
, iov
, 2);
2158 int fuse_lowlevel_notify_inval_inode(struct fuse_chan
*ch
, fuse_ino_t ino
,
2159 off_t off
, off_t len
)
2161 struct fuse_notify_inval_inode_out outarg
;
2163 struct iovec iov
[2];
2168 f
= fuse_chan_session(ch
)->f
;
2176 iov
[1].iov_base
= &outarg
;
2177 iov
[1].iov_len
= sizeof(outarg
);
2179 return send_notify_iov(f
, ch
, FUSE_NOTIFY_INVAL_INODE
, iov
, 2);
2182 int fuse_lowlevel_notify_inval_entry(struct fuse_chan
*ch
, fuse_ino_t parent
,
2183 const char *name
, size_t namelen
)
2185 struct fuse_notify_inval_entry_out outarg
;
2187 struct iovec iov
[3];
2192 f
= fuse_chan_session(ch
)->f
;
2196 outarg
.parent
= parent
;
2197 outarg
.namelen
= namelen
;
2200 iov
[1].iov_base
= &outarg
;
2201 iov
[1].iov_len
= sizeof(outarg
);
2202 iov
[2].iov_base
= (void *)name
;
2203 iov
[2].iov_len
= namelen
+ 1;
2205 return send_notify_iov(f
, ch
, FUSE_NOTIFY_INVAL_ENTRY
, iov
, 3);
2208 int fuse_lowlevel_notify_delete(struct fuse_chan
*ch
,
2209 fuse_ino_t parent
, fuse_ino_t child
,
2210 const char *name
, size_t namelen
)
2212 struct fuse_notify_delete_out outarg
;
2214 struct iovec iov
[3];
2219 f
= fuse_chan_session(ch
)->f
;
2223 if (f
->conn
.proto_minor
< 18)
2226 outarg
.parent
= parent
;
2227 outarg
.child
= child
;
2228 outarg
.namelen
= namelen
;
2231 iov
[1].iov_base
= &outarg
;
2232 iov
[1].iov_len
= sizeof(outarg
);
2233 iov
[2].iov_base
= (void *)name
;
2234 iov
[2].iov_len
= namelen
+ 1;
2236 return send_notify_iov(f
, ch
, FUSE_NOTIFY_DELETE
, iov
, 3);
2239 int fuse_lowlevel_notify_store(struct fuse_chan
*ch
, fuse_ino_t ino
,
2240 off_t offset
, struct fuse_bufvec
*bufv
,
2241 enum fuse_buf_copy_flags flags
)
2243 struct fuse_out_header out
;
2244 struct fuse_notify_store_out outarg
;
2246 struct iovec iov
[3];
2247 size_t size
= fuse_buf_size(bufv
);
2253 f
= fuse_chan_session(ch
)->f
;
2257 if (f
->conn
.proto_minor
< 15)
2261 out
.error
= FUSE_NOTIFY_STORE
;
2263 outarg
.nodeid
= ino
;
2264 outarg
.offset
= offset
;
2267 iov
[0].iov_base
= &out
;
2268 iov
[0].iov_len
= sizeof(out
);
2269 iov
[1].iov_base
= &outarg
;
2270 iov
[1].iov_len
= sizeof(outarg
);
2272 res
= fuse_send_data_iov(f
, ch
, iov
, 2, bufv
, flags
);
2279 struct fuse_retrieve_req
{
2280 struct fuse_notify_req nreq
;
2284 static void fuse_ll_retrieve_reply(struct fuse_notify_req
*nreq
,
2285 fuse_req_t req
, fuse_ino_t ino
,
2287 const struct fuse_buf
*ibuf
)
2289 struct fuse_ll
*f
= req
->f
;
2290 struct fuse_retrieve_req
*rreq
=
2291 container_of(nreq
, struct fuse_retrieve_req
, nreq
);
2292 const struct fuse_notify_retrieve_in
*arg
= inarg
;
2293 struct fuse_bufvec bufv
= {
2298 if (!(bufv
.buf
[0].flags
& FUSE_BUF_IS_FD
))
2299 bufv
.buf
[0].mem
= PARAM(arg
);
2301 bufv
.buf
[0].size
-= sizeof(struct fuse_in_header
) +
2302 sizeof(struct fuse_notify_retrieve_in
);
2304 if (bufv
.buf
[0].size
< arg
->size
) {
2305 fprintf(stderr
, "fuse: retrieve reply: buffer size too small\n");
2306 fuse_reply_none(req
);
2309 bufv
.buf
[0].size
= arg
->size
;
2311 if (req
->f
->op
.retrieve_reply
) {
2312 req
->f
->op
.retrieve_reply(req
, rreq
->cookie
, ino
,
2313 arg
->offset
, &bufv
);
2315 fuse_reply_none(req
);
2319 if ((ibuf
->flags
& FUSE_BUF_IS_FD
) && bufv
.idx
< bufv
.count
)
2320 fuse_ll_clear_pipe(f
);
2323 int fuse_lowlevel_notify_retrieve(struct fuse_chan
*ch
, fuse_ino_t ino
,
2324 size_t size
, off_t offset
, void *cookie
)
2326 struct fuse_notify_retrieve_out outarg
;
2328 struct iovec iov
[2];
2329 struct fuse_retrieve_req
*rreq
;
2335 f
= fuse_chan_session(ch
)->f
;
2339 if (f
->conn
.proto_minor
< 15)
2342 rreq
= malloc(sizeof(*rreq
));
2346 pthread_mutex_lock(&f
->lock
);
2347 rreq
->cookie
= cookie
;
2348 rreq
->nreq
.unique
= f
->notify_ctr
++;
2349 rreq
->nreq
.reply
= fuse_ll_retrieve_reply
;
2350 list_add_nreq(&rreq
->nreq
, &f
->notify_list
);
2351 pthread_mutex_unlock(&f
->lock
);
2353 outarg
.notify_unique
= rreq
->nreq
.unique
;
2354 outarg
.nodeid
= ino
;
2355 outarg
.offset
= offset
;
2358 iov
[1].iov_base
= &outarg
;
2359 iov
[1].iov_len
= sizeof(outarg
);
2361 err
= send_notify_iov(f
, ch
, FUSE_NOTIFY_RETRIEVE
, iov
, 2);
2363 pthread_mutex_lock(&f
->lock
);
2364 list_del_nreq(&rreq
->nreq
);
2365 pthread_mutex_unlock(&f
->lock
);
2372 void *fuse_req_userdata(fuse_req_t req
)
2374 return req
->f
->userdata
;
2377 const struct fuse_ctx
*fuse_req_ctx(fuse_req_t req
)
2382 void fuse_req_interrupt_func(fuse_req_t req
, fuse_interrupt_func_t func
,
2385 pthread_mutex_lock(&req
->lock
);
2386 pthread_mutex_lock(&req
->f
->lock
);
2387 req
->u
.ni
.func
= func
;
2388 req
->u
.ni
.data
= data
;
2389 pthread_mutex_unlock(&req
->f
->lock
);
2390 if (req
->interrupted
&& func
)
2392 pthread_mutex_unlock(&req
->lock
);
2395 int fuse_req_interrupted(fuse_req_t req
)
2399 pthread_mutex_lock(&req
->f
->lock
);
2400 interrupted
= req
->interrupted
;
2401 pthread_mutex_unlock(&req
->f
->lock
);
2407 void (*func
)(fuse_req_t
, fuse_ino_t
, const void *);
2410 [FUSE_LOOKUP
] = { do_lookup
, "LOOKUP" },
2411 [FUSE_FORGET
] = { do_forget
, "FORGET" },
2412 [FUSE_GETATTR
] = { do_getattr
, "GETATTR" },
2413 [FUSE_SETATTR
] = { do_setattr
, "SETATTR" },
2414 [FUSE_READLINK
] = { do_readlink
, "READLINK" },
2415 [FUSE_SYMLINK
] = { do_symlink
, "SYMLINK" },
2416 [FUSE_MKNOD
] = { do_mknod
, "MKNOD" },
2417 [FUSE_MKDIR
] = { do_mkdir
, "MKDIR" },
2418 [FUSE_UNLINK
] = { do_unlink
, "UNLINK" },
2419 [FUSE_RMDIR
] = { do_rmdir
, "RMDIR" },
2420 [FUSE_RENAME
] = { do_rename
, "RENAME" },
2421 [FUSE_LINK
] = { do_link
, "LINK" },
2422 [FUSE_OPEN
] = { do_open
, "OPEN" },
2423 [FUSE_READ
] = { do_read
, "READ" },
2424 [FUSE_WRITE
] = { do_write
, "WRITE" },
2425 [FUSE_STATFS
] = { do_statfs
, "STATFS" },
2426 [FUSE_RELEASE
] = { do_release
, "RELEASE" },
2427 [FUSE_FSYNC
] = { do_fsync
, "FSYNC" },
2428 [FUSE_SETXATTR
] = { do_setxattr
, "SETXATTR" },
2429 [FUSE_GETXATTR
] = { do_getxattr
, "GETXATTR" },
2430 [FUSE_LISTXATTR
] = { do_listxattr
, "LISTXATTR" },
2431 [FUSE_REMOVEXATTR
] = { do_removexattr
, "REMOVEXATTR" },
2432 [FUSE_FLUSH
] = { do_flush
, "FLUSH" },
2433 [FUSE_INIT
] = { do_init
, "INIT" },
2434 [FUSE_OPENDIR
] = { do_opendir
, "OPENDIR" },
2435 [FUSE_READDIR
] = { do_readdir
, "READDIR" },
2436 [FUSE_RELEASEDIR
] = { do_releasedir
, "RELEASEDIR" },
2437 [FUSE_FSYNCDIR
] = { do_fsyncdir
, "FSYNCDIR" },
2438 [FUSE_GETLK
] = { do_getlk
, "GETLK" },
2439 [FUSE_SETLK
] = { do_setlk
, "SETLK" },
2440 [FUSE_SETLKW
] = { do_setlkw
, "SETLKW" },
2441 [FUSE_ACCESS
] = { do_access
, "ACCESS" },
2442 [FUSE_CREATE
] = { do_create
, "CREATE" },
2443 [FUSE_INTERRUPT
] = { do_interrupt
, "INTERRUPT" },
2444 [FUSE_BMAP
] = { do_bmap
, "BMAP" },
2445 [FUSE_IOCTL
] = { do_ioctl
, "IOCTL" },
2446 [FUSE_POLL
] = { do_poll
, "POLL" },
2447 [FUSE_FALLOCATE
] = { do_fallocate
, "FALLOCATE" },
2448 [FUSE_DESTROY
] = { do_destroy
, "DESTROY" },
2449 [FUSE_NOTIFY_REPLY
] = { (void *) 1, "NOTIFY_REPLY" },
2450 [FUSE_BATCH_FORGET
] = { do_batch_forget
, "BATCH_FORGET" },
2451 [FUSE_READDIRPLUS
] = { do_readdirplus
, "READDIRPLUS"},
2452 [FUSE_RENAME2
] = { do_rename2
, "RENAME2" },
2453 [CUSE_INIT
] = { cuse_lowlevel_init
, "CUSE_INIT" },
2456 #define FUSE_MAXOP (sizeof(fuse_ll_ops) / sizeof(fuse_ll_ops[0]))
2458 static const char *opname(enum fuse_opcode opcode
)
2460 if (opcode
>= FUSE_MAXOP
|| !fuse_ll_ops
[opcode
].name
)
2463 return fuse_ll_ops
[opcode
].name
;
2466 static int fuse_ll_copy_from_pipe(struct fuse_bufvec
*dst
,
2467 struct fuse_bufvec
*src
)
2469 int res
= fuse_buf_copy(dst
, src
, 0);
2471 fprintf(stderr
, "fuse: copy from pipe: %s\n", strerror(-res
));
2474 if (res
< fuse_buf_size(dst
)) {
2475 fprintf(stderr
, "fuse: copy from pipe: short read\n");
2481 void fuse_session_process_buf(struct fuse_session
*se
,
2482 const struct fuse_buf
*buf
, struct fuse_chan
*ch
)
2484 struct fuse_ll
*f
= se
->f
;
2485 const size_t write_header_size
= sizeof(struct fuse_in_header
) +
2486 sizeof(struct fuse_write_in
);
2487 struct fuse_bufvec bufv
= { .buf
[0] = *buf
, .count
= 1 };
2488 struct fuse_bufvec tmpbuf
= FUSE_BUFVEC_INIT(write_header_size
);
2489 struct fuse_in_header
*in
;
2491 struct fuse_req
*req
;
2496 if (buf
->flags
& FUSE_BUF_IS_FD
) {
2497 if (buf
->size
< tmpbuf
.buf
[0].size
)
2498 tmpbuf
.buf
[0].size
= buf
->size
;
2500 mbuf
= malloc(tmpbuf
.buf
[0].size
);
2502 fprintf(stderr
, "fuse: failed to allocate header\n");
2505 tmpbuf
.buf
[0].mem
= mbuf
;
2507 res
= fuse_ll_copy_from_pipe(&tmpbuf
, &bufv
);
2518 "unique: %llu, opcode: %s (%i), nodeid: %llu, insize: %zu, pid: %u\n",
2519 (unsigned long long) in
->unique
,
2520 opname((enum fuse_opcode
) in
->opcode
), in
->opcode
,
2521 (unsigned long long) in
->nodeid
, buf
->size
, in
->pid
);
2524 req
= fuse_ll_alloc_req(f
);
2526 struct fuse_out_header out
= {
2527 .unique
= in
->unique
,
2530 struct iovec iov
= {
2532 .iov_len
= sizeof(struct fuse_out_header
),
2535 fuse_send_msg(f
, ch
, &iov
, 1);
2539 req
->unique
= in
->unique
;
2540 req
->ctx
.uid
= in
->uid
;
2541 req
->ctx
.gid
= in
->gid
;
2542 req
->ctx
.pid
= in
->pid
;
2543 req
->ch
= fuse_chan_get(ch
);
2547 enum fuse_opcode expected
;
2549 expected
= f
->cuse_data
? CUSE_INIT
: FUSE_INIT
;
2550 if (in
->opcode
!= expected
)
2552 } else if (in
->opcode
== FUSE_INIT
|| in
->opcode
== CUSE_INIT
)
2556 if (f
->allow_root
&& in
->uid
!= f
->owner
&& in
->uid
!= 0 &&
2557 in
->opcode
!= FUSE_INIT
&& in
->opcode
!= FUSE_READ
&&
2558 in
->opcode
!= FUSE_WRITE
&& in
->opcode
!= FUSE_FSYNC
&&
2559 in
->opcode
!= FUSE_RELEASE
&& in
->opcode
!= FUSE_READDIR
&&
2560 in
->opcode
!= FUSE_FSYNCDIR
&& in
->opcode
!= FUSE_RELEASEDIR
&&
2561 in
->opcode
!= FUSE_NOTIFY_REPLY
&&
2562 in
->opcode
!= FUSE_READDIRPLUS
)
2566 if (in
->opcode
>= FUSE_MAXOP
|| !fuse_ll_ops
[in
->opcode
].func
)
2568 if (in
->opcode
!= FUSE_INTERRUPT
) {
2569 struct fuse_req
*intr
;
2570 pthread_mutex_lock(&f
->lock
);
2571 intr
= check_interrupt(f
, req
);
2572 list_add_req(req
, &f
->list
);
2573 pthread_mutex_unlock(&f
->lock
);
2575 fuse_reply_err(intr
, EAGAIN
);
2578 if ((buf
->flags
& FUSE_BUF_IS_FD
) && write_header_size
< buf
->size
&&
2579 (in
->opcode
!= FUSE_WRITE
|| !f
->op
.write_buf
) &&
2580 in
->opcode
!= FUSE_NOTIFY_REPLY
) {
2584 newmbuf
= realloc(mbuf
, buf
->size
);
2585 if (newmbuf
== NULL
)
2589 tmpbuf
= FUSE_BUFVEC_INIT(buf
->size
- write_header_size
);
2590 tmpbuf
.buf
[0].mem
= mbuf
+ write_header_size
;
2592 res
= fuse_ll_copy_from_pipe(&tmpbuf
, &bufv
);
2600 inarg
= (void *) &in
[1];
2601 if (in
->opcode
== FUSE_WRITE
&& f
->op
.write_buf
)
2602 do_write_buf(req
, in
->nodeid
, inarg
, buf
);
2603 else if (in
->opcode
== FUSE_NOTIFY_REPLY
)
2604 do_notify_reply(req
, in
->nodeid
, inarg
, buf
);
2606 fuse_ll_ops
[in
->opcode
].func(req
, in
->nodeid
, inarg
);
2613 fuse_reply_err(req
, err
);
2615 if (buf
->flags
& FUSE_BUF_IS_FD
)
2616 fuse_ll_clear_pipe(f
);
2625 static const struct fuse_opt fuse_ll_opts
[] = {
2626 { "debug", offsetof(struct fuse_ll
, debug
), 1 },
2627 { "-d", offsetof(struct fuse_ll
, debug
), 1 },
2628 { "allow_root", offsetof(struct fuse_ll
, allow_root
), 1 },
2629 { "max_write=%u", offsetof(struct fuse_ll
, conn
.max_write
), 0 },
2630 { "max_readahead=%u", offsetof(struct fuse_ll
, conn
.max_readahead
), 0 },
2631 { "max_background=%u", offsetof(struct fuse_ll
, conn
.max_background
), 0 },
2632 { "congestion_threshold=%u",
2633 offsetof(struct fuse_ll
, conn
.congestion_threshold
), 0 },
2634 { "async_read", offsetof(struct fuse_ll
, conn
.async_read
), 1 },
2635 { "sync_read", offsetof(struct fuse_ll
, conn
.async_read
), 0 },
2636 { "atomic_o_trunc", offsetof(struct fuse_ll
, atomic_o_trunc
), 1},
2637 { "no_remote_lock", offsetof(struct fuse_ll
, no_remote_posix_lock
), 1},
2638 { "no_remote_lock", offsetof(struct fuse_ll
, no_remote_flock
), 1},
2639 { "no_remote_flock", offsetof(struct fuse_ll
, no_remote_flock
), 1},
2640 { "no_remote_posix_lock", offsetof(struct fuse_ll
, no_remote_posix_lock
), 1},
2641 { "big_writes", offsetof(struct fuse_ll
, big_writes
), 1},
2642 { "splice_write", offsetof(struct fuse_ll
, splice_write
), 1},
2643 { "no_splice_write", offsetof(struct fuse_ll
, no_splice_write
), 1},
2644 { "splice_move", offsetof(struct fuse_ll
, splice_move
), 1},
2645 { "no_splice_move", offsetof(struct fuse_ll
, no_splice_move
), 1},
2646 { "splice_read", offsetof(struct fuse_ll
, splice_read
), 1},
2647 { "no_splice_read", offsetof(struct fuse_ll
, no_splice_read
), 1},
2648 { "auto_inval_data", offsetof(struct fuse_ll
, auto_inval_data
), 1},
2649 { "no_auto_inval_data", offsetof(struct fuse_ll
, no_auto_inval_data
), 1},
2650 { "readdirplus=no", offsetof(struct fuse_ll
, no_readdirplus
), 1},
2651 { "readdirplus=yes", offsetof(struct fuse_ll
, no_readdirplus
), 0},
2652 { "readdirplus=yes", offsetof(struct fuse_ll
, no_readdirplus_auto
), 1},
2653 { "readdirplus=auto", offsetof(struct fuse_ll
, no_readdirplus
), 0},
2654 { "readdirplus=auto", offsetof(struct fuse_ll
, no_readdirplus_auto
), 0},
2655 { "async_dio", offsetof(struct fuse_ll
, async_dio
), 1},
2656 { "no_async_dio", offsetof(struct fuse_ll
, no_async_dio
), 1},
2657 { "writeback_cache", offsetof(struct fuse_ll
, writeback_cache
), 1},
2658 { "no_writeback_cache", offsetof(struct fuse_ll
, no_writeback_cache
), 1},
2659 { "time_gran=%u", offsetof(struct fuse_ll
, conn
.time_gran
), 0 },
2660 { "clone_fd", offsetof(struct fuse_ll
, clone_fd
), 1 },
2661 FUSE_OPT_KEY("max_read=", FUSE_OPT_KEY_DISCARD
),
2662 FUSE_OPT_KEY("-h", KEY_HELP
),
2663 FUSE_OPT_KEY("--help", KEY_HELP
),
2664 FUSE_OPT_KEY("-V", KEY_VERSION
),
2665 FUSE_OPT_KEY("--version", KEY_VERSION
),
2669 static void fuse_ll_version(void)
2671 printf("using FUSE kernel interface version %i.%i\n",
2672 FUSE_KERNEL_VERSION
, FUSE_KERNEL_MINOR_VERSION
);
2675 static void fuse_ll_help(void)
2678 " -o max_write=N set maximum size of write requests\n"
2679 " -o max_readahead=N set maximum readahead\n"
2680 " -o max_background=N set number of maximum background requests\n"
2681 " -o congestion_threshold=N set kernel's congestion threshold\n"
2682 " -o async_read perform reads asynchronously (default)\n"
2683 " -o sync_read perform reads synchronously\n"
2684 " -o atomic_o_trunc enable atomic open+truncate support\n"
2685 " -o big_writes enable larger than 4kB writes\n"
2686 " -o no_remote_lock disable remote file locking\n"
2687 " -o no_remote_flock disable remote file locking (BSD)\n"
2688 " -o no_remote_posix_lock disable remove file locking (POSIX)\n"
2689 " -o [no_]splice_write use splice to write to the fuse device\n"
2690 " -o [no_]splice_move move data while splicing to the fuse device\n"
2691 " -o [no_]splice_read use splice to read from the fuse device\n"
2692 " -o [no_]auto_inval_data use automatic kernel cache invalidation logic\n"
2693 " -o readdirplus=S control readdirplus use (yes|no|auto)\n"
2694 " -o [no_]async_dio asynchronous direct I/O\n"
2695 " -o [no_]writeback_cache asynchronous, buffered writes\n"
2696 " -o time_gran=N time granularity in nsec\n"
2697 " -o clone_fd clone fuse device file descriptors\n"
2701 static int fuse_ll_opt_proc(void *data
, const char *arg
, int key
,
2702 struct fuse_args
*outargs
)
2704 (void) data
; (void) outargs
;
2716 fprintf(stderr
, "fuse: unknown option `%s'\n", arg
);
2722 static void fuse_ll_destroy(struct fuse_ll
*f
)
2724 struct fuse_ll_pipe
*llp
;
2726 if (f
->got_init
&& !f
->got_destroy
) {
2728 f
->op
.destroy(f
->userdata
);
2730 llp
= pthread_getspecific(f
->pipe_key
);
2732 fuse_ll_pipe_free(llp
);
2733 pthread_key_delete(f
->pipe_key
);
2734 pthread_mutex_destroy(&f
->lock
);
2739 void fuse_session_destroy(struct fuse_session
*se
)
2741 fuse_ll_destroy(se
->f
);
2742 fuse_chan_put(se
->ch
);
2747 static void fuse_ll_pipe_destructor(void *data
)
2749 struct fuse_ll_pipe
*llp
= data
;
2750 fuse_ll_pipe_free(llp
);
2754 int fuse_session_receive_buf(struct fuse_session
*se
, struct fuse_buf
*buf
,
2755 struct fuse_chan
*ch
)
2757 struct fuse_ll
*f
= se
->f
;
2758 size_t bufsize
= f
->bufsize
;
2759 struct fuse_ll_pipe
*llp
;
2760 struct fuse_buf tmpbuf
;
2764 if (f
->conn
.proto_minor
< 14 || !(f
->conn
.want
& FUSE_CAP_SPLICE_READ
))
2767 llp
= fuse_ll_get_pipe(f
);
2771 if (llp
->size
< bufsize
) {
2772 if (llp
->can_grow
) {
2773 res
= fcntl(llp
->pipe
[0], F_SETPIPE_SZ
, bufsize
);
2780 if (llp
->size
< bufsize
)
2784 res
= splice(fuse_chan_fd(ch
), NULL
, llp
->pipe
[1], NULL
, bufsize
, 0);
2787 if (fuse_session_exited(se
))
2791 if (err
== ENODEV
) {
2792 fuse_session_exit(se
);
2795 if (err
!= EINTR
&& err
!= EAGAIN
)
2796 perror("fuse: splice from device");
2800 if (res
< sizeof(struct fuse_in_header
)) {
2801 fprintf(stderr
, "short splice from fuse device\n");
2805 tmpbuf
= (struct fuse_buf
) {
2807 .flags
= FUSE_BUF_IS_FD
,
2812 * Don't bother with zero copy for small requests.
2813 * fuse_loop_mt() needs to check for FORGET so this more than
2814 * just an optimization.
2816 if (res
< sizeof(struct fuse_in_header
) +
2817 sizeof(struct fuse_write_in
) + pagesize
) {
2818 struct fuse_bufvec src
= { .buf
[0] = tmpbuf
, .count
= 1 };
2819 struct fuse_bufvec dst
= { .count
= 1 };
2822 buf
->mem
= malloc(f
->bufsize
);
2825 "fuse: failed to allocate read buffer\n");
2829 buf
->size
= f
->bufsize
;
2833 res
= fuse_buf_copy(&dst
, &src
, 0);
2835 fprintf(stderr
, "fuse: copy from pipe: %s\n",
2837 fuse_ll_clear_pipe(f
);
2840 if (res
< tmpbuf
.size
) {
2841 fprintf(stderr
, "fuse: copy from pipe: short read\n");
2842 fuse_ll_clear_pipe(f
);
2845 assert(res
== tmpbuf
.size
);
2848 /* Don't overwrite buf->mem, as that would cause a leak */
2849 buf
->fd
= tmpbuf
.fd
;
2850 buf
->flags
= tmpbuf
.flags
;
2852 buf
->size
= tmpbuf
.size
;
2857 return fuse_chan_recv(se
, buf
, ch
);
2860 int fuse_session_receive_buf(struct fuse_session
*se
, struct fuse_buf
*buf
,
2861 struct fuse_chan
*ch
)
2863 return fuse_chan_recv(se
, buf
, ch
);
2867 #define MIN_BUFSIZE 0x21000
2869 struct fuse_session
*fuse_lowlevel_new(struct fuse_args
*args
,
2870 const struct fuse_lowlevel_ops
*op
,
2871 size_t op_size
, void *userdata
)
2875 struct fuse_session
*se
;
2877 if (sizeof(struct fuse_lowlevel_ops
) < op_size
) {
2878 fprintf(stderr
, "fuse: warning: library too old, some operations may not work\n");
2879 op_size
= sizeof(struct fuse_lowlevel_ops
);
2882 f
= (struct fuse_ll
*) calloc(1, sizeof(struct fuse_ll
));
2884 fprintf(stderr
, "fuse: failed to allocate fuse object\n");
2888 f
->conn
.async_read
= 1;
2889 f
->conn
.max_write
= UINT_MAX
;
2890 f
->conn
.max_readahead
= UINT_MAX
;
2891 f
->atomic_o_trunc
= 0;
2892 f
->bufsize
= getpagesize() + 0x1000;
2893 f
->bufsize
= f
->bufsize
< MIN_BUFSIZE
? MIN_BUFSIZE
: f
->bufsize
;
2895 list_init_req(&f
->list
);
2896 list_init_req(&f
->interrupts
);
2897 list_init_nreq(&f
->notify_list
);
2899 fuse_mutex_init(&f
->lock
);
2901 err
= pthread_key_create(&f
->pipe_key
, fuse_ll_pipe_destructor
);
2903 fprintf(stderr
, "fuse: failed to create thread specific key: %s\n",
2908 if (fuse_opt_parse(args
, f
, fuse_ll_opts
, fuse_ll_opt_proc
) == -1)
2909 goto out_key_destroy
;
2912 fprintf(stderr
, "FUSE library version: %s\n", PACKAGE_VERSION
);
2914 memcpy(&f
->op
, op
, op_size
);
2915 f
->owner
= getuid();
2916 f
->userdata
= userdata
;
2918 se
= fuse_session_new();
2920 goto out_key_destroy
;
2927 pthread_key_delete(f
->pipe_key
);
2929 pthread_mutex_destroy(&f
->lock
);
2936 int fuse_req_getgroups(fuse_req_t req
, int size
, gid_t list
[])
2939 size_t bufsize
= 1024;
2943 unsigned long pid
= req
->ctx
.pid
;
2946 sprintf(path
, "/proc/%lu/task/%lu/status", pid
, pid
);
2949 buf
= malloc(bufsize
);
2954 fd
= open(path
, O_RDONLY
);
2958 ret
= read(fd
, buf
, bufsize
);
2965 if (ret
== bufsize
) {
2972 s
= strstr(buf
, "\nGroups:");
2980 unsigned long val
= strtoul(s
, &end
, 0);
2996 * This is currently not implemented on other than Linux...
2998 int fuse_req_getgroups(fuse_req_t req
, int size
, gid_t list
[])