14 #include "fuse_config.h" 
   16 #include "fuse_kernel.h" 
   18 #include "fuse_misc.h" 
   19 #include "mount_util.h" 
   31 #ifndef F_LINUX_SPECIFIC_BASE 
   32 #define F_LINUX_SPECIFIC_BASE       1024 
   35 #define F_SETPIPE_SZ    (F_LINUX_SPECIFIC_BASE + 7) 
   39 #define PARAM(inarg) (((char *)(inarg)) + sizeof(*(inarg))) 
   40 #define OFFSET_MAX 0x7fffffffffffffffLL 
   42 #define container_of(ptr, type, member) ({                              \ 
   43                         const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 
   44                         (type *)( (char *)__mptr - offsetof(type,member) );}) 
   46 struct fuse_pollhandle {
 
   48         struct fuse_session *se;
 
   51 static size_t pagesize;
 
   53 static __attribute__((constructor)) 
void fuse_ll_init_pagesize(
void)
 
   55         pagesize = getpagesize();
 
   58 static void convert_stat(
const struct stat *stbuf, 
struct fuse_attr *attr)
 
   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);
 
   77 static void convert_attr(
const struct fuse_setattr_in *attr, 
struct stat *stbuf)
 
   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);
 
   91 static  size_t iov_length(
const struct iovec *iov, 
size_t count)
 
   96         for (seg = 0; seg < count; seg++)
 
   97                 ret += iov[seg].iov_len;
 
  101 static void list_init_req(
struct fuse_req *req)
 
  107 static void list_del_req(
struct fuse_req *req)
 
  109         struct fuse_req *prev = req->prev;
 
  110         struct fuse_req *next = req->next;
 
  115 static void list_add_req(
struct fuse_req *req, 
struct fuse_req *next)
 
  117         struct fuse_req *prev = next->prev;
 
  126         assert(req->ch == NULL);
 
  127         pthread_mutex_destroy(&req->lock);
 
  134         struct fuse_session *se = req->se;
 
  136         pthread_mutex_lock(&se->lock);
 
  137         req->u.ni.func = NULL;
 
  138         req->u.ni.data = NULL;
 
  141         fuse_chan_put(req->ch);
 
  143         pthread_mutex_unlock(&se->lock);
 
  148 static struct fuse_req *fuse_ll_alloc_req(
struct fuse_session *se)
 
  150         struct fuse_req *req;
 
  152         req = (
struct fuse_req *) calloc(1, 
sizeof(
struct fuse_req));
 
  154                 fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate request\n");
 
  159                 pthread_mutex_init(&req->lock, NULL);
 
  166 static int fuse_send_msg(
struct fuse_session *se, 
struct fuse_chan *ch,
 
  167                          struct iovec *iov, 
int count)
 
  169         struct fuse_out_header *out = iov[0].iov_base;
 
  172         out->len = iov_length(iov, count);
 
  174                 if (out->unique == 0) {
 
  175                         fuse_log(FUSE_LOG_DEBUG, 
"NOTIFY: code=%d length=%u\n",
 
  176                                 out->error, out->len);
 
  177                 } 
else if (out->error) {
 
  179                                 "   unique: %llu, error: %i (%s), outsize: %i\n",
 
  180                                 (
unsigned long long) out->unique, out->error,
 
  181                                 strerror(-out->error), out->len);
 
  184                                 "   unique: %llu, success, outsize: %i\n",
 
  185                                 (
unsigned long long) out->unique, out->len);
 
  193                 res = se->io->writev(ch ? ch->fd : se->fd, iov, count,
 
  196                 res = writev(ch ? ch->fd : se->fd, iov, count);
 
  203                         perror(
"fuse: writing device");
 
  211 int fuse_send_reply_iov_nofree(
fuse_req_t req, 
int error, 
struct iovec *iov,
 
  214         struct fuse_out_header out;
 
  216         if (error <= -1000 || error > 0) {
 
  217                 fuse_log(FUSE_LOG_ERR, 
"fuse: bad error value: %i\n",   error);
 
  221         out.unique = req->unique;
 
  224         iov[0].iov_base = &out;
 
  225         iov[0].iov_len = 
sizeof(
struct fuse_out_header);
 
  227         return fuse_send_msg(req->se, req->ch, iov, count);
 
  230 static int send_reply_iov(
fuse_req_t req, 
int error, 
struct iovec *iov,
 
  235         res = fuse_send_reply_iov_nofree(req, error, iov, count);
 
  240 static int send_reply(
fuse_req_t req, 
int error, 
const void *arg,
 
  246                 iov[1].iov_base = (
void *) arg;
 
  247                 iov[1].iov_len = argsize;
 
  250         return send_reply_iov(req, error, iov, count);
 
  256         struct iovec *padded_iov;
 
  258         padded_iov = malloc((count + 1) * 
sizeof(
struct iovec));
 
  259         if (padded_iov == NULL)
 
  262         memcpy(padded_iov + 1, iov, count * 
sizeof(
struct iovec));
 
  265         res = send_reply_iov(req, 0, padded_iov, count);
 
  275                          const char *name, 
const struct stat *stbuf, off_t off)
 
  280         size_t entlen_padded;
 
  281         struct fuse_dirent *dirent;
 
  283         namelen = strlen(name);
 
  284         entlen = FUSE_NAME_OFFSET + namelen;
 
  285         entlen_padded = FUSE_DIRENT_ALIGN(entlen);
 
  287         if ((buf == NULL) || (entlen_padded > bufsize))
 
  288           return entlen_padded;
 
  290         dirent = (
struct fuse_dirent*) buf;
 
  291         dirent->ino = stbuf->st_ino;
 
  293         dirent->namelen = namelen;
 
  294         dirent->type = (stbuf->st_mode & S_IFMT) >> 12;
 
  295         memcpy(dirent->name, name, namelen);
 
  296         memset(dirent->name + namelen, 0, entlen_padded - entlen);
 
  298         return entlen_padded;
 
  301 static void convert_statfs(
const struct statvfs *stbuf,
 
  302                            struct fuse_kstatfs *kstatfs)
 
  304         kstatfs->bsize   = stbuf->f_bsize;
 
  305         kstatfs->frsize  = stbuf->f_frsize;
 
  306         kstatfs->blocks  = stbuf->f_blocks;
 
  307         kstatfs->bfree   = stbuf->f_bfree;
 
  308         kstatfs->bavail  = stbuf->f_bavail;
 
  309         kstatfs->files   = stbuf->f_files;
 
  310         kstatfs->ffree   = stbuf->f_ffree;
 
  311         kstatfs->namelen = stbuf->f_namemax;
 
  314 static int send_reply_ok(
fuse_req_t req, 
const void *arg, 
size_t argsize)
 
  316         return send_reply(req, 0, arg, argsize);
 
  321         return send_reply(req, -err, NULL, 0);
 
  329 static unsigned long calc_timeout_sec(
double t)
 
  331         if (t > (
double) ULONG_MAX)
 
  336                 return (
unsigned long) t;
 
  339 static unsigned int calc_timeout_nsec(
double t)
 
  341         double f = t - (double) calc_timeout_sec(t);
 
  344         else if (f >= 0.999999999)
 
  347                 return (
unsigned int) (f * 1.0e9);
 
  350 static void fill_entry(
struct fuse_entry_out *arg,
 
  353         arg->nodeid = e->
ino;
 
  358         arg->attr_valid_nsec = calc_timeout_nsec(e->
attr_timeout);
 
  359         convert_stat(&e->
attr, &arg->attr);
 
  371         size_t entlen_padded;
 
  373         namelen = strlen(name);
 
  374         entlen = FUSE_NAME_OFFSET_DIRENTPLUS + namelen;
 
  375         entlen_padded = FUSE_DIRENT_ALIGN(entlen);
 
  376         if ((buf == NULL) || (entlen_padded > bufsize))
 
  377           return entlen_padded;
 
  379         struct fuse_direntplus *dp = (
struct fuse_direntplus *) buf;
 
  380         memset(&dp->entry_out, 0, 
sizeof(dp->entry_out));
 
  381         fill_entry(&dp->entry_out, e);
 
  383         struct fuse_dirent *dirent = &dp->dirent;
 
  384         dirent->ino = e->
attr.st_ino;
 
  386         dirent->namelen = namelen;
 
  387         dirent->type = (e->
attr.st_mode & S_IFMT) >> 12;
 
  388         memcpy(dirent->name, name, namelen);
 
  389         memset(dirent->name + namelen, 0, entlen_padded - entlen);
 
  391         return entlen_padded;
 
  394 static void fill_open(
struct fuse_open_out *arg,
 
  399                 arg->open_flags |= FOPEN_DIRECT_IO;
 
  401                 arg->open_flags |= FOPEN_KEEP_CACHE;
 
  403                 arg->open_flags |= FOPEN_CACHE_DIR;
 
  405                 arg->open_flags |= FOPEN_NONSEEKABLE;
 
  407                 arg->open_flags |= FOPEN_NOFLUSH;
 
  409                 arg->open_flags |= FOPEN_PARALLEL_DIRECT_WRITES;
 
  414         struct fuse_entry_out arg;
 
  415         size_t size = req->se->conn.proto_minor < 9 ?
 
  416                 FUSE_COMPAT_ENTRY_OUT_SIZE : 
sizeof(arg);
 
  420         if (!e->
ino && req->se->conn.proto_minor < 4)
 
  423         memset(&arg, 0, 
sizeof(arg));
 
  425         return send_reply_ok(req, &arg, size);
 
  431         char buf[
sizeof(
struct fuse_entry_out) + sizeof(struct fuse_open_out)];
 
  432         size_t entrysize = req->se->conn.proto_minor < 9 ?
 
  433                 FUSE_COMPAT_ENTRY_OUT_SIZE : 
sizeof(
struct fuse_entry_out);
 
  434         struct fuse_entry_out *earg = (
struct fuse_entry_out *) buf;
 
  435         struct fuse_open_out *oarg = (
struct fuse_open_out *) (buf + entrysize);
 
  437         memset(buf, 0, 
sizeof(buf));
 
  440         return send_reply_ok(req, buf,
 
  441                              entrysize + 
sizeof(
struct fuse_open_out));
 
  447         struct fuse_attr_out arg;
 
  448         size_t size = req->se->conn.proto_minor < 9 ?
 
  449                 FUSE_COMPAT_ATTR_OUT_SIZE : 
sizeof(arg);
 
  451         memset(&arg, 0, 
sizeof(arg));
 
  452         arg.attr_valid = calc_timeout_sec(attr_timeout);
 
  453         arg.attr_valid_nsec = calc_timeout_nsec(attr_timeout);
 
  454         convert_stat(attr, &arg.attr);
 
  456         return send_reply_ok(req, &arg, size);
 
  461         return send_reply_ok(req, linkname, strlen(linkname));
 
  466         struct fuse_open_out arg;
 
  468         memset(&arg, 0, 
sizeof(arg));
 
  470         return send_reply_ok(req, &arg, 
sizeof(arg));
 
  475         struct fuse_write_out arg;
 
  477         memset(&arg, 0, 
sizeof(arg));
 
  480         return send_reply_ok(req, &arg, 
sizeof(arg));
 
  485         return send_reply_ok(req, buf, size);
 
  488 static int fuse_send_data_iov_fallback(
struct fuse_session *se,
 
  489                                        struct fuse_chan *ch,
 
  490                                        struct iovec *iov, 
int iov_count,
 
  494         struct fuse_bufvec mem_buf = FUSE_BUFVEC_INIT(len);
 
  499         if (
buf->count == 1 && 
buf->idx == 0 && 
buf->off == 0 &&
 
  504                 iov[iov_count].iov_base = 
buf->buf[0].
mem;
 
  505                 iov[iov_count].iov_len = len;
 
  507                 return fuse_send_msg(se, ch, iov, iov_count);
 
  510         res = posix_memalign(&mbuf, pagesize, len);
 
  514         mem_buf.
buf[0].
mem = mbuf;
 
  522         iov[iov_count].iov_base = mbuf;
 
  523         iov[iov_count].iov_len = len;
 
  525         res = fuse_send_msg(se, ch, iov, iov_count);
 
  531 struct fuse_ll_pipe {
 
  537 static void fuse_ll_pipe_free(
struct fuse_ll_pipe *llp)
 
  545 #if !defined(HAVE_PIPE2) || !defined(O_CLOEXEC) 
  546 static int fuse_pipe(
int fds[2])
 
  553         if (fcntl(fds[0], F_SETFL, O_NONBLOCK) == -1 ||
 
  554             fcntl(fds[1], F_SETFL, O_NONBLOCK) == -1 ||
 
  555             fcntl(fds[0], F_SETFD, FD_CLOEXEC) == -1 ||
 
  556             fcntl(fds[1], F_SETFD, FD_CLOEXEC) == -1) {
 
  564 static int fuse_pipe(
int fds[2])
 
  566         return pipe2(fds, O_CLOEXEC | O_NONBLOCK);
 
  570 static struct fuse_ll_pipe *fuse_ll_get_pipe(
struct fuse_session *se)
 
  572         struct fuse_ll_pipe *llp = pthread_getspecific(se->pipe_key);
 
  576                 llp = malloc(
sizeof(
struct fuse_ll_pipe));
 
  580                 res = fuse_pipe(llp->pipe);
 
  589                 llp->size = pagesize * 16;
 
  592                 pthread_setspecific(se->pipe_key, llp);
 
  599 static void fuse_ll_clear_pipe(
struct fuse_session *se)
 
  601         struct fuse_ll_pipe *llp = pthread_getspecific(se->pipe_key);
 
  603                 pthread_setspecific(se->pipe_key, NULL);
 
  604                 fuse_ll_pipe_free(llp);
 
  608 #if defined(HAVE_SPLICE) && defined(HAVE_VMSPLICE) 
  609 static int read_back(
int fd, 
char *buf, 
size_t len)
 
  613         res = read(fd, buf, len);
 
  615                 fuse_log(FUSE_LOG_ERR, 
"fuse: internal error: failed to read back from pipe: %s\n", strerror(errno));
 
  619                 fuse_log(FUSE_LOG_ERR, 
"fuse: internal error: short read back from pipe: %i from %zi\n", res, len);
 
  625 static int grow_pipe_to_max(
int pipefd)
 
  632         maxfd = open(
"/proc/sys/fs/pipe-max-size", O_RDONLY);
 
  636         res = read(maxfd, buf, 
sizeof(buf) - 1);
 
  648         res = fcntl(pipefd, F_SETPIPE_SZ, max);
 
  654 static int fuse_send_data_iov(
struct fuse_session *se, 
struct fuse_chan *ch,
 
  655                                struct iovec *iov, 
int iov_count,
 
  660         struct fuse_out_header *out = iov[0].iov_base;
 
  661         struct fuse_ll_pipe *llp;
 
  664         size_t total_buf_size;
 
  667         struct fuse_bufvec pipe_buf = FUSE_BUFVEC_INIT(len);
 
  669         if (se->broken_splice_nonblock)
 
  679                         total_buf_size -= 
buf->off;
 
  681         if (total_buf_size < 2 * pagesize)
 
  684         if (se->conn.proto_minor < 14 ||
 
  688         llp = fuse_ll_get_pipe(se);
 
  693         headerlen = iov_length(iov, iov_count);
 
  695         out->len = headerlen + len;
 
  701         pipesize = pagesize * (iov_count + 
buf->count + 1) + out->len;
 
  703         if (llp->size < pipesize) {
 
  705                         res = fcntl(llp->pipe[0], F_SETPIPE_SZ, pipesize);
 
  707                                 res = grow_pipe_to_max(llp->pipe[0]);
 
  715                 if (llp->size < pipesize)
 
  720         res = vmsplice(llp->pipe[1], iov, iov_count, SPLICE_F_NONBLOCK);
 
  724         if (res != headerlen) {
 
  726                 fuse_log(FUSE_LOG_ERR, 
"fuse: short vmsplice to pipe: %u/%zu\n", res,
 
  732         pipe_buf.
buf[0].
fd = llp->pipe[1];
 
  737                 if (res == -EAGAIN || res == -EINVAL) {
 
  749                                 se->broken_splice_nonblock = 1;
 
  751                         pthread_setspecific(se->pipe_key, NULL);
 
  752                         fuse_ll_pipe_free(llp);
 
  759         if (res != 0 && res < len) {
 
  760                 struct fuse_bufvec mem_buf = FUSE_BUFVEC_INIT(len);
 
  762                 size_t now_len = res;
 
  772                 res = posix_memalign(&mbuf, pagesize, len);
 
  776                 mem_buf.
buf[0].
mem = mbuf;
 
  777                 mem_buf.
off = now_len;
 
  781                         size_t extra_len = res;
 
  787                         tmpbuf = malloc(headerlen);
 
  788                         if (tmpbuf == NULL) {
 
  793                         res = read_back(llp->pipe[0], tmpbuf, headerlen);
 
  799                         res = read_back(llp->pipe[0], mbuf, now_len);
 
  804                         len = now_len + extra_len;
 
  805                         iov[iov_count].iov_base = mbuf;
 
  806                         iov[iov_count].iov_len = len;
 
  808                         res = fuse_send_msg(se, ch, iov, iov_count);
 
  816         out->len = headerlen + len;
 
  820                         "   unique: %llu, success, outsize: %i (splice)\n",
 
  821                         (
unsigned long long) out->unique, out->len);
 
  827                 splice_flags |= SPLICE_F_MOVE;
 
  829         if (se->io != NULL && se->io->splice_send != NULL) {
 
  830                 res = se->io->splice_send(llp->pipe[0], NULL,
 
  831                                                   ch ? ch->fd : se->fd, NULL, out->len,
 
  832                                                   splice_flags, se->userdata);
 
  834                 res = splice(llp->pipe[0], NULL, ch ? ch->fd : se->fd, NULL,
 
  835                                out->len, splice_flags);
 
  839                 perror(
"fuse: splice from pipe");
 
  842         if (res != out->len) {
 
  844                 fuse_log(FUSE_LOG_ERR, 
"fuse: short splice from pipe: %u/%u\n",
 
  851         fuse_ll_clear_pipe(se);
 
  855         return fuse_send_data_iov_fallback(se, ch, iov, iov_count, 
buf, len);
 
  858 static int fuse_send_data_iov(
struct fuse_session *se, 
struct fuse_chan *ch,
 
  859                                struct iovec *iov, 
int iov_count,
 
  865         return fuse_send_data_iov_fallback(se, ch, iov, iov_count, 
buf, len);
 
  873         struct fuse_out_header out;
 
  876         iov[0].iov_base = &out;
 
  877         iov[0].iov_len = 
sizeof(
struct fuse_out_header);
 
  879         out.unique = req->unique;
 
  882         res = fuse_send_data_iov(req->se, req->ch, iov, 1, bufv, flags);
 
  893         struct fuse_statfs_out arg;
 
  894         size_t size = req->se->conn.proto_minor < 4 ?
 
  895                 FUSE_COMPAT_STATFS_SIZE : 
sizeof(arg);
 
  897         memset(&arg, 0, 
sizeof(arg));
 
  898         convert_statfs(stbuf, &arg.st);
 
  900         return send_reply_ok(req, &arg, size);
 
  905         struct fuse_getxattr_out arg;
 
  907         memset(&arg, 0, 
sizeof(arg));
 
  910         return send_reply_ok(req, &arg, 
sizeof(arg));
 
  915         struct fuse_lk_out arg;
 
  917         memset(&arg, 0, 
sizeof(arg));
 
  918         arg.lk.type = lock->l_type;
 
  919         if (lock->l_type != F_UNLCK) {
 
  920                 arg.lk.start = lock->l_start;
 
  921                 if (lock->l_len == 0)
 
  922                         arg.lk.end = OFFSET_MAX;
 
  924                         arg.lk.end = lock->l_start + lock->l_len - 1;
 
  926         arg.lk.pid = lock->l_pid;
 
  927         return send_reply_ok(req, &arg, 
sizeof(arg));
 
  932         struct fuse_bmap_out arg;
 
  934         memset(&arg, 0, 
sizeof(arg));
 
  937         return send_reply_ok(req, &arg, 
sizeof(arg));
 
  940 static struct fuse_ioctl_iovec *fuse_ioctl_iovec_copy(
const struct iovec *iov,
 
  943         struct fuse_ioctl_iovec *fiov;
 
  946         fiov = malloc(
sizeof(fiov[0]) * count);
 
  950         for (i = 0; i < count; i++) {
 
  951                 fiov[i].base = (uintptr_t) iov[i].iov_base;
 
  952                 fiov[i].len = iov[i].iov_len;
 
  959                            const struct iovec *in_iov, 
size_t in_count,
 
  960                            const struct iovec *out_iov, 
size_t out_count)
 
  962         struct fuse_ioctl_out arg;
 
  963         struct fuse_ioctl_iovec *in_fiov = NULL;
 
  964         struct fuse_ioctl_iovec *out_fiov = NULL;
 
  969         memset(&arg, 0, 
sizeof(arg));
 
  970         arg.flags |= FUSE_IOCTL_RETRY;
 
  971         arg.in_iovs = in_count;
 
  972         arg.out_iovs = out_count;
 
  973         iov[count].iov_base = &arg;
 
  974         iov[count].iov_len = 
sizeof(arg);
 
  977         if (req->se->conn.proto_minor < 16) {
 
  979                         iov[count].iov_base = (
void *)in_iov;
 
  980                         iov[count].iov_len = 
sizeof(in_iov[0]) * in_count;
 
  985                         iov[count].iov_base = (
void *)out_iov;
 
  986                         iov[count].iov_len = 
sizeof(out_iov[0]) * out_count;
 
  991                 if (
sizeof(
void *) == 4 && req->ioctl_64bit) {
 
  997                         in_fiov = fuse_ioctl_iovec_copy(in_iov, in_count);
 
 1001                         iov[count].iov_base = (
void *)in_fiov;
 
 1002                         iov[count].iov_len = 
sizeof(in_fiov[0]) * in_count;
 
 1006                         out_fiov = fuse_ioctl_iovec_copy(out_iov, out_count);
 
 1010                         iov[count].iov_base = (
void *)out_fiov;
 
 1011                         iov[count].iov_len = 
sizeof(out_fiov[0]) * out_count;
 
 1016         res = send_reply_iov(req, 0, iov, count);
 
 1030         struct fuse_ioctl_out arg;
 
 1031         struct iovec iov[3];
 
 1034         memset(&arg, 0, 
sizeof(arg));
 
 1035         arg.result = result;
 
 1036         iov[count].iov_base = &arg;
 
 1037         iov[count].iov_len = 
sizeof(arg);
 
 1041                 iov[count].iov_base = (
char *) buf;
 
 1042                 iov[count].iov_len = size;
 
 1046         return send_reply_iov(req, 0, iov, count);
 
 1052         struct iovec *padded_iov;
 
 1053         struct fuse_ioctl_out arg;
 
 1056         padded_iov = malloc((count + 2) * 
sizeof(
struct iovec));
 
 1057         if (padded_iov == NULL)
 
 1060         memset(&arg, 0, 
sizeof(arg));
 
 1061         arg.result = result;
 
 1062         padded_iov[1].iov_base = &arg;
 
 1063         padded_iov[1].iov_len = 
sizeof(arg);
 
 1065         memcpy(&padded_iov[2], iov, count * 
sizeof(
struct iovec));
 
 1067         res = send_reply_iov(req, 0, padded_iov, count + 2);
 
 1075         struct fuse_poll_out arg;
 
 1077         memset(&arg, 0, 
sizeof(arg));
 
 1078         arg.revents = revents;
 
 1080         return send_reply_ok(req, &arg, 
sizeof(arg));
 
 1085         struct fuse_lseek_out arg;
 
 1087         memset(&arg, 0, 
sizeof(arg));
 
 1090         return send_reply_ok(req, &arg, 
sizeof(arg));
 
 1095         char *name = (
char *) inarg;
 
 1097         if (req->se->op.lookup)
 
 1098                 req->se->op.lookup(req, nodeid, name);
 
 1105         struct fuse_forget_in *arg = (
struct fuse_forget_in *) inarg;
 
 1107         if (req->se->op.forget)
 
 1108                 req->se->op.forget(req, nodeid, arg->nlookup);
 
 1116         struct fuse_batch_forget_in *arg = (
void *) inarg;
 
 1117         struct fuse_forget_one *param = (
void *) PARAM(arg);
 
 1122         if (req->se->op.forget_multi) {
 
 1123                 req->se->op.forget_multi(req, arg->count,
 
 1124                                      (
struct fuse_forget_data *) param);
 
 1125         } 
else if (req->se->op.forget) {
 
 1126                 for (i = 0; i < arg->count; i++) {
 
 1127                         struct fuse_forget_one *forget = ¶m[i];
 
 1128                         struct fuse_req *dummy_req;
 
 1130                         dummy_req = fuse_ll_alloc_req(req->se);
 
 1131                         if (dummy_req == NULL)
 
 1134                         dummy_req->unique = req->unique;
 
 1135                         dummy_req->ctx = req->ctx;
 
 1136                         dummy_req->ch = NULL;
 
 1138                         req->se->op.forget(dummy_req, forget->nodeid,
 
 1152         if (req->se->conn.proto_minor >= 9) {
 
 1153                 struct fuse_getattr_in *arg = (
struct fuse_getattr_in *) inarg;
 
 1155                 if (arg->getattr_flags & FUSE_GETATTR_FH) {
 
 1156                         memset(&fi, 0, 
sizeof(fi));
 
 1162         if (req->se->op.getattr)
 
 1163                 req->se->op.getattr(req, nodeid, fip);
 
 1170         struct fuse_setattr_in *arg = (
struct fuse_setattr_in *) inarg;
 
 1172         if (req->se->op.setattr) {
 
 1176                 memset(&stbuf, 0, 
sizeof(stbuf));
 
 1177                 convert_attr(arg, &stbuf);
 
 1178                 if (arg->valid & FATTR_FH) {
 
 1179                         arg->valid &= ~FATTR_FH;
 
 1180                         memset(&fi_store, 0, 
sizeof(fi_store));
 
 1185                         FUSE_SET_ATTR_MODE      |
 
 1188                         FUSE_SET_ATTR_SIZE      |
 
 1189                         FUSE_SET_ATTR_ATIME     |
 
 1190                         FUSE_SET_ATTR_MTIME     |
 
 1191                         FUSE_SET_ATTR_KILL_SUID |
 
 1192                         FUSE_SET_ATTR_KILL_SGID |
 
 1193                         FUSE_SET_ATTR_ATIME_NOW |
 
 1194                         FUSE_SET_ATTR_MTIME_NOW |
 
 1195                         FUSE_SET_ATTR_CTIME;
 
 1197                 req->se->op.setattr(req, nodeid, &stbuf, arg->valid, fi);
 
 1204         struct fuse_access_in *arg = (
struct fuse_access_in *) inarg;
 
 1206         if (req->se->op.access)
 
 1207                 req->se->op.access(req, nodeid, arg->mask);
 
 1216         if (req->se->op.readlink)
 
 1217                 req->se->op.readlink(req, nodeid);
 
 1224         struct fuse_mknod_in *arg = (
struct fuse_mknod_in *) inarg;
 
 1225         char *name = PARAM(arg);
 
 1227         if (req->se->conn.proto_minor >= 12)
 
 1228                 req->ctx.umask = arg->umask;
 
 1230                 name = (
char *) inarg + FUSE_COMPAT_MKNOD_IN_SIZE;
 
 1232         if (req->se->op.mknod)
 
 1233                 req->se->op.mknod(req, nodeid, name, arg->mode, arg->rdev);
 
 1240         struct fuse_mkdir_in *arg = (
struct fuse_mkdir_in *) inarg;
 
 1242         if (req->se->conn.proto_minor >= 12)
 
 1243                 req->ctx.umask = arg->umask;
 
 1245         if (req->se->op.mkdir)
 
 1246                 req->se->op.mkdir(req, nodeid, PARAM(arg), arg->mode);
 
 1253         char *name = (
char *) inarg;
 
 1255         if (req->se->op.unlink)
 
 1256                 req->se->op.unlink(req, nodeid, name);
 
 1263         char *name = (
char *) inarg;
 
 1265         if (req->se->op.rmdir)
 
 1266                 req->se->op.rmdir(req, nodeid, name);
 
 1273         char *name = (
char *) inarg;
 
 1274         char *linkname = ((
char *) inarg) + strlen((
char *) inarg) + 1;
 
 1276         if (req->se->op.symlink)
 
 1277                 req->se->op.symlink(req, linkname, nodeid, name);
 
 1284         struct fuse_rename_in *arg = (
struct fuse_rename_in *) inarg;
 
 1285         char *oldname = PARAM(arg);
 
 1286         char *newname = oldname + strlen(oldname) + 1;
 
 1288         if (req->se->op.rename)
 
 1289                 req->se->op.rename(req, nodeid, oldname, arg->newdir, newname,
 
 1297         struct fuse_rename2_in *arg = (
struct fuse_rename2_in *) inarg;
 
 1298         char *oldname = PARAM(arg);
 
 1299         char *newname = oldname + strlen(oldname) + 1;
 
 1301         if (req->se->op.rename)
 
 1302                 req->se->op.rename(req, nodeid, oldname, arg->newdir, newname,
 
 1310         struct fuse_link_in *arg = (
struct fuse_link_in *) inarg;
 
 1312         if (req->se->op.link)
 
 1313                 req->se->op.link(req, arg->oldnodeid, nodeid, PARAM(arg));
 
 1320         struct fuse_create_in *arg = (
struct fuse_create_in *) inarg;
 
 1322         if (req->se->op.create) {
 
 1324                 char *name = PARAM(arg);
 
 1326                 memset(&fi, 0, 
sizeof(fi));
 
 1327                 fi.
flags = arg->flags;
 
 1329                 if (req->se->conn.proto_minor >= 12)
 
 1330                         req->ctx.umask = arg->umask;
 
 1332                         name = (
char *) inarg + 
sizeof(
struct fuse_open_in);
 
 1334                 req->se->op.create(req, nodeid, name, arg->mode, &fi);
 
 1341         struct fuse_open_in *arg = (
struct fuse_open_in *) inarg;
 
 1344         memset(&fi, 0, 
sizeof(fi));
 
 1345         fi.
flags = arg->flags;
 
 1347         if (req->se->op.open)
 
 1348                 req->se->op.open(req, nodeid, &fi);
 
 1355         struct fuse_read_in *arg = (
struct fuse_read_in *) inarg;
 
 1357         if (req->se->op.read) {
 
 1360                 memset(&fi, 0, 
sizeof(fi));
 
 1362                 if (req->se->conn.proto_minor >= 9) {
 
 1364                         fi.
flags = arg->flags;
 
 1366                 req->se->op.read(req, nodeid, arg->size, arg->offset, &fi);
 
 1373         struct fuse_write_in *arg = (
struct fuse_write_in *) inarg;
 
 1377         memset(&fi, 0, 
sizeof(fi));
 
 1379         fi.
writepage = (arg->write_flags & FUSE_WRITE_CACHE) != 0;
 
 1381         if (req->se->conn.proto_minor < 9) {
 
 1382                 param = ((
char *) arg) + FUSE_COMPAT_WRITE_IN_SIZE;
 
 1385                 fi.
flags = arg->flags;
 
 1389         if (req->se->op.write)
 
 1390                 req->se->op.write(req, nodeid, param, arg->size,
 
 1399         struct fuse_session *se = req->se;
 
 1404         struct fuse_write_in *arg = (
struct fuse_write_in *) inarg;
 
 1407         memset(&fi, 0, 
sizeof(fi));
 
 1409         fi.
writepage = arg->write_flags & FUSE_WRITE_CACHE;
 
 1411         if (se->conn.proto_minor < 9) {
 
 1412                 bufv.
buf[0].
mem = ((
char *) arg) + FUSE_COMPAT_WRITE_IN_SIZE;
 
 1413                 bufv.
buf[0].
size -= 
sizeof(
struct fuse_in_header) +
 
 1414                         FUSE_COMPAT_WRITE_IN_SIZE;
 
 1418                 fi.
flags = arg->flags;
 
 1420                         bufv.
buf[0].
mem = PARAM(arg);
 
 1422                 bufv.
buf[0].
size -= 
sizeof(
struct fuse_in_header) +
 
 1423                         sizeof(struct fuse_write_in);
 
 1425         if (bufv.
buf[0].
size < arg->size) {
 
 1426                 fuse_log(FUSE_LOG_ERR, 
"fuse: do_write_buf: buffer size too small\n");
 
 1432         se->op.write_buf(req, nodeid, &bufv, arg->offset, &fi);
 
 1437                 fuse_ll_clear_pipe(se);
 
 1442         struct fuse_flush_in *arg = (
struct fuse_flush_in *) inarg;
 
 1445         memset(&fi, 0, 
sizeof(fi));
 
 1448         if (req->se->conn.proto_minor >= 7)
 
 1451         if (req->se->op.flush)
 
 1452                 req->se->op.flush(req, nodeid, &fi);
 
 1459         struct fuse_release_in *arg = (
struct fuse_release_in *) inarg;
 
 1462         memset(&fi, 0, 
sizeof(fi));
 
 1463         fi.
flags = arg->flags;
 
 1465         if (req->se->conn.proto_minor >= 8) {
 
 1466                 fi.
flush = (arg->release_flags & FUSE_RELEASE_FLUSH) ? 1 : 0;
 
 1469         if (arg->release_flags & FUSE_RELEASE_FLOCK_UNLOCK) {
 
 1470                 fi.flock_release = 1;
 
 1474         if (req->se->op.release)
 
 1475                 req->se->op.release(req, nodeid, &fi);
 
 1482         struct fuse_fsync_in *arg = (
struct fuse_fsync_in *) inarg;
 
 1484         int datasync = arg->fsync_flags & 1;
 
 1486         memset(&fi, 0, 
sizeof(fi));
 
 1489         if (req->se->op.fsync)
 
 1490                 req->se->op.fsync(req, nodeid, datasync, &fi);
 
 1497         struct fuse_open_in *arg = (
struct fuse_open_in *) inarg;
 
 1500         memset(&fi, 0, 
sizeof(fi));
 
 1501         fi.
flags = arg->flags;
 
 1503         if (req->se->op.opendir)
 
 1504                 req->se->op.opendir(req, nodeid, &fi);
 
 1511         struct fuse_read_in *arg = (
struct fuse_read_in *) inarg;
 
 1514         memset(&fi, 0, 
sizeof(fi));
 
 1517         if (req->se->op.readdir)
 
 1518                 req->se->op.readdir(req, nodeid, arg->size, arg->offset, &fi);
 
 1525         struct fuse_read_in *arg = (
struct fuse_read_in *) inarg;
 
 1528         memset(&fi, 0, 
sizeof(fi));
 
 1531         if (req->se->op.readdirplus)
 
 1532                 req->se->op.readdirplus(req, nodeid, arg->size, arg->offset, &fi);
 
 1539         struct fuse_release_in *arg = (
struct fuse_release_in *) inarg;
 
 1542         memset(&fi, 0, 
sizeof(fi));
 
 1543         fi.
flags = arg->flags;
 
 1546         if (req->se->op.releasedir)
 
 1547                 req->se->op.releasedir(req, nodeid, &fi);
 
 1554         struct fuse_fsync_in *arg = (
struct fuse_fsync_in *) inarg;
 
 1556         int datasync = arg->fsync_flags & 1;
 
 1558         memset(&fi, 0, 
sizeof(fi));
 
 1561         if (req->se->op.fsyncdir)
 
 1562                 req->se->op.fsyncdir(req, nodeid, datasync, &fi);
 
 1572         if (req->se->op.statfs)
 
 1573                 req->se->op.statfs(req, nodeid);
 
 1575                 struct statvfs buf = {
 
 1585         struct fuse_session *se = req->se;
 
 1587         struct fuse_setxattr_in *arg = (
struct fuse_setxattr_in *) inarg;
 
 1588         char *name = xattr_ext ? PARAM(arg) :
 
 1589                      (char *)arg + FUSE_COMPAT_SETXATTR_IN_SIZE;
 
 1590         char *value = name + strlen(name) + 1;
 
 1593         if (req->se->op.setxattr)
 
 1594                 req->se->op.setxattr(req, nodeid, name, value, arg->size,
 
 1602         struct fuse_getxattr_in *arg = (
struct fuse_getxattr_in *) inarg;
 
 1604         if (req->se->op.getxattr)
 
 1605                 req->se->op.getxattr(req, nodeid, PARAM(arg), arg->size);
 
 1612         struct fuse_getxattr_in *arg = (
struct fuse_getxattr_in *) inarg;
 
 1614         if (req->se->op.listxattr)
 
 1615                 req->se->op.listxattr(req, nodeid, arg->size);
 
 1622         char *name = (
char *) inarg;
 
 1624         if (req->se->op.removexattr)
 
 1625                 req->se->op.removexattr(req, nodeid, name);
 
 1630 static void convert_fuse_file_lock(
struct fuse_file_lock *fl,
 
 1631                                    struct flock *flock)
 
 1633         memset(flock, 0, 
sizeof(
struct flock));
 
 1634         flock->l_type = fl->type;
 
 1635         flock->l_whence = SEEK_SET;
 
 1636         flock->l_start = fl->start;
 
 1637         if (fl->end == OFFSET_MAX)
 
 1640                 flock->l_len = fl->end - fl->start + 1;
 
 1641         flock->l_pid = fl->pid;
 
 1646         struct fuse_lk_in *arg = (
struct fuse_lk_in *) inarg;
 
 1650         memset(&fi, 0, 
sizeof(fi));
 
 1654         convert_fuse_file_lock(&arg->lk, &flock);
 
 1655         if (req->se->op.getlk)
 
 1656                 req->se->op.getlk(req, nodeid, &fi, &flock);
 
 1662                             const void *inarg, 
int sleep)
 
 1664         struct fuse_lk_in *arg = (
struct fuse_lk_in *) inarg;
 
 1668         memset(&fi, 0, 
sizeof(fi));
 
 1672         if (arg->lk_flags & FUSE_LK_FLOCK) {
 
 1675                 switch (arg->lk.type) {
 
 1689                 if (req->se->op.flock)
 
 1690                         req->se->op.flock(req, nodeid, &fi, op);
 
 1694                 convert_fuse_file_lock(&arg->lk, &flock);
 
 1695                 if (req->se->op.setlk)
 
 1696                         req->se->op.setlk(req, nodeid, &fi, &flock, sleep);
 
 1704         do_setlk_common(req, nodeid, inarg, 0);
 
 1709         do_setlk_common(req, nodeid, inarg, 1);
 
 1712 static int find_interrupted(
struct fuse_session *se, 
struct fuse_req *req)
 
 1714         struct fuse_req *curr;
 
 1716         for (curr = se->list.next; curr != &se->list; curr = curr->next) {
 
 1717                 if (curr->unique == req->u.i.unique) {
 
 1722                         pthread_mutex_unlock(&se->lock);
 
 1725                         pthread_mutex_lock(&curr->lock);
 
 1726                         pthread_mutex_lock(&se->lock);
 
 1727                         curr->interrupted = 1;
 
 1728                         func = curr->u.ni.func;
 
 1729                         data = curr->u.ni.data;
 
 1730                         pthread_mutex_unlock(&se->lock);
 
 1733                         pthread_mutex_unlock(&curr->lock);
 
 1735                         pthread_mutex_lock(&se->lock);
 
 1738                                 fuse_chan_put(req->ch);
 
 1746         for (curr = se->interrupts.next; curr != &se->interrupts;
 
 1747              curr = curr->next) {
 
 1748                 if (curr->u.i.unique == req->u.i.unique)
 
 1756         struct fuse_interrupt_in *arg = (
struct fuse_interrupt_in *) inarg;
 
 1757         struct fuse_session *se = req->se;
 
 1761                 fuse_log(FUSE_LOG_DEBUG, 
"INTERRUPT: %llu\n",
 
 1762                         (
unsigned long long) arg->unique);
 
 1764         req->u.i.unique = arg->unique;
 
 1766         pthread_mutex_lock(&se->lock);
 
 1767         if (find_interrupted(se, req)) {
 
 1768                 fuse_chan_put(req->ch);
 
 1772                 list_add_req(req, &se->interrupts);
 
 1773         pthread_mutex_unlock(&se->lock);
 
 1776 static struct fuse_req *check_interrupt(
struct fuse_session *se,
 
 1777                                         struct fuse_req *req)
 
 1779         struct fuse_req *curr;
 
 1781         for (curr = se->interrupts.next; curr != &se->interrupts;
 
 1782              curr = curr->next) {
 
 1783                 if (curr->u.i.unique == req->unique) {
 
 1784                         req->interrupted = 1;
 
 1786                         fuse_chan_put(curr->ch);
 
 1792         curr = se->interrupts.next;
 
 1793         if (curr != &se->interrupts) {
 
 1795                 list_init_req(curr);
 
 1803         struct fuse_bmap_in *arg = (
struct fuse_bmap_in *) inarg;
 
 1805         if (req->se->op.bmap)
 
 1806                 req->se->op.bmap(req, nodeid, arg->blocksize, arg->block);
 
 1813         struct fuse_ioctl_in *arg = (
struct fuse_ioctl_in *) inarg;
 
 1814         unsigned int flags = arg->flags;
 
 1815         void *in_buf = arg->in_size ? PARAM(arg) : NULL;
 
 1818         if (
flags & FUSE_IOCTL_DIR &&
 
 1824         memset(&fi, 0, 
sizeof(fi));
 
 1827         if (
sizeof(
void *) == 4 && req->se->conn.proto_minor >= 16 &&
 
 1828             !(
flags & FUSE_IOCTL_32BIT)) {
 
 1829                 req->ioctl_64bit = 1;
 
 1832         if (req->se->op.ioctl)
 
 1833                 req->se->op.ioctl(req, nodeid, arg->cmd,
 
 1834                                  (
void *)(uintptr_t)arg->arg, &fi, 
flags,
 
 1835                                  in_buf, arg->in_size, arg->out_size);
 
 1847         struct fuse_poll_in *arg = (
struct fuse_poll_in *) inarg;
 
 1850         memset(&fi, 0, 
sizeof(fi));
 
 1854         if (req->se->op.poll) {
 
 1855                 struct fuse_pollhandle *ph = NULL;
 
 1857                 if (arg->flags & FUSE_POLL_SCHEDULE_NOTIFY) {
 
 1858                         ph = malloc(
sizeof(
struct fuse_pollhandle));
 
 1867                 req->se->op.poll(req, nodeid, &fi, ph);
 
 1875         struct fuse_fallocate_in *arg = (
struct fuse_fallocate_in *) inarg;
 
 1878         memset(&fi, 0, 
sizeof(fi));
 
 1881         if (req->se->op.fallocate)
 
 1882                 req->se->op.fallocate(req, nodeid, arg->mode, arg->offset, arg->length, &fi);
 
 1889         struct fuse_copy_file_range_in *arg = (
struct fuse_copy_file_range_in *) inarg;
 
 1892         memset(&fi_in, 0, 
sizeof(fi_in));
 
 1893         fi_in.fh = arg->fh_in;
 
 1895         memset(&fi_out, 0, 
sizeof(fi_out));
 
 1896         fi_out.fh = arg->fh_out;
 
 1899         if (req->se->op.copy_file_range)
 
 1900                 req->se->op.copy_file_range(req, nodeid_in, arg->off_in,
 
 1901                                             &fi_in, arg->nodeid_out,
 
 1902                                             arg->off_out, &fi_out, arg->len,
 
 1910         struct fuse_lseek_in *arg = (
struct fuse_lseek_in *) inarg;
 
 1913         memset(&fi, 0, 
sizeof(fi));
 
 1916         if (req->se->op.lseek)
 
 1917                 req->se->op.lseek(req, nodeid, arg->offset, arg->whence, &fi);
 
 1924 static __attribute__((no_sanitize(
"thread")))
 
 1927         struct fuse_init_in *arg = (
struct fuse_init_in *) inarg;
 
 1928         struct fuse_init_out outarg;
 
 1929         struct fuse_session *se = req->se;
 
 1930         size_t bufsize = se->bufsize;
 
 1931         size_t outargsize = 
sizeof(outarg);
 
 1932         uint64_t inargflags = 0;
 
 1933         uint64_t outargflags = 0;
 
 1936                 fuse_log(FUSE_LOG_DEBUG, 
"INIT: %u.%u\n", arg->major, arg->minor);
 
 1937                 if (arg->major == 7 && arg->minor >= 6) {
 
 1938                         fuse_log(FUSE_LOG_DEBUG, 
"flags=0x%08x\n", arg->flags);
 
 1939                         fuse_log(FUSE_LOG_DEBUG, 
"max_readahead=0x%08x\n",
 
 1940                                 arg->max_readahead);
 
 1943         se->conn.proto_major = arg->major;
 
 1944         se->conn.proto_minor = arg->minor;
 
 1945         se->conn.capable = 0;
 
 1948         memset(&outarg, 0, 
sizeof(outarg));
 
 1949         outarg.major = FUSE_KERNEL_VERSION;
 
 1950         outarg.minor = FUSE_KERNEL_MINOR_VERSION;
 
 1952         if (arg->major < 7) {
 
 1953                 fuse_log(FUSE_LOG_ERR, 
"fuse: unsupported protocol version: %u.%u\n",
 
 1954                         arg->major, arg->minor);
 
 1959         if (arg->major > 7) {
 
 1961                 send_reply_ok(req, &outarg, 
sizeof(outarg));
 
 1965         if (arg->minor >= 6) {
 
 1966                 if (arg->max_readahead < se->conn.max_readahead)
 
 1967                         se->conn.max_readahead = arg->max_readahead;
 
 1968                 inargflags = arg->flags;
 
 1969                 if (inargflags & FUSE_INIT_EXT)
 
 1970                         inargflags = inargflags | (uint64_t) arg->flags2 << 32;
 
 1971                 if (inargflags & FUSE_ASYNC_READ)
 
 1973                 if (inargflags & FUSE_POSIX_LOCKS)
 
 1975                 if (inargflags & FUSE_ATOMIC_O_TRUNC)
 
 1977                 if (inargflags & FUSE_EXPORT_SUPPORT)
 
 1979                 if (inargflags & FUSE_DONT_MASK)
 
 1981                 if (inargflags & FUSE_FLOCK_LOCKS)
 
 1983                 if (inargflags & FUSE_AUTO_INVAL_DATA)
 
 1985                 if (inargflags & FUSE_DO_READDIRPLUS)
 
 1987                 if (inargflags & FUSE_READDIRPLUS_AUTO)
 
 1989                 if (inargflags & FUSE_ASYNC_DIO)
 
 1991                 if (inargflags & FUSE_WRITEBACK_CACHE)
 
 1993                 if (inargflags & FUSE_NO_OPEN_SUPPORT)
 
 1995                 if (inargflags & FUSE_PARALLEL_DIROPS)
 
 1997                 if (inargflags & FUSE_POSIX_ACL)
 
 1999                 if (inargflags & FUSE_HANDLE_KILLPRIV)
 
 2001                 if (inargflags & FUSE_CACHE_SYMLINKS)
 
 2003                 if (inargflags & FUSE_NO_OPENDIR_SUPPORT)
 
 2005                 if (inargflags & FUSE_EXPLICIT_INVAL_DATA)
 
 2007                 if (inargflags & FUSE_SETXATTR_EXT)
 
 2009                 if (!(inargflags & FUSE_MAX_PAGES)) {
 
 2010                         size_t max_bufsize =
 
 2011                                 FUSE_DEFAULT_MAX_PAGES_PER_REQ * getpagesize()
 
 2012                                 + FUSE_BUFFER_HEADER_SIZE;
 
 2013                         if (bufsize > max_bufsize) {
 
 2014                                 bufsize = max_bufsize;
 
 2017                 if (arg->minor >= 38)
 
 2020                 se->conn.max_readahead = 0;
 
 2023         if (se->conn.proto_minor >= 14) {
 
 2025 #ifdef HAVE_VMSPLICE 
 2026                 if ((se->io == NULL) || (se->io->splice_send != NULL)) {
 
 2030                 if ((se->io == NULL) || (se->io->splice_receive != NULL)) {
 
 2035         if (se->conn.proto_minor >= 18)
 
 2045 #define LL_SET_DEFAULT(cond, cap) \ 
 2046         if ((cond) && (se->conn.capable & (cap))) \ 
 2047                 se->conn.want |= (cap) 
 2056         LL_SET_DEFAULT(se->op.getlk && se->op.setlk,
 
 2060         LL_SET_DEFAULT(se->op.readdirplus && se->op.readdir,
 
 2068         se->conn.time_gran = 1;
 
 2070         if (bufsize < FUSE_MIN_READ_BUFFER) {
 
 2071                 fuse_log(FUSE_LOG_ERR, 
"fuse: warning: buffer size too small: %zu\n",
 
 2073                 bufsize = FUSE_MIN_READ_BUFFER;
 
 2075         se->bufsize = bufsize;
 
 2077         if (se->conn.max_write > bufsize - FUSE_BUFFER_HEADER_SIZE)
 
 2078                 se->conn.max_write = bufsize - FUSE_BUFFER_HEADER_SIZE;
 
 2082                 se->op.init(se->userdata, &se->conn);
 
 2084         if (se->conn.want & (~se->conn.capable)) {
 
 2085                 fuse_log(FUSE_LOG_ERR, 
"fuse: error: filesystem requested capabilities " 
 2086                         "0x%x that are not supported by kernel, aborting.\n",
 
 2087                         se->conn.want & (~se->conn.capable));
 
 2089                 se->error = -EPROTO;
 
 2094         unsigned max_read_mo = get_max_read(se->mo);
 
 2095         if (se->conn.max_read != max_read_mo) {
 
 2096                 fuse_log(FUSE_LOG_ERR, 
"fuse: error: init() and fuse_session_new() " 
 2097                         "requested different maximum read size (%u vs %u)\n",
 
 2098                         se->conn.max_read, max_read_mo);
 
 2100                 se->error = -EPROTO;
 
 2105         if (se->conn.max_write < bufsize - FUSE_BUFFER_HEADER_SIZE) {
 
 2106                 se->bufsize = se->conn.max_write + FUSE_BUFFER_HEADER_SIZE;
 
 2108         if (arg->flags & FUSE_MAX_PAGES) {
 
 2109                 outarg.flags |= FUSE_MAX_PAGES;
 
 2110                 outarg.max_pages = (se->conn.max_write - 1) / getpagesize() + 1;
 
 2112         outargflags = outarg.flags;
 
 2115         outargflags |= FUSE_BIG_WRITES;
 
 2118                 outargflags |= FUSE_ASYNC_READ;
 
 2120                 outargflags |= FUSE_POSIX_LOCKS;
 
 2122                 outargflags |= FUSE_ATOMIC_O_TRUNC;
 
 2124                 outargflags |= FUSE_EXPORT_SUPPORT;
 
 2126                 outargflags |= FUSE_DONT_MASK;
 
 2128                 outargflags |= FUSE_FLOCK_LOCKS;
 
 2130                 outargflags |= FUSE_AUTO_INVAL_DATA;
 
 2132                 outargflags |= FUSE_DO_READDIRPLUS;
 
 2134                 outargflags |= FUSE_READDIRPLUS_AUTO;
 
 2136                 outargflags |= FUSE_ASYNC_DIO;
 
 2138                 outargflags |= FUSE_WRITEBACK_CACHE;
 
 2140                 outargflags |= FUSE_POSIX_ACL;
 
 2142                 outargflags |= FUSE_CACHE_SYMLINKS;
 
 2144                 outargflags |= FUSE_EXPLICIT_INVAL_DATA;
 
 2146                 outargflags |= FUSE_SETXATTR_EXT;
 
 2148         if (inargflags & FUSE_INIT_EXT) {
 
 2149                 outargflags |= FUSE_INIT_EXT;
 
 2150                 outarg.flags2 = outargflags >> 32;
 
 2153         outarg.flags = outargflags;
 
 2155         outarg.max_readahead = se->conn.max_readahead;
 
 2156         outarg.max_write = se->conn.max_write;
 
 2157         if (se->conn.proto_minor >= 13) {
 
 2158                 if (se->conn.max_background >= (1 << 16))
 
 2159                         se->conn.max_background = (1 << 16) - 1;
 
 2160                 if (se->conn.congestion_threshold > se->conn.max_background)
 
 2161                         se->conn.congestion_threshold = se->conn.max_background;
 
 2162                 if (!se->conn.congestion_threshold) {
 
 2163                         se->conn.congestion_threshold =
 
 2164                                 se->conn.max_background * 3 / 4;
 
 2167                 outarg.max_background = se->conn.max_background;
 
 2168                 outarg.congestion_threshold = se->conn.congestion_threshold;
 
 2170         if (se->conn.proto_minor >= 23)
 
 2171                 outarg.time_gran = se->conn.time_gran;
 
 2174                 fuse_log(FUSE_LOG_DEBUG, 
"   INIT: %u.%u\n", outarg.major, outarg.minor);
 
 2175                 fuse_log(FUSE_LOG_DEBUG, 
"   flags=0x%08x\n", outarg.flags);
 
 2176                 fuse_log(FUSE_LOG_DEBUG, 
"   max_readahead=0x%08x\n",
 
 2177                         outarg.max_readahead);
 
 2178                 fuse_log(FUSE_LOG_DEBUG, 
"   max_write=0x%08x\n", outarg.max_write);
 
 2179                 fuse_log(FUSE_LOG_DEBUG, 
"   max_background=%i\n",
 
 2180                         outarg.max_background);
 
 2181                 fuse_log(FUSE_LOG_DEBUG, 
"   congestion_threshold=%i\n",
 
 2182                         outarg.congestion_threshold);
 
 2183                 fuse_log(FUSE_LOG_DEBUG, 
"   time_gran=%u\n",
 
 2187                 outargsize = FUSE_COMPAT_INIT_OUT_SIZE;
 
 2188         else if (arg->minor < 23)
 
 2189                 outargsize = FUSE_COMPAT_22_INIT_OUT_SIZE;
 
 2191         send_reply_ok(req, &outarg, outargsize);
 
 2196         struct fuse_session *se = req->se;
 
 2201         se->got_destroy = 1;
 
 2203                 se->op.destroy(se->userdata);
 
 2205         send_reply_ok(req, NULL, 0);
 
 2208 static void list_del_nreq(
struct fuse_notify_req *nreq)
 
 2210         struct fuse_notify_req *prev = nreq->prev;
 
 2211         struct fuse_notify_req *next = nreq->next;
 
 2216 static void list_add_nreq(
struct fuse_notify_req *nreq,
 
 2217                           struct fuse_notify_req *next)
 
 2219         struct fuse_notify_req *prev = next->prev;
 
 2226 static void list_init_nreq(
struct fuse_notify_req *nreq)
 
 2233                             const void *inarg, 
const struct fuse_buf *buf)
 
 2235         struct fuse_session *se = req->se;
 
 2236         struct fuse_notify_req *nreq;
 
 2237         struct fuse_notify_req *head;
 
 2239         pthread_mutex_lock(&se->lock);
 
 2240         head = &se->notify_list;
 
 2241         for (nreq = head->next; nreq != head; nreq = nreq->next) {
 
 2242                 if (nreq->unique == req->unique) {
 
 2243                         list_del_nreq(nreq);
 
 2247         pthread_mutex_unlock(&se->lock);
 
 2250                 nreq->reply(nreq, req, nodeid, inarg, buf);
 
 2253 static int send_notify_iov(
struct fuse_session *se, 
int notify_code,
 
 2254                            struct iovec *iov, 
int count)
 
 2256         struct fuse_out_header out;
 
 2262         out.error = notify_code;
 
 2263         iov[0].iov_base = &out;
 
 2264         iov[0].iov_len = 
sizeof(
struct fuse_out_header);
 
 2266         return fuse_send_msg(se, NULL, iov, count);
 
 2272                 struct fuse_notify_poll_wakeup_out outarg;
 
 2273                 struct iovec iov[2];
 
 2277                 iov[1].iov_base = &outarg;
 
 2278                 iov[1].iov_len = 
sizeof(outarg);
 
 2280                 return send_notify_iov(ph->se, FUSE_NOTIFY_POLL, iov, 2);
 
 2287                                      off_t off, off_t len)
 
 2289         struct fuse_notify_inval_inode_out outarg;
 
 2290         struct iovec iov[2];
 
 2295         if (se->conn.proto_minor < 12)
 
 2302         iov[1].iov_base = &outarg;
 
 2303         iov[1].iov_len = 
sizeof(outarg);
 
 2305         return send_notify_iov(se, FUSE_NOTIFY_INVAL_INODE, iov, 2);
 
 2309                                       const char *name, 
size_t namelen,
 
 2312         struct fuse_notify_inval_entry_out outarg;
 
 2313         struct iovec iov[3];
 
 2318         if (se->conn.proto_minor < 12)
 
 2321         outarg.parent = parent;
 
 2322         outarg.namelen = namelen;
 
 2324         if (flags & FUSE_LL_EXPIRE_ONLY)
 
 2325                 outarg.flags |= FUSE_EXPIRE_ONLY;
 
 2327         iov[1].iov_base = &outarg;
 
 2328         iov[1].iov_len = 
sizeof(outarg);
 
 2329         iov[2].iov_base = (
void *)name;
 
 2330         iov[2].iov_len = namelen + 1;
 
 2332         return send_notify_iov(se, FUSE_NOTIFY_INVAL_ENTRY, iov, 3);
 
 2336                                      const char *name, 
size_t namelen)
 
 2344                                 const char *name, 
size_t namelen)
 
 2346         struct fuse_notify_delete_out outarg;
 
 2347         struct iovec iov[3];
 
 2352         if (se->conn.proto_minor < 18)
 
 2355         outarg.parent = parent;
 
 2356         outarg.child = child;
 
 2357         outarg.namelen = namelen;
 
 2360         iov[1].iov_base = &outarg;
 
 2361         iov[1].iov_len = 
sizeof(outarg);
 
 2362         iov[2].iov_base = (
void *)name;
 
 2363         iov[2].iov_len = namelen + 1;
 
 2365         return send_notify_iov(se, FUSE_NOTIFY_DELETE, iov, 3);
 
 2372         struct fuse_out_header out;
 
 2373         struct fuse_notify_store_out outarg;
 
 2374         struct iovec iov[3];
 
 2381         if (se->conn.proto_minor < 15)
 
 2385         out.error = FUSE_NOTIFY_STORE;
 
 2387         outarg.nodeid = ino;
 
 2388         outarg.offset = offset;
 
 2392         iov[0].iov_base = &out;
 
 2393         iov[0].iov_len = 
sizeof(out);
 
 2394         iov[1].iov_base = &outarg;
 
 2395         iov[1].iov_len = 
sizeof(outarg);
 
 2397         res = fuse_send_data_iov(se, NULL, iov, 2, bufv, flags);
 
 2404 struct fuse_retrieve_req {
 
 2405         struct fuse_notify_req nreq;
 
 2409 static void fuse_ll_retrieve_reply(
struct fuse_notify_req *nreq,
 
 2414         struct fuse_session *se = req->se;
 
 2415         struct fuse_retrieve_req *rreq =
 
 2416                 container_of(nreq, 
struct fuse_retrieve_req, nreq);
 
 2417         const struct fuse_notify_retrieve_in *arg = inarg;
 
 2424                 bufv.
buf[0].
mem = PARAM(arg);
 
 2426         bufv.
buf[0].
size -= 
sizeof(
struct fuse_in_header) +
 
 2427                 sizeof(struct fuse_notify_retrieve_in);
 
 2429         if (bufv.
buf[0].
size < arg->size) {
 
 2430                 fuse_log(FUSE_LOG_ERR, 
"fuse: retrieve reply: buffer size too small\n");
 
 2436         if (se->op.retrieve_reply) {
 
 2437                 se->op.retrieve_reply(req, rreq->cookie, ino,
 
 2438                                           arg->offset, &bufv);
 
 2445                 fuse_ll_clear_pipe(se);
 
 2449                                   size_t size, off_t offset, 
void *cookie)
 
 2451         struct fuse_notify_retrieve_out outarg;
 
 2452         struct iovec iov[2];
 
 2453         struct fuse_retrieve_req *rreq;
 
 2459         if (se->conn.proto_minor < 15)
 
 2462         rreq = malloc(
sizeof(*rreq));
 
 2466         pthread_mutex_lock(&se->lock);
 
 2467         rreq->cookie = cookie;
 
 2468         rreq->nreq.unique = se->notify_ctr++;
 
 2469         rreq->nreq.reply = fuse_ll_retrieve_reply;
 
 2470         list_add_nreq(&rreq->nreq, &se->notify_list);
 
 2471         pthread_mutex_unlock(&se->lock);
 
 2473         outarg.notify_unique = rreq->nreq.unique;
 
 2474         outarg.nodeid = ino;
 
 2475         outarg.offset = offset;
 
 2479         iov[1].iov_base = &outarg;
 
 2480         iov[1].iov_len = 
sizeof(outarg);
 
 2482         err = send_notify_iov(se, FUSE_NOTIFY_RETRIEVE, iov, 2);
 
 2484                 pthread_mutex_lock(&se->lock);
 
 2485                 list_del_nreq(&rreq->nreq);
 
 2486                 pthread_mutex_unlock(&se->lock);
 
 2495         return req->se->userdata;
 
 2506         pthread_mutex_lock(&req->lock);
 
 2507         pthread_mutex_lock(&req->se->lock);
 
 2508         req->u.ni.func = func;
 
 2509         req->u.ni.data = data;
 
 2510         pthread_mutex_unlock(&req->se->lock);
 
 2511         if (req->interrupted && func)
 
 2513         pthread_mutex_unlock(&req->lock);
 
 2520         pthread_mutex_lock(&req->se->lock);
 
 2521         interrupted = req->interrupted;
 
 2522         pthread_mutex_unlock(&req->se->lock);
 
 2531         [FUSE_LOOKUP]      = { do_lookup,      
"LOOKUP"      },
 
 2532         [FUSE_FORGET]      = { do_forget,      
"FORGET"      },
 
 2533         [FUSE_GETATTR]     = { do_getattr,     
"GETATTR"     },
 
 2534         [FUSE_SETATTR]     = { do_setattr,     
"SETATTR"     },
 
 2535         [FUSE_READLINK]    = { do_readlink,    
"READLINK"    },
 
 2536         [FUSE_SYMLINK]     = { do_symlink,     
"SYMLINK"     },
 
 2537         [FUSE_MKNOD]       = { do_mknod,       
"MKNOD"       },
 
 2538         [FUSE_MKDIR]       = { do_mkdir,       
"MKDIR"       },
 
 2539         [FUSE_UNLINK]      = { do_unlink,      
"UNLINK"      },
 
 2540         [FUSE_RMDIR]       = { do_rmdir,       
"RMDIR"       },
 
 2541         [FUSE_RENAME]      = { do_rename,      
"RENAME"      },
 
 2542         [FUSE_LINK]        = { do_link,        
"LINK"        },
 
 2543         [FUSE_OPEN]        = { do_open,        
"OPEN"        },
 
 2544         [FUSE_READ]        = { do_read,        
"READ"        },
 
 2545         [FUSE_WRITE]       = { do_write,       
"WRITE"       },
 
 2546         [FUSE_STATFS]      = { do_statfs,      
"STATFS"      },
 
 2547         [FUSE_RELEASE]     = { do_release,     
"RELEASE"     },
 
 2548         [FUSE_FSYNC]       = { do_fsync,       
"FSYNC"       },
 
 2549         [FUSE_SETXATTR]    = { do_setxattr,    
"SETXATTR"    },
 
 2550         [FUSE_GETXATTR]    = { do_getxattr,    
"GETXATTR"    },
 
 2551         [FUSE_LISTXATTR]   = { do_listxattr,   
"LISTXATTR"   },
 
 2552         [FUSE_REMOVEXATTR] = { do_removexattr, 
"REMOVEXATTR" },
 
 2553         [FUSE_FLUSH]       = { do_flush,       
"FLUSH"       },
 
 2554         [FUSE_INIT]        = { do_init,        
"INIT"        },
 
 2555         [FUSE_OPENDIR]     = { do_opendir,     
"OPENDIR"     },
 
 2556         [FUSE_READDIR]     = { do_readdir,     
"READDIR"     },
 
 2557         [FUSE_RELEASEDIR]  = { do_releasedir,  
"RELEASEDIR"  },
 
 2558         [FUSE_FSYNCDIR]    = { do_fsyncdir,    
"FSYNCDIR"    },
 
 2559         [FUSE_GETLK]       = { do_getlk,       
"GETLK"       },
 
 2560         [FUSE_SETLK]       = { do_setlk,       
"SETLK"       },
 
 2561         [FUSE_SETLKW]      = { do_setlkw,      
"SETLKW"      },
 
 2562         [FUSE_ACCESS]      = { do_access,      
"ACCESS"      },
 
 2563         [FUSE_CREATE]      = { do_create,      
"CREATE"      },
 
 2564         [FUSE_INTERRUPT]   = { do_interrupt,   
"INTERRUPT"   },
 
 2565         [FUSE_BMAP]        = { do_bmap,        
"BMAP"        },
 
 2566         [FUSE_IOCTL]       = { do_ioctl,       
"IOCTL"       },
 
 2567         [FUSE_POLL]        = { do_poll,        
"POLL"        },
 
 2568         [FUSE_FALLOCATE]   = { do_fallocate,   
"FALLOCATE"   },
 
 2569         [FUSE_DESTROY]     = { do_destroy,     
"DESTROY"     },
 
 2570         [FUSE_NOTIFY_REPLY] = { (
void *) 1,    
"NOTIFY_REPLY" },
 
 2571         [FUSE_BATCH_FORGET] = { do_batch_forget, 
"BATCH_FORGET" },
 
 2572         [FUSE_READDIRPLUS] = { do_readdirplus,  
"READDIRPLUS"},
 
 2573         [FUSE_RENAME2]     = { do_rename2,      
"RENAME2"    },
 
 2574         [FUSE_COPY_FILE_RANGE] = { do_copy_file_range, 
"COPY_FILE_RANGE" },
 
 2575         [FUSE_LSEEK]       = { do_lseek,       
"LSEEK"       },
 
 2576         [CUSE_INIT]        = { cuse_lowlevel_init, 
"CUSE_INIT"   },
 
 2579 #define FUSE_MAXOP (sizeof(fuse_ll_ops) / sizeof(fuse_ll_ops[0])) 
 2581 static const char *opname(
enum fuse_opcode opcode)
 
 2583         if (opcode >= FUSE_MAXOP || !fuse_ll_ops[opcode].name)
 
 2586                 return fuse_ll_ops[opcode].name;
 
 2589 static int fuse_ll_copy_from_pipe(
struct fuse_bufvec *dst,
 
 2594                 fuse_log(FUSE_LOG_ERR, 
"fuse: copy from pipe: %s\n", strerror(-res));
 
 2598                 fuse_log(FUSE_LOG_ERR, 
"fuse: copy from pipe: short read\n");
 
 2607         fuse_session_process_buf_int(se, buf, NULL);
 
 2610 void fuse_session_process_buf_int(
struct fuse_session *se,
 
 2611                                   const struct fuse_buf *buf, 
struct fuse_chan *ch)
 
 2613         const size_t write_header_size = 
sizeof(
struct fuse_in_header) +
 
 2614                 sizeof(struct fuse_write_in);
 
 2616         struct fuse_bufvec tmpbuf = FUSE_BUFVEC_INIT(write_header_size);
 
 2617         struct fuse_in_header *in;
 
 2619         struct fuse_req *req;
 
 2628                 mbuf = malloc(tmpbuf.
buf[0].
size);
 
 2630                         fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate header\n");
 
 2633                 tmpbuf.
buf[0].
mem = mbuf;
 
 2635                 res = fuse_ll_copy_from_pipe(&tmpbuf, &bufv);
 
 2646                         "unique: %llu, opcode: %s (%i), nodeid: %llu, insize: %zu, pid: %u\n",
 
 2647                         (
unsigned long long) in->unique,
 
 2648                         opname((
enum fuse_opcode) in->opcode), in->opcode,
 
 2649                         (
unsigned long long) in->nodeid, buf->
size, in->pid);
 
 2652         req = fuse_ll_alloc_req(se);
 
 2654                 struct fuse_out_header out = {
 
 2655                         .unique = in->unique,
 
 2658                 struct iovec iov = {
 
 2660                         .iov_len = 
sizeof(
struct fuse_out_header),
 
 2663                 fuse_send_msg(se, ch, &iov, 1);
 
 2667         req->unique = in->unique;
 
 2668         req->ctx.uid = in->uid;
 
 2669         req->ctx.gid = in->gid;
 
 2670         req->ctx.pid = in->pid;
 
 2671         req->ch = ch ? fuse_chan_get(ch) : NULL;
 
 2674         if (!se->got_init) {
 
 2675                 enum fuse_opcode expected;
 
 2677                 expected = se->cuse_data ? CUSE_INIT : FUSE_INIT;
 
 2678                 if (in->opcode != expected)
 
 2680         } 
else if (in->opcode == FUSE_INIT || in->opcode == CUSE_INIT)
 
 2685         if (se->deny_others && in->uid != se->owner && in->uid != 0 &&
 
 2686                  in->opcode != FUSE_INIT && in->opcode != FUSE_READ &&
 
 2687                  in->opcode != FUSE_WRITE && in->opcode != FUSE_FSYNC &&
 
 2688                  in->opcode != FUSE_RELEASE && in->opcode != FUSE_READDIR &&
 
 2689                  in->opcode != FUSE_FSYNCDIR && in->opcode != FUSE_RELEASEDIR &&
 
 2690                  in->opcode != FUSE_NOTIFY_REPLY &&
 
 2691                  in->opcode != FUSE_READDIRPLUS)
 
 2695         if (in->opcode >= FUSE_MAXOP || !fuse_ll_ops[in->opcode].func)
 
 2697         if (in->opcode != FUSE_INTERRUPT) {
 
 2698                 struct fuse_req *intr;
 
 2699                 pthread_mutex_lock(&se->lock);
 
 2700                 intr = check_interrupt(se, req);
 
 2701                 list_add_req(req, &se->list);
 
 2702                 pthread_mutex_unlock(&se->lock);
 
 2708             (in->opcode != FUSE_WRITE || !se->op.write_buf) &&
 
 2709             in->opcode != FUSE_NOTIFY_REPLY) {
 
 2713                 newmbuf = realloc(mbuf, buf->
size);
 
 2714                 if (newmbuf == NULL)
 
 2718                 tmpbuf = FUSE_BUFVEC_INIT(buf->
size - write_header_size);
 
 2719                 tmpbuf.
buf[0].
mem = (
char *)mbuf + write_header_size;
 
 2721                 res = fuse_ll_copy_from_pipe(&tmpbuf, &bufv);
 
 2729         inarg = (
void *) &in[1];
 
 2730         if (in->opcode == FUSE_WRITE && se->op.write_buf)
 
 2731                 do_write_buf(req, in->nodeid, inarg, buf);
 
 2732         else if (in->opcode == FUSE_NOTIFY_REPLY)
 
 2733                 do_notify_reply(req, in->nodeid, inarg, buf);
 
 2735                 fuse_ll_ops[in->opcode].func(req, in->nodeid, inarg);
 
 2745                 fuse_ll_clear_pipe(se);
 
 2749 #define LL_OPTION(n,o,v) \ 
 2750         { n, offsetof(struct fuse_session, o), v } 
 2752 static const struct fuse_opt fuse_ll_opts[] = {
 
 2753         LL_OPTION(
"debug", debug, 1),
 
 2754         LL_OPTION(
"-d", debug, 1),
 
 2755         LL_OPTION(
"--debug", debug, 1),
 
 2756         LL_OPTION(
"allow_root", deny_others, 1),
 
 2762         printf(
"using FUSE kernel interface version %i.%i\n",
 
 2763                FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION);
 
 2764         fuse_mount_version();
 
 2772 "    -o allow_other         allow access by all users\n" 
 2773 "    -o allow_root          allow access by root\n" 
 2774 "    -o auto_unmount        auto unmount on process termination\n");
 
 2779         struct fuse_ll_pipe *llp;
 
 2781         if (se->got_init && !se->got_destroy) {
 
 2783                         se->op.destroy(se->userdata);
 
 2785         llp = pthread_getspecific(se->pipe_key);
 
 2787                 fuse_ll_pipe_free(llp);
 
 2788         pthread_key_delete(se->pipe_key);
 
 2789         pthread_mutex_destroy(&se->lock);
 
 2790         free(se->cuse_data);
 
 2795         destroy_mount_opts(se->mo);
 
 2800 static void fuse_ll_pipe_destructor(
void *data)
 
 2802         struct fuse_ll_pipe *llp = data;
 
 2803         fuse_ll_pipe_free(llp);
 
 2808         return fuse_session_receive_buf_int(se, buf, NULL);
 
 2811 int fuse_session_receive_buf_int(
struct fuse_session *se, 
struct fuse_buf *buf,
 
 2812                                  struct fuse_chan *ch)
 
 2817         size_t bufsize = se->bufsize;
 
 2818         struct fuse_ll_pipe *llp;
 
 2824         llp = fuse_ll_get_pipe(se);
 
 2828         if (llp->size < bufsize) {
 
 2829                 if (llp->can_grow) {
 
 2830                         res = fcntl(llp->pipe[0], F_SETPIPE_SZ, bufsize);
 
 2833                                 res = grow_pipe_to_max(llp->pipe[0]);
 
 2840                 if (llp->size < bufsize)
 
 2844         if (se->io != NULL && se->io->splice_receive != NULL) {
 
 2845                 res = se->io->splice_receive(ch ? ch->fd : se->fd, NULL,
 
 2846                                                      llp->pipe[1], NULL, bufsize, 0,
 
 2849                 res = splice(ch ? ch->fd : se->fd, NULL, llp->pipe[1], NULL,
 
 2858                 if (err == ENODEV) {
 
 2864                 if (err != EINTR && err != EAGAIN)
 
 2865                         perror(
"fuse: splice from device");
 
 2869         if (res < 
sizeof(
struct fuse_in_header)) {
 
 2870                 fuse_log(FUSE_LOG_ERR, 
"short splice from fuse device\n");
 
 2885         if (res < 
sizeof(
struct fuse_in_header) +
 
 2886             sizeof(
struct fuse_write_in) + pagesize) {
 
 2891                         buf->
mem = malloc(se->bufsize);
 
 2894                                         "fuse: failed to allocate read buffer\n");
 
 2904                         fuse_log(FUSE_LOG_ERR, 
"fuse: copy from pipe: %s\n",
 
 2906                         fuse_ll_clear_pipe(se);
 
 2909                 if (res < tmpbuf.size) {
 
 2910                         fuse_log(FUSE_LOG_ERR, 
"fuse: copy from pipe: short read\n");
 
 2911                         fuse_ll_clear_pipe(se);
 
 2914                 assert(res == tmpbuf.size);
 
 2918                 buf->
fd = tmpbuf.fd;
 
 2928                 buf->
mem = malloc(se->bufsize);
 
 2931                                 "fuse: failed to allocate read buffer\n");
 
 2937         if (se->io != NULL) {
 
 2940                 res = se->io->read(ch ? ch->fd : se->fd, 
buf->
mem, se->bufsize,
 
 2943                 res = read(ch ? ch->fd : se->fd, 
buf->
mem, se->bufsize);
 
 2955                 if (err == ENODEV) {
 
 2964                 if (err != EINTR && err != EAGAIN)
 
 2965                         perror(
"fuse: reading device");
 
 2968         if ((
size_t) res < 
sizeof(
struct fuse_in_header)) {
 
 2969                 fuse_log(FUSE_LOG_ERR, 
"short read on fuse device\n");
 
 2980                                       size_t op_size, 
void *userdata)
 
 2983         struct fuse_session *se;
 
 2984         struct mount_opts *mo;
 
 2987                 fuse_log(FUSE_LOG_ERR, 
"fuse: warning: library too old, some operations may not work\n");
 
 2991         if (args->
argc == 0) {
 
 2992                 fuse_log(FUSE_LOG_ERR, 
"fuse: empty argv passed to fuse_session_new().\n");
 
 2996         se = (
struct fuse_session *) calloc(1, 
sizeof(
struct fuse_session));
 
 2998                 fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate fuse object\n");
 
 3002         se->conn.max_write = UINT_MAX;
 
 3003         se->conn.max_readahead = UINT_MAX;
 
 3008         if(se->deny_others) {
 
 3018         mo = parse_mount_opts(args);
 
 3022         if(args->
argc == 1 &&
 
 3023            args->
argv[0][0] == 
'-') {
 
 3024                 fuse_log(FUSE_LOG_ERR, 
"fuse: warning: argv[0] looks like an option, but " 
 3025                         "will be ignored\n");
 
 3026         } 
else if (args->
argc != 1) {
 
 3028                 fuse_log(FUSE_LOG_ERR, 
"fuse: unknown option(s): `");
 
 3029                 for(i = 1; i < args->
argc-1; i++)
 
 3036                 fuse_log(FUSE_LOG_DEBUG, 
"FUSE library version: %s\n", PACKAGE_VERSION);
 
 3038         se->bufsize = FUSE_MAX_MAX_PAGES * getpagesize() +
 
 3039                 FUSE_BUFFER_HEADER_SIZE;
 
 3041         list_init_req(&se->list);
 
 3042         list_init_req(&se->interrupts);
 
 3043         list_init_nreq(&se->notify_list);
 
 3045         pthread_mutex_init(&se->lock, NULL);
 
 3047         err = pthread_key_create(&se->pipe_key, fuse_ll_pipe_destructor);
 
 3049                 fuse_log(FUSE_LOG_ERR, 
"fuse: failed to create thread specific key: %s\n",
 
 3054         memcpy(&se->op, op, op_size);
 
 3055         se->owner = getuid();
 
 3056         se->userdata = userdata;
 
 3062         pthread_mutex_destroy(&se->lock);
 
 3067                 destroy_mount_opts(mo);
 
 3078                 fuse_log(FUSE_LOG_ERR, 
"Invalid file descriptor value %d passed to " 
 3079                         "fuse_session_custom_io()\n", fd);
 
 3083                 fuse_log(FUSE_LOG_ERR, 
"No custom IO passed to " 
 3084                         "fuse_session_custom_io()\n");
 
 3086         } 
else if (io->read == NULL || io->writev == NULL) {
 
 3091                 fuse_log(FUSE_LOG_ERR, 
"io passed to fuse_session_custom_io() must " 
 3092                         "implement both io->read() and io->writev\n");
 
 3096         se->io = malloc(
sizeof(
struct fuse_custom_io));
 
 3097         if (se->io == NULL) {
 
 3098                 fuse_log(FUSE_LOG_ERR, 
"Failed to allocate memory for custom io. " 
 3099                         "Error: %s\n", strerror(errno));
 
 3117                 fd = open(
"/dev/null", O_RDWR);
 
 3120         } 
while (fd >= 0 && fd <= 2);
 
 3128         fd = fuse_mnt_parse_fuse_fd(mountpoint);
 
 3130                 if (fcntl(fd, F_GETFD) == -1) {
 
 3132                                 "fuse: Invalid file descriptor /dev/fd/%u\n",
 
 3141         fd = fuse_kern_mount(mountpoint, se->mo);
 
 3147         se->mountpoint = strdup(mountpoint);
 
 3148         if (se->mountpoint == NULL)
 
 3154         fuse_kern_unmount(mountpoint, fd);
 
 3165         if (se->mountpoint != NULL) {
 
 3166                 fuse_kern_unmount(se->mountpoint, se->fd);
 
 3168                 free(se->mountpoint);
 
 3169                 se->mountpoint = NULL;
 
 3177         size_t bufsize = 1024;
 
 3181         unsigned long pid = req->ctx.pid;
 
 3184         sprintf(path, 
"/proc/%lu/task/%lu/status", pid, pid);
 
 3187         buf = malloc(bufsize);
 
 3192         fd = open(path, O_RDONLY);
 
 3196         ret = read(fd, buf, bufsize);
 
 3203         if ((
size_t)ret == bufsize) {
 
 3210         s = strstr(buf, 
"\nGroups:");
 
 3218                 unsigned long val = strtoul(s, &end, 0);
 
 3238         (void) req; (void) size; (void) list;
 
 3245 __attribute__((no_sanitize_thread))
 
 3251 __attribute__((no_sanitize_thread))
 
 3258 __attribute__((no_sanitize_thread))
 
#define FUSE_CAP_IOCTL_DIR
#define FUSE_CAP_DONT_MASK
#define FUSE_CAP_HANDLE_KILLPRIV
#define FUSE_CAP_AUTO_INVAL_DATA
#define FUSE_CAP_SPLICE_READ
#define FUSE_CAP_PARALLEL_DIROPS
size_t fuse_buf_size(const struct fuse_bufvec *bufv)
#define FUSE_CAP_WRITEBACK_CACHE
#define FUSE_CAP_EXPIRE_ONLY
#define FUSE_CAP_ATOMIC_O_TRUNC
#define FUSE_CAP_ASYNC_READ
#define FUSE_CAP_SPLICE_WRITE
#define FUSE_CAP_CACHE_SYMLINKS
#define FUSE_CAP_POSIX_ACL
#define FUSE_CAP_EXPORT_SUPPORT
#define FUSE_CAP_POSIX_LOCKS
#define FUSE_CAP_EXPLICIT_INVAL_DATA
#define FUSE_CAP_READDIRPLUS_AUTO
ssize_t fuse_buf_copy(struct fuse_bufvec *dst, struct fuse_bufvec *src, enum fuse_buf_copy_flags flags)
#define FUSE_CAP_NO_OPENDIR_SUPPORT
#define FUSE_CAP_ASYNC_DIO
#define FUSE_CAP_NO_OPEN_SUPPORT
#define FUSE_CAP_READDIRPLUS
void fuse_pollhandle_destroy(struct fuse_pollhandle *ph)
@ FUSE_BUF_SPLICE_NONBLOCK
#define FUSE_CAP_SPLICE_MOVE
#define FUSE_CAP_FLOCK_LOCKS
void fuse_log(enum fuse_log_level level, const char *fmt,...)
void fuse_session_destroy(struct fuse_session *se)
int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv, enum fuse_buf_copy_flags flags)
int fuse_reply_lock(fuse_req_t req, const struct flock *lock)
int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi)
void fuse_session_exit(struct fuse_session *se)
void(* fuse_interrupt_func_t)(fuse_req_t req, void *data)
int fuse_reply_poll(fuse_req_t req, unsigned revents)
int fuse_reply_err(fuse_req_t req, int err)
int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size)
struct fuse_req * fuse_req_t
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)
int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov, int count)
int fuse_lowlevel_notify_delete(struct fuse_session *se, fuse_ino_t parent, fuse_ino_t child, const char *name, size_t namelen)
void fuse_session_process_buf(struct fuse_session *se, const struct fuse_buf *buf)
int fuse_session_exited(struct fuse_session *se)
int fuse_session_fd(struct fuse_session *se)
int fuse_req_interrupted(fuse_req_t req)
int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[])
int fuse_lowlevel_notify_retrieve(struct fuse_session *se, fuse_ino_t ino, size_t size, off_t offset, void *cookie)
int fuse_reply_readlink(fuse_req_t req, const char *link)
int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count)
int fuse_reply_bmap(fuse_req_t req, uint64_t idx)
int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e)
void fuse_session_unmount(struct fuse_session *se)
void fuse_reply_none(fuse_req_t req)
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)
void fuse_lowlevel_help(void)
int fuse_lowlevel_notify_inval_inode(struct fuse_session *se, fuse_ino_t ino, off_t off, off_t len)
struct fuse_session * fuse_session_new(struct fuse_args *args, const struct fuse_lowlevel_ops *op, size_t op_size, void *userdata)
int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf)
int fuse_reply_write(fuse_req_t req, size_t count)
int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf)
int fuse_session_mount(struct fuse_session *se, const char *mountpoint)
void * fuse_req_userdata(fuse_req_t req)
int fuse_lowlevel_notify_expire_entry(struct fuse_session *se, fuse_ino_t parent, const char *name, size_t namelen, enum fuse_expire_flags flags)
int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph)
int fuse_lowlevel_notify_inval_entry(struct fuse_session *se, fuse_ino_t parent, const char *name, size_t namelen)
void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func, void *data)
void fuse_session_reset(struct fuse_session *se)
int fuse_session_custom_io(struct fuse_session *se, const struct fuse_custom_io *io, int fd)
int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e, const struct fuse_file_info *fi)
int fuse_reply_lseek(fuse_req_t req, off_t off)
void fuse_lowlevel_version(void)
size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize, const char *name, const struct stat *stbuf, off_t off)
const struct fuse_ctx * fuse_req_ctx(fuse_req_t req)
int fuse_reply_attr(fuse_req_t req, const struct stat *attr, double attr_timeout)
int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size)
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)
int fuse_reply_xattr(fuse_req_t req, size_t count)
int fuse_opt_add_arg(struct fuse_args *args, const char *arg)
void fuse_opt_free_args(struct fuse_args *args)
int fuse_opt_parse(struct fuse_args *args, void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc)
#define FUSE_CAP_SETXATTR_EXT
enum fuse_buf_flags flags
unsigned int parallel_direct_writes
unsigned int cache_readdir