15#include "fuse_config.h" 
   17#include "fuse_kernel.h" 
   20#include "mount_util.h" 
   35#ifndef F_LINUX_SPECIFIC_BASE 
   36#define F_LINUX_SPECIFIC_BASE       1024 
   39#define F_SETPIPE_SZ    (F_LINUX_SPECIFIC_BASE + 7) 
   43#define PARAM(inarg) (((char *)(inarg)) + sizeof(*(inarg))) 
   44#define OFFSET_MAX 0x7fffffffffffffffLL 
   46#define container_of(ptr, type, member) ({                              \ 
   47                        const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 
   48                        (type *)( (char *)__mptr - offsetof(type,member) );}) 
   50struct fuse_pollhandle {
 
   52        struct fuse_session *se;
 
   55static size_t pagesize;
 
   57static __attribute__((constructor)) 
void fuse_ll_init_pagesize(
void)
 
   59        pagesize = getpagesize();
 
   62static void convert_stat(
const struct stat *stbuf, 
struct fuse_attr *attr)
 
   64        attr->ino       = stbuf->st_ino;
 
   65        attr->mode      = stbuf->st_mode;
 
   66        attr->nlink     = stbuf->st_nlink;
 
   67        attr->uid       = stbuf->st_uid;
 
   68        attr->gid       = stbuf->st_gid;
 
   69        attr->rdev      = stbuf->st_rdev;
 
   70        attr->size      = stbuf->st_size;
 
   71        attr->blksize   = stbuf->st_blksize;
 
   72        attr->blocks    = stbuf->st_blocks;
 
   73        attr->atime     = stbuf->st_atime;
 
   74        attr->mtime     = stbuf->st_mtime;
 
   75        attr->ctime     = stbuf->st_ctime;
 
   76        attr->atimensec = ST_ATIM_NSEC(stbuf);
 
   77        attr->mtimensec = ST_MTIM_NSEC(stbuf);
 
   78        attr->ctimensec = ST_CTIM_NSEC(stbuf);
 
   81static void convert_attr(
const struct fuse_setattr_in *attr, 
struct stat *stbuf)
 
   83        stbuf->st_mode         = attr->mode;
 
   84        stbuf->st_uid          = attr->uid;
 
   85        stbuf->st_gid          = attr->gid;
 
   86        stbuf->st_size         = attr->size;
 
   87        stbuf->st_atime        = attr->atime;
 
   88        stbuf->st_mtime        = attr->mtime;
 
   89        stbuf->st_ctime        = attr->ctime;
 
   90        ST_ATIM_NSEC_SET(stbuf, attr->atimensec);
 
   91        ST_MTIM_NSEC_SET(stbuf, attr->mtimensec);
 
   92        ST_CTIM_NSEC_SET(stbuf, attr->ctimensec);
 
   95static  size_t iov_length(
const struct iovec *iov, 
size_t count)
 
  100        for (seg = 0; seg < count; seg++)
 
  101                ret += iov[seg].iov_len;
 
  105static void list_init_req(
struct fuse_req *req)
 
  111static void list_del_req(
struct fuse_req *req)
 
  113        struct fuse_req *prev = req->prev;
 
  114        struct fuse_req *next = req->next;
 
  119static void list_add_req(
struct fuse_req *req, 
struct fuse_req *next)
 
  121        struct fuse_req *prev = next->prev;
 
  130        assert(req->ch == NULL);
 
  131        pthread_mutex_destroy(&req->lock);
 
  138        struct fuse_session *se = req->se;
 
  140        if (se->conn.no_interrupt) {
 
  141                ctr = --req->ref_cnt;
 
  142                fuse_chan_put(req->ch);
 
  145                pthread_mutex_lock(&se->lock);
 
  146                req->u.ni.func = NULL;
 
  147                req->u.ni.data = NULL;
 
  149                ctr = --req->ref_cnt;
 
  150                fuse_chan_put(req->ch);
 
  152                pthread_mutex_unlock(&se->lock);
 
  158static struct fuse_req *fuse_ll_alloc_req(
struct fuse_session *se)
 
  160        struct fuse_req *req;
 
  162        req = (
struct fuse_req *) calloc(1, 
sizeof(
struct fuse_req));
 
  164                fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate request\n");
 
  169                pthread_mutex_init(&req->lock, NULL);
 
  176static int fuse_send_msg(
struct fuse_session *se, 
struct fuse_chan *ch,
 
  177                         struct iovec *iov, 
int count)
 
  179        struct fuse_out_header *out = iov[0].iov_base;
 
  182        out->len = iov_length(iov, count);
 
  184                if (out->unique == 0) {
 
  185                        fuse_log(FUSE_LOG_DEBUG, 
"NOTIFY: code=%d length=%u\n",
 
  186                                out->error, out->len);
 
  187                } 
else if (out->error) {
 
  189                                "   unique: %llu, error: %i (%s), outsize: %i\n",
 
  190                                (
unsigned long long) out->unique, out->error,
 
  191                                strerror(-out->error), out->len);
 
  194                                "   unique: %llu, success, outsize: %i\n",
 
  195                                (
unsigned long long) out->unique, out->len);
 
  203                res = se->io->writev(ch ? ch->fd : se->fd, iov, count,
 
  206                res = writev(ch ? ch->fd : se->fd, iov, count);
 
  213                        perror(
"fuse: writing device");
 
  221int fuse_send_reply_iov_nofree(
fuse_req_t req, 
int error, 
struct iovec *iov,
 
  224        struct fuse_out_header out;
 
  226#if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 32 
  227        const char *str = strerrordesc_np(error * -1);
 
  228        if ((str == NULL && error != 0) || error > 0) {
 
  230        if (error <= -1000 || error > 0) {
 
  232                fuse_log(FUSE_LOG_ERR, 
"fuse: bad error value: %i\n",   error);
 
  236        out.unique = req->unique;
 
  239        iov[0].iov_base = &out;
 
  240        iov[0].iov_len = 
sizeof(
struct fuse_out_header);
 
  242        return fuse_send_msg(req->se, req->ch, iov, count);
 
  245static int send_reply_iov(
fuse_req_t req, 
int error, 
struct iovec *iov,
 
  250        res = fuse_send_reply_iov_nofree(req, error, iov, count);
 
  255static int send_reply(
fuse_req_t req, 
int error, 
const void *arg,
 
  261                iov[1].iov_base = (
void *) arg;
 
  262                iov[1].iov_len = argsize;
 
  265        return send_reply_iov(req, error, iov, count);
 
  271        struct iovec *padded_iov;
 
  273        padded_iov = malloc((count + 1) * 
sizeof(
struct iovec));
 
  274        if (padded_iov == NULL)
 
  277        memcpy(padded_iov + 1, iov, count * 
sizeof(
struct iovec));
 
  280        res = send_reply_iov(req, 0, padded_iov, count);
 
 
  290                         const char *name, 
const struct stat *stbuf, off_t off)
 
  295        size_t entlen_padded;
 
  296        struct fuse_dirent *dirent;
 
  298        namelen = strlen(name);
 
  299        entlen = FUSE_NAME_OFFSET + namelen;
 
  300        entlen_padded = FUSE_DIRENT_ALIGN(entlen);
 
  302        if ((buf == NULL) || (entlen_padded > bufsize))
 
  303          return entlen_padded;
 
  305        dirent = (
struct fuse_dirent*) buf;
 
  306        dirent->ino = stbuf->st_ino;
 
  308        dirent->namelen = namelen;
 
  309        dirent->type = (stbuf->st_mode & S_IFMT) >> 12;
 
  310        memcpy(dirent->name, name, namelen);
 
  311        memset(dirent->name + namelen, 0, entlen_padded - entlen);
 
  313        return entlen_padded;
 
 
  316static void convert_statfs(
const struct statvfs *stbuf,
 
  317                           struct fuse_kstatfs *kstatfs)
 
  319        kstatfs->bsize   = stbuf->f_bsize;
 
  320        kstatfs->frsize  = stbuf->f_frsize;
 
  321        kstatfs->blocks  = stbuf->f_blocks;
 
  322        kstatfs->bfree   = stbuf->f_bfree;
 
  323        kstatfs->bavail  = stbuf->f_bavail;
 
  324        kstatfs->files   = stbuf->f_files;
 
  325        kstatfs->ffree   = stbuf->f_ffree;
 
  326        kstatfs->namelen = stbuf->f_namemax;
 
  329static int send_reply_ok(
fuse_req_t req, 
const void *arg, 
size_t argsize)
 
  331        return send_reply(req, 0, arg, argsize);
 
  336        return send_reply(req, -err, NULL, 0);
 
 
  344static unsigned long calc_timeout_sec(
double t)
 
  346        if (t > (
double) ULONG_MAX)
 
  351                return (
unsigned long) t;
 
  354static unsigned int calc_timeout_nsec(
double t)
 
  356        double f = t - (double) calc_timeout_sec(t);
 
  359        else if (f >= 0.999999999)
 
  362                return (
unsigned int) (f * 1.0e9);
 
  365static void fill_entry(
struct fuse_entry_out *arg,
 
  368        arg->nodeid = e->
ino;
 
  373        arg->attr_valid_nsec = calc_timeout_nsec(e->
attr_timeout);
 
  374        convert_stat(&e->
attr, &arg->attr);
 
  386        size_t entlen_padded;
 
  388        namelen = strlen(name);
 
  389        entlen = FUSE_NAME_OFFSET_DIRENTPLUS + namelen;
 
  390        entlen_padded = FUSE_DIRENT_ALIGN(entlen);
 
  391        if ((buf == NULL) || (entlen_padded > bufsize))
 
  392          return entlen_padded;
 
  394        struct fuse_direntplus *dp = (
struct fuse_direntplus *) buf;
 
  395        memset(&dp->entry_out, 0, 
sizeof(dp->entry_out));
 
  396        fill_entry(&dp->entry_out, e);
 
  398        struct fuse_dirent *dirent = &dp->dirent;
 
  399        dirent->ino = e->
attr.st_ino;
 
  401        dirent->namelen = namelen;
 
  402        dirent->type = (e->
attr.st_mode & S_IFMT) >> 12;
 
  403        memcpy(dirent->name, name, namelen);
 
  404        memset(dirent->name + namelen, 0, entlen_padded - entlen);
 
  406        return entlen_padded;
 
 
  409static void fill_open(
struct fuse_open_out *arg,
 
  415                arg->open_flags |= FOPEN_PASSTHROUGH;
 
  418                arg->open_flags |= FOPEN_DIRECT_IO;
 
  420                arg->open_flags |= FOPEN_KEEP_CACHE;
 
  422                arg->open_flags |= FOPEN_CACHE_DIR;
 
  424                arg->open_flags |= FOPEN_NONSEEKABLE;
 
  426                arg->open_flags |= FOPEN_NOFLUSH;
 
  428                arg->open_flags |= FOPEN_PARALLEL_DIRECT_WRITES;
 
  433        struct fuse_entry_out arg;
 
  434        size_t size = req->se->conn.proto_minor < 9 ?
 
  435                FUSE_COMPAT_ENTRY_OUT_SIZE : 
sizeof(arg);
 
  439        if (!e->
ino && req->se->conn.proto_minor < 4)
 
  442        memset(&arg, 0, 
sizeof(arg));
 
  444        return send_reply_ok(req, &arg, size);
 
 
  450        alignas(uint64_t) 
char buf[
sizeof(
struct fuse_entry_out) + 
sizeof(
struct fuse_open_out)];
 
  451        size_t entrysize = req->se->conn.proto_minor < 9 ?
 
  452                FUSE_COMPAT_ENTRY_OUT_SIZE : 
sizeof(
struct fuse_entry_out);
 
  453        struct fuse_entry_out *earg = (
struct fuse_entry_out *) buf;
 
  454        struct fuse_open_out *oarg = (
struct fuse_open_out *) (buf + entrysize);
 
  456        memset(buf, 0, 
sizeof(buf));
 
  459        return send_reply_ok(req, buf,
 
  460                             entrysize + 
sizeof(
struct fuse_open_out));
 
 
  466        struct fuse_attr_out arg;
 
  467        size_t size = req->se->conn.proto_minor < 9 ?
 
  468                FUSE_COMPAT_ATTR_OUT_SIZE : 
sizeof(arg);
 
  470        memset(&arg, 0, 
sizeof(arg));
 
  471        arg.attr_valid = calc_timeout_sec(attr_timeout);
 
  472        arg.attr_valid_nsec = calc_timeout_nsec(attr_timeout);
 
  473        convert_stat(attr, &arg.attr);
 
  475        return send_reply_ok(req, &arg, size);
 
 
  480        return send_reply_ok(req, linkname, strlen(linkname));
 
 
  485        struct fuse_backing_map map = { .fd = fd };
 
  488        ret = ioctl(req->se->fd, FUSE_DEV_IOC_BACKING_OPEN, &map);
 
  490                fuse_log(FUSE_LOG_ERR, 
"fuse: passthrough_open: %s\n", strerror(errno));
 
 
  497int fuse_passthrough_close(
fuse_req_t req, 
int backing_id)
 
  501        ret = ioctl(req->se->fd, FUSE_DEV_IOC_BACKING_CLOSE, &backing_id);
 
  503                fuse_log(FUSE_LOG_ERR, 
"fuse: passthrough_close: %s\n", strerror(errno));
 
  510        struct fuse_open_out arg;
 
  512        memset(&arg, 0, 
sizeof(arg));
 
  514        return send_reply_ok(req, &arg, 
sizeof(arg));
 
 
  519        struct fuse_write_out arg;
 
  521        memset(&arg, 0, 
sizeof(arg));
 
  524        return send_reply_ok(req, &arg, 
sizeof(arg));
 
 
  529        return send_reply_ok(req, buf, size);
 
 
  532static int fuse_send_data_iov_fallback(
struct fuse_session *se,
 
  533                                       struct fuse_chan *ch,
 
  534                                       struct iovec *iov, 
int iov_count,
 
  538        struct fuse_bufvec mem_buf = FUSE_BUFVEC_INIT(len);
 
  543        if (
buf->count == 1 && 
buf->idx == 0 && 
buf->off == 0 &&
 
  548                iov[iov_count].iov_base = 
buf->buf[0].
mem;
 
  549                iov[iov_count].iov_len = len;
 
  551                return fuse_send_msg(se, ch, iov, iov_count);
 
  554        res = posix_memalign(&mbuf, pagesize, len);
 
  558        mem_buf.
buf[0].
mem = mbuf;
 
  566        iov[iov_count].iov_base = mbuf;
 
  567        iov[iov_count].iov_len = len;
 
  569        res = fuse_send_msg(se, ch, iov, iov_count);
 
  581static void fuse_ll_pipe_free(
struct fuse_ll_pipe *llp)
 
  589#if !defined(HAVE_PIPE2) || !defined(O_CLOEXEC) 
  590static int fuse_pipe(
int fds[2])
 
  597        if (fcntl(fds[0], F_SETFL, O_NONBLOCK) == -1 ||
 
  598            fcntl(fds[1], F_SETFL, O_NONBLOCK) == -1 ||
 
  599            fcntl(fds[0], F_SETFD, FD_CLOEXEC) == -1 ||
 
  600            fcntl(fds[1], F_SETFD, FD_CLOEXEC) == -1) {
 
  608static int fuse_pipe(
int fds[2])
 
  610        return pipe2(fds, O_CLOEXEC | O_NONBLOCK);
 
  614static struct fuse_ll_pipe *fuse_ll_get_pipe(
struct fuse_session *se)
 
  616        struct fuse_ll_pipe *llp = pthread_getspecific(se->pipe_key);
 
  620                llp = malloc(
sizeof(
struct fuse_ll_pipe));
 
  624                res = fuse_pipe(llp->pipe);
 
  633                llp->size = pagesize * 16;
 
  636                pthread_setspecific(se->pipe_key, llp);
 
  643static void fuse_ll_clear_pipe(
struct fuse_session *se)
 
  645        struct fuse_ll_pipe *llp = pthread_getspecific(se->pipe_key);
 
  647                pthread_setspecific(se->pipe_key, NULL);
 
  648                fuse_ll_pipe_free(llp);
 
  652#if defined(HAVE_SPLICE) && defined(HAVE_VMSPLICE) 
  653static int read_back(
int fd, 
char *buf, 
size_t len)
 
  657        res = read(fd, buf, len);
 
  659                fuse_log(FUSE_LOG_ERR, 
"fuse: internal error: failed to read back from pipe: %s\n", strerror(errno));
 
  663                fuse_log(FUSE_LOG_ERR, 
"fuse: internal error: short read back from pipe: %i from %zi\n", res, len);
 
  669static int grow_pipe_to_max(
int pipefd)
 
  676        maxfd = open(
"/proc/sys/fs/pipe-max-size", O_RDONLY);
 
  680        res = read(maxfd, buf, 
sizeof(buf) - 1);
 
  691        res = libfuse_strtol(buf, &max);
 
  694        res = fcntl(pipefd, F_SETPIPE_SZ, max);
 
  700static int fuse_send_data_iov(
struct fuse_session *se, 
struct fuse_chan *ch,
 
  701                               struct iovec *iov, 
int iov_count,
 
  706        struct fuse_out_header *out = iov[0].iov_base;
 
  707        struct fuse_ll_pipe *llp;
 
  710        size_t total_buf_size;
 
  713        struct fuse_bufvec pipe_buf = FUSE_BUFVEC_INIT(len);
 
  715        if (se->broken_splice_nonblock)
 
  725                        total_buf_size -= 
buf->off;
 
  727        if (total_buf_size < 2 * pagesize)
 
  730        if (se->conn.proto_minor < 14 ||
 
  734        llp = fuse_ll_get_pipe(se);
 
  739        headerlen = iov_length(iov, iov_count);
 
  741        out->len = headerlen + len;
 
  747        pipesize = pagesize * (iov_count + 
buf->count + 1) + out->len;
 
  749        if (llp->size < pipesize) {
 
  751                        res = fcntl(llp->pipe[0], F_SETPIPE_SZ, pipesize);
 
  753                                res = grow_pipe_to_max(llp->pipe[0]);
 
  761                if (llp->size < pipesize)
 
  766        res = vmsplice(llp->pipe[1], iov, iov_count, SPLICE_F_NONBLOCK);
 
  770        if (res != headerlen) {
 
  772                fuse_log(FUSE_LOG_ERR, 
"fuse: short vmsplice to pipe: %u/%zu\n", res,
 
  778        pipe_buf.
buf[0].
fd = llp->pipe[1];
 
  783                if (res == -EAGAIN || res == -EINVAL) {
 
  795                                se->broken_splice_nonblock = 1;
 
  797                        pthread_setspecific(se->pipe_key, NULL);
 
  798                        fuse_ll_pipe_free(llp);
 
  805        if (res != 0 && res < len) {
 
  806                struct fuse_bufvec mem_buf = FUSE_BUFVEC_INIT(len);
 
  808                size_t now_len = res;
 
  818                res = posix_memalign(&mbuf, pagesize, len);
 
  822                mem_buf.
buf[0].
mem = mbuf;
 
  823                mem_buf.
off = now_len;
 
  827                        size_t extra_len = res;
 
  833                        tmpbuf = malloc(headerlen);
 
  834                        if (tmpbuf == NULL) {
 
  839                        res = read_back(llp->pipe[0], tmpbuf, headerlen);
 
  845                        res = read_back(llp->pipe[0], mbuf, now_len);
 
  850                        len = now_len + extra_len;
 
  851                        iov[iov_count].iov_base = mbuf;
 
  852                        iov[iov_count].iov_len = len;
 
  854                        res = fuse_send_msg(se, ch, iov, iov_count);
 
  862        out->len = headerlen + len;
 
  866                        "   unique: %llu, success, outsize: %i (splice)\n",
 
  867                        (
unsigned long long) out->unique, out->len);
 
  873                splice_flags |= SPLICE_F_MOVE;
 
  875        if (se->io != NULL && se->io->splice_send != NULL) {
 
  876                res = se->io->splice_send(llp->pipe[0], NULL,
 
  877                                                  ch ? ch->fd : se->fd, NULL, out->len,
 
  878                                                  splice_flags, se->userdata);
 
  880                res = splice(llp->pipe[0], NULL, ch ? ch->fd : se->fd, NULL,
 
  881                               out->len, splice_flags);
 
  885                perror(
"fuse: splice from pipe");
 
  888        if (res != out->len) {
 
  890                fuse_log(FUSE_LOG_ERR, 
"fuse: short splice from pipe: %u/%u\n",
 
  897        fuse_ll_clear_pipe(se);
 
  901        return fuse_send_data_iov_fallback(se, ch, iov, iov_count, 
buf, len);
 
  904static int fuse_send_data_iov(
struct fuse_session *se, 
struct fuse_chan *ch,
 
  905                               struct iovec *iov, 
int iov_count,
 
  911        return fuse_send_data_iov_fallback(se, ch, iov, iov_count, 
buf, len);
 
  919        struct fuse_out_header out;
 
  922        iov[0].iov_base = &out;
 
  923        iov[0].iov_len = 
sizeof(
struct fuse_out_header);
 
  925        out.unique = req->unique;
 
  928        res = fuse_send_data_iov(req->se, req->ch, iov, 1, bufv, flags);
 
 
  939        struct fuse_statfs_out arg;
 
  940        size_t size = req->se->conn.proto_minor < 4 ?
 
  941                FUSE_COMPAT_STATFS_SIZE : 
sizeof(arg);
 
  943        memset(&arg, 0, 
sizeof(arg));
 
  944        convert_statfs(stbuf, &arg.st);
 
  946        return send_reply_ok(req, &arg, size);
 
 
  951        struct fuse_getxattr_out arg;
 
  953        memset(&arg, 0, 
sizeof(arg));
 
  956        return send_reply_ok(req, &arg, 
sizeof(arg));
 
 
  961        struct fuse_lk_out arg;
 
  963        memset(&arg, 0, 
sizeof(arg));
 
  964        arg.lk.type = lock->l_type;
 
  965        if (lock->l_type != F_UNLCK) {
 
  966                arg.lk.start = lock->l_start;
 
  967                if (lock->l_len == 0)
 
  968                        arg.lk.end = OFFSET_MAX;
 
  970                        arg.lk.end = lock->l_start + lock->l_len - 1;
 
  972        arg.lk.pid = lock->l_pid;
 
  973        return send_reply_ok(req, &arg, 
sizeof(arg));
 
 
  978        struct fuse_bmap_out arg;
 
  980        memset(&arg, 0, 
sizeof(arg));
 
  983        return send_reply_ok(req, &arg, 
sizeof(arg));
 
 
  986static struct fuse_ioctl_iovec *fuse_ioctl_iovec_copy(
const struct iovec *iov,
 
  989        struct fuse_ioctl_iovec *fiov;
 
  992        fiov = malloc(
sizeof(fiov[0]) * count);
 
  996        for (i = 0; i < count; i++) {
 
  997                fiov[i].base = (uintptr_t) iov[i].iov_base;
 
  998                fiov[i].len = iov[i].iov_len;
 
 1005                           const struct iovec *in_iov, 
size_t in_count,
 
 1006                           const struct iovec *out_iov, 
size_t out_count)
 
 1008        struct fuse_ioctl_out arg;
 
 1009        struct fuse_ioctl_iovec *in_fiov = NULL;
 
 1010        struct fuse_ioctl_iovec *out_fiov = NULL;
 
 1011        struct iovec iov[4];
 
 1015        memset(&arg, 0, 
sizeof(arg));
 
 1016        arg.flags |= FUSE_IOCTL_RETRY;
 
 1017        arg.in_iovs = in_count;
 
 1018        arg.out_iovs = out_count;
 
 1019        iov[count].iov_base = &arg;
 
 1020        iov[count].iov_len = 
sizeof(arg);
 
 1023        if (req->se->conn.proto_minor < 16) {
 
 1025                        iov[count].iov_base = (
void *)in_iov;
 
 1026                        iov[count].iov_len = 
sizeof(in_iov[0]) * in_count;
 
 1031                        iov[count].iov_base = (
void *)out_iov;
 
 1032                        iov[count].iov_len = 
sizeof(out_iov[0]) * out_count;
 
 1037                if (
sizeof(
void *) == 4 && req->ioctl_64bit) {
 
 1043                        in_fiov = fuse_ioctl_iovec_copy(in_iov, in_count);
 
 1047                        iov[count].iov_base = (
void *)in_fiov;
 
 1048                        iov[count].iov_len = 
sizeof(in_fiov[0]) * in_count;
 
 1052                        out_fiov = fuse_ioctl_iovec_copy(out_iov, out_count);
 
 1056                        iov[count].iov_base = (
void *)out_fiov;
 
 1057                        iov[count].iov_len = 
sizeof(out_fiov[0]) * out_count;
 
 1062        res = send_reply_iov(req, 0, iov, count);
 
 
 1076        struct fuse_ioctl_out arg;
 
 1077        struct iovec iov[3];
 
 1080        memset(&arg, 0, 
sizeof(arg));
 
 1081        arg.result = result;
 
 1082        iov[count].iov_base = &arg;
 
 1083        iov[count].iov_len = 
sizeof(arg);
 
 1087                iov[count].iov_base = (
char *) buf;
 
 1088                iov[count].iov_len = size;
 
 1092        return send_reply_iov(req, 0, iov, count);
 
 
 1098        struct iovec *padded_iov;
 
 1099        struct fuse_ioctl_out arg;
 
 1102        padded_iov = malloc((count + 2) * 
sizeof(
struct iovec));
 
 1103        if (padded_iov == NULL)
 
 1106        memset(&arg, 0, 
sizeof(arg));
 
 1107        arg.result = result;
 
 1108        padded_iov[1].iov_base = &arg;
 
 1109        padded_iov[1].iov_len = 
sizeof(arg);
 
 1111        memcpy(&padded_iov[2], iov, count * 
sizeof(
struct iovec));
 
 1113        res = send_reply_iov(req, 0, padded_iov, count + 2);
 
 
 1121        struct fuse_poll_out arg;
 
 1123        memset(&arg, 0, 
sizeof(arg));
 
 1124        arg.revents = revents;
 
 1126        return send_reply_ok(req, &arg, 
sizeof(arg));
 
 
 1131        struct fuse_lseek_out arg;
 
 1133        memset(&arg, 0, 
sizeof(arg));
 
 1136        return send_reply_ok(req, &arg, 
sizeof(arg));
 
 
 1141        char *name = (
char *) inarg;
 
 1143        if (req->se->op.lookup)
 
 1144                req->se->op.lookup(req, nodeid, name);
 
 1151        struct fuse_forget_in *arg = (
struct fuse_forget_in *) inarg;
 
 1153        if (req->se->op.forget)
 
 1154                req->se->op.forget(req, nodeid, arg->nlookup);
 
 1162        struct fuse_batch_forget_in *arg = (
void *) inarg;
 
 1163        struct fuse_forget_one *param = (
void *) PARAM(arg);
 
 1168        if (req->se->op.forget_multi) {
 
 1169                req->se->op.forget_multi(req, arg->count,
 
 1170                                     (
struct fuse_forget_data *) param);
 
 1171        } 
else if (req->se->op.forget) {
 
 1172                for (i = 0; i < arg->count; i++) {
 
 1173                        struct fuse_forget_one *forget = ¶m[i];
 
 1174                        struct fuse_req *dummy_req;
 
 1176                        dummy_req = fuse_ll_alloc_req(req->se);
 
 1177                        if (dummy_req == NULL)
 
 1180                        dummy_req->unique = req->unique;
 
 1181                        dummy_req->ctx = req->ctx;
 
 1182                        dummy_req->ch = NULL;
 
 1184                        req->se->op.forget(dummy_req, forget->nodeid,
 
 1198        if (req->se->conn.proto_minor >= 9) {
 
 1199                struct fuse_getattr_in *arg = (
struct fuse_getattr_in *) inarg;
 
 1201                if (arg->getattr_flags & FUSE_GETATTR_FH) {
 
 1202                        memset(&fi, 0, 
sizeof(fi));
 
 1208        if (req->se->op.getattr)
 
 1209                req->se->op.getattr(req, nodeid, fip);
 
 1216        struct fuse_setattr_in *arg = (
struct fuse_setattr_in *) inarg;
 
 1218        if (req->se->op.setattr) {
 
 1222                memset(&stbuf, 0, 
sizeof(stbuf));
 
 1223                convert_attr(arg, &stbuf);
 
 1224                if (arg->valid & FATTR_FH) {
 
 1225                        arg->valid &= ~FATTR_FH;
 
 1226                        memset(&fi_store, 0, 
sizeof(fi_store));
 
 1231                        FUSE_SET_ATTR_MODE      |
 
 1234                        FUSE_SET_ATTR_SIZE      |
 
 1235                        FUSE_SET_ATTR_ATIME     |
 
 1236                        FUSE_SET_ATTR_MTIME     |
 
 1237                        FUSE_SET_ATTR_KILL_SUID |
 
 1238                        FUSE_SET_ATTR_KILL_SGID |
 
 1239                        FUSE_SET_ATTR_ATIME_NOW |
 
 1240                        FUSE_SET_ATTR_MTIME_NOW |
 
 1241                        FUSE_SET_ATTR_CTIME;
 
 1243                req->se->op.setattr(req, nodeid, &stbuf, arg->valid, fi);
 
 1250        struct fuse_access_in *arg = (
struct fuse_access_in *) inarg;
 
 1252        if (req->se->op.access)
 
 1253                req->se->op.access(req, nodeid, arg->mask);
 
 1262        if (req->se->op.readlink)
 
 1263                req->se->op.readlink(req, nodeid);
 
 1270        struct fuse_mknod_in *arg = (
struct fuse_mknod_in *) inarg;
 
 1271        char *name = PARAM(arg);
 
 1273        if (req->se->conn.proto_minor >= 12)
 
 1274                req->ctx.umask = arg->umask;
 
 1276                name = (
char *) inarg + FUSE_COMPAT_MKNOD_IN_SIZE;
 
 1278        if (req->se->op.mknod)
 
 1279                req->se->op.mknod(req, nodeid, name, arg->mode, arg->rdev);
 
 1286        struct fuse_mkdir_in *arg = (
struct fuse_mkdir_in *) inarg;
 
 1288        if (req->se->conn.proto_minor >= 12)
 
 1289                req->ctx.umask = arg->umask;
 
 1291        if (req->se->op.mkdir)
 
 1292                req->se->op.mkdir(req, nodeid, PARAM(arg), arg->mode);
 
 1299        char *name = (
char *) inarg;
 
 1301        if (req->se->op.unlink)
 
 1302                req->se->op.unlink(req, nodeid, name);
 
 1309        char *name = (
char *) inarg;
 
 1311        if (req->se->op.rmdir)
 
 1312                req->se->op.rmdir(req, nodeid, name);
 
 1319        char *name = (
char *) inarg;
 
 1320        char *linkname = ((
char *) inarg) + strlen((
char *) inarg) + 1;
 
 1322        if (req->se->op.symlink)
 
 1323                req->se->op.symlink(req, linkname, nodeid, name);
 
 1330        struct fuse_rename_in *arg = (
struct fuse_rename_in *) inarg;
 
 1331        char *oldname = PARAM(arg);
 
 1332        char *newname = oldname + strlen(oldname) + 1;
 
 1334        if (req->se->op.rename)
 
 1335                req->se->op.rename(req, nodeid, oldname, arg->newdir, newname,
 
 1343        struct fuse_rename2_in *arg = (
struct fuse_rename2_in *) inarg;
 
 1344        char *oldname = PARAM(arg);
 
 1345        char *newname = oldname + strlen(oldname) + 1;
 
 1347        if (req->se->op.rename)
 
 1348                req->se->op.rename(req, nodeid, oldname, arg->newdir, newname,
 
 1356        struct fuse_link_in *arg = (
struct fuse_link_in *) inarg;
 
 1358        if (req->se->op.link)
 
 1359                req->se->op.link(req, arg->oldnodeid, nodeid, PARAM(arg));
 
 1366        struct fuse_create_in *arg = (
struct fuse_create_in *) inarg;
 
 1368        if (req->se->op.tmpfile) {
 
 1371                memset(&fi, 0, 
sizeof(fi));
 
 1372                fi.
flags = arg->flags;
 
 1374                if (req->se->conn.proto_minor >= 12)
 
 1375                        req->ctx.umask = arg->umask;
 
 1377                req->se->op.tmpfile(req, nodeid, arg->mode, &fi);
 
 1384        struct fuse_create_in *arg = (
struct fuse_create_in *) inarg;
 
 1386        if (req->se->op.create) {
 
 1388                char *name = PARAM(arg);
 
 1390                memset(&fi, 0, 
sizeof(fi));
 
 1391                fi.
flags = arg->flags;
 
 1393                if (req->se->conn.proto_minor >= 12)
 
 1394                        req->ctx.umask = arg->umask;
 
 1396                        name = (
char *) inarg + 
sizeof(
struct fuse_open_in);
 
 1398                req->se->op.create(req, nodeid, name, arg->mode, &fi);
 
 1405        struct fuse_open_in *arg = (
struct fuse_open_in *) inarg;
 
 1408        memset(&fi, 0, 
sizeof(fi));
 
 1409        fi.
flags = arg->flags;
 
 1411        if (req->se->op.open)
 
 1412                req->se->op.open(req, nodeid, &fi);
 
 1421        struct fuse_read_in *arg = (
struct fuse_read_in *) inarg;
 
 1423        if (req->se->op.read) {
 
 1426                memset(&fi, 0, 
sizeof(fi));
 
 1428                if (req->se->conn.proto_minor >= 9) {
 
 1430                        fi.
flags = arg->flags;
 
 1432                req->se->op.read(req, nodeid, arg->size, arg->offset, &fi);
 
 1439        struct fuse_write_in *arg = (
struct fuse_write_in *) inarg;
 
 1443        memset(&fi, 0, 
sizeof(fi));
 
 1445        fi.
writepage = (arg->write_flags & FUSE_WRITE_CACHE) != 0;
 
 1447        if (req->se->conn.proto_minor < 9) {
 
 1448                param = ((
char *) arg) + FUSE_COMPAT_WRITE_IN_SIZE;
 
 1451                fi.
flags = arg->flags;
 
 1455        if (req->se->op.write)
 
 1456                req->se->op.write(req, nodeid, param, arg->size,
 
 1465        struct fuse_session *se = req->se;
 
 1470        struct fuse_write_in *arg = (
struct fuse_write_in *) inarg;
 
 1473        memset(&fi, 0, 
sizeof(fi));
 
 1475        fi.
writepage = arg->write_flags & FUSE_WRITE_CACHE;
 
 1477        if (se->conn.proto_minor < 9) {
 
 1478                bufv.
buf[0].
mem = ((
char *) arg) + FUSE_COMPAT_WRITE_IN_SIZE;
 
 1479                bufv.
buf[0].
size -= 
sizeof(
struct fuse_in_header) +
 
 1480                        FUSE_COMPAT_WRITE_IN_SIZE;
 
 1484                fi.
flags = arg->flags;
 
 1486                        bufv.
buf[0].
mem = PARAM(arg);
 
 1488                bufv.
buf[0].
size -= 
sizeof(
struct fuse_in_header) +
 
 1489                        sizeof(struct fuse_write_in);
 
 1491        if (bufv.
buf[0].
size < arg->size) {
 
 1492                fuse_log(FUSE_LOG_ERR, 
"fuse: do_write_buf: buffer size too small\n");
 
 1498        se->op.write_buf(req, nodeid, &bufv, arg->offset, &fi);
 
 1503                fuse_ll_clear_pipe(se);
 
 1508        struct fuse_flush_in *arg = (
struct fuse_flush_in *) inarg;
 
 1511        memset(&fi, 0, 
sizeof(fi));
 
 1514        if (req->se->conn.proto_minor >= 7)
 
 1517        if (req->se->op.flush)
 
 1518                req->se->op.flush(req, nodeid, &fi);
 
 1525        struct fuse_release_in *arg = (
struct fuse_release_in *) inarg;
 
 1528        memset(&fi, 0, 
sizeof(fi));
 
 1529        fi.
flags = arg->flags;
 
 1531        if (req->se->conn.proto_minor >= 8) {
 
 1532                fi.
flush = (arg->release_flags & FUSE_RELEASE_FLUSH) ? 1 : 0;
 
 1535        if (arg->release_flags & FUSE_RELEASE_FLOCK_UNLOCK) {
 
 1536                fi.flock_release = 1;
 
 1540        if (req->se->op.release)
 
 1541                req->se->op.release(req, nodeid, &fi);
 
 1548        struct fuse_fsync_in *arg = (
struct fuse_fsync_in *) inarg;
 
 1550        int datasync = arg->fsync_flags & 1;
 
 1552        memset(&fi, 0, 
sizeof(fi));
 
 1555        if (req->se->op.fsync)
 
 1556                req->se->op.fsync(req, nodeid, datasync, &fi);
 
 1563        struct fuse_open_in *arg = (
struct fuse_open_in *) inarg;
 
 1566        memset(&fi, 0, 
sizeof(fi));
 
 1567        fi.
flags = arg->flags;
 
 1569        if (req->se->op.opendir)
 
 1570                req->se->op.opendir(req, nodeid, &fi);
 
 1579        struct fuse_read_in *arg = (
struct fuse_read_in *) inarg;
 
 1582        memset(&fi, 0, 
sizeof(fi));
 
 1585        if (req->se->op.readdir)
 
 1586                req->se->op.readdir(req, nodeid, arg->size, arg->offset, &fi);
 
 1593        struct fuse_read_in *arg = (
struct fuse_read_in *) inarg;
 
 1596        memset(&fi, 0, 
sizeof(fi));
 
 1599        if (req->se->op.readdirplus)
 
 1600                req->se->op.readdirplus(req, nodeid, arg->size, arg->offset, &fi);
 
 1607        struct fuse_release_in *arg = (
struct fuse_release_in *) inarg;
 
 1610        memset(&fi, 0, 
sizeof(fi));
 
 1611        fi.
flags = arg->flags;
 
 1614        if (req->se->op.releasedir)
 
 1615                req->se->op.releasedir(req, nodeid, &fi);
 
 1622        struct fuse_fsync_in *arg = (
struct fuse_fsync_in *) inarg;
 
 1624        int datasync = arg->fsync_flags & 1;
 
 1626        memset(&fi, 0, 
sizeof(fi));
 
 1629        if (req->se->op.fsyncdir)
 
 1630                req->se->op.fsyncdir(req, nodeid, datasync, &fi);
 
 1640        if (req->se->op.statfs)
 
 1641                req->se->op.statfs(req, nodeid);
 
 1643                struct statvfs buf = {
 
 1653        struct fuse_session *se = req->se;
 
 1655        struct fuse_setxattr_in *arg = (
struct fuse_setxattr_in *) inarg;
 
 1656        char *name = xattr_ext ? PARAM(arg) :
 
 1657                     (char *)arg + FUSE_COMPAT_SETXATTR_IN_SIZE;
 
 1658        char *value = name + strlen(name) + 1;
 
 1661        if (req->se->op.setxattr)
 
 1662                req->se->op.setxattr(req, nodeid, name, value, arg->size,
 
 1670        struct fuse_getxattr_in *arg = (
struct fuse_getxattr_in *) inarg;
 
 1672        if (req->se->op.getxattr)
 
 1673                req->se->op.getxattr(req, nodeid, PARAM(arg), arg->size);
 
 1680        struct fuse_getxattr_in *arg = (
struct fuse_getxattr_in *) inarg;
 
 1682        if (req->se->op.listxattr)
 
 1683                req->se->op.listxattr(req, nodeid, arg->size);
 
 1690        char *name = (
char *) inarg;
 
 1692        if (req->se->op.removexattr)
 
 1693                req->se->op.removexattr(req, nodeid, name);
 
 1698static void convert_fuse_file_lock(
struct fuse_file_lock *fl,
 
 1699                                   struct flock *flock)
 
 1701        memset(flock, 0, 
sizeof(
struct flock));
 
 1702        flock->l_type = fl->type;
 
 1703        flock->l_whence = SEEK_SET;
 
 1704        flock->l_start = fl->start;
 
 1705        if (fl->end == OFFSET_MAX)
 
 1708                flock->l_len = fl->end - fl->start + 1;
 
 1709        flock->l_pid = fl->pid;
 
 1714        struct fuse_lk_in *arg = (
struct fuse_lk_in *) inarg;
 
 1718        memset(&fi, 0, 
sizeof(fi));
 
 1722        convert_fuse_file_lock(&arg->lk, &flock);
 
 1723        if (req->se->op.getlk)
 
 1724                req->se->op.getlk(req, nodeid, &fi, &flock);
 
 1730                            const void *inarg, 
int sleep)
 
 1732        struct fuse_lk_in *arg = (
struct fuse_lk_in *) inarg;
 
 1736        memset(&fi, 0, 
sizeof(fi));
 
 1740        if (arg->lk_flags & FUSE_LK_FLOCK) {
 
 1743                switch (arg->lk.type) {
 
 1757                if (req->se->op.flock)
 
 1758                        req->se->op.flock(req, nodeid, &fi, op);
 
 1762                convert_fuse_file_lock(&arg->lk, &flock);
 
 1763                if (req->se->op.setlk)
 
 1764                        req->se->op.setlk(req, nodeid, &fi, &flock, sleep);
 
 1772        do_setlk_common(req, nodeid, inarg, 0);
 
 1777        do_setlk_common(req, nodeid, inarg, 1);
 
 1780static int find_interrupted(
struct fuse_session *se, 
struct fuse_req *req)
 
 1782        struct fuse_req *curr;
 
 1784        for (curr = se->list.next; curr != &se->list; curr = curr->next) {
 
 1785                if (curr->unique == req->u.i.unique) {
 
 1790                        pthread_mutex_unlock(&se->lock);
 
 1793                        pthread_mutex_lock(&curr->lock);
 
 1794                        pthread_mutex_lock(&se->lock);
 
 1795                        curr->interrupted = 1;
 
 1796                        func = curr->u.ni.func;
 
 1797                        data = curr->u.ni.data;
 
 1798                        pthread_mutex_unlock(&se->lock);
 
 1801                        pthread_mutex_unlock(&curr->lock);
 
 1803                        pthread_mutex_lock(&se->lock);
 
 1805                        if (!curr->ref_cnt) {
 
 1812        for (curr = se->interrupts.next; curr != &se->interrupts;
 
 1813             curr = curr->next) {
 
 1814                if (curr->u.i.unique == req->u.i.unique)
 
 1822        struct fuse_interrupt_in *arg = (
struct fuse_interrupt_in *) inarg;
 
 1823        struct fuse_session *se = req->se;
 
 1827                fuse_log(FUSE_LOG_DEBUG, 
"INTERRUPT: %llu\n",
 
 1828                        (
unsigned long long) arg->unique);
 
 1830        req->u.i.unique = arg->unique;
 
 1832        pthread_mutex_lock(&se->lock);
 
 1833        if (find_interrupted(se, req)) {
 
 1834                fuse_chan_put(req->ch);
 
 1838                list_add_req(req, &se->interrupts);
 
 1839        pthread_mutex_unlock(&se->lock);
 
 1842static struct fuse_req *check_interrupt(
struct fuse_session *se,
 
 1843                                        struct fuse_req *req)
 
 1845        struct fuse_req *curr;
 
 1847        for (curr = se->interrupts.next; curr != &se->interrupts;
 
 1848             curr = curr->next) {
 
 1849                if (curr->u.i.unique == req->unique) {
 
 1850                        req->interrupted = 1;
 
 1852                        fuse_chan_put(curr->ch);
 
 1858        curr = se->interrupts.next;
 
 1859        if (curr != &se->interrupts) {
 
 1861                list_init_req(curr);
 
 1869        struct fuse_bmap_in *arg = (
struct fuse_bmap_in *) inarg;
 
 1871        if (req->se->op.bmap)
 
 1872                req->se->op.bmap(req, nodeid, arg->blocksize, arg->block);
 
 1879        struct fuse_ioctl_in *arg = (
struct fuse_ioctl_in *) inarg;
 
 1880        unsigned int flags = arg->flags;
 
 1881        void *in_buf = arg->in_size ? PARAM(arg) : NULL;
 
 1884        if (
flags & FUSE_IOCTL_DIR &&
 
 1890        memset(&fi, 0, 
sizeof(fi));
 
 1893        if (
sizeof(
void *) == 4 && req->se->conn.proto_minor >= 16 &&
 
 1894            !(
flags & FUSE_IOCTL_32BIT)) {
 
 1895                req->ioctl_64bit = 1;
 
 1898        if (req->se->op.ioctl)
 
 1899                req->se->op.ioctl(req, nodeid, arg->cmd,
 
 1900                                 (
void *)(uintptr_t)arg->arg, &fi, 
flags,
 
 1901                                 in_buf, arg->in_size, arg->out_size);
 
 1913        struct fuse_poll_in *arg = (
struct fuse_poll_in *) inarg;
 
 1916        memset(&fi, 0, 
sizeof(fi));
 
 1920        if (req->se->op.poll) {
 
 1921                struct fuse_pollhandle *ph = NULL;
 
 1923                if (arg->flags & FUSE_POLL_SCHEDULE_NOTIFY) {
 
 1924                        ph = malloc(
sizeof(
struct fuse_pollhandle));
 
 1933                req->se->op.poll(req, nodeid, &fi, ph);
 
 1941        struct fuse_fallocate_in *arg = (
struct fuse_fallocate_in *) inarg;
 
 1944        memset(&fi, 0, 
sizeof(fi));
 
 1947        if (req->se->op.fallocate)
 
 1948                req->se->op.fallocate(req, nodeid, arg->mode, arg->offset, arg->length, &fi);
 
 1955        struct fuse_copy_file_range_in *arg = (
struct fuse_copy_file_range_in *) inarg;
 
 1958        memset(&fi_in, 0, 
sizeof(fi_in));
 
 1959        fi_in.fh = arg->fh_in;
 
 1961        memset(&fi_out, 0, 
sizeof(fi_out));
 
 1962        fi_out.fh = arg->fh_out;
 
 1965        if (req->se->op.copy_file_range)
 
 1966                req->se->op.copy_file_range(req, nodeid_in, arg->off_in,
 
 1967                                            &fi_in, arg->nodeid_out,
 
 1968                                            arg->off_out, &fi_out, arg->len,
 
 1976        struct fuse_lseek_in *arg = (
struct fuse_lseek_in *) inarg;
 
 1979        memset(&fi, 0, 
sizeof(fi));
 
 1982        if (req->se->op.lseek)
 
 1983                req->se->op.lseek(req, nodeid, arg->offset, arg->whence, &fi);
 
 1988static bool want_flags_valid(uint64_t capable, uint64_t want)
 
 1990        uint64_t unknown_flags = want & (~capable);
 
 1991        if (unknown_flags != 0) {
 
 1993                         "fuse: unknown connection 'want' flags: 0x%08lx\n",
 
 2003static inline int convert_to_conn_want_ext(
struct fuse_conn_info *conn,
 
 2004                                           uint64_t want_ext_default)
 
 2007        if (conn->
want != 0) {
 
 2008                if (conn->
want_ext != want_ext_default) {
 
 2010                                 "fuse: both 'want' and 'want_ext' are set\n");
 
 2021static __attribute__((no_sanitize(
"thread")))
 
 2024        struct fuse_init_in *arg = (
struct fuse_init_in *) inarg;
 
 2025        struct fuse_init_out outarg;
 
 2026        struct fuse_session *se = req->se;
 
 2027        size_t bufsize = se->bufsize;
 
 2028        size_t outargsize = 
sizeof(outarg);
 
 2029        uint64_t inargflags = 0;
 
 2030        uint64_t outargflags = 0;
 
 2031        bool buf_reallocable = se->buf_reallocable;
 
 2034                fuse_log(FUSE_LOG_DEBUG, 
"INIT: %u.%u\n", arg->major, arg->minor);
 
 2035                if (arg->major == 7 && arg->minor >= 6) {
 
 2036                        fuse_log(FUSE_LOG_DEBUG, 
"flags=0x%08x\n", arg->flags);
 
 2037                        fuse_log(FUSE_LOG_DEBUG, 
"max_readahead=0x%08x\n",
 
 2038                                arg->max_readahead);
 
 2041        se->conn.proto_major = arg->major;
 
 2042        se->conn.proto_minor = arg->minor;
 
 2043        se->conn.capable_ext = 0;
 
 2044        se->conn.want_ext = 0;
 
 2046        memset(&outarg, 0, 
sizeof(outarg));
 
 2047        outarg.major = FUSE_KERNEL_VERSION;
 
 2048        outarg.minor = FUSE_KERNEL_MINOR_VERSION;
 
 2050        if (arg->major < 7) {
 
 2051                fuse_log(FUSE_LOG_ERR, 
"fuse: unsupported protocol version: %u.%u\n",
 
 2052                        arg->major, arg->minor);
 
 2057        if (arg->major > 7) {
 
 2059                send_reply_ok(req, &outarg, 
sizeof(outarg));
 
 2063        if (arg->minor >= 6) {
 
 2064                if (arg->max_readahead < se->conn.max_readahead)
 
 2065                        se->conn.max_readahead = arg->max_readahead;
 
 2066                inargflags = arg->flags;
 
 2067                if (inargflags & FUSE_INIT_EXT)
 
 2068                        inargflags = inargflags | (uint64_t) arg->flags2 << 32;
 
 2069                if (inargflags & FUSE_ASYNC_READ)
 
 2071                if (inargflags & FUSE_POSIX_LOCKS)
 
 2073                if (inargflags & FUSE_ATOMIC_O_TRUNC)
 
 2075                if (inargflags & FUSE_EXPORT_SUPPORT)
 
 2077                if (inargflags & FUSE_DONT_MASK)
 
 2079                if (inargflags & FUSE_FLOCK_LOCKS)
 
 2081                if (inargflags & FUSE_AUTO_INVAL_DATA)
 
 2083                if (inargflags & FUSE_DO_READDIRPLUS)
 
 2085                if (inargflags & FUSE_READDIRPLUS_AUTO)
 
 2087                if (inargflags & FUSE_ASYNC_DIO)
 
 2089                if (inargflags & FUSE_WRITEBACK_CACHE)
 
 2091                if (inargflags & FUSE_NO_OPEN_SUPPORT)
 
 2093                if (inargflags & FUSE_PARALLEL_DIROPS)
 
 2095                if (inargflags & FUSE_POSIX_ACL)
 
 2097                if (inargflags & FUSE_HANDLE_KILLPRIV)
 
 2099                if (inargflags & FUSE_HANDLE_KILLPRIV_V2)
 
 2101                if (inargflags & FUSE_CACHE_SYMLINKS)
 
 2103                if (inargflags & FUSE_NO_OPENDIR_SUPPORT)
 
 2105                if (inargflags & FUSE_EXPLICIT_INVAL_DATA)
 
 2107                if (inargflags & FUSE_SETXATTR_EXT)
 
 2109                if (!(inargflags & FUSE_MAX_PAGES)) {
 
 2110                        size_t max_bufsize =
 
 2111                                FUSE_DEFAULT_MAX_PAGES_PER_REQ * getpagesize()
 
 2112                                + FUSE_BUFFER_HEADER_SIZE;
 
 2113                        if (bufsize > max_bufsize) {
 
 2114                                bufsize = max_bufsize;
 
 2116                        buf_reallocable = 
false;
 
 2118                if (inargflags & FUSE_DIRECT_IO_ALLOW_MMAP)
 
 2120                if (arg->minor >= 38 || (inargflags & FUSE_HAS_EXPIRE_ONLY))
 
 2122                if (inargflags & FUSE_PASSTHROUGH)
 
 2124                if (inargflags & FUSE_NO_EXPORT_SUPPORT)
 
 2127                se->conn.max_readahead = 0;
 
 2130        if (se->conn.proto_minor >= 14) {
 
 2133                if ((se->io == NULL) || (se->io->splice_send != NULL)) {
 
 2138                if ((se->io == NULL) || (se->io->splice_receive != NULL)) {
 
 2143        if (se->conn.proto_minor >= 18)
 
 2153#define LL_SET_DEFAULT(cond, cap)                     \ 
 2155                fuse_set_feature_flag(&se->conn, cap) 
 2163        LL_SET_DEFAULT(se->op.getlk && se->op.setlk,
 
 2167        LL_SET_DEFAULT(se->op.readdirplus && se->op.readdir,
 
 2175        se->conn.time_gran = 1;
 
 2179                uint64_t want_ext_default = se->conn.want_ext;
 
 2184                        (uint32_t)(se->conn.capable_ext & 0xFFFFFFFF);
 
 2186                se->op.init(se->userdata, &se->conn);
 
 2193                rc = convert_to_conn_want_ext(&se->conn, want_ext_default);
 
 2196                        se->error = -EPROTO;
 
 2202        if (!want_flags_valid(se->conn.capable_ext, se->conn.want_ext)) {
 
 2204                se->error = -EPROTO;
 
 2209        unsigned max_read_mo = get_max_read(se->mo);
 
 2210        if (se->conn.max_read != max_read_mo) {
 
 2211                fuse_log(FUSE_LOG_ERR, 
"fuse: error: init() and fuse_session_new() " 
 2212                        "requested different maximum read size (%u vs %u)\n",
 
 2213                        se->conn.max_read, max_read_mo);
 
 2215                se->error = -EPROTO;
 
 2220        if (bufsize < FUSE_MIN_READ_BUFFER) {
 
 2222                         "fuse: warning: buffer size too small: %zu\n",
 
 2224                bufsize = FUSE_MIN_READ_BUFFER;
 
 2227        if (buf_reallocable)
 
 2229        se->conn.max_write = MIN(se->conn.max_write, bufsize - FUSE_BUFFER_HEADER_SIZE);
 
 2230        se->bufsize = se->conn.max_write + FUSE_BUFFER_HEADER_SIZE;
 
 2232        if (arg->flags & FUSE_MAX_PAGES) {
 
 2233                outarg.flags |= FUSE_MAX_PAGES;
 
 2234                outarg.max_pages = (se->conn.max_write - 1) / getpagesize() + 1;
 
 2236        outargflags = outarg.flags;
 
 2239        outargflags |= FUSE_BIG_WRITES;
 
 2242                outargflags |= FUSE_ASYNC_READ;
 
 2244                outargflags |= FUSE_POSIX_LOCKS;
 
 2246                outargflags |= FUSE_ATOMIC_O_TRUNC;
 
 2248                outargflags |= FUSE_EXPORT_SUPPORT;
 
 2250                outargflags |= FUSE_DONT_MASK;
 
 2252                outargflags |= FUSE_FLOCK_LOCKS;
 
 2254                outargflags |= FUSE_AUTO_INVAL_DATA;
 
 2256                outargflags |= FUSE_DO_READDIRPLUS;
 
 2258                outargflags |= FUSE_READDIRPLUS_AUTO;
 
 2260                outargflags |= FUSE_ASYNC_DIO;
 
 2262                outargflags |= FUSE_WRITEBACK_CACHE;
 
 2264                outargflags |= FUSE_PARALLEL_DIROPS;
 
 2266                outargflags |= FUSE_POSIX_ACL;
 
 2268                outargflags |= FUSE_HANDLE_KILLPRIV;
 
 2270                outargflags |= FUSE_HANDLE_KILLPRIV_V2;
 
 2272                outargflags |= FUSE_CACHE_SYMLINKS;
 
 2274                outargflags |= FUSE_EXPLICIT_INVAL_DATA;
 
 2276                outargflags |= FUSE_SETXATTR_EXT;
 
 2278                outargflags |= FUSE_DIRECT_IO_ALLOW_MMAP;
 
 2280                outargflags |= FUSE_PASSTHROUGH;
 
 2285                outarg.max_stack_depth = se->conn.max_backing_stack_depth + 1;
 
 2288                outargflags |= FUSE_NO_EXPORT_SUPPORT;
 
 2290        if (inargflags & FUSE_INIT_EXT) {
 
 2291                outargflags |= FUSE_INIT_EXT;
 
 2292                outarg.flags2 = outargflags >> 32;
 
 2295        outarg.flags = outargflags;
 
 2297        outarg.max_readahead = se->conn.max_readahead;
 
 2298        outarg.max_write = se->conn.max_write;
 
 2299        if (se->conn.proto_minor >= 13) {
 
 2300                if (se->conn.max_background >= (1 << 16))
 
 2301                        se->conn.max_background = (1 << 16) - 1;
 
 2302                if (se->conn.congestion_threshold > se->conn.max_background)
 
 2303                        se->conn.congestion_threshold = se->conn.max_background;
 
 2304                if (!se->conn.congestion_threshold) {
 
 2305                        se->conn.congestion_threshold =
 
 2306                                se->conn.max_background * 3 / 4;
 
 2309                outarg.max_background = se->conn.max_background;
 
 2310                outarg.congestion_threshold = se->conn.congestion_threshold;
 
 2312        if (se->conn.proto_minor >= 23)
 
 2313                outarg.time_gran = se->conn.time_gran;
 
 2316                fuse_log(FUSE_LOG_DEBUG, 
"   INIT: %u.%u\n", outarg.major, outarg.minor);
 
 2317                fuse_log(FUSE_LOG_DEBUG, 
"   flags=0x%08x\n", outarg.flags);
 
 2318                fuse_log(FUSE_LOG_DEBUG, 
"   max_readahead=0x%08x\n",
 
 2319                        outarg.max_readahead);
 
 2320                fuse_log(FUSE_LOG_DEBUG, 
"   max_write=0x%08x\n", outarg.max_write);
 
 2321                fuse_log(FUSE_LOG_DEBUG, 
"   max_background=%i\n",
 
 2322                        outarg.max_background);
 
 2323                fuse_log(FUSE_LOG_DEBUG, 
"   congestion_threshold=%i\n",
 
 2324                        outarg.congestion_threshold);
 
 2325                fuse_log(FUSE_LOG_DEBUG, 
"   time_gran=%u\n",
 
 2328                        fuse_log(FUSE_LOG_DEBUG, 
"   max_stack_depth=%u\n",
 
 2329                                outarg.max_stack_depth);
 
 2332                outargsize = FUSE_COMPAT_INIT_OUT_SIZE;
 
 2333        else if (arg->minor < 23)
 
 2334                outargsize = FUSE_COMPAT_22_INIT_OUT_SIZE;
 
 2336        send_reply_ok(req, &outarg, outargsize);
 
 2341        struct fuse_session *se = req->se;
 
 2346        se->got_destroy = 1;
 
 2349                se->op.destroy(se->userdata);
 
 2351        send_reply_ok(req, NULL, 0);
 
 2354static void list_del_nreq(
struct fuse_notify_req *nreq)
 
 2356        struct fuse_notify_req *prev = nreq->prev;
 
 2357        struct fuse_notify_req *next = nreq->next;
 
 2362static void list_add_nreq(
struct fuse_notify_req *nreq,
 
 2363                          struct fuse_notify_req *next)
 
 2365        struct fuse_notify_req *prev = next->prev;
 
 2372static void list_init_nreq(
struct fuse_notify_req *nreq)
 
 2379                            const void *inarg, 
const struct fuse_buf *buf)
 
 2381        struct fuse_session *se = req->se;
 
 2382        struct fuse_notify_req *nreq;
 
 2383        struct fuse_notify_req *head;
 
 2385        pthread_mutex_lock(&se->lock);
 
 2386        head = &se->notify_list;
 
 2387        for (nreq = head->next; nreq != head; nreq = nreq->next) {
 
 2388                if (nreq->unique == req->unique) {
 
 2389                        list_del_nreq(nreq);
 
 2393        pthread_mutex_unlock(&se->lock);
 
 2396                nreq->reply(nreq, req, nodeid, inarg, buf);
 
 2399static int send_notify_iov(
struct fuse_session *se, 
int notify_code,
 
 2400                           struct iovec *iov, 
int count)
 
 2402        struct fuse_out_header out;
 
 2408        out.error = notify_code;
 
 2409        iov[0].iov_base = &out;
 
 2410        iov[0].iov_len = 
sizeof(
struct fuse_out_header);
 
 2412        return fuse_send_msg(se, NULL, iov, count);
 
 2418                struct fuse_notify_poll_wakeup_out outarg;
 
 2419                struct iovec iov[2];
 
 2423                iov[1].iov_base = &outarg;
 
 2424                iov[1].iov_len = 
sizeof(outarg);
 
 2426                return send_notify_iov(ph->se, FUSE_NOTIFY_POLL, iov, 2);
 
 
 2433                                     off_t off, off_t len)
 
 2435        struct fuse_notify_inval_inode_out outarg;
 
 2436        struct iovec iov[2];
 
 2441        if (se->conn.proto_minor < 12)
 
 2448        iov[1].iov_base = &outarg;
 
 2449        iov[1].iov_len = 
sizeof(outarg);
 
 2451        return send_notify_iov(se, FUSE_NOTIFY_INVAL_INODE, iov, 2);
 
 
 2473static int fuse_lowlevel_notify_entry(
struct fuse_session *se, 
fuse_ino_t parent,
 
 2474                                                        const char *name, 
size_t namelen,
 
 2477        struct fuse_notify_inval_entry_out outarg;
 
 2478        struct iovec iov[3];
 
 2483        if (se->conn.proto_minor < 12)
 
 2486        outarg.parent = parent;
 
 2487        outarg.namelen = namelen;
 
 2489        if (flags & FUSE_LL_EXPIRE_ONLY)
 
 2490                outarg.flags |= FUSE_EXPIRE_ONLY;
 
 2492        iov[1].iov_base = &outarg;
 
 2493        iov[1].iov_len = 
sizeof(outarg);
 
 2494        iov[2].iov_base = (
void *)name;
 
 2495        iov[2].iov_len = namelen + 1;
 
 2497        return send_notify_iov(se, FUSE_NOTIFY_INVAL_ENTRY, iov, 3);
 
 2501                                                 const char *name, 
size_t namelen)
 
 2503        return fuse_lowlevel_notify_entry(se, parent, name, namelen, FUSE_LL_INVALIDATE);
 
 
 2507                                                        const char *name, 
size_t namelen)
 
 2515        return fuse_lowlevel_notify_entry(se, parent, name, namelen, FUSE_LL_EXPIRE_ONLY);
 
 
 2521                                const char *name, 
size_t namelen)
 
 2523        struct fuse_notify_delete_out outarg;
 
 2524        struct iovec iov[3];
 
 2529        if (se->conn.proto_minor < 18)
 
 2532        outarg.parent = parent;
 
 2533        outarg.child = child;
 
 2534        outarg.namelen = namelen;
 
 2537        iov[1].iov_base = &outarg;
 
 2538        iov[1].iov_len = 
sizeof(outarg);
 
 2539        iov[2].iov_base = (
void *)name;
 
 2540        iov[2].iov_len = namelen + 1;
 
 2542        return send_notify_iov(se, FUSE_NOTIFY_DELETE, iov, 3);
 
 
 2549        struct fuse_out_header out;
 
 2550        struct fuse_notify_store_out outarg;
 
 2551        struct iovec iov[3];
 
 2558        if (se->conn.proto_minor < 15)
 
 2562        out.error = FUSE_NOTIFY_STORE;
 
 2564        outarg.nodeid = ino;
 
 2565        outarg.offset = offset;
 
 2569        iov[0].iov_base = &out;
 
 2570        iov[0].iov_len = 
sizeof(out);
 
 2571        iov[1].iov_base = &outarg;
 
 2572        iov[1].iov_len = 
sizeof(outarg);
 
 2574        res = fuse_send_data_iov(se, NULL, iov, 2, bufv, flags);
 
 
 2581struct fuse_retrieve_req {
 
 2582        struct fuse_notify_req nreq;
 
 2586static void fuse_ll_retrieve_reply(
struct fuse_notify_req *nreq,
 
 2591        struct fuse_session *se = req->se;
 
 2592        struct fuse_retrieve_req *rreq =
 
 2593                container_of(nreq, 
struct fuse_retrieve_req, nreq);
 
 2594        const struct fuse_notify_retrieve_in *arg = inarg;
 
 2601                bufv.
buf[0].
mem = PARAM(arg);
 
 2603        bufv.
buf[0].
size -= 
sizeof(
struct fuse_in_header) +
 
 2604                sizeof(struct fuse_notify_retrieve_in);
 
 2606        if (bufv.
buf[0].
size < arg->size) {
 
 2607                fuse_log(FUSE_LOG_ERR, 
"fuse: retrieve reply: buffer size too small\n");
 
 2613        if (se->op.retrieve_reply) {
 
 2614                se->op.retrieve_reply(req, rreq->cookie, ino,
 
 2615                                          arg->offset, &bufv);
 
 2622                fuse_ll_clear_pipe(se);
 
 2626                                  size_t size, off_t offset, 
void *cookie)
 
 2628        struct fuse_notify_retrieve_out outarg;
 
 2629        struct iovec iov[2];
 
 2630        struct fuse_retrieve_req *rreq;
 
 2636        if (se->conn.proto_minor < 15)
 
 2639        rreq = malloc(
sizeof(*rreq));
 
 2643        pthread_mutex_lock(&se->lock);
 
 2644        rreq->cookie = cookie;
 
 2645        rreq->nreq.unique = se->notify_ctr++;
 
 2646        rreq->nreq.reply = fuse_ll_retrieve_reply;
 
 2647        list_add_nreq(&rreq->nreq, &se->notify_list);
 
 2648        pthread_mutex_unlock(&se->lock);
 
 2650        outarg.notify_unique = rreq->nreq.unique;
 
 2651        outarg.nodeid = ino;
 
 2652        outarg.offset = offset;
 
 2656        iov[1].iov_base = &outarg;
 
 2657        iov[1].iov_len = 
sizeof(outarg);
 
 2659        err = send_notify_iov(se, FUSE_NOTIFY_RETRIEVE, iov, 2);
 
 2661                pthread_mutex_lock(&se->lock);
 
 2662                list_del_nreq(&rreq->nreq);
 
 2663                pthread_mutex_unlock(&se->lock);
 
 
 2672        return req->se->userdata;
 
 
 2683        pthread_mutex_lock(&req->lock);
 
 2684        pthread_mutex_lock(&req->se->lock);
 
 2685        req->u.ni.func = func;
 
 2686        req->u.ni.data = data;
 
 2687        pthread_mutex_unlock(&req->se->lock);
 
 2688        if (req->interrupted && func)
 
 2690        pthread_mutex_unlock(&req->lock);
 
 
 2697        pthread_mutex_lock(&req->se->lock);
 
 2698        interrupted = req->interrupted;
 
 2699        pthread_mutex_unlock(&req->se->lock);
 
 
 2708        [FUSE_LOOKUP]      = { do_lookup,      
"LOOKUP"      },
 
 2709        [FUSE_FORGET]      = { do_forget,      
"FORGET"      },
 
 2710        [FUSE_GETATTR]     = { do_getattr,     
"GETATTR"     },
 
 2711        [FUSE_SETATTR]     = { do_setattr,     
"SETATTR"     },
 
 2712        [FUSE_READLINK]    = { do_readlink,    
"READLINK"    },
 
 2713        [FUSE_SYMLINK]     = { do_symlink,     
"SYMLINK"     },
 
 2714        [FUSE_MKNOD]       = { do_mknod,       
"MKNOD"       },
 
 2715        [FUSE_MKDIR]       = { do_mkdir,       
"MKDIR"       },
 
 2716        [FUSE_UNLINK]      = { do_unlink,      
"UNLINK"      },
 
 2717        [FUSE_RMDIR]       = { do_rmdir,       
"RMDIR"       },
 
 2718        [FUSE_RENAME]      = { do_rename,      
"RENAME"      },
 
 2719        [FUSE_LINK]        = { do_link,        
"LINK"        },
 
 2720        [FUSE_OPEN]        = { do_open,        
"OPEN"        },
 
 2721        [FUSE_READ]        = { do_read,        
"READ"        },
 
 2722        [FUSE_WRITE]       = { do_write,       
"WRITE"       },
 
 2723        [FUSE_STATFS]      = { do_statfs,      
"STATFS"      },
 
 2724        [FUSE_RELEASE]     = { do_release,     
"RELEASE"     },
 
 2725        [FUSE_FSYNC]       = { do_fsync,       
"FSYNC"       },
 
 2726        [FUSE_SETXATTR]    = { do_setxattr,    
"SETXATTR"    },
 
 2727        [FUSE_GETXATTR]    = { do_getxattr,    
"GETXATTR"    },
 
 2728        [FUSE_LISTXATTR]   = { do_listxattr,   
"LISTXATTR"   },
 
 2729        [FUSE_REMOVEXATTR] = { do_removexattr, 
"REMOVEXATTR" },
 
 2730        [FUSE_FLUSH]       = { do_flush,       
"FLUSH"       },
 
 2731        [FUSE_INIT]        = { do_init,        
"INIT"        },
 
 2732        [FUSE_OPENDIR]     = { do_opendir,     
"OPENDIR"     },
 
 2733        [FUSE_READDIR]     = { do_readdir,     
"READDIR"     },
 
 2734        [FUSE_RELEASEDIR]  = { do_releasedir,  
"RELEASEDIR"  },
 
 2735        [FUSE_FSYNCDIR]    = { do_fsyncdir,    
"FSYNCDIR"    },
 
 2736        [FUSE_GETLK]       = { do_getlk,       
"GETLK"       },
 
 2737        [FUSE_SETLK]       = { do_setlk,       
"SETLK"       },
 
 2738        [FUSE_SETLKW]      = { do_setlkw,      
"SETLKW"      },
 
 2739        [FUSE_ACCESS]      = { do_access,      
"ACCESS"      },
 
 2740        [FUSE_CREATE]      = { do_create,      
"CREATE"      },
 
 2741        [FUSE_TMPFILE]     = { do_tmpfile,     
"TMPFILE"        },
 
 2742        [FUSE_INTERRUPT]   = { do_interrupt,   
"INTERRUPT"   },
 
 2743        [FUSE_BMAP]        = { do_bmap,        
"BMAP"        },
 
 2744        [FUSE_IOCTL]       = { do_ioctl,       
"IOCTL"       },
 
 2745        [FUSE_POLL]        = { do_poll,        
"POLL"        },
 
 2746        [FUSE_FALLOCATE]   = { do_fallocate,   
"FALLOCATE"   },
 
 2747        [FUSE_DESTROY]     = { do_destroy,     
"DESTROY"     },
 
 2748        [FUSE_NOTIFY_REPLY] = { (
void *) 1,    
"NOTIFY_REPLY" },
 
 2749        [FUSE_BATCH_FORGET] = { do_batch_forget, 
"BATCH_FORGET" },
 
 2750        [FUSE_READDIRPLUS] = { do_readdirplus,  
"READDIRPLUS"},
 
 2751        [FUSE_RENAME2]     = { do_rename2,      
"RENAME2"    },
 
 2752        [FUSE_COPY_FILE_RANGE] = { do_copy_file_range, 
"COPY_FILE_RANGE" },
 
 2753        [FUSE_LSEEK]       = { do_lseek,       
"LSEEK"       },
 
 2754        [CUSE_INIT]        = { cuse_lowlevel_init, 
"CUSE_INIT"   },
 
 2762#define FUSE_MAXOP (CUSE_INIT + 1) 
 2764static const char *opname(
enum fuse_opcode opcode)
 
 2766        if (opcode >= FUSE_MAXOP || !fuse_ll_ops[opcode].name)
 
 2769                return fuse_ll_ops[opcode].name;
 
 2772static int fuse_ll_copy_from_pipe(
struct fuse_bufvec *dst,
 
 2777                fuse_log(FUSE_LOG_ERR, 
"fuse: copy from pipe: %s\n", strerror(-res));
 
 2781                fuse_log(FUSE_LOG_ERR, 
"fuse: copy from pipe: short read\n");
 
 2790        fuse_session_process_buf_internal(se, buf, NULL);
 
 
 2794void fuse_session_process_buf_internal(
struct fuse_session *se,
 
 2795                                  const struct fuse_buf *buf, 
struct fuse_chan *ch)
 
 2797        const size_t write_header_size = 
sizeof(
struct fuse_in_header) +
 
 2798                sizeof(struct fuse_write_in);
 
 2800        struct fuse_bufvec tmpbuf = FUSE_BUFVEC_INIT(write_header_size);
 
 2801        struct fuse_in_header *in;
 
 2803        struct fuse_req *req;
 
 2812                mbuf = malloc(tmpbuf.
buf[0].
size);
 
 2814                        fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate header\n");
 
 2817                tmpbuf.
buf[0].
mem = mbuf;
 
 2819                res = fuse_ll_copy_from_pipe(&tmpbuf, &bufv);
 
 2830                        "unique: %llu, opcode: %s (%i), nodeid: %llu, insize: %zu, pid: %u\n",
 
 2831                        (
unsigned long long) in->unique,
 
 2832                        opname((
enum fuse_opcode) in->opcode), in->opcode,
 
 2833                        (
unsigned long long) in->nodeid, buf->
size, in->pid);
 
 2836        req = fuse_ll_alloc_req(se);
 
 2838                struct fuse_out_header out = {
 
 2839                        .unique = in->unique,
 
 2842                struct iovec iov = {
 
 2844                        .iov_len = 
sizeof(
struct fuse_out_header),
 
 2847                fuse_send_msg(se, ch, &iov, 1);
 
 2851        req->unique = in->unique;
 
 2852        req->ctx.uid = in->uid;
 
 2853        req->ctx.gid = in->gid;
 
 2854        req->ctx.pid = in->pid;
 
 2855        req->ch = ch ? fuse_chan_get(ch) : NULL;
 
 2858        if (!se->got_init) {
 
 2859                enum fuse_opcode expected;
 
 2861                expected = se->cuse_data ? CUSE_INIT : FUSE_INIT;
 
 2862                if (in->opcode != expected)
 
 2864        } 
else if (in->opcode == FUSE_INIT || in->opcode == CUSE_INIT)
 
 2869        if (se->deny_others && in->uid != se->owner && in->uid != 0 &&
 
 2870                 in->opcode != FUSE_INIT && in->opcode != FUSE_READ &&
 
 2871                 in->opcode != FUSE_WRITE && in->opcode != FUSE_FSYNC &&
 
 2872                 in->opcode != FUSE_RELEASE && in->opcode != FUSE_READDIR &&
 
 2873                 in->opcode != FUSE_FSYNCDIR && in->opcode != FUSE_RELEASEDIR &&
 
 2874                 in->opcode != FUSE_NOTIFY_REPLY &&
 
 2875                 in->opcode != FUSE_READDIRPLUS)
 
 2879        if (in->opcode >= FUSE_MAXOP || !fuse_ll_ops[in->opcode].func)
 
 2882        if (se->conn.no_interrupt && in->opcode == FUSE_INTERRUPT) {
 
 2884                        fuse_log(FUSE_LOG_DEBUG, 
"FUSE_INTERRUPT: reply to kernel to disable interrupt\n");
 
 2887        if (!se->conn.no_interrupt && in->opcode != FUSE_INTERRUPT) {
 
 2888                struct fuse_req *intr;
 
 2889                pthread_mutex_lock(&se->lock);
 
 2890                intr = check_interrupt(se, req);
 
 2891                list_add_req(req, &se->list);
 
 2892                pthread_mutex_unlock(&se->lock);
 
 2898            (in->opcode != FUSE_WRITE || !se->op.write_buf) &&
 
 2899            in->opcode != FUSE_NOTIFY_REPLY) {
 
 2903                newmbuf = realloc(mbuf, buf->
size);
 
 2904                if (newmbuf == NULL)
 
 2908                tmpbuf = FUSE_BUFVEC_INIT(buf->
size - write_header_size);
 
 2909                tmpbuf.
buf[0].
mem = (
char *)mbuf + write_header_size;
 
 2911                res = fuse_ll_copy_from_pipe(&tmpbuf, &bufv);
 
 2919        inarg = (
void *) &in[1];
 
 2920        if (in->opcode == FUSE_WRITE && se->op.write_buf)
 
 2921                do_write_buf(req, in->nodeid, inarg, buf);
 
 2922        else if (in->opcode == FUSE_NOTIFY_REPLY)
 
 2923                do_notify_reply(req, in->nodeid, inarg, buf);
 
 2925                fuse_ll_ops[in->opcode].func(req, in->nodeid, inarg);
 
 2935                fuse_ll_clear_pipe(se);
 
 2939#define LL_OPTION(n,o,v) \ 
 2940        { n, offsetof(struct fuse_session, o), v } 
 2942static const struct fuse_opt fuse_ll_opts[] = {
 
 2943        LL_OPTION(
"debug", debug, 1),
 
 2944        LL_OPTION(
"-d", debug, 1),
 
 2945        LL_OPTION(
"--debug", debug, 1),
 
 2946        LL_OPTION(
"allow_root", deny_others, 1),
 
 2952        printf(
"using FUSE kernel interface version %i.%i\n",
 
 2953               FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION);
 
 2954        fuse_mount_version();
 
 
 2962"    -o allow_other         allow access by all users\n" 
 2963"    -o allow_root          allow access by root\n" 
 2964"    -o auto_unmount        auto unmount on process termination\n");
 
 
 2969        struct fuse_ll_pipe *llp;
 
 2971        if (se->got_init && !se->got_destroy) {
 
 2973                        se->op.destroy(se->userdata);
 
 2975        llp = pthread_getspecific(se->pipe_key);
 
 2977                fuse_ll_pipe_free(llp);
 
 2978        pthread_key_delete(se->pipe_key);
 
 2979        pthread_mutex_destroy(&se->lock);
 
 2980        free(se->cuse_data);
 
 2985        destroy_mount_opts(se->mo);
 
 
 2990static void fuse_ll_pipe_destructor(
void *data)
 
 2992        struct fuse_ll_pipe *llp = data;
 
 2993        fuse_ll_pipe_free(llp);
 
 2996void fuse_buf_free(
struct fuse_buf *buf)
 
 2998        if (buf->
mem == NULL)
 
 3001        size_t write_header_sz =
 
 3002                sizeof(
struct fuse_in_header) + sizeof(struct fuse_write_in);
 
 3004        char *ptr = (
char *)buf->
mem - pagesize + write_header_sz;
 
 3012static void *buf_alloc(
size_t size, 
bool internal)
 
 3020                size_t write_header_sz = 
sizeof(
struct fuse_in_header) +
 
 3021                                         sizeof(struct fuse_write_in);
 
 3022                size_t new_size = ROUND_UP(size + write_header_sz, pagesize);
 
 3024                char *buf = aligned_alloc(pagesize, new_size);
 
 3028                buf += pagesize - write_header_sz;
 
 3032                return malloc(size);
 
 3039static int _fuse_session_receive_buf(
struct fuse_session *se,
 
 3040                                     struct fuse_buf *buf, 
struct fuse_chan *ch,
 
 3045        size_t bufsize = se->bufsize;
 
 3047        struct fuse_ll_pipe *llp;
 
 3050        if (se->conn.proto_minor < 14 ||
 
 3054        llp = fuse_ll_get_pipe(se);
 
 3058        if (llp->size < bufsize) {
 
 3059                if (llp->can_grow) {
 
 3060                        res = fcntl(llp->pipe[0], F_SETPIPE_SZ, bufsize);
 
 3063                                res = grow_pipe_to_max(llp->pipe[0]);
 
 3070                if (llp->size < bufsize)
 
 3074        if (se->io != NULL && se->io->splice_receive != NULL) {
 
 3075                res = se->io->splice_receive(ch ? ch->fd : se->
fd, NULL,
 
 3076                                             llp->pipe[1], NULL, bufsize, 0,
 
 3079                res = splice(ch ? ch->fd : se->
fd, NULL, llp->pipe[1], NULL,
 
 3088                if (err == ENODEV) {
 
 3094                if (err != EINTR && err != EAGAIN)
 
 3095                        perror(
"fuse: splice from device");
 
 3099        if (res < 
sizeof(
struct fuse_in_header)) {
 
 3100                fuse_log(FUSE_LOG_ERR, 
"short splice from fuse device\n");
 
 3115        if (res < 
sizeof(
struct fuse_in_header) + 
sizeof(
struct fuse_write_in) +
 
 3121                        buf->
mem = buf_alloc(se->bufsize, internal);
 
 3125                                        "fuse: failed to allocate read buffer\n");
 
 3130                                se->buf_reallocable = 
true;
 
 3138                        fuse_log(FUSE_LOG_ERR, 
"fuse: copy from pipe: %s\n",
 
 3140                        fuse_ll_clear_pipe(se);
 
 3143                if (res < tmpbuf.size) {
 
 3145                                 "fuse: copy from pipe: short read\n");
 
 3146                        fuse_ll_clear_pipe(se);
 
 3149                assert(res == tmpbuf.size);
 
 3153                buf->
fd = tmpbuf.fd;
 
 3163                buf->
mem = buf_alloc(se->bufsize, internal);
 
 3166                                 "fuse: failed to allocate read buffer\n");
 
 3171                        se->buf_reallocable = 
true;
 
 3175        if (se->buf_reallocable)
 
 3177        if (se->io != NULL) {
 
 3180                res = se->io->read(ch ? ch->fd : se->fd, 
buf->mem, bufsize,
 
 3183                res = read(ch ? ch->fd : se->fd, 
buf->mem, bufsize);
 
 3190                if (err == EINVAL && se->buf_reallocable &&
 
 3192                        void *newbuf = buf_alloc(se->bufsize, internal);
 
 3196                                        "fuse: failed to (re)allocate read buffer\n");
 
 3202                        se->buf_reallocable = 
true;
 
 3211                if (err == ENODEV) {
 
 3220                if (err != EINTR && err != EAGAIN)
 
 3221                        perror(
"fuse: reading device");
 
 3224        if ((
size_t)res < 
sizeof(
struct fuse_in_header)) {
 
 3225                fuse_log(FUSE_LOG_ERR, 
"short read on fuse device\n");
 
 3236        return _fuse_session_receive_buf(se, 
buf, NULL, 
false);
 
 
 3240int fuse_session_receive_buf_internal(
struct fuse_session *se,
 
 3242                                      struct fuse_chan *ch)
 
 3244        return _fuse_session_receive_buf(se, 
buf, ch, 
true);
 
 3247struct fuse_session *
 
 3248fuse_session_new_versioned(
struct fuse_args *args,
 
 3251struct fuse_session *
 
 3252fuse_session_new_versioned(
struct fuse_args *args,
 
 3257        struct fuse_session *se;
 
 3258        struct mount_opts *mo;
 
 3261                fuse_log(FUSE_LOG_ERR, 
"fuse: warning: library too old, some operations may not work\n");
 
 3265        if (args->
argc == 0) {
 
 3266                fuse_log(FUSE_LOG_ERR, 
"fuse: empty argv passed to fuse_session_new().\n");
 
 3270        se = (
struct fuse_session *) calloc(1, 
sizeof(
struct fuse_session));
 
 3272                fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate fuse object\n");
 
 3276        se->conn.max_write = FUSE_DEFAULT_MAX_PAGES_LIMIT * getpagesize();
 
 3277        se->bufsize = se->conn.max_write + FUSE_BUFFER_HEADER_SIZE;
 
 3278        se->conn.max_readahead = UINT_MAX;
 
 3283        if(se->deny_others) {
 
 3293        mo = parse_mount_opts(args);
 
 3297        if(args->
argc == 1 &&
 
 3298           args->
argv[0][0] == 
'-') {
 
 3299                fuse_log(FUSE_LOG_ERR, 
"fuse: warning: argv[0] looks like an option, but " 
 3300                        "will be ignored\n");
 
 3301        } 
else if (args->
argc != 1) {
 
 3303                fuse_log(FUSE_LOG_ERR, 
"fuse: unknown option(s): `");
 
 3304                for(i = 1; i < args->
argc-1; i++)
 
 3311                fuse_log(FUSE_LOG_DEBUG, 
"FUSE library version: %s\n", PACKAGE_VERSION);
 
 3313        list_init_req(&se->list);
 
 3314        list_init_req(&se->interrupts);
 
 3315        list_init_nreq(&se->notify_list);
 
 3317        pthread_mutex_init(&se->lock, NULL);
 
 3319        err = pthread_key_create(&se->pipe_key, fuse_ll_pipe_destructor);
 
 3321                fuse_log(FUSE_LOG_ERR, 
"fuse: failed to create thread specific key: %s\n",
 
 3326        memcpy(&se->op, op, op_size);
 
 3327        se->owner = getuid();
 
 3328        se->userdata = userdata;
 
 3337        se->version = *version;
 
 3342        pthread_mutex_destroy(&se->lock);
 
 3347                destroy_mount_opts(mo);
 
 3354struct fuse_session *fuse_session_new_30(
struct fuse_args *args,
 
 3356                                         size_t op_size, 
void *userdata);
 
 3357struct fuse_session *fuse_session_new_30(
struct fuse_args *args,
 
 3365        return fuse_session_new_versioned(args, op, op_size, &version,
 
 3369FUSE_SYMVER(
"fuse_session_custom_io_317", 
"fuse_session_custom_io@@FUSE_3.17")
 
 3370int fuse_session_custom_io_317(struct fuse_session *se,
 
 3371                                const struct fuse_custom_io *io, 
size_t op_size, 
int fd)
 
 3373        if (
sizeof(
struct fuse_custom_io) < op_size) {
 
 3374                fuse_log(FUSE_LOG_ERR, 
"fuse: warning: library too old, some operations may not work\n");
 
 3375                op_size = 
sizeof(
struct fuse_custom_io);
 
 3379                fuse_log(FUSE_LOG_ERR, 
"Invalid file descriptor value %d passed to " 
 3380                        "fuse_session_custom_io()\n", fd);
 
 3384                fuse_log(FUSE_LOG_ERR, 
"No custom IO passed to " 
 3385                        "fuse_session_custom_io()\n");
 
 3387        } 
else if (io->read == NULL || io->writev == NULL) {
 
 3392                fuse_log(FUSE_LOG_ERR, 
"io passed to fuse_session_custom_io() must " 
 3393                        "implement both io->read() and io->writev\n");
 
 3397        se->io = calloc(1, 
sizeof(
struct fuse_custom_io));
 
 3398        if (se->io == NULL) {
 
 3399                fuse_log(FUSE_LOG_ERR, 
"Failed to allocate memory for custom io. " 
 3400                        "Error: %s\n", strerror(errno));
 
 3405        memcpy(se->io, io, op_size);
 
 3409int fuse_session_custom_io_30(
struct fuse_session *se,
 
 3410                        const struct fuse_custom_io *io, 
int fd);
 
 3411FUSE_SYMVER(
"fuse_session_custom_io_30", 
"fuse_session_custom_io@FUSE_3.0")
 
 3412int fuse_session_custom_io_30(struct fuse_session *se,
 
 3413                        const struct fuse_custom_io *io, 
int fd)
 
 3415        return fuse_session_custom_io_317(se, io,
 
 3416                        offsetof(
struct fuse_custom_io, clone_fd), fd);
 
 3423        if (mountpoint == NULL) {
 
 3424                fuse_log(FUSE_LOG_ERR, 
"Invalid null-ptr mountpoint!\n");
 
 3433                fd = open(
"/dev/null", O_RDWR);
 
 3436        } 
while (fd >= 0 && fd <= 2);
 
 3444        fd = fuse_mnt_parse_fuse_fd(mountpoint);
 
 3446                if (fcntl(fd, F_GETFD) == -1) {
 
 3448                                "fuse: Invalid file descriptor /dev/fd/%u\n",
 
 3457        fd = fuse_kern_mount(mountpoint, se->mo);
 
 3463        se->mountpoint = strdup(mountpoint);
 
 3464        if (se->mountpoint == NULL)
 
 3470        fuse_kern_unmount(mountpoint, fd);
 
 
 3481        if (se->mountpoint != NULL) {
 
 3482                fuse_kern_unmount(se->mountpoint, se->fd);
 
 3484                free(se->mountpoint);
 
 3485                se->mountpoint = NULL;
 
 
 3493        size_t bufsize = 1024;
 
 3497        unsigned long pid = req->ctx.pid;
 
 3500        sprintf(path, 
"/proc/%lu/task/%lu/status", pid, pid);
 
 3503        buf = malloc(bufsize);
 
 3508        fd = open(path, O_RDONLY);
 
 3512        ret = read(fd, buf, bufsize);
 
 3519        if ((
size_t)ret == bufsize) {
 
 3527        s = strstr(buf, 
"\nGroups:");
 
 3535                unsigned long val = strtoul(s, &end, 0);
 
 3555        (void) req; (void) size; (void) list;
 
 
 3562__attribute__((no_sanitize_thread))
 
 3568__attribute__((no_sanitize_thread))
 
 3575__attribute__((no_sanitize_thread))
 
size_t fuse_buf_size(const struct fuse_bufvec *bufv)
ssize_t fuse_buf_copy(struct fuse_bufvec *dst, struct fuse_bufvec *src, enum fuse_buf_copy_flags flags)
@ FUSE_BUF_SPLICE_NONBLOCK
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)
void * fuse_req_userdata(fuse_req_t req)
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_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_reply_none(fuse_req_t req)
int fuse_lowlevel_notify_expire_entry(struct fuse_session *se, fuse_ino_t parent, const char *name, size_t namelen)
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)
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_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_session_reset(struct fuse_session *se)
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)
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_passthrough_open(fuse_req_t req, int fd)
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_IOCTL_DIR
#define FUSE_CAP_DONT_MASK
#define FUSE_CAP_HANDLE_KILLPRIV
#define FUSE_CAP_AUTO_INVAL_DATA
#define FUSE_CAP_HANDLE_KILLPRIV_V2
#define FUSE_CAP_SPLICE_READ
#define FUSE_CAP_PARALLEL_DIROPS
#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
#define FUSE_CAP_NO_OPENDIR_SUPPORT
#define FUSE_CAP_ASYNC_DIO
#define FUSE_CAP_PASSTHROUGH
#define FUSE_CAP_DIRECT_IO_ALLOW_MMAP
#define FUSE_CAP_NO_OPEN_SUPPORT
#define FUSE_CAP_READDIRPLUS
void fuse_pollhandle_destroy(struct fuse_pollhandle *ph)
#define FUSE_CAP_SETXATTR_EXT
#define FUSE_CAP_SPLICE_MOVE
#define FUSE_CAP_NO_EXPORT_SUPPORT
#define FUSE_CAP_FLOCK_LOCKS
const struct fuse_ctx * fuse_req_ctx(fuse_req_t req)
struct fuse_req * fuse_req_t
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[])
void fuse_session_unmount(struct fuse_session *se)
int fuse_session_mount(struct fuse_session *se, const char *mountpoint)
void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func, void *data)
enum fuse_buf_flags flags
uint32_t parallel_direct_writes