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
9 #include "fuse_lowlevel.h"
10 #include "fuse_kernel.h"
18 static int fuse_kern_chan_receive(struct fuse_chan
**chp
, char *buf
,
21 struct fuse_chan
*ch
= *chp
;
24 struct fuse_session
*se
= fuse_chan_session(ch
);
28 res
= read(fuse_chan_fd(ch
), buf
, size
);
31 if (fuse_session_exited(se
))
34 /* ENOENT means the operation was interrupted, it's safe
40 fuse_session_exit(se
);
43 /* Errors occurring during normal operation: EINTR (read
44 interrupted), EAGAIN (nonblocking I/O), ENODEV (filesystem
46 if (err
!= EINTR
&& err
!= EAGAIN
)
47 perror("fuse: reading device");
50 if ((size_t) res
< sizeof(struct fuse_in_header
)) {
51 fprintf(stderr
, "short read on fuse device\n");
57 static int fuse_kern_chan_send(struct fuse_chan
*ch
, const struct iovec iov
[],
61 ssize_t res
= writev(fuse_chan_fd(ch
), iov
, count
);
65 struct fuse_session
*se
= fuse_chan_session(ch
);
69 /* ENOENT means the operation was interrupted */
70 if (!fuse_session_exited(se
) && err
!= ENOENT
)
71 perror("fuse: writing device");
78 static void fuse_kern_chan_destroy(struct fuse_chan
*ch
)
80 close(fuse_chan_fd(ch
));
83 #define MIN_BUFSIZE 0x21000
85 struct fuse_chan
*fuse_kern_chan_new(int fd
)
87 struct fuse_chan_ops op
= {
88 .receive
= fuse_kern_chan_receive
,
89 .send
= fuse_kern_chan_send
,
90 .destroy
= fuse_kern_chan_destroy
,
92 size_t bufsize
= getpagesize() + 0x1000;
93 bufsize
= bufsize
< MIN_BUFSIZE
? MIN_BUFSIZE
: bufsize
;
94 return fuse_chan_new(&op
, fd
, bufsize
, NULL
);