14#include "fuse_config.h"
16#include "fuse_kernel.h"
19#include "mount_util.h"
36#ifndef F_LINUX_SPECIFIC_BASE
37#define F_LINUX_SPECIFIC_BASE 1024
40#define F_SETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 7)
44#define PARAM(inarg) (((char *)(inarg)) + sizeof(*(inarg)))
45#define OFFSET_MAX 0x7fffffffffffffffLL
47struct fuse_pollhandle {
49 struct fuse_session *se;
52static size_t pagesize;
54static __attribute__((constructor))
void fuse_ll_init_pagesize(
void)
56 pagesize = getpagesize();
59static void convert_stat(
const struct stat *stbuf,
struct fuse_attr *attr)
61 attr->ino = stbuf->st_ino;
62 attr->mode = stbuf->st_mode;
63 attr->nlink = stbuf->st_nlink;
64 attr->uid = stbuf->st_uid;
65 attr->gid = stbuf->st_gid;
66 attr->rdev = stbuf->st_rdev;
67 attr->size = stbuf->st_size;
68 attr->blksize = stbuf->st_blksize;
69 attr->blocks = stbuf->st_blocks;
70 attr->atime = stbuf->st_atime;
71 attr->mtime = stbuf->st_mtime;
72 attr->ctime = stbuf->st_ctime;
73 attr->atimensec = ST_ATIM_NSEC(stbuf);
74 attr->mtimensec = ST_MTIM_NSEC(stbuf);
75 attr->ctimensec = ST_CTIM_NSEC(stbuf);
78static void convert_attr(
const struct fuse_setattr_in *attr,
struct stat *stbuf)
80 stbuf->st_mode = attr->mode;
81 stbuf->st_uid = attr->uid;
82 stbuf->st_gid = attr->gid;
83 stbuf->st_size = attr->size;
84 stbuf->st_atime = attr->atime;
85 stbuf->st_mtime = attr->mtime;
86 stbuf->st_ctime = attr->ctime;
87 ST_ATIM_NSEC_SET(stbuf, attr->atimensec);
88 ST_MTIM_NSEC_SET(stbuf, attr->mtimensec);
89 ST_CTIM_NSEC_SET(stbuf, attr->ctimensec);
92static size_t iov_length(
const struct iovec *iov,
size_t count)
97 for (seg = 0; seg < count; seg++)
98 ret += iov[seg].iov_len;
102static void list_init_req(
struct fuse_req *req)
108static void list_del_req(
struct fuse_req *req)
110 struct fuse_req *prev = req->prev;
111 struct fuse_req *next = req->next;
116static void list_add_req(
struct fuse_req *req,
struct fuse_req *next)
118 struct fuse_req *prev = next->prev;
127 assert(req->ch == NULL);
128 pthread_mutex_destroy(&req->lock);
135 struct fuse_session *se = req->se;
137 if (se->conn.no_interrupt) {
138 ctr = --req->ref_cnt;
139 fuse_chan_put(req->ch);
142 pthread_mutex_lock(&se->lock);
143 req->u.ni.func = NULL;
144 req->u.ni.data = NULL;
146 ctr = --req->ref_cnt;
147 fuse_chan_put(req->ch);
149 pthread_mutex_unlock(&se->lock);
155static struct fuse_req *fuse_ll_alloc_req(
struct fuse_session *se)
157 struct fuse_req *req;
159 req = (
struct fuse_req *) calloc(1,
sizeof(
struct fuse_req));
161 fuse_log(FUSE_LOG_ERR,
"fuse: failed to allocate request\n");
166 pthread_mutex_init(&req->lock, NULL);
173static int fuse_send_msg(
struct fuse_session *se,
struct fuse_chan *ch,
174 struct iovec *iov,
int count)
176 struct fuse_out_header *out = iov[0].iov_base;
179 out->len = iov_length(iov, count);
181 if (out->unique == 0) {
182 fuse_log(FUSE_LOG_DEBUG,
"NOTIFY: code=%d length=%u\n",
183 out->error, out->len);
184 }
else if (out->error) {
186 " unique: %llu, error: %i (%s), outsize: %i\n",
187 (
unsigned long long) out->unique, out->error,
188 strerror(-out->error), out->len);
191 " unique: %llu, success, outsize: %i\n",
192 (
unsigned long long) out->unique, out->len);
200 res = se->io->writev(ch ? ch->fd : se->fd, iov, count,
203 res = writev(ch ? ch->fd : se->fd, iov, count);
210 perror(
"fuse: writing device");
218int fuse_send_reply_iov_nofree(
fuse_req_t req,
int error,
struct iovec *iov,
221 struct fuse_out_header out;
223#if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 32
224 const char *str = strerrordesc_np(error * -1);
225 if ((str == NULL && error != 0) || error > 0) {
227 if (error <= -1000 || error > 0) {
229 fuse_log(FUSE_LOG_ERR,
"fuse: bad error value: %i\n", error);
233 out.unique = req->unique;
236 iov[0].iov_base = &out;
237 iov[0].iov_len =
sizeof(
struct fuse_out_header);
239 return fuse_send_msg(req->se, req->ch, iov, count);
242static int send_reply_iov(
fuse_req_t req,
int error,
struct iovec *iov,
247 res = fuse_send_reply_iov_nofree(req, error, iov, count);
252static int send_reply(
fuse_req_t req,
int error,
const void *arg,
258 iov[1].iov_base = (
void *) arg;
259 iov[1].iov_len = argsize;
262 return send_reply_iov(req, error, iov, count);
268 struct iovec *padded_iov;
270 padded_iov = malloc((count + 1) *
sizeof(
struct iovec));
271 if (padded_iov == NULL)
274 memcpy(padded_iov + 1, iov, count *
sizeof(
struct iovec));
277 res = send_reply_iov(req, 0, padded_iov, count);
287 const char *name,
const struct stat *stbuf, off_t off)
292 size_t entlen_padded;
293 struct fuse_dirent *dirent;
295 namelen = strlen(name);
296 entlen = FUSE_NAME_OFFSET + namelen;
297 entlen_padded = FUSE_DIRENT_ALIGN(entlen);
299 if ((buf == NULL) || (entlen_padded > bufsize))
300 return entlen_padded;
302 dirent = (
struct fuse_dirent*) buf;
303 dirent->ino = stbuf->st_ino;
305 dirent->namelen = namelen;
306 dirent->type = (stbuf->st_mode & S_IFMT) >> 12;
307 memcpy(dirent->name, name, namelen);
308 memset(dirent->name + namelen, 0, entlen_padded - entlen);
310 return entlen_padded;
313static void convert_statfs(
const struct statvfs *stbuf,
314 struct fuse_kstatfs *kstatfs)
316 kstatfs->bsize = stbuf->f_bsize;
317 kstatfs->frsize = stbuf->f_frsize;
318 kstatfs->blocks = stbuf->f_blocks;
319 kstatfs->bfree = stbuf->f_bfree;
320 kstatfs->bavail = stbuf->f_bavail;
321 kstatfs->files = stbuf->f_files;
322 kstatfs->ffree = stbuf->f_ffree;
323 kstatfs->namelen = stbuf->f_namemax;
326static int send_reply_ok(
fuse_req_t req,
const void *arg,
size_t argsize)
328 return send_reply(req, 0, arg, argsize);
333 return send_reply(req, -err, NULL, 0);
341static unsigned long calc_timeout_sec(
double t)
343 if (t > (
double) ULONG_MAX)
348 return (
unsigned long) t;
351static unsigned int calc_timeout_nsec(
double t)
353 double f = t - (double) calc_timeout_sec(t);
356 else if (f >= 0.999999999)
359 return (
unsigned int) (f * 1.0e9);
362static void fill_entry(
struct fuse_entry_out *arg,
365 arg->nodeid = e->
ino;
370 arg->attr_valid_nsec = calc_timeout_nsec(e->
attr_timeout);
371 convert_stat(&e->
attr, &arg->attr);
383 size_t entlen_padded;
385 namelen = strlen(name);
386 entlen = FUSE_NAME_OFFSET_DIRENTPLUS + namelen;
387 entlen_padded = FUSE_DIRENT_ALIGN(entlen);
388 if ((buf == NULL) || (entlen_padded > bufsize))
389 return entlen_padded;
391 struct fuse_direntplus *dp = (
struct fuse_direntplus *) buf;
392 memset(&dp->entry_out, 0,
sizeof(dp->entry_out));
393 fill_entry(&dp->entry_out, e);
395 struct fuse_dirent *dirent = &dp->dirent;
396 dirent->ino = e->
attr.st_ino;
398 dirent->namelen = namelen;
399 dirent->type = (e->
attr.st_mode & S_IFMT) >> 12;
400 memcpy(dirent->name, name, namelen);
401 memset(dirent->name + namelen, 0, entlen_padded - entlen);
403 return entlen_padded;
406static void fill_open(
struct fuse_open_out *arg,
412 arg->open_flags |= FOPEN_PASSTHROUGH;
415 arg->open_flags |= FOPEN_DIRECT_IO;
417 arg->open_flags |= FOPEN_KEEP_CACHE;
419 arg->open_flags |= FOPEN_CACHE_DIR;
421 arg->open_flags |= FOPEN_NONSEEKABLE;
423 arg->open_flags |= FOPEN_NOFLUSH;
425 arg->open_flags |= FOPEN_PARALLEL_DIRECT_WRITES;
430 struct fuse_entry_out arg;
431 size_t size = req->se->conn.proto_minor < 9 ?
432 FUSE_COMPAT_ENTRY_OUT_SIZE :
sizeof(arg);
436 if (!e->
ino && req->se->conn.proto_minor < 4)
439 memset(&arg, 0,
sizeof(arg));
441 return send_reply_ok(req, &arg, size);
447 alignas(uint64_t)
char buf[
sizeof(
struct fuse_entry_out) +
sizeof(
struct fuse_open_out)];
448 size_t entrysize = req->se->conn.proto_minor < 9 ?
449 FUSE_COMPAT_ENTRY_OUT_SIZE :
sizeof(
struct fuse_entry_out);
450 struct fuse_entry_out *earg = (
struct fuse_entry_out *) buf;
451 struct fuse_open_out *oarg = (
struct fuse_open_out *) (buf + entrysize);
453 memset(buf, 0,
sizeof(buf));
456 return send_reply_ok(req, buf,
457 entrysize +
sizeof(
struct fuse_open_out));
463 struct fuse_attr_out arg;
464 size_t size = req->se->conn.proto_minor < 9 ?
465 FUSE_COMPAT_ATTR_OUT_SIZE :
sizeof(arg);
467 memset(&arg, 0,
sizeof(arg));
468 arg.attr_valid = calc_timeout_sec(attr_timeout);
469 arg.attr_valid_nsec = calc_timeout_nsec(attr_timeout);
470 convert_stat(attr, &arg.attr);
472 return send_reply_ok(req, &arg, size);
477 return send_reply_ok(req, linkname, strlen(linkname));
482 struct fuse_backing_map map = { .fd = fd };
485 ret = ioctl(req->se->fd, FUSE_DEV_IOC_BACKING_OPEN, &map);
487 fuse_log(FUSE_LOG_ERR,
"fuse: passthrough_open: %s\n", strerror(errno));
494int fuse_passthrough_close(
fuse_req_t req,
int backing_id)
498 ret = ioctl(req->se->fd, FUSE_DEV_IOC_BACKING_CLOSE, &backing_id);
500 fuse_log(FUSE_LOG_ERR,
"fuse: passthrough_close: %s\n", strerror(errno));
507 struct fuse_open_out arg;
509 memset(&arg, 0,
sizeof(arg));
511 return send_reply_ok(req, &arg,
sizeof(arg));
516 struct fuse_write_out arg;
518 memset(&arg, 0,
sizeof(arg));
521 return send_reply_ok(req, &arg,
sizeof(arg));
526 return send_reply_ok(req, buf, size);
529static int fuse_send_data_iov_fallback(
struct fuse_session *se,
530 struct fuse_chan *ch,
531 struct iovec *iov,
int iov_count,
535 struct fuse_bufvec mem_buf = FUSE_BUFVEC_INIT(len);
540 if (
buf->count == 1 &&
buf->idx == 0 &&
buf->off == 0 &&
545 iov[iov_count].iov_base =
buf->buf[0].
mem;
546 iov[iov_count].iov_len = len;
548 return fuse_send_msg(se, ch, iov, iov_count);
551 res = posix_memalign(&mbuf, pagesize, len);
555 mem_buf.
buf[0].
mem = mbuf;
563 iov[iov_count].iov_base = mbuf;
564 iov[iov_count].iov_len = len;
566 res = fuse_send_msg(se, ch, iov, iov_count);
578static void fuse_ll_pipe_free(
struct fuse_ll_pipe *llp)
586#if !defined(HAVE_PIPE2) || !defined(O_CLOEXEC)
587static int fuse_pipe(
int fds[2])
594 if (fcntl(fds[0], F_SETFL, O_NONBLOCK) == -1 ||
595 fcntl(fds[1], F_SETFL, O_NONBLOCK) == -1 ||
596 fcntl(fds[0], F_SETFD, FD_CLOEXEC) == -1 ||
597 fcntl(fds[1], F_SETFD, FD_CLOEXEC) == -1) {
605static int fuse_pipe(
int fds[2])
607 return pipe2(fds, O_CLOEXEC | O_NONBLOCK);
611static struct fuse_ll_pipe *fuse_ll_get_pipe(
struct fuse_session *se)
613 struct fuse_ll_pipe *llp = pthread_getspecific(se->pipe_key);
617 llp = malloc(
sizeof(
struct fuse_ll_pipe));
621 res = fuse_pipe(llp->pipe);
630 llp->size = pagesize * 16;
633 pthread_setspecific(se->pipe_key, llp);
640static void fuse_ll_clear_pipe(
struct fuse_session *se)
642 struct fuse_ll_pipe *llp = pthread_getspecific(se->pipe_key);
644 pthread_setspecific(se->pipe_key, NULL);
645 fuse_ll_pipe_free(llp);
649#if defined(HAVE_SPLICE) && defined(HAVE_VMSPLICE)
650static int read_back(
int fd,
char *buf,
size_t len)
654 res = read(fd, buf, len);
656 fuse_log(FUSE_LOG_ERR,
"fuse: internal error: failed to read back from pipe: %s\n", strerror(errno));
660 fuse_log(FUSE_LOG_ERR,
"fuse: internal error: short read back from pipe: %i from %zi\n", res, len);
666static int grow_pipe_to_max(
int pipefd)
673 maxfd = open(
"/proc/sys/fs/pipe-max-size", O_RDONLY);
677 res = read(maxfd, buf,
sizeof(buf) - 1);
688 res = libfuse_strtol(buf, &max);
691 res = fcntl(pipefd, F_SETPIPE_SZ, max);
697static int fuse_send_data_iov(
struct fuse_session *se,
struct fuse_chan *ch,
698 struct iovec *iov,
int iov_count,
703 struct fuse_out_header *out = iov[0].iov_base;
704 struct fuse_ll_pipe *llp;
707 size_t total_buf_size;
710 struct fuse_bufvec pipe_buf = FUSE_BUFVEC_INIT(len);
712 if (se->broken_splice_nonblock)
722 total_buf_size -=
buf->off;
724 if (total_buf_size < 2 * pagesize)
727 if (se->conn.proto_minor < 14 ||
731 llp = fuse_ll_get_pipe(se);
736 headerlen = iov_length(iov, iov_count);
738 out->len = headerlen + len;
744 pipesize = pagesize * (iov_count +
buf->count + 1) + out->len;
746 if (llp->size < pipesize) {
748 res = fcntl(llp->pipe[0], F_SETPIPE_SZ, pipesize);
750 res = grow_pipe_to_max(llp->pipe[0]);
758 if (llp->size < pipesize)
763 res = vmsplice(llp->pipe[1], iov, iov_count, SPLICE_F_NONBLOCK);
767 if (res != headerlen) {
769 fuse_log(FUSE_LOG_ERR,
"fuse: short vmsplice to pipe: %u/%zu\n", res,
775 pipe_buf.
buf[0].
fd = llp->pipe[1];
780 if (res == -EAGAIN || res == -EINVAL) {
792 se->broken_splice_nonblock = 1;
794 pthread_setspecific(se->pipe_key, NULL);
795 fuse_ll_pipe_free(llp);
802 if (res != 0 && res < len) {
803 struct fuse_bufvec mem_buf = FUSE_BUFVEC_INIT(len);
805 size_t now_len = res;
815 res = posix_memalign(&mbuf, pagesize, len);
819 mem_buf.
buf[0].
mem = mbuf;
820 mem_buf.
off = now_len;
824 size_t extra_len = res;
830 tmpbuf = malloc(headerlen);
831 if (tmpbuf == NULL) {
836 res = read_back(llp->pipe[0], tmpbuf, headerlen);
842 res = read_back(llp->pipe[0], mbuf, now_len);
847 len = now_len + extra_len;
848 iov[iov_count].iov_base = mbuf;
849 iov[iov_count].iov_len = len;
851 res = fuse_send_msg(se, ch, iov, iov_count);
859 out->len = headerlen + len;
863 " unique: %llu, success, outsize: %i (splice)\n",
864 (
unsigned long long) out->unique, out->len);
870 splice_flags |= SPLICE_F_MOVE;
872 if (se->io != NULL && se->io->splice_send != NULL) {
873 res = se->io->splice_send(llp->pipe[0], NULL,
874 ch ? ch->fd : se->fd, NULL, out->len,
875 splice_flags, se->userdata);
877 res = splice(llp->pipe[0], NULL, ch ? ch->fd : se->fd, NULL,
878 out->len, splice_flags);
882 perror(
"fuse: splice from pipe");
885 if (res != out->len) {
887 fuse_log(FUSE_LOG_ERR,
"fuse: short splice from pipe: %u/%u\n",
894 fuse_ll_clear_pipe(se);
898 return fuse_send_data_iov_fallback(se, ch, iov, iov_count,
buf, len);
901static int fuse_send_data_iov(
struct fuse_session *se,
struct fuse_chan *ch,
902 struct iovec *iov,
int iov_count,
908 return fuse_send_data_iov_fallback(se, ch, iov, iov_count,
buf, len);
916 struct fuse_out_header out;
919 iov[0].iov_base = &out;
920 iov[0].iov_len =
sizeof(
struct fuse_out_header);
922 out.unique = req->unique;
925 res = fuse_send_data_iov(req->se, req->ch, iov, 1, bufv, flags);
936 struct fuse_statfs_out arg;
937 size_t size = req->se->conn.proto_minor < 4 ?
938 FUSE_COMPAT_STATFS_SIZE :
sizeof(arg);
940 memset(&arg, 0,
sizeof(arg));
941 convert_statfs(stbuf, &arg.st);
943 return send_reply_ok(req, &arg, size);
948 struct fuse_getxattr_out arg;
950 memset(&arg, 0,
sizeof(arg));
953 return send_reply_ok(req, &arg,
sizeof(arg));
958 struct fuse_lk_out arg;
960 memset(&arg, 0,
sizeof(arg));
961 arg.lk.type = lock->l_type;
962 if (lock->l_type != F_UNLCK) {
963 arg.lk.start = lock->l_start;
964 if (lock->l_len == 0)
965 arg.lk.end = OFFSET_MAX;
967 arg.lk.end = lock->l_start + lock->l_len - 1;
969 arg.lk.pid = lock->l_pid;
970 return send_reply_ok(req, &arg,
sizeof(arg));
975 struct fuse_bmap_out arg;
977 memset(&arg, 0,
sizeof(arg));
980 return send_reply_ok(req, &arg,
sizeof(arg));
983static struct fuse_ioctl_iovec *fuse_ioctl_iovec_copy(
const struct iovec *iov,
986 struct fuse_ioctl_iovec *fiov;
989 fiov = malloc(
sizeof(fiov[0]) * count);
993 for (i = 0; i < count; i++) {
994 fiov[i].base = (uintptr_t) iov[i].iov_base;
995 fiov[i].len = iov[i].iov_len;
1002 const struct iovec *in_iov,
size_t in_count,
1003 const struct iovec *out_iov,
size_t out_count)
1005 struct fuse_ioctl_out arg;
1006 struct fuse_ioctl_iovec *in_fiov = NULL;
1007 struct fuse_ioctl_iovec *out_fiov = NULL;
1008 struct iovec iov[4];
1012 memset(&arg, 0,
sizeof(arg));
1013 arg.flags |= FUSE_IOCTL_RETRY;
1014 arg.in_iovs = in_count;
1015 arg.out_iovs = out_count;
1016 iov[count].iov_base = &arg;
1017 iov[count].iov_len =
sizeof(arg);
1020 if (req->se->conn.proto_minor < 16) {
1022 iov[count].iov_base = (
void *)in_iov;
1023 iov[count].iov_len =
sizeof(in_iov[0]) * in_count;
1028 iov[count].iov_base = (
void *)out_iov;
1029 iov[count].iov_len =
sizeof(out_iov[0]) * out_count;
1034 if (
sizeof(
void *) == 4 && req->ioctl_64bit) {
1040 in_fiov = fuse_ioctl_iovec_copy(in_iov, in_count);
1044 iov[count].iov_base = (
void *)in_fiov;
1045 iov[count].iov_len =
sizeof(in_fiov[0]) * in_count;
1049 out_fiov = fuse_ioctl_iovec_copy(out_iov, out_count);
1053 iov[count].iov_base = (
void *)out_fiov;
1054 iov[count].iov_len =
sizeof(out_fiov[0]) * out_count;
1059 res = send_reply_iov(req, 0, iov, count);
1073 struct fuse_ioctl_out arg;
1074 struct iovec iov[3];
1077 memset(&arg, 0,
sizeof(arg));
1078 arg.result = result;
1079 iov[count].iov_base = &arg;
1080 iov[count].iov_len =
sizeof(arg);
1084 iov[count].iov_base = (
char *) buf;
1085 iov[count].iov_len = size;
1089 return send_reply_iov(req, 0, iov, count);
1095 struct iovec *padded_iov;
1096 struct fuse_ioctl_out arg;
1099 padded_iov = malloc((count + 2) *
sizeof(
struct iovec));
1100 if (padded_iov == NULL)
1103 memset(&arg, 0,
sizeof(arg));
1104 arg.result = result;
1105 padded_iov[1].iov_base = &arg;
1106 padded_iov[1].iov_len =
sizeof(arg);
1108 memcpy(&padded_iov[2], iov, count *
sizeof(
struct iovec));
1110 res = send_reply_iov(req, 0, padded_iov, count + 2);
1118 struct fuse_poll_out arg;
1120 memset(&arg, 0,
sizeof(arg));
1121 arg.revents = revents;
1123 return send_reply_ok(req, &arg,
sizeof(arg));
1128 struct fuse_lseek_out arg;
1130 memset(&arg, 0,
sizeof(arg));
1133 return send_reply_ok(req, &arg,
sizeof(arg));
1138 char *name = (
char *) inarg;
1140 if (req->se->op.lookup)
1141 req->se->op.lookup(req, nodeid, name);
1148 struct fuse_forget_in *arg = (
struct fuse_forget_in *) inarg;
1150 if (req->se->op.forget)
1151 req->se->op.forget(req, nodeid, arg->nlookup);
1159 struct fuse_batch_forget_in *arg = (
void *) inarg;
1160 struct fuse_forget_one *param = (
void *) PARAM(arg);
1165 if (req->se->op.forget_multi) {
1166 req->se->op.forget_multi(req, arg->count,
1167 (
struct fuse_forget_data *) param);
1168 }
else if (req->se->op.forget) {
1169 for (i = 0; i < arg->count; i++) {
1170 struct fuse_forget_one *forget = ¶m[i];
1171 struct fuse_req *dummy_req;
1173 dummy_req = fuse_ll_alloc_req(req->se);
1174 if (dummy_req == NULL)
1177 dummy_req->unique = req->unique;
1178 dummy_req->ctx = req->ctx;
1179 dummy_req->ch = NULL;
1181 req->se->op.forget(dummy_req, forget->nodeid,
1195 if (req->se->conn.proto_minor >= 9) {
1196 struct fuse_getattr_in *arg = (
struct fuse_getattr_in *) inarg;
1198 if (arg->getattr_flags & FUSE_GETATTR_FH) {
1199 memset(&fi, 0,
sizeof(fi));
1205 if (req->se->op.getattr)
1206 req->se->op.getattr(req, nodeid, fip);
1213 struct fuse_setattr_in *arg = (
struct fuse_setattr_in *) inarg;
1215 if (req->se->op.setattr) {
1219 memset(&stbuf, 0,
sizeof(stbuf));
1220 convert_attr(arg, &stbuf);
1221 if (arg->valid & FATTR_FH) {
1222 arg->valid &= ~FATTR_FH;
1223 memset(&fi_store, 0,
sizeof(fi_store));
1228 FUSE_SET_ATTR_MODE |
1231 FUSE_SET_ATTR_SIZE |
1232 FUSE_SET_ATTR_ATIME |
1233 FUSE_SET_ATTR_MTIME |
1234 FUSE_SET_ATTR_KILL_SUID |
1235 FUSE_SET_ATTR_KILL_SGID |
1236 FUSE_SET_ATTR_ATIME_NOW |
1237 FUSE_SET_ATTR_MTIME_NOW |
1238 FUSE_SET_ATTR_CTIME;
1240 req->se->op.setattr(req, nodeid, &stbuf, arg->valid, fi);
1247 struct fuse_access_in *arg = (
struct fuse_access_in *) inarg;
1249 if (req->se->op.access)
1250 req->se->op.access(req, nodeid, arg->mask);
1259 if (req->se->op.readlink)
1260 req->se->op.readlink(req, nodeid);
1267 struct fuse_mknod_in *arg = (
struct fuse_mknod_in *) inarg;
1268 char *name = PARAM(arg);
1270 if (req->se->conn.proto_minor >= 12)
1271 req->ctx.umask = arg->umask;
1273 name = (
char *) inarg + FUSE_COMPAT_MKNOD_IN_SIZE;
1275 if (req->se->op.mknod)
1276 req->se->op.mknod(req, nodeid, name, arg->mode, arg->rdev);
1283 struct fuse_mkdir_in *arg = (
struct fuse_mkdir_in *) inarg;
1285 if (req->se->conn.proto_minor >= 12)
1286 req->ctx.umask = arg->umask;
1288 if (req->se->op.mkdir)
1289 req->se->op.mkdir(req, nodeid, PARAM(arg), arg->mode);
1296 char *name = (
char *) inarg;
1298 if (req->se->op.unlink)
1299 req->se->op.unlink(req, nodeid, name);
1306 char *name = (
char *) inarg;
1308 if (req->se->op.rmdir)
1309 req->se->op.rmdir(req, nodeid, name);
1316 char *name = (
char *) inarg;
1317 char *linkname = ((
char *) inarg) + strlen((
char *) inarg) + 1;
1319 if (req->se->op.symlink)
1320 req->se->op.symlink(req, linkname, nodeid, name);
1327 struct fuse_rename_in *arg = (
struct fuse_rename_in *) inarg;
1328 char *oldname = PARAM(arg);
1329 char *newname = oldname + strlen(oldname) + 1;
1331 if (req->se->op.rename)
1332 req->se->op.rename(req, nodeid, oldname, arg->newdir, newname,
1340 struct fuse_rename2_in *arg = (
struct fuse_rename2_in *) inarg;
1341 char *oldname = PARAM(arg);
1342 char *newname = oldname + strlen(oldname) + 1;
1344 if (req->se->op.rename)
1345 req->se->op.rename(req, nodeid, oldname, arg->newdir, newname,
1353 struct fuse_link_in *arg = (
struct fuse_link_in *) inarg;
1355 if (req->se->op.link)
1356 req->se->op.link(req, arg->oldnodeid, nodeid, PARAM(arg));
1363 struct fuse_create_in *arg = (
struct fuse_create_in *) inarg;
1365 if (req->se->op.tmpfile) {
1368 memset(&fi, 0,
sizeof(fi));
1369 fi.
flags = arg->flags;
1371 if (req->se->conn.proto_minor >= 12)
1372 req->ctx.umask = arg->umask;
1374 req->se->op.tmpfile(req, nodeid, arg->mode, &fi);
1381 struct fuse_create_in *arg = (
struct fuse_create_in *) inarg;
1383 if (req->se->op.create) {
1385 char *name = PARAM(arg);
1387 memset(&fi, 0,
sizeof(fi));
1388 fi.
flags = arg->flags;
1390 if (req->se->conn.proto_minor >= 12)
1391 req->ctx.umask = arg->umask;
1393 name = (
char *) inarg +
sizeof(
struct fuse_open_in);
1395 req->se->op.create(req, nodeid, name, arg->mode, &fi);
1402 struct fuse_open_in *arg = (
struct fuse_open_in *) inarg;
1405 memset(&fi, 0,
sizeof(fi));
1406 fi.
flags = arg->flags;
1408 if (req->se->op.open)
1409 req->se->op.open(req, nodeid, &fi);
1418 struct fuse_read_in *arg = (
struct fuse_read_in *) inarg;
1420 if (req->se->op.read) {
1423 memset(&fi, 0,
sizeof(fi));
1425 if (req->se->conn.proto_minor >= 9) {
1427 fi.
flags = arg->flags;
1429 req->se->op.read(req, nodeid, arg->size, arg->offset, &fi);
1436 struct fuse_write_in *arg = (
struct fuse_write_in *) inarg;
1440 memset(&fi, 0,
sizeof(fi));
1442 fi.
writepage = (arg->write_flags & FUSE_WRITE_CACHE) != 0;
1444 if (req->se->conn.proto_minor < 9) {
1445 param = ((
char *) arg) + FUSE_COMPAT_WRITE_IN_SIZE;
1448 fi.
flags = arg->flags;
1452 if (req->se->op.write)
1453 req->se->op.write(req, nodeid, param, arg->size,
1462 struct fuse_session *se = req->se;
1467 struct fuse_write_in *arg = (
struct fuse_write_in *) inarg;
1470 memset(&fi, 0,
sizeof(fi));
1472 fi.
writepage = arg->write_flags & FUSE_WRITE_CACHE;
1474 if (se->conn.proto_minor < 9) {
1475 bufv.
buf[0].
mem = ((
char *) arg) + FUSE_COMPAT_WRITE_IN_SIZE;
1476 bufv.
buf[0].
size -=
sizeof(
struct fuse_in_header) +
1477 FUSE_COMPAT_WRITE_IN_SIZE;
1481 fi.
flags = arg->flags;
1483 bufv.
buf[0].
mem = PARAM(arg);
1485 bufv.
buf[0].
size -=
sizeof(
struct fuse_in_header) +
1486 sizeof(struct fuse_write_in);
1488 if (bufv.
buf[0].
size < arg->size) {
1489 fuse_log(FUSE_LOG_ERR,
"fuse: do_write_buf: buffer size too small\n");
1495 se->op.write_buf(req, nodeid, &bufv, arg->offset, &fi);
1500 fuse_ll_clear_pipe(se);
1505 struct fuse_flush_in *arg = (
struct fuse_flush_in *) inarg;
1508 memset(&fi, 0,
sizeof(fi));
1511 if (req->se->conn.proto_minor >= 7)
1514 if (req->se->op.flush)
1515 req->se->op.flush(req, nodeid, &fi);
1522 struct fuse_release_in *arg = (
struct fuse_release_in *) inarg;
1525 memset(&fi, 0,
sizeof(fi));
1526 fi.
flags = arg->flags;
1528 if (req->se->conn.proto_minor >= 8) {
1529 fi.
flush = (arg->release_flags & FUSE_RELEASE_FLUSH) ? 1 : 0;
1532 if (arg->release_flags & FUSE_RELEASE_FLOCK_UNLOCK) {
1533 fi.flock_release = 1;
1537 if (req->se->op.release)
1538 req->se->op.release(req, nodeid, &fi);
1545 struct fuse_fsync_in *arg = (
struct fuse_fsync_in *) inarg;
1547 int datasync = arg->fsync_flags & 1;
1549 memset(&fi, 0,
sizeof(fi));
1552 if (req->se->op.fsync)
1553 req->se->op.fsync(req, nodeid, datasync, &fi);
1560 struct fuse_open_in *arg = (
struct fuse_open_in *) inarg;
1563 memset(&fi, 0,
sizeof(fi));
1564 fi.
flags = arg->flags;
1566 if (req->se->op.opendir)
1567 req->se->op.opendir(req, nodeid, &fi);
1576 struct fuse_read_in *arg = (
struct fuse_read_in *) inarg;
1579 memset(&fi, 0,
sizeof(fi));
1582 if (req->se->op.readdir)
1583 req->se->op.readdir(req, nodeid, arg->size, arg->offset, &fi);
1590 struct fuse_read_in *arg = (
struct fuse_read_in *) inarg;
1593 memset(&fi, 0,
sizeof(fi));
1596 if (req->se->op.readdirplus)
1597 req->se->op.readdirplus(req, nodeid, arg->size, arg->offset, &fi);
1604 struct fuse_release_in *arg = (
struct fuse_release_in *) inarg;
1607 memset(&fi, 0,
sizeof(fi));
1608 fi.
flags = arg->flags;
1611 if (req->se->op.releasedir)
1612 req->se->op.releasedir(req, nodeid, &fi);
1619 struct fuse_fsync_in *arg = (
struct fuse_fsync_in *) inarg;
1621 int datasync = arg->fsync_flags & 1;
1623 memset(&fi, 0,
sizeof(fi));
1626 if (req->se->op.fsyncdir)
1627 req->se->op.fsyncdir(req, nodeid, datasync, &fi);
1637 if (req->se->op.statfs)
1638 req->se->op.statfs(req, nodeid);
1640 struct statvfs buf = {
1650 struct fuse_session *se = req->se;
1652 struct fuse_setxattr_in *arg = (
struct fuse_setxattr_in *) inarg;
1653 char *name = xattr_ext ? PARAM(arg) :
1654 (char *)arg + FUSE_COMPAT_SETXATTR_IN_SIZE;
1655 char *value = name + strlen(name) + 1;
1658 if (req->se->op.setxattr)
1659 req->se->op.setxattr(req, nodeid, name, value, arg->size,
1667 struct fuse_getxattr_in *arg = (
struct fuse_getxattr_in *) inarg;
1669 if (req->se->op.getxattr)
1670 req->se->op.getxattr(req, nodeid, PARAM(arg), arg->size);
1677 struct fuse_getxattr_in *arg = (
struct fuse_getxattr_in *) inarg;
1679 if (req->se->op.listxattr)
1680 req->se->op.listxattr(req, nodeid, arg->size);
1687 char *name = (
char *) inarg;
1689 if (req->se->op.removexattr)
1690 req->se->op.removexattr(req, nodeid, name);
1695static void convert_fuse_file_lock(
struct fuse_file_lock *fl,
1696 struct flock *flock)
1698 memset(flock, 0,
sizeof(
struct flock));
1699 flock->l_type = fl->type;
1700 flock->l_whence = SEEK_SET;
1701 flock->l_start = fl->start;
1702 if (fl->end == OFFSET_MAX)
1705 flock->l_len = fl->end - fl->start + 1;
1706 flock->l_pid = fl->pid;
1711 struct fuse_lk_in *arg = (
struct fuse_lk_in *) inarg;
1715 memset(&fi, 0,
sizeof(fi));
1719 convert_fuse_file_lock(&arg->lk, &flock);
1720 if (req->se->op.getlk)
1721 req->se->op.getlk(req, nodeid, &fi, &flock);
1727 const void *inarg,
int sleep)
1729 struct fuse_lk_in *arg = (
struct fuse_lk_in *) inarg;
1733 memset(&fi, 0,
sizeof(fi));
1737 if (arg->lk_flags & FUSE_LK_FLOCK) {
1740 switch (arg->lk.type) {
1754 if (req->se->op.flock)
1755 req->se->op.flock(req, nodeid, &fi, op);
1759 convert_fuse_file_lock(&arg->lk, &flock);
1760 if (req->se->op.setlk)
1761 req->se->op.setlk(req, nodeid, &fi, &flock, sleep);
1769 do_setlk_common(req, nodeid, inarg, 0);
1774 do_setlk_common(req, nodeid, inarg, 1);
1777static int find_interrupted(
struct fuse_session *se,
struct fuse_req *req)
1779 struct fuse_req *curr;
1781 for (curr = se->list.next; curr != &se->list; curr = curr->next) {
1782 if (curr->unique == req->u.i.unique) {
1787 pthread_mutex_unlock(&se->lock);
1790 pthread_mutex_lock(&curr->lock);
1791 pthread_mutex_lock(&se->lock);
1792 curr->interrupted = 1;
1793 func = curr->u.ni.func;
1794 data = curr->u.ni.data;
1795 pthread_mutex_unlock(&se->lock);
1798 pthread_mutex_unlock(&curr->lock);
1800 pthread_mutex_lock(&se->lock);
1802 if (!curr->ref_cnt) {
1809 for (curr = se->interrupts.next; curr != &se->interrupts;
1810 curr = curr->next) {
1811 if (curr->u.i.unique == req->u.i.unique)
1819 struct fuse_interrupt_in *arg = (
struct fuse_interrupt_in *) inarg;
1820 struct fuse_session *se = req->se;
1824 fuse_log(FUSE_LOG_DEBUG,
"INTERRUPT: %llu\n",
1825 (
unsigned long long) arg->unique);
1827 req->u.i.unique = arg->unique;
1829 pthread_mutex_lock(&se->lock);
1830 if (find_interrupted(se, req)) {
1831 fuse_chan_put(req->ch);
1835 list_add_req(req, &se->interrupts);
1836 pthread_mutex_unlock(&se->lock);
1839static struct fuse_req *check_interrupt(
struct fuse_session *se,
1840 struct fuse_req *req)
1842 struct fuse_req *curr;
1844 for (curr = se->interrupts.next; curr != &se->interrupts;
1845 curr = curr->next) {
1846 if (curr->u.i.unique == req->unique) {
1847 req->interrupted = 1;
1849 fuse_chan_put(curr->ch);
1855 curr = se->interrupts.next;
1856 if (curr != &se->interrupts) {
1858 list_init_req(curr);
1866 struct fuse_bmap_in *arg = (
struct fuse_bmap_in *) inarg;
1868 if (req->se->op.bmap)
1869 req->se->op.bmap(req, nodeid, arg->blocksize, arg->block);
1876 struct fuse_ioctl_in *arg = (
struct fuse_ioctl_in *) inarg;
1877 unsigned int flags = arg->flags;
1878 void *in_buf = arg->in_size ? PARAM(arg) : NULL;
1881 if (
flags & FUSE_IOCTL_DIR &&
1887 memset(&fi, 0,
sizeof(fi));
1890 if (
sizeof(
void *) == 4 && req->se->conn.proto_minor >= 16 &&
1891 !(
flags & FUSE_IOCTL_32BIT)) {
1892 req->ioctl_64bit = 1;
1895 if (req->se->op.ioctl)
1896 req->se->op.ioctl(req, nodeid, arg->cmd,
1897 (
void *)(uintptr_t)arg->arg, &fi,
flags,
1898 in_buf, arg->in_size, arg->out_size);
1910 struct fuse_poll_in *arg = (
struct fuse_poll_in *) inarg;
1913 memset(&fi, 0,
sizeof(fi));
1917 if (req->se->op.poll) {
1918 struct fuse_pollhandle *ph = NULL;
1920 if (arg->flags & FUSE_POLL_SCHEDULE_NOTIFY) {
1921 ph = malloc(
sizeof(
struct fuse_pollhandle));
1930 req->se->op.poll(req, nodeid, &fi, ph);
1938 struct fuse_fallocate_in *arg = (
struct fuse_fallocate_in *) inarg;
1941 memset(&fi, 0,
sizeof(fi));
1944 if (req->se->op.fallocate)
1945 req->se->op.fallocate(req, nodeid, arg->mode, arg->offset, arg->length, &fi);
1952 struct fuse_copy_file_range_in *arg = (
struct fuse_copy_file_range_in *) inarg;
1955 memset(&fi_in, 0,
sizeof(fi_in));
1956 fi_in.fh = arg->fh_in;
1958 memset(&fi_out, 0,
sizeof(fi_out));
1959 fi_out.fh = arg->fh_out;
1962 if (req->se->op.copy_file_range)
1963 req->se->op.copy_file_range(req, nodeid_in, arg->off_in,
1964 &fi_in, arg->nodeid_out,
1965 arg->off_out, &fi_out, arg->len,
1973 struct fuse_lseek_in *arg = (
struct fuse_lseek_in *) inarg;
1976 memset(&fi, 0,
sizeof(fi));
1979 if (req->se->op.lseek)
1980 req->se->op.lseek(req, nodeid, arg->offset, arg->whence, &fi);
1985static bool want_flags_valid(uint64_t capable, uint64_t want)
1987 uint64_t unknown_flags = want & (~capable);
1988 if (unknown_flags != 0) {
1990 "fuse: unknown connection 'want' flags: 0x%08lx\n",
2002 struct fuse_session *se = container_of(conn,
struct fuse_session, conn);
2013 if (conn->
want != se->conn_want &&
2015 if (conn->
want_ext != se->conn_want_ext) {
2017 "%s: Both conn->want_ext and conn->want are set.\n"
2018 "want=%x, want_ext=%lx, se->want=%lx se->want_ext=%lx\n",
2020 se->conn_want, se->conn_want_ext);
2038 struct fuse_session *se = container_of(conn,
struct fuse_session, conn);
2042 se->conn_want_ext |= flag;
2044 se->conn_want |= flag;
2053 struct fuse_session *se = container_of(conn,
struct fuse_session, conn);
2056 se->conn_want_ext &= ~flag;
2057 conn->
want &= ~flag;
2058 se->conn_want &= ~flag;
2070static __attribute__((no_sanitize(
"thread")))
2073 struct fuse_init_in *arg = (
struct fuse_init_in *) inarg;
2074 struct fuse_init_out outarg;
2075 struct fuse_session *se = req->se;
2076 size_t bufsize = se->bufsize;
2077 size_t outargsize =
sizeof(outarg);
2078 uint64_t inargflags = 0;
2079 uint64_t outargflags = 0;
2080 bool buf_reallocable = se->buf_reallocable;
2083 fuse_log(FUSE_LOG_DEBUG,
"INIT: %u.%u\n", arg->major, arg->minor);
2084 if (arg->major == 7 && arg->minor >= 6) {
2085 fuse_log(FUSE_LOG_DEBUG,
"flags=0x%08x\n", arg->flags);
2086 fuse_log(FUSE_LOG_DEBUG,
"max_readahead=0x%08x\n",
2087 arg->max_readahead);
2090 se->conn.proto_major = arg->major;
2091 se->conn.proto_minor = arg->minor;
2092 se->conn.capable_ext = 0;
2093 se->conn.want_ext = 0;
2095 memset(&outarg, 0,
sizeof(outarg));
2096 outarg.major = FUSE_KERNEL_VERSION;
2097 outarg.minor = FUSE_KERNEL_MINOR_VERSION;
2099 if (arg->major < 7) {
2100 fuse_log(FUSE_LOG_ERR,
"fuse: unsupported protocol version: %u.%u\n",
2101 arg->major, arg->minor);
2106 if (arg->major > 7) {
2108 send_reply_ok(req, &outarg,
sizeof(outarg));
2112 if (arg->minor >= 6) {
2113 if (arg->max_readahead < se->conn.max_readahead)
2114 se->conn.max_readahead = arg->max_readahead;
2115 inargflags = arg->flags;
2116 if (inargflags & FUSE_INIT_EXT)
2117 inargflags = inargflags | (uint64_t) arg->flags2 << 32;
2118 if (inargflags & FUSE_ASYNC_READ)
2120 if (inargflags & FUSE_POSIX_LOCKS)
2122 if (inargflags & FUSE_ATOMIC_O_TRUNC)
2124 if (inargflags & FUSE_EXPORT_SUPPORT)
2126 if (inargflags & FUSE_DONT_MASK)
2128 if (inargflags & FUSE_FLOCK_LOCKS)
2130 if (inargflags & FUSE_AUTO_INVAL_DATA)
2132 if (inargflags & FUSE_DO_READDIRPLUS)
2134 if (inargflags & FUSE_READDIRPLUS_AUTO)
2136 if (inargflags & FUSE_ASYNC_DIO)
2138 if (inargflags & FUSE_WRITEBACK_CACHE)
2140 if (inargflags & FUSE_NO_OPEN_SUPPORT)
2142 if (inargflags & FUSE_PARALLEL_DIROPS)
2144 if (inargflags & FUSE_POSIX_ACL)
2146 if (inargflags & FUSE_HANDLE_KILLPRIV)
2148 if (inargflags & FUSE_HANDLE_KILLPRIV_V2)
2150 if (inargflags & FUSE_CACHE_SYMLINKS)
2152 if (inargflags & FUSE_NO_OPENDIR_SUPPORT)
2154 if (inargflags & FUSE_EXPLICIT_INVAL_DATA)
2156 if (inargflags & FUSE_SETXATTR_EXT)
2158 if (!(inargflags & FUSE_MAX_PAGES)) {
2159 size_t max_bufsize =
2160 FUSE_DEFAULT_MAX_PAGES_PER_REQ * getpagesize()
2161 + FUSE_BUFFER_HEADER_SIZE;
2162 if (bufsize > max_bufsize) {
2163 bufsize = max_bufsize;
2165 buf_reallocable =
false;
2167 if (inargflags & FUSE_DIRECT_IO_ALLOW_MMAP)
2169 if (arg->minor >= 38 || (inargflags & FUSE_HAS_EXPIRE_ONLY))
2171 if (inargflags & FUSE_PASSTHROUGH)
2173 if (inargflags & FUSE_NO_EXPORT_SUPPORT)
2176 se->conn.max_readahead = 0;
2179 if (se->conn.proto_minor >= 14) {
2182 if ((se->io == NULL) || (se->io->splice_send != NULL)) {
2187 if ((se->io == NULL) || (se->io->splice_receive != NULL)) {
2192 if (se->conn.proto_minor >= 18)
2202#define LL_SET_DEFAULT(cond, cap) \
2204 fuse_set_feature_flag(&se->conn, cap)
2212 LL_SET_DEFAULT(se->op.getlk && se->op.setlk,
2216 LL_SET_DEFAULT(se->op.readdirplus && se->op.readdir,
2224 se->conn.time_gran = 1;
2229 se->conn.capable = fuse_lower_32_bits(se->conn.capable_ext);
2231 se->op.init(se->userdata, &se->conn);
2241 if (!want_flags_valid(se->conn.capable_ext, se->conn.want_ext)) {
2243 se->error = -EPROTO;
2248 unsigned max_read_mo = get_max_read(se->mo);
2249 if (se->conn.max_read != max_read_mo) {
2250 fuse_log(FUSE_LOG_ERR,
"fuse: error: init() and fuse_session_new() "
2251 "requested different maximum read size (%u vs %u)\n",
2252 se->conn.max_read, max_read_mo);
2254 se->error = -EPROTO;
2259 if (bufsize < FUSE_MIN_READ_BUFFER) {
2261 "fuse: warning: buffer size too small: %zu\n",
2263 bufsize = FUSE_MIN_READ_BUFFER;
2266 if (buf_reallocable)
2268 se->conn.max_write = MIN(se->conn.max_write, bufsize - FUSE_BUFFER_HEADER_SIZE);
2269 se->bufsize = se->conn.max_write + FUSE_BUFFER_HEADER_SIZE;
2271 if (arg->flags & FUSE_MAX_PAGES) {
2272 outarg.flags |= FUSE_MAX_PAGES;
2273 outarg.max_pages = (se->conn.max_write - 1) / getpagesize() + 1;
2275 outargflags = outarg.flags;
2278 outargflags |= FUSE_BIG_WRITES;
2281 outargflags |= FUSE_ASYNC_READ;
2283 outargflags |= FUSE_POSIX_LOCKS;
2285 outargflags |= FUSE_ATOMIC_O_TRUNC;
2287 outargflags |= FUSE_EXPORT_SUPPORT;
2289 outargflags |= FUSE_DONT_MASK;
2291 outargflags |= FUSE_FLOCK_LOCKS;
2293 outargflags |= FUSE_AUTO_INVAL_DATA;
2295 outargflags |= FUSE_DO_READDIRPLUS;
2297 outargflags |= FUSE_READDIRPLUS_AUTO;
2299 outargflags |= FUSE_ASYNC_DIO;
2301 outargflags |= FUSE_WRITEBACK_CACHE;
2303 outargflags |= FUSE_PARALLEL_DIROPS;
2305 outargflags |= FUSE_POSIX_ACL;
2307 outargflags |= FUSE_HANDLE_KILLPRIV;
2309 outargflags |= FUSE_HANDLE_KILLPRIV_V2;
2311 outargflags |= FUSE_CACHE_SYMLINKS;
2313 outargflags |= FUSE_EXPLICIT_INVAL_DATA;
2315 outargflags |= FUSE_SETXATTR_EXT;
2317 outargflags |= FUSE_DIRECT_IO_ALLOW_MMAP;
2319 outargflags |= FUSE_PASSTHROUGH;
2324 outarg.max_stack_depth = se->conn.max_backing_stack_depth + 1;
2327 outargflags |= FUSE_NO_EXPORT_SUPPORT;
2329 if (inargflags & FUSE_INIT_EXT) {
2330 outargflags |= FUSE_INIT_EXT;
2331 outarg.flags2 = outargflags >> 32;
2334 outarg.flags = outargflags;
2336 outarg.max_readahead = se->conn.max_readahead;
2337 outarg.max_write = se->conn.max_write;
2338 if (se->conn.proto_minor >= 13) {
2339 if (se->conn.max_background >= (1 << 16))
2340 se->conn.max_background = (1 << 16) - 1;
2341 if (se->conn.congestion_threshold > se->conn.max_background)
2342 se->conn.congestion_threshold = se->conn.max_background;
2343 if (!se->conn.congestion_threshold) {
2344 se->conn.congestion_threshold =
2345 se->conn.max_background * 3 / 4;
2348 outarg.max_background = se->conn.max_background;
2349 outarg.congestion_threshold = se->conn.congestion_threshold;
2351 if (se->conn.proto_minor >= 23)
2352 outarg.time_gran = se->conn.time_gran;
2355 fuse_log(FUSE_LOG_DEBUG,
" INIT: %u.%u\n", outarg.major, outarg.minor);
2356 fuse_log(FUSE_LOG_DEBUG,
" flags=0x%08x\n", outarg.flags);
2357 fuse_log(FUSE_LOG_DEBUG,
" max_readahead=0x%08x\n",
2358 outarg.max_readahead);
2359 fuse_log(FUSE_LOG_DEBUG,
" max_write=0x%08x\n", outarg.max_write);
2360 fuse_log(FUSE_LOG_DEBUG,
" max_background=%i\n",
2361 outarg.max_background);
2362 fuse_log(FUSE_LOG_DEBUG,
" congestion_threshold=%i\n",
2363 outarg.congestion_threshold);
2364 fuse_log(FUSE_LOG_DEBUG,
" time_gran=%u\n",
2367 fuse_log(FUSE_LOG_DEBUG,
" max_stack_depth=%u\n",
2368 outarg.max_stack_depth);
2371 outargsize = FUSE_COMPAT_INIT_OUT_SIZE;
2372 else if (arg->minor < 23)
2373 outargsize = FUSE_COMPAT_22_INIT_OUT_SIZE;
2375 send_reply_ok(req, &outarg, outargsize);
2380 struct fuse_session *se = req->se;
2386 mountpoint = atomic_exchange(&se->mountpoint, NULL);
2389 se->got_destroy = 1;
2392 se->op.destroy(se->userdata);
2394 send_reply_ok(req, NULL, 0);
2397static void list_del_nreq(
struct fuse_notify_req *nreq)
2399 struct fuse_notify_req *prev = nreq->prev;
2400 struct fuse_notify_req *next = nreq->next;
2405static void list_add_nreq(
struct fuse_notify_req *nreq,
2406 struct fuse_notify_req *next)
2408 struct fuse_notify_req *prev = next->prev;
2415static void list_init_nreq(
struct fuse_notify_req *nreq)
2422 const void *inarg,
const struct fuse_buf *buf)
2424 struct fuse_session *se = req->se;
2425 struct fuse_notify_req *nreq;
2426 struct fuse_notify_req *head;
2428 pthread_mutex_lock(&se->lock);
2429 head = &se->notify_list;
2430 for (nreq = head->next; nreq != head; nreq = nreq->next) {
2431 if (nreq->unique == req->unique) {
2432 list_del_nreq(nreq);
2436 pthread_mutex_unlock(&se->lock);
2439 nreq->reply(nreq, req, nodeid, inarg, buf);
2442static int send_notify_iov(
struct fuse_session *se,
int notify_code,
2443 struct iovec *iov,
int count)
2445 struct fuse_out_header out;
2451 out.error = notify_code;
2452 iov[0].iov_base = &out;
2453 iov[0].iov_len =
sizeof(
struct fuse_out_header);
2455 return fuse_send_msg(se, NULL, iov, count);
2461 struct fuse_notify_poll_wakeup_out outarg;
2462 struct iovec iov[2];
2466 iov[1].iov_base = &outarg;
2467 iov[1].iov_len =
sizeof(outarg);
2469 return send_notify_iov(ph->se, FUSE_NOTIFY_POLL, iov, 2);
2476 off_t off, off_t len)
2478 struct fuse_notify_inval_inode_out outarg;
2479 struct iovec iov[2];
2484 if (se->conn.proto_minor < 12)
2491 iov[1].iov_base = &outarg;
2492 iov[1].iov_len =
sizeof(outarg);
2494 return send_notify_iov(se, FUSE_NOTIFY_INVAL_INODE, iov, 2);
2516static int fuse_lowlevel_notify_entry(
struct fuse_session *se,
fuse_ino_t parent,
2517 const char *name,
size_t namelen,
2520 struct fuse_notify_inval_entry_out outarg;
2521 struct iovec iov[3];
2526 if (se->conn.proto_minor < 12)
2529 outarg.parent = parent;
2530 outarg.namelen = namelen;
2532 if (flags & FUSE_LL_EXPIRE_ONLY)
2533 outarg.flags |= FUSE_EXPIRE_ONLY;
2535 iov[1].iov_base = &outarg;
2536 iov[1].iov_len =
sizeof(outarg);
2537 iov[2].iov_base = (
void *)name;
2538 iov[2].iov_len = namelen + 1;
2540 return send_notify_iov(se, FUSE_NOTIFY_INVAL_ENTRY, iov, 3);
2544 const char *name,
size_t namelen)
2546 return fuse_lowlevel_notify_entry(se, parent, name, namelen, FUSE_LL_INVALIDATE);
2550 const char *name,
size_t namelen)
2558 return fuse_lowlevel_notify_entry(se, parent, name, namelen, FUSE_LL_EXPIRE_ONLY);
2564 const char *name,
size_t namelen)
2566 struct fuse_notify_delete_out outarg;
2567 struct iovec iov[3];
2572 if (se->conn.proto_minor < 18)
2575 outarg.parent = parent;
2576 outarg.child = child;
2577 outarg.namelen = namelen;
2580 iov[1].iov_base = &outarg;
2581 iov[1].iov_len =
sizeof(outarg);
2582 iov[2].iov_base = (
void *)name;
2583 iov[2].iov_len = namelen + 1;
2585 return send_notify_iov(se, FUSE_NOTIFY_DELETE, iov, 3);
2592 struct fuse_out_header out;
2593 struct fuse_notify_store_out outarg;
2594 struct iovec iov[3];
2601 if (se->conn.proto_minor < 15)
2605 out.error = FUSE_NOTIFY_STORE;
2607 outarg.nodeid = ino;
2608 outarg.offset = offset;
2612 iov[0].iov_base = &out;
2613 iov[0].iov_len =
sizeof(out);
2614 iov[1].iov_base = &outarg;
2615 iov[1].iov_len =
sizeof(outarg);
2617 res = fuse_send_data_iov(se, NULL, iov, 2, bufv, flags);
2624struct fuse_retrieve_req {
2625 struct fuse_notify_req nreq;
2629static void fuse_ll_retrieve_reply(
struct fuse_notify_req *nreq,
2634 struct fuse_session *se = req->se;
2635 struct fuse_retrieve_req *rreq =
2636 container_of(nreq,
struct fuse_retrieve_req, nreq);
2637 const struct fuse_notify_retrieve_in *arg = inarg;
2644 bufv.
buf[0].
mem = PARAM(arg);
2646 bufv.
buf[0].
size -=
sizeof(
struct fuse_in_header) +
2647 sizeof(struct fuse_notify_retrieve_in);
2649 if (bufv.
buf[0].
size < arg->size) {
2650 fuse_log(FUSE_LOG_ERR,
"fuse: retrieve reply: buffer size too small\n");
2656 if (se->op.retrieve_reply) {
2657 se->op.retrieve_reply(req, rreq->cookie, ino,
2658 arg->offset, &bufv);
2665 fuse_ll_clear_pipe(se);
2669 size_t size, off_t offset,
void *cookie)
2671 struct fuse_notify_retrieve_out outarg;
2672 struct iovec iov[2];
2673 struct fuse_retrieve_req *rreq;
2679 if (se->conn.proto_minor < 15)
2682 rreq = malloc(
sizeof(*rreq));
2686 pthread_mutex_lock(&se->lock);
2687 rreq->cookie = cookie;
2688 rreq->nreq.unique = se->notify_ctr++;
2689 rreq->nreq.reply = fuse_ll_retrieve_reply;
2690 list_add_nreq(&rreq->nreq, &se->notify_list);
2691 pthread_mutex_unlock(&se->lock);
2693 outarg.notify_unique = rreq->nreq.unique;
2694 outarg.nodeid = ino;
2695 outarg.offset = offset;
2699 iov[1].iov_base = &outarg;
2700 iov[1].iov_len =
sizeof(outarg);
2702 err = send_notify_iov(se, FUSE_NOTIFY_RETRIEVE, iov, 2);
2704 pthread_mutex_lock(&se->lock);
2705 list_del_nreq(&rreq->nreq);
2706 pthread_mutex_unlock(&se->lock);
2715 return req->se->userdata;
2726 pthread_mutex_lock(&req->lock);
2727 pthread_mutex_lock(&req->se->lock);
2728 req->u.ni.func = func;
2729 req->u.ni.data = data;
2730 pthread_mutex_unlock(&req->se->lock);
2731 if (req->interrupted && func)
2733 pthread_mutex_unlock(&req->lock);
2740 pthread_mutex_lock(&req->se->lock);
2741 interrupted = req->interrupted;
2742 pthread_mutex_unlock(&req->se->lock);
2751 [FUSE_LOOKUP] = { do_lookup,
"LOOKUP" },
2752 [FUSE_FORGET] = { do_forget,
"FORGET" },
2753 [FUSE_GETATTR] = { do_getattr,
"GETATTR" },
2754 [FUSE_SETATTR] = { do_setattr,
"SETATTR" },
2755 [FUSE_READLINK] = { do_readlink,
"READLINK" },
2756 [FUSE_SYMLINK] = { do_symlink,
"SYMLINK" },
2757 [FUSE_MKNOD] = { do_mknod,
"MKNOD" },
2758 [FUSE_MKDIR] = { do_mkdir,
"MKDIR" },
2759 [FUSE_UNLINK] = { do_unlink,
"UNLINK" },
2760 [FUSE_RMDIR] = { do_rmdir,
"RMDIR" },
2761 [FUSE_RENAME] = { do_rename,
"RENAME" },
2762 [FUSE_LINK] = { do_link,
"LINK" },
2763 [FUSE_OPEN] = { do_open,
"OPEN" },
2764 [FUSE_READ] = { do_read,
"READ" },
2765 [FUSE_WRITE] = { do_write,
"WRITE" },
2766 [FUSE_STATFS] = { do_statfs,
"STATFS" },
2767 [FUSE_RELEASE] = { do_release,
"RELEASE" },
2768 [FUSE_FSYNC] = { do_fsync,
"FSYNC" },
2769 [FUSE_SETXATTR] = { do_setxattr,
"SETXATTR" },
2770 [FUSE_GETXATTR] = { do_getxattr,
"GETXATTR" },
2771 [FUSE_LISTXATTR] = { do_listxattr,
"LISTXATTR" },
2772 [FUSE_REMOVEXATTR] = { do_removexattr,
"REMOVEXATTR" },
2773 [FUSE_FLUSH] = { do_flush,
"FLUSH" },
2774 [FUSE_INIT] = { do_init,
"INIT" },
2775 [FUSE_OPENDIR] = { do_opendir,
"OPENDIR" },
2776 [FUSE_READDIR] = { do_readdir,
"READDIR" },
2777 [FUSE_RELEASEDIR] = { do_releasedir,
"RELEASEDIR" },
2778 [FUSE_FSYNCDIR] = { do_fsyncdir,
"FSYNCDIR" },
2779 [FUSE_GETLK] = { do_getlk,
"GETLK" },
2780 [FUSE_SETLK] = { do_setlk,
"SETLK" },
2781 [FUSE_SETLKW] = { do_setlkw,
"SETLKW" },
2782 [FUSE_ACCESS] = { do_access,
"ACCESS" },
2783 [FUSE_CREATE] = { do_create,
"CREATE" },
2784 [FUSE_TMPFILE] = { do_tmpfile,
"TMPFILE" },
2785 [FUSE_INTERRUPT] = { do_interrupt,
"INTERRUPT" },
2786 [FUSE_BMAP] = { do_bmap,
"BMAP" },
2787 [FUSE_IOCTL] = { do_ioctl,
"IOCTL" },
2788 [FUSE_POLL] = { do_poll,
"POLL" },
2789 [FUSE_FALLOCATE] = { do_fallocate,
"FALLOCATE" },
2790 [FUSE_DESTROY] = { do_destroy,
"DESTROY" },
2791 [FUSE_NOTIFY_REPLY] = { (
void *) 1,
"NOTIFY_REPLY" },
2792 [FUSE_BATCH_FORGET] = { do_batch_forget,
"BATCH_FORGET" },
2793 [FUSE_READDIRPLUS] = { do_readdirplus,
"READDIRPLUS"},
2794 [FUSE_RENAME2] = { do_rename2,
"RENAME2" },
2795 [FUSE_COPY_FILE_RANGE] = { do_copy_file_range,
"COPY_FILE_RANGE" },
2796 [FUSE_LSEEK] = { do_lseek,
"LSEEK" },
2797 [CUSE_INIT] = { cuse_lowlevel_init,
"CUSE_INIT" },
2805#define FUSE_MAXOP (CUSE_INIT + 1)
2807static const char *opname(
enum fuse_opcode opcode)
2809 if (opcode >= FUSE_MAXOP || !fuse_ll_ops[opcode].name)
2812 return fuse_ll_ops[opcode].name;
2815static int fuse_ll_copy_from_pipe(
struct fuse_bufvec *dst,
2820 fuse_log(FUSE_LOG_ERR,
"fuse: copy from pipe: %s\n", strerror(-res));
2824 fuse_log(FUSE_LOG_ERR,
"fuse: copy from pipe: short read\n");
2833 fuse_session_process_buf_internal(se, buf, NULL);
2837void fuse_session_process_buf_internal(
struct fuse_session *se,
2838 const struct fuse_buf *buf,
struct fuse_chan *ch)
2840 const size_t write_header_size =
sizeof(
struct fuse_in_header) +
2841 sizeof(struct fuse_write_in);
2843 struct fuse_bufvec tmpbuf = FUSE_BUFVEC_INIT(write_header_size);
2844 struct fuse_in_header *in;
2846 struct fuse_req *req;
2855 mbuf = malloc(tmpbuf.
buf[0].
size);
2857 fuse_log(FUSE_LOG_ERR,
"fuse: failed to allocate header\n");
2860 tmpbuf.
buf[0].
mem = mbuf;
2862 res = fuse_ll_copy_from_pipe(&tmpbuf, &bufv);
2873 "unique: %llu, opcode: %s (%i), nodeid: %llu, insize: %zu, pid: %u\n",
2874 (
unsigned long long) in->unique,
2875 opname((
enum fuse_opcode) in->opcode), in->opcode,
2876 (
unsigned long long) in->nodeid, buf->
size, in->pid);
2879 req = fuse_ll_alloc_req(se);
2881 struct fuse_out_header out = {
2882 .unique = in->unique,
2885 struct iovec iov = {
2887 .iov_len =
sizeof(
struct fuse_out_header),
2890 fuse_send_msg(se, ch, &iov, 1);
2894 req->unique = in->unique;
2895 req->ctx.uid = in->uid;
2896 req->ctx.gid = in->gid;
2897 req->ctx.pid = in->pid;
2898 req->ch = ch ? fuse_chan_get(ch) : NULL;
2901 if (!se->got_init) {
2902 enum fuse_opcode expected;
2904 expected = se->cuse_data ? CUSE_INIT : FUSE_INIT;
2905 if (in->opcode != expected)
2907 }
else if (in->opcode == FUSE_INIT || in->opcode == CUSE_INIT)
2912 if (se->deny_others && in->uid != se->owner && in->uid != 0 &&
2913 in->opcode != FUSE_INIT && in->opcode != FUSE_READ &&
2914 in->opcode != FUSE_WRITE && in->opcode != FUSE_FSYNC &&
2915 in->opcode != FUSE_RELEASE && in->opcode != FUSE_READDIR &&
2916 in->opcode != FUSE_FSYNCDIR && in->opcode != FUSE_RELEASEDIR &&
2917 in->opcode != FUSE_NOTIFY_REPLY &&
2918 in->opcode != FUSE_READDIRPLUS)
2922 if (in->opcode >= FUSE_MAXOP || !fuse_ll_ops[in->opcode].func)
2925 if (se->conn.no_interrupt && in->opcode == FUSE_INTERRUPT) {
2927 fuse_log(FUSE_LOG_DEBUG,
"FUSE_INTERRUPT: reply to kernel to disable interrupt\n");
2930 if (!se->conn.no_interrupt && in->opcode != FUSE_INTERRUPT) {
2931 struct fuse_req *intr;
2932 pthread_mutex_lock(&se->lock);
2933 intr = check_interrupt(se, req);
2934 list_add_req(req, &se->list);
2935 pthread_mutex_unlock(&se->lock);
2941 (in->opcode != FUSE_WRITE || !se->op.write_buf) &&
2942 in->opcode != FUSE_NOTIFY_REPLY) {
2946 newmbuf = realloc(mbuf, buf->
size);
2947 if (newmbuf == NULL)
2951 tmpbuf = FUSE_BUFVEC_INIT(buf->
size - write_header_size);
2952 tmpbuf.
buf[0].
mem = (
char *)mbuf + write_header_size;
2954 res = fuse_ll_copy_from_pipe(&tmpbuf, &bufv);
2962 inarg = (
void *) &in[1];
2963 if (in->opcode == FUSE_WRITE && se->op.write_buf)
2964 do_write_buf(req, in->nodeid, inarg, buf);
2965 else if (in->opcode == FUSE_NOTIFY_REPLY)
2966 do_notify_reply(req, in->nodeid, inarg, buf);
2968 fuse_ll_ops[in->opcode].func(req, in->nodeid, inarg);
2978 fuse_ll_clear_pipe(se);
2982#define LL_OPTION(n,o,v) \
2983 { n, offsetof(struct fuse_session, o), v }
2985static const struct fuse_opt fuse_ll_opts[] = {
2986 LL_OPTION(
"debug", debug, 1),
2987 LL_OPTION(
"-d", debug, 1),
2988 LL_OPTION(
"--debug", debug, 1),
2989 LL_OPTION(
"allow_root", deny_others, 1),
2995 printf(
"using FUSE kernel interface version %i.%i\n",
2996 FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION);
2997 fuse_mount_version();
3005" -o allow_other allow access by all users\n"
3006" -o allow_root allow access by root\n"
3007" -o auto_unmount auto unmount on process termination\n");
3012 struct fuse_ll_pipe *llp;
3014 if (se->got_init && !se->got_destroy) {
3016 se->op.destroy(se->userdata);
3018 llp = pthread_getspecific(se->pipe_key);
3020 fuse_ll_pipe_free(llp);
3021 pthread_key_delete(se->pipe_key);
3022 pthread_mutex_destroy(&se->lock);
3023 free(se->cuse_data);
3028 destroy_mount_opts(se->mo);
3033static void fuse_ll_pipe_destructor(
void *data)
3035 struct fuse_ll_pipe *llp = data;
3036 fuse_ll_pipe_free(llp);
3039void fuse_buf_free(
struct fuse_buf *buf)
3041 if (buf->
mem == NULL)
3044 size_t write_header_sz =
3045 sizeof(
struct fuse_in_header) + sizeof(struct fuse_write_in);
3047 char *ptr = (
char *)buf->
mem - pagesize + write_header_sz;
3055static void *buf_alloc(
size_t size,
bool internal)
3063 size_t write_header_sz =
sizeof(
struct fuse_in_header) +
3064 sizeof(struct fuse_write_in);
3065 size_t new_size = ROUND_UP(size + write_header_sz, pagesize);
3067 char *buf = aligned_alloc(pagesize, new_size);
3071 buf += pagesize - write_header_sz;
3075 return malloc(size);
3082static int _fuse_session_receive_buf(
struct fuse_session *se,
3083 struct fuse_buf *buf,
struct fuse_chan *ch,
3090 struct fuse_ll_pipe *llp;
3094 bufsize = se->bufsize;
3096 if (se->conn.proto_minor < 14 ||
3100 llp = fuse_ll_get_pipe(se);
3104 if (llp->size < bufsize) {
3105 if (llp->can_grow) {
3106 res = fcntl(llp->pipe[0], F_SETPIPE_SZ, bufsize);
3109 res = grow_pipe_to_max(llp->pipe[0]);
3116 if (llp->size < bufsize)
3120 if (se->io != NULL && se->io->splice_receive != NULL) {
3121 res = se->io->splice_receive(ch ? ch->fd : se->
fd, NULL,
3122 llp->pipe[1], NULL, bufsize, 0,
3125 res = splice(ch ? ch->fd : se->
fd, NULL, llp->pipe[1], NULL,
3134 if (err == ENODEV) {
3142 if (err == EINVAL && bufsize < se->bufsize) {
3143 fuse_ll_clear_pipe(se);
3147 if (err != EINTR && err != EAGAIN)
3148 perror(
"fuse: splice from device");
3152 if (res <
sizeof(
struct fuse_in_header)) {
3153 fuse_log(FUSE_LOG_ERR,
"short splice from fuse device\n");
3168 if (res <
sizeof(
struct fuse_in_header) +
sizeof(
struct fuse_write_in) +
3174 buf->
mem = buf_alloc(bufsize, internal);
3178 "fuse: failed to allocate read buffer\n");
3189 fuse_log(FUSE_LOG_ERR,
"fuse: copy from pipe: %s\n",
3191 fuse_ll_clear_pipe(se);
3194 if (res < tmpbuf.size) {
3196 "fuse: copy from pipe: short read\n");
3197 fuse_ll_clear_pipe(se);
3200 assert(res == tmpbuf.size);
3204 buf->
fd = tmpbuf.fd;
3215 bufsize = se->bufsize;
3216 buf->
mem = buf_alloc(bufsize, internal);
3219 "fuse: failed to allocate read buffer\n");
3228 if (se->io != NULL) {
3231 res = se->io->read(ch ? ch->fd : se->fd,
buf->mem, bufsize,
3234 res = read(ch ? ch->fd : se->fd,
buf->mem, bufsize);
3241 if (err == EINVAL && internal && se->bufsize > bufsize) {
3243 bufsize = se->bufsize;
3244 void *newbuf = buf_alloc(bufsize, internal);
3248 "fuse: failed to (re)allocate read buffer\n");
3262 if (err == ENODEV) {
3271 if (err != EINTR && err != EAGAIN)
3272 perror(
"fuse: reading device");
3275 if ((
size_t)res <
sizeof(
struct fuse_in_header)) {
3276 fuse_log(FUSE_LOG_ERR,
"short read on fuse device\n");
3287 return _fuse_session_receive_buf(se,
buf, NULL,
false);
3291int fuse_session_receive_buf_internal(
struct fuse_session *se,
3293 struct fuse_chan *ch)
3299 if (unlikely(!se->got_init) && !se->buf_reallocable)
3300 se->buf_reallocable =
true;
3302 return _fuse_session_receive_buf(se,
buf, ch,
true);
3305struct fuse_session *
3306fuse_session_new_versioned(
struct fuse_args *args,
3311 struct fuse_session *se;
3312 struct mount_opts *mo;
3315 fuse_log(FUSE_LOG_ERR,
"fuse: warning: library too old, some operations may not work\n");
3319 if (args->
argc == 0) {
3320 fuse_log(FUSE_LOG_ERR,
"fuse: empty argv passed to fuse_session_new().\n");
3324 se = (
struct fuse_session *) calloc(1,
sizeof(
struct fuse_session));
3326 fuse_log(FUSE_LOG_ERR,
"fuse: failed to allocate fuse object\n");
3330 se->conn.max_write = FUSE_DEFAULT_MAX_PAGES_LIMIT * getpagesize();
3331 se->bufsize = se->conn.max_write + FUSE_BUFFER_HEADER_SIZE;
3332 se->conn.max_readahead = UINT_MAX;
3337 if(se->deny_others) {
3347 mo = parse_mount_opts(args);
3351 if(args->
argc == 1 &&
3352 args->
argv[0][0] ==
'-') {
3353 fuse_log(FUSE_LOG_ERR,
"fuse: warning: argv[0] looks like an option, but "
3354 "will be ignored\n");
3355 }
else if (args->
argc != 1) {
3357 fuse_log(FUSE_LOG_ERR,
"fuse: unknown option(s): `");
3358 for(i = 1; i < args->
argc-1; i++)
3365 fuse_log(FUSE_LOG_DEBUG,
"FUSE library version: %s\n", PACKAGE_VERSION);
3367 list_init_req(&se->list);
3368 list_init_req(&se->interrupts);
3369 list_init_nreq(&se->notify_list);
3371 pthread_mutex_init(&se->lock, NULL);
3373 err = pthread_key_create(&se->pipe_key, fuse_ll_pipe_destructor);
3375 fuse_log(FUSE_LOG_ERR,
"fuse: failed to create thread specific key: %s\n",
3380 memcpy(&se->op, op, op_size);
3381 se->owner = getuid();
3382 se->userdata = userdata;
3391 se->version = *version;
3396 pthread_mutex_destroy(&se->lock);
3401 destroy_mount_opts(mo);
3408struct fuse_session *fuse_session_new_30(
struct fuse_args *args,
3410 size_t op_size,
void *userdata);
3411struct fuse_session *fuse_session_new_30(
struct fuse_args *args,
3419 return fuse_session_new_versioned(args, op, op_size, &version,
3423FUSE_SYMVER(
"fuse_session_custom_io_317",
"fuse_session_custom_io@@FUSE_3.17")
3424int fuse_session_custom_io_317(struct fuse_session *se,
3425 const struct fuse_custom_io *io,
size_t op_size,
int fd)
3427 if (
sizeof(
struct fuse_custom_io) < op_size) {
3428 fuse_log(FUSE_LOG_ERR,
"fuse: warning: library too old, some operations may not work\n");
3429 op_size =
sizeof(
struct fuse_custom_io);
3433 fuse_log(FUSE_LOG_ERR,
"Invalid file descriptor value %d passed to "
3434 "fuse_session_custom_io()\n", fd);
3438 fuse_log(FUSE_LOG_ERR,
"No custom IO passed to "
3439 "fuse_session_custom_io()\n");
3441 }
else if (io->read == NULL || io->writev == NULL) {
3446 fuse_log(FUSE_LOG_ERR,
"io passed to fuse_session_custom_io() must "
3447 "implement both io->read() and io->writev\n");
3451 se->io = calloc(1,
sizeof(
struct fuse_custom_io));
3452 if (se->io == NULL) {
3453 fuse_log(FUSE_LOG_ERR,
"Failed to allocate memory for custom io. "
3454 "Error: %s\n", strerror(errno));
3459 memcpy(se->io, io, op_size);
3463int fuse_session_custom_io_30(
struct fuse_session *se,
3464 const struct fuse_custom_io *io,
int fd);
3465FUSE_SYMVER(
"fuse_session_custom_io_30",
"fuse_session_custom_io@FUSE_3.0")
3466int fuse_session_custom_io_30(struct fuse_session *se,
3467 const struct fuse_custom_io *io,
int fd)
3469 return fuse_session_custom_io_317(se, io,
3470 offsetof(
struct fuse_custom_io, clone_fd), fd);
3478 if (_mountpoint == NULL) {
3479 fuse_log(FUSE_LOG_ERR,
"Invalid null-ptr mountpoint!\n");
3483 mountpoint = strdup(_mountpoint);
3484 if (mountpoint == NULL) {
3485 fuse_log(FUSE_LOG_ERR,
"Failed to allocate memory for mountpoint. Error: %s\n",
3495 fd = open(
"/dev/null", O_RDWR);
3498 }
while (fd >= 0 && fd <= 2);
3506 fd = fuse_mnt_parse_fuse_fd(mountpoint);
3508 if (fcntl(fd, F_GETFD) == -1) {
3510 "fuse: Invalid file descriptor /dev/fd/%u\n",
3519 fd = fuse_kern_mount(mountpoint, se->mo);
3525 se->mountpoint = mountpoint;
3541 if (se->mountpoint != NULL) {
3542 char *mountpoint = atomic_exchange(&se->mountpoint, NULL);
3544 fuse_kern_unmount(mountpoint, se->fd);
3554 size_t bufsize = 1024;
3558 unsigned long pid = req->ctx.pid;
3561 sprintf(path,
"/proc/%lu/task/%lu/status", pid, pid);
3564 buf = malloc(bufsize);
3569 fd = open(path, O_RDONLY);
3573 ret = read(fd, buf, bufsize);
3580 if ((
size_t)ret == bufsize) {
3588 s = strstr(buf,
"\nGroups:");
3596 unsigned long val = strtoul(s, &end, 0);
3616 (void) req; (void) size; (void) list;
3623__attribute__((no_sanitize_thread))
3629__attribute__((no_sanitize_thread))
3636__attribute__((no_sanitize_thread))
#define FUSE_CAP_IOCTL_DIR
#define FUSE_CAP_DONT_MASK
void fuse_unset_feature_flag(struct fuse_conn_info *conn, uint64_t flag)
int fuse_convert_to_conn_want_ext(struct fuse_conn_info *conn)
bool fuse_set_feature_flag(struct fuse_conn_info *conn, uint64_t flag)
#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
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
bool fuse_get_feature_flag(struct fuse_conn_info *conn, uint64_t flag)
#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)
@ FUSE_BUF_SPLICE_NONBLOCK
#define FUSE_CAP_SETXATTR_EXT
#define FUSE_CAP_SPLICE_MOVE
#define FUSE_CAP_NO_EXPORT_SUPPORT
#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)
const struct fuse_ctx * fuse_req_ctx(fuse_req_t req)
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_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_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_session_mount(struct fuse_session *se, const char *mountpoint)
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_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)
enum fuse_buf_flags flags
uint32_t parallel_direct_writes