diff options
author | Tofik Sonono <tofik.sonono@intel.com> | 2023-01-10 10:04:35 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-10 10:04:35 +0000 |
commit | 50c74e645928affa1af6e9a5a6ea6a3b9d3c52dc (patch) | |
tree | 58f7deff5dfca5ba8ec3a757ddcb04c535eea48e /include/fuse_lowlevel.h | |
parent | c0a344e3797844896d04efc4b565a2627067b67f (diff) | |
download | libfuse-50c74e645928affa1af6e9a5a6ea6a3b9d3c52dc.tar.gz |
Support application-defined I/O functions for FUSE fd
The io for FUSE requests and responses can now be further customized by allowing to write custom functions for reading/writing the responses. This includes overriding the splice io.
The reason for this addition is that having a custom file descriptor is not sufficient to allow custom io. Different types of file descriptor require different mechanisms of io interaction. For example, some file descriptor communication has boundaries (SOCK_DGRAM, EOF, etc...), while other types of fd:s might be unbounded (SOCK_STREAMS, ...). For unbounded communication, you have to read the header of the FUSE request first, and then read the remaining packet data. Furthermore, the one read call does not necessarily return all the data expected, requiring further
calls in a loop.
Diffstat (limited to 'include/fuse_lowlevel.h')
-rw-r--r-- | include/fuse_lowlevel.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h index 6bad70e..ff0d966 100644 --- a/include/fuse_lowlevel.h +++ b/include/fuse_lowlevel.h @@ -127,6 +127,17 @@ struct fuse_forget_data { uint64_t nlookup; }; +struct fuse_custom_io { + ssize_t (*writev)(int fd, struct iovec *iov, int count, void *userdata); + ssize_t (*read)(int fd, void *buf, size_t buf_len, void *userdata); + ssize_t (*splice_receive)(int fdin, __off64_t *offin, int fdout, + __off64_t *offout, size_t len, + unsigned int flags, void *userdata); + ssize_t (*splice_send)(int fdin, __off64_t *offin, int fdout, + __off64_t *offout, size_t len, + unsigned int flags, void *userdata); +}; + /** * Flags for fuse_lowlevel_notify_expire_entry() * 0 = invalidate entry @@ -1995,6 +2006,36 @@ struct fuse_session *fuse_session_new(struct fuse_args *args, size_t op_size, void *userdata); /** + * Set a file descriptor for the session. + * + * This function can be used if you want to have a custom communication + * interface instead of using a mountpoint. In practice, this means that instead + * of calling fuse_session_mount() and fuse_session_unmount(), one could call + * fuse_session_custom_io() where fuse_session_mount() would have otherwise been + * called. + * + * In `io`, implementations for read and writev MUST be provided. Otherwise -1 + * will be returned and `fd` will not be used. Implementations for `splice_send` + * and `splice_receive` are optional. If they are not provided splice will not + * be used for send or receive respectively. + * + * The provided file descriptor `fd` will be closed when fuse_session_destroy() + * is called. + * + * @param se session object + * @param io Custom io to use when retrieving/sending requests/responses + * @param fd file descriptor for the session + * + * @return 0 on success + * @return -EINVAL if `io`, `io->read` or `ìo->writev` are NULL + * @return -EBADF if `fd` was smaller than 0 + * @return -errno if failed to allocate memory to store `io` + * + **/ +int fuse_session_custom_io(struct fuse_session *se, + const struct fuse_custom_io *io, int fd); + +/** * Mount a FUSE file system. * * @param mountpoint the mount point path |