libfuse
Data Structures | Macros | Typedefs | Enumerations | Functions
fuse_lowlevel.h File Reference
#include "fuse_common.h"
#include <utime.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <sys/uio.h>

Go to the source code of this file.

Data Structures

struct  fuse_entry_param
 
struct  fuse_ctx
 
struct  fuse_lowlevel_ops
 
struct  fuse_cmdline_opts
 

Macros

#define FUSE_ROOT_ID   1
 

Typedefs

typedef uint64_t fuse_ino_t
 
typedef struct fuse_req * fuse_req_t
 
typedef void(* fuse_interrupt_func_t) (fuse_req_t req, void *data)
 

Enumerations

enum  fuse_notify_entry_flags
 

Functions

int fuse_reply_err (fuse_req_t req, int err)
 
void fuse_reply_none (fuse_req_t req)
 
int fuse_reply_entry (fuse_req_t req, const struct fuse_entry_param *e)
 
int fuse_reply_create (fuse_req_t req, const struct fuse_entry_param *e, const struct fuse_file_info *fi)
 
int fuse_reply_attr (fuse_req_t req, const struct stat *attr, double attr_timeout)
 
int fuse_reply_readlink (fuse_req_t req, const char *link)
 
int fuse_reply_open (fuse_req_t req, const struct fuse_file_info *fi)
 
int fuse_reply_write (fuse_req_t req, size_t count)
 
int fuse_reply_buf (fuse_req_t req, const char *buf, size_t size)
 
int fuse_reply_data (fuse_req_t req, struct fuse_bufvec *bufv, enum fuse_buf_copy_flags flags)
 
int fuse_reply_iov (fuse_req_t req, const struct iovec *iov, int count)
 
int fuse_reply_statfs (fuse_req_t req, const struct statvfs *stbuf)
 
int fuse_reply_xattr (fuse_req_t req, size_t count)
 
int fuse_reply_lock (fuse_req_t req, const struct flock *lock)
 
int fuse_reply_bmap (fuse_req_t req, uint64_t idx)
 
size_t fuse_add_direntry (fuse_req_t req, char *buf, size_t bufsize, const char *name, const struct stat *stbuf, off_t off)
 
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_retry (fuse_req_t req, const struct iovec *in_iov, size_t in_count, const struct iovec *out_iov, size_t out_count)
 
int fuse_reply_ioctl (fuse_req_t req, int result, const void *buf, size_t size)
 
int fuse_reply_ioctl_iov (fuse_req_t req, int result, const struct iovec *iov, int count)
 
int fuse_reply_poll (fuse_req_t req, unsigned revents)
 
int fuse_reply_lseek (fuse_req_t req, off_t off)
 
int fuse_lowlevel_notify_poll (struct fuse_pollhandle *ph)
 
int fuse_lowlevel_notify_inval_inode (struct fuse_session *se, fuse_ino_t ino, off_t off, off_t len)
 
int fuse_lowlevel_notify_inval_entry (struct fuse_session *se, fuse_ino_t parent, const char *name, size_t namelen)
 
int fuse_lowlevel_notify_expire_entry (struct fuse_session *se, fuse_ino_t parent, const char *name, size_t namelen)
 
int fuse_lowlevel_notify_delete (struct fuse_session *se, fuse_ino_t parent, fuse_ino_t child, const char *name, size_t namelen)
 
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_lowlevel_notify_retrieve (struct fuse_session *se, fuse_ino_t ino, size_t size, off_t offset, void *cookie)
 
void * fuse_req_userdata (fuse_req_t req)
 
const struct fuse_ctxfuse_req_ctx (fuse_req_t req)
 
int fuse_req_getgroups (fuse_req_t req, int size, gid_t list[])
 
void fuse_req_interrupt_func (fuse_req_t req, fuse_interrupt_func_t func, void *data)
 
int fuse_req_interrupted (fuse_req_t req)
 
void fuse_lowlevel_version (void)
 
void fuse_lowlevel_help (void)
 
void fuse_cmdline_help (void)
 
int fuse_parse_cmdline_30 (struct fuse_args *args, struct fuse_cmdline_opts *opts)
 
struct fuse_session * fuse_session_new (struct fuse_args *args, const struct fuse_lowlevel_ops *op, size_t op_size, void *userdata)
 
int fuse_session_custom_io (struct fuse_session *se, const struct fuse_custom_io *io, int fd)
 
int fuse_session_mount (struct fuse_session *se, const char *mountpoint)
 
int fuse_session_loop (struct fuse_session *se)
 
void fuse_session_exit (struct fuse_session *se)
 
void fuse_session_reset (struct fuse_session *se)
 
int fuse_session_exited (struct fuse_session *se)
 
void fuse_session_unmount (struct fuse_session *se)
 
void fuse_session_destroy (struct fuse_session *se)
 
int fuse_session_fd (struct fuse_session *se)
 
void fuse_session_process_buf (struct fuse_session *se, const struct fuse_buf *buf)
 
int fuse_session_receive_buf (struct fuse_session *se, struct fuse_buf *buf)
 

Detailed Description

Low level API

IMPORTANT: you should define FUSE_USE_VERSION before including this header. To use the newest API define it to 35 (recommended for any new application).

Definition in file fuse_lowlevel.h.

Macro Definition Documentation

◆ FUSE_ROOT_ID

#define FUSE_ROOT_ID   1

The node ID of the root inode

Definition at line 43 of file fuse_lowlevel.h.

Typedef Documentation

◆ fuse_ino_t

typedef uint64_t fuse_ino_t

Inode number type

Definition at line 46 of file fuse_lowlevel.h.

◆ fuse_interrupt_func_t

typedef void(* fuse_interrupt_func_t) (fuse_req_t req, void *data)

Callback function for an interrupt

Parameters
reqinterrupted request
datauser data

Definition at line 1886 of file fuse_lowlevel.h.

◆ fuse_req_t

typedef struct fuse_req* fuse_req_t

Request pointer type

Definition at line 49 of file fuse_lowlevel.h.

Enumeration Type Documentation

◆ fuse_notify_entry_flags

Flags for fuse_lowlevel_notify_entry() 0 = invalidate entry FUSE_LL_EXPIRE_ONLY = expire entry

Definition at line 146 of file fuse_lowlevel.h.

Function Documentation

◆ fuse_add_direntry()

size_t fuse_add_direntry ( fuse_req_t  req,
char *  buf,
size_t  bufsize,
const char *  name,
const struct stat *  stbuf,
off_t  off 
)

Add a directory entry to the buffer

Buffer needs to be large enough to hold the entry. If it's not, then the entry is not filled in but the size of the entry is still returned. The caller can check this by comparing the bufsize parameter with the returned entry size. If the entry size is larger than the buffer size, the operation failed.

From the 'stbuf' argument the st_ino field and bits 12-15 of the st_mode field are used. The other fields are ignored.

off should be any non-zero value that the filesystem can use to identify the current point in the directory stream. It does not need to be the actual physical position. A value of zero is reserved to mean "from the beginning", and should therefore never be used (the first call to fuse_add_direntry should be passed the offset of the second directory entry).

Parameters
reqrequest handle
bufthe point where the new entry will be added to the buffer
bufsizeremaining size of the buffer
namethe name of the entry
stbufthe file attributes
offthe offset of the next entry
Returns
the space needed for the entry

Definition at line 279 of file fuse_lowlevel.c.

◆ fuse_add_direntry_plus()

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 
)

Add a directory entry to the buffer with the attributes

See documentation of fuse_add_direntry() for more details.

Parameters
reqrequest handle
bufthe point where the new entry will be added to the buffer
bufsizeremaining size of the buffer
namethe name of the entry
ethe directory entry
offthe offset of the next entry
Returns
the space needed for the entry

Definition at line 369 of file fuse_lowlevel.c.

◆ fuse_cmdline_help()

void fuse_cmdline_help ( void  )

Print available options for fuse_parse_cmdline().

Definition at line 130 of file helper.c.

◆ fuse_lowlevel_help()

void fuse_lowlevel_help ( void  )

Print available low-level options to stdout. This is not an exhaustive list, but includes only those options that may be of interest to an end-user of a file system.

Definition at line 2803 of file fuse_lowlevel.c.

◆ fuse_lowlevel_notify_delete()

int fuse_lowlevel_notify_delete ( struct fuse_session *  se,
fuse_ino_t  parent,
fuse_ino_t  child,
const char *  name,
size_t  namelen 
)

This function behaves like fuse_lowlevel_notify_inval_entry() with the following additional effect (at least as of Linux kernel 4.8):

If the provided child inode matches the inode that is currently associated with the cached dentry, and if there are any inotify watches registered for the dentry, then the watchers are informed that the dentry has been deleted.

To avoid a deadlock this function must not be called while executing a related filesystem operation or while holding a lock that could be needed to execute such an operation (see the description of fuse_lowlevel_notify_inval_entry() for more details).

When called correctly, this function will never block.

Added in FUSE protocol version 7.18. If the kernel does not support this (or a newer) version, the function will return -ENOSYS and do nothing.

Parameters
sethe session object
parentinode number
childinode number
namefile name
namelenstrlen() of file name
Returns
zero for success, -errno for failure

Definition at line 2378 of file fuse_lowlevel.c.

◆ fuse_lowlevel_notify_expire_entry()

int fuse_lowlevel_notify_expire_entry ( struct fuse_session *  se,
fuse_ino_t  parent,
const char *  name,
size_t  namelen 
)

Notify to expire parent attributes and the dentry matching parent/name

Same restrictions apply as for fuse_lowlevel_notify_inval_entry()

Compared to invalidating an entry, expiring the entry results not in a forceful removal of that entry from kernel cache but instead the next access to it forces a lookup from the filesystem.

This makes a difference for overmounted dentries, where plain invalidation would detach all submounts before dropping the dentry from the cache. If only expiry is set on the dentry, then any overmounts are left alone and until ->d_revalidate() is called.

Note: ->d_revalidate() is not called for the case of following a submount, so invalidation will only be triggered for the non-overmounted case. The dentry could also be mounted in a different mount instance, in which case any submounts will still be detached.

Added in FUSE protocol version 7.38. If the kernel does not support this (or a newer) version, the function will return -ENOSYS and do nothing.

Parameters
sethe session object
parentinode number
namefile name
namelenstrlen() of file name
Returns
zero for success, -errno for failure, -enosys if no kernel support

Definition at line 2365 of file fuse_lowlevel.c.

◆ fuse_lowlevel_notify_inval_entry()

int fuse_lowlevel_notify_inval_entry ( struct fuse_session *  se,
fuse_ino_t  parent,
const char *  name,
size_t  namelen 
)

Notify to invalidate parent attributes and the dentry matching parent/name

To avoid a deadlock this function must not be called in the execution path of a related filesystem operation or within any code that could hold a lock that could be needed to execute such an operation. As of kernel 4.18, a "related operation" is a lookup(), symlink(), mknod(), mkdir(), unlink(), rename(), link() or create() request for the parent, and a setattr(), unlink(), rmdir(), rename(), setxattr(), removexattr(), readdir() or readdirplus() request for the inode itself.

When called correctly, this function will never block.

Added in FUSE protocol version 7.12. If the kernel does not support this (or a newer) version, the function will return -ENOSYS and do nothing.

Parameters
sethe session object
parentinode number
namefile name
namelenstrlen() of file name
Returns
zero for success, -errno for failure

Definition at line 2359 of file fuse_lowlevel.c.

◆ fuse_lowlevel_notify_inval_inode()

int fuse_lowlevel_notify_inval_inode ( struct fuse_session *  se,
fuse_ino_t  ino,
off_t  off,
off_t  len 
)

Notify to invalidate cache for an inode.

Added in FUSE protocol version 7.12. If the kernel does not support this (or a newer) version, the function will return -ENOSYS and do nothing.

If the filesystem has writeback caching enabled, invalidating an inode will first trigger a writeback of all dirty pages. The call will block until all writeback requests have completed and the inode has been invalidated. It will, however, not wait for completion of pending writeback requests that have been issued before.

If there are no dirty pages, this function will never block.

Parameters
sethe session object
inothe inode number
offthe offset in the inode where to start invalidating or negative to invalidate attributes only
lenthe amount of cache to invalidate or 0 for all
Returns
zero for success, -errno for failure

Definition at line 2291 of file fuse_lowlevel.c.

◆ fuse_lowlevel_notify_poll()

int fuse_lowlevel_notify_poll ( struct fuse_pollhandle *  ph)

Notify IO readiness event

For more information, please read comment for poll operation.

Parameters
phpoll handle to notify IO readiness event for

Definition at line 2274 of file fuse_lowlevel.c.

◆ fuse_lowlevel_notify_retrieve()

int fuse_lowlevel_notify_retrieve ( struct fuse_session *  se,
fuse_ino_t  ino,
size_t  size,
off_t  offset,
void *  cookie 
)

Retrieve data from the kernel buffers

Retrieve data in the kernel buffers belonging to the given inode. If successful then the retrieve_reply() method will be called with the returned data.

Only present pages are returned in the retrieve reply. Retrieving stops when it finds a non-present page and only data prior to that is returned.

If this function returns an error, then the retrieve will not be completed and no reply will be sent.

This function doesn't change the dirty state of pages in the kernel buffer. For dirty pages the write() method will be called regardless of having been retrieved previously.

Added in FUSE protocol version 7.15. If the kernel does not support this (or a newer) version, the function will return -ENOSYS and do nothing.

Parameters
sethe session object
inothe inode number
sizethe number of bytes to retrieve
offsetthe starting offset into the file to retrieve from
cookieuser data to supply to the reply callback
Returns
zero for success, -errno for failure

Definition at line 2484 of file fuse_lowlevel.c.

◆ fuse_lowlevel_notify_store()

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 
)

Store data to the kernel buffers

Synchronously store data in the kernel buffers belonging to the given inode. The stored data is marked up-to-date (no read will be performed against it, unless it's invalidated or evicted from the cache).

If the stored data overflows the current file size, then the size is extended, similarly to a write(2) on the filesystem.

If this function returns an error, then the store wasn't fully completed, but it may have been partially completed.

Added in FUSE protocol version 7.15. If the kernel does not support this (or a newer) version, the function will return -ENOSYS and do nothing.

Parameters
sethe session object
inothe inode number
offsetthe starting offset into the file to store to
bufvbuffer vector
flagsflags controlling the copy
Returns
zero for success, -errno for failure

Definition at line 2404 of file fuse_lowlevel.c.

◆ fuse_lowlevel_version()

void fuse_lowlevel_version ( void  )

Print low-level version information to stdout.

Definition at line 2796 of file fuse_lowlevel.c.

◆ fuse_parse_cmdline_30()

int fuse_parse_cmdline_30 ( struct fuse_args args,
struct fuse_cmdline_opts opts 
)

Utility function to parse common options for simple file systems using the low-level API. A help text that describes the available options can be printed with fuse_cmdline_help. A single non-option argument is treated as the mountpoint. Multiple non-option arguments will result in an error.

If neither -o subtype= or -o fsname= options are given, a new subtype option will be added and set to the basename of the program (the fsname will remain unset, and then defaults to "fuse").

Known options will be removed from args, unknown options will remain.

Parameters
argsargument vector (input+output)
optsoutput argument for parsed options
Returns
0 on success, -1 on failure

struct fuse_cmdline_opts got extended in libfuse-3.12

Definition at line 237 of file helper.c.

◆ fuse_reply_attr()

int fuse_reply_attr ( fuse_req_t  req,
const struct stat *  attr,
double  attr_timeout 
)

Reply with attributes

Possible requests: getattr, setattr

Parameters
reqrequest handle
attrthe attributes
attr_timeoutvalidity timeout (in seconds) for the attributes
Returns
zero for success, -errno for failure to send reply

Definition at line 449 of file fuse_lowlevel.c.

◆ fuse_reply_bmap()

int fuse_reply_bmap ( fuse_req_t  req,
uint64_t  idx 
)

Reply with block index

Possible requests: bmap

Parameters
reqrequest handle
idxblock index within device
Returns
zero for success, -errno for failure to send reply

Definition at line 935 of file fuse_lowlevel.c.

◆ fuse_reply_buf()

int fuse_reply_buf ( fuse_req_t  req,
const char *  buf,
size_t  size 
)

Reply with data

Possible requests: read, readdir, getxattr, listxattr

Parameters
reqrequest handle
bufbuffer containing data
sizethe size of data in bytes
Returns
zero for success, -errno for failure to send reply

Definition at line 488 of file fuse_lowlevel.c.

◆ fuse_reply_create()

int fuse_reply_create ( fuse_req_t  req,
const struct fuse_entry_param e,
const struct fuse_file_info fi 
)

Reply with a directory entry and open parameters

currently the following members of 'fi' are used: fh, direct_io, keep_cache

Possible requests: create

Side effects: increments the lookup count on success

Parameters
reqrequest handle
ethe entry parameters
fifile information
Returns
zero for success, -errno for failure to send reply

Definition at line 433 of file fuse_lowlevel.c.

◆ fuse_reply_data()

int fuse_reply_data ( fuse_req_t  req,
struct fuse_bufvec bufv,
enum fuse_buf_copy_flags  flags 
)

Reply with data copied/moved from buffer(s)

Zero copy data transfer ("splicing") will be used under the following circumstances:

  1. FUSE_CAP_SPLICE_WRITE is set in fuse_conn_info.want, and
  2. the kernel supports splicing from the fuse device (FUSE_CAP_SPLICE_WRITE is set in fuse_conn_info.capable), and
  3. flags does not contain FUSE_BUF_NO_SPLICE
  4. The amount of data that is provided in file-descriptor backed buffers (i.e., buffers for which bufv[n].flags == FUSE_BUF_FD) is at least twice the page size.

In order for SPLICE_F_MOVE to be used, the following additional conditions have to be fulfilled:

  1. FUSE_CAP_SPLICE_MOVE is set in fuse_conn_info.want, and
  2. the kernel supports it (i.e, FUSE_CAP_SPLICE_MOVE is set in fuse_conn_info.capable), and
  3. flags contains FUSE_BUF_SPLICE_MOVE

Note that, if splice is used, the data is actually spliced twice: once into a temporary pipe (to prepend header data), and then again into the kernel. If some of the provided buffers are memory-backed, the data in them is copied in step one and spliced in step two.

The FUSE_BUF_SPLICE_FORCE_SPLICE and FUSE_BUF_SPLICE_NONBLOCK flags are silently ignored.

Possible requests: read, readdir, getxattr, listxattr

Side effects: when used to return data from a readdirplus() (but not readdir()) call, increments the lookup count of each returned entry by one on success.

Parameters
reqrequest handle
bufvbuffer vector
flagsflags controlling the copy
Returns
zero for success, -errno for failure to send reply

Definition at line 874 of file fuse_lowlevel.c.

◆ fuse_reply_entry()

int fuse_reply_entry ( fuse_req_t  req,
const struct fuse_entry_param e 
)

Reply with a directory entry

Possible requests: lookup, mknod, mkdir, symlink, link

Side effects: increments the lookup count on success

Parameters
reqrequest handle
ethe entry parameters
Returns
zero for success, -errno for failure to send reply

Definition at line 417 of file fuse_lowlevel.c.

◆ fuse_reply_err()

int fuse_reply_err ( fuse_req_t  req,
int  err 
)

Reply with an error code or success.

Possible requests: all except forget, forget_multi, retrieve_reply

Wherever possible, error codes should be chosen from the list of documented error conditions in the corresponding system calls manpage.

An error code of ENOSYS is sometimes treated specially. This is indicated in the documentation of the affected handler functions.

The following requests may be answered with a zero error code: unlink, rmdir, rename, flush, release, fsync, fsyncdir, setxattr, removexattr, setlk.

Parameters
reqrequest handle
errthe positive error value, or zero for success
Returns
zero for success, -errno for failure to send reply

Definition at line 324 of file fuse_lowlevel.c.

◆ fuse_reply_ioctl()

int fuse_reply_ioctl ( fuse_req_t  req,
int  result,
const void *  buf,
size_t  size 
)

Reply to finish ioctl

Possible requests: ioctl

Parameters
reqrequest handle
resultresult to be passed to the caller
bufbuffer containing output data
sizelength of output data

Definition at line 1033 of file fuse_lowlevel.c.

◆ fuse_reply_ioctl_iov()

int fuse_reply_ioctl_iov ( fuse_req_t  req,
int  result,
const struct iovec *  iov,
int  count 
)

Reply to finish ioctl with iov buffer

Possible requests: ioctl

Parameters
reqrequest handle
resultresult to be passed to the caller
iovthe vector containing the data
countthe size of vector

Definition at line 1054 of file fuse_lowlevel.c.

◆ fuse_reply_ioctl_retry()

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 
)

Reply to ask for data fetch and output buffer preparation. ioctl will be retried with the specified input data fetched and output buffer prepared.

Possible requests: ioctl

Parameters
reqrequest handle
in_ioviovec specifying data to fetch from the caller
in_countnumber of entries in in_iov
out_ioviovec specifying addresses to write output to
out_countnumber of entries in out_iov
Returns
zero for success, -errno for failure to send reply

Definition at line 963 of file fuse_lowlevel.c.

◆ fuse_reply_iov()

int fuse_reply_iov ( fuse_req_t  req,
const struct iovec *  iov,
int  count 
)

Reply with data vector

Possible requests: read, readdir, getxattr, listxattr

Parameters
reqrequest handle
iovthe vector containing the data
countthe size of vector
Returns
zero for success, -errno for failure to send reply

Definition at line 258 of file fuse_lowlevel.c.

◆ fuse_reply_lock()

int fuse_reply_lock ( fuse_req_t  req,
const struct flock *  lock 
)

Reply with file lock information

Possible requests: getlk

Parameters
reqrequest handle
lockthe lock information
Returns
zero for success, -errno for failure to send reply

Definition at line 918 of file fuse_lowlevel.c.

◆ fuse_reply_lseek()

int fuse_reply_lseek ( fuse_req_t  req,
off_t  off 
)

Reply with offset

Possible requests: lseek

Parameters
reqrequest handle
offoffset of next data or hole
Returns
zero for success, -errno for failure to send reply

Definition at line 1088 of file fuse_lowlevel.c.

◆ fuse_reply_none()

void fuse_reply_none ( fuse_req_t  req)

Don't send reply

Possible requests: forget forget_multi retrieve_reply

Parameters
reqrequest handle

Definition at line 329 of file fuse_lowlevel.c.

◆ fuse_reply_open()

int fuse_reply_open ( fuse_req_t  req,
const struct fuse_file_info fi 
)

Reply with open parameters

currently the following members of 'fi' are used: fh, direct_io, keep_cache

Possible requests: open, opendir

Parameters
reqrequest handle
fifile information
Returns
zero for success, -errno for failure to send reply

Definition at line 469 of file fuse_lowlevel.c.

◆ fuse_reply_poll()

int fuse_reply_poll ( fuse_req_t  req,
unsigned  revents 
)

Reply with poll result event mask

Parameters
reqrequest handle
reventspoll result event mask

Definition at line 1078 of file fuse_lowlevel.c.

◆ fuse_reply_readlink()

int fuse_reply_readlink ( fuse_req_t  req,
const char *  link 
)

Reply with the contents of a symbolic link

Possible requests: readlink

Parameters
reqrequest handle
linksymbolic link contents
Returns
zero for success, -errno for failure to send reply

Definition at line 464 of file fuse_lowlevel.c.

◆ fuse_reply_statfs()

int fuse_reply_statfs ( fuse_req_t  req,
const struct statvfs *  stbuf 
)

Reply with filesystem statistics

Possible requests: statfs

Parameters
reqrequest handle
stbuffilesystem statistics
Returns
zero for success, -errno for failure to send reply

Definition at line 896 of file fuse_lowlevel.c.

◆ fuse_reply_write()

int fuse_reply_write ( fuse_req_t  req,
size_t  count 
)

Reply with number of bytes written

Possible requests: write

Parameters
reqrequest handle
countthe number of bytes written
Returns
zero for success, -errno for failure to send reply

Definition at line 478 of file fuse_lowlevel.c.

◆ fuse_reply_xattr()

int fuse_reply_xattr ( fuse_req_t  req,
size_t  count 
)

Reply with needed buffer size

Possible requests: getxattr, listxattr

Parameters
reqrequest handle
countthe buffer size needed in bytes
Returns
zero for success, -errno for failure to send reply

Definition at line 908 of file fuse_lowlevel.c.

◆ fuse_req_ctx()

const struct fuse_ctx * fuse_req_ctx ( fuse_req_t  req)

Get the context from the request

The pointer returned by this function will only be valid for the request's lifetime

Parameters
reqrequest handle
Returns
the context structure

Definition at line 2534 of file fuse_lowlevel.c.

◆ fuse_req_getgroups()

int fuse_req_getgroups ( fuse_req_t  req,
int  size,
gid_t  list[] 
)

Get the current supplementary group IDs for the specified request

Similar to the getgroups(2) system call, except the return value is always the total number of group IDs, even if it is larger than the specified size.

The current fuse kernel module in linux (as of 2.6.30) doesn't pass the group list to userspace, hence this function needs to parse "/proc/$TID/task/$TID/status" to get the group IDs.

This feature may not be supported on all operating systems. In such a case this function will return -ENOSYS.

Parameters
reqrequest handle
sizesize of given array
listarray of group IDs to be filled in
Returns
the total number of supplementary group IDs or -errno on failure

Definition at line 3272 of file fuse_lowlevel.c.

◆ fuse_req_interrupt_func()

void fuse_req_interrupt_func ( fuse_req_t  req,
fuse_interrupt_func_t  func,
void *  data 
)

Register/unregister callback for an interrupt

If an interrupt has already happened, then the callback function is called from within this function, hence it's not possible for interrupts to be lost.

Parameters
reqrequest handle
functhe callback function or NULL for unregister
datauser data passed to the callback function

Definition at line 2539 of file fuse_lowlevel.c.

◆ fuse_req_interrupted()

int fuse_req_interrupted ( fuse_req_t  req)

Check if a request has already been interrupted

Parameters
reqrequest handle
Returns
1 if the request has been interrupted, 0 otherwise

Definition at line 2552 of file fuse_lowlevel.c.

◆ fuse_req_userdata()

void * fuse_req_userdata ( fuse_req_t  req)

Get the userdata from the request

Parameters
reqrequest handle
Returns
the user data passed to fuse_session_new()

Definition at line 2529 of file fuse_lowlevel.c.

◆ fuse_session_custom_io()

int fuse_session_custom_io ( struct fuse_session *  se,
const struct fuse_custom_io *  io,
int  fd 
)

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.

Parameters
sesession object
ioCustom io to use when retrieving/sending requests/responses
fdfile descriptor for the session
Returns
0 on success
-EINVAL if io, io->read or ìo->writev are NULL
-EBADF if fd was smaller than 0
-errno if failed to allocate memory to store io

Definition at line 3110 of file fuse_lowlevel.c.

◆ fuse_session_destroy()

void fuse_session_destroy ( struct fuse_session *  se)

Destroy a session

Parameters
sethe session

Definition at line 2813 of file fuse_lowlevel.c.

◆ fuse_session_exit()

void fuse_session_exit ( struct fuse_session *  se)

Flag a session as terminated.

This will cause any running event loops to terminate on the next opportunity. If this function is called by a thread that is not a FUSE worker thread, the next opportunity will be when FUSE a request is received (which may be far in the future if the filesystem is not currently being used by any clients). One way to avoid this delay is to afterwards sent a signal to the main thread (if fuse_set_signal_handlers() is used, SIGPIPE will cause the main thread to wake-up but otherwise be ignored).

Parameters
sethe session

◆ fuse_session_exited()

int fuse_session_exited ( struct fuse_session *  se)

Query the terminated flag of a session

Parameters
sethe session
Returns
1 if exited, 0 if not exited

◆ fuse_session_fd()

int fuse_session_fd ( struct fuse_session *  se)

Return file descriptor for communication with kernel.

The file selector can be used to integrate FUSE with a custom event loop. Whenever data is available for reading on the provided fd, the event loop should call fuse_session_receive_buf followed by fuse_session_process_buf to process the request.

The returned file descriptor is valid until fuse_session_unmount is called.

Parameters
sethe session
Returns
a file descriptor

Definition at line 3194 of file fuse_lowlevel.c.

◆ fuse_session_loop()

int fuse_session_loop ( struct fuse_session *  se)

Enter a single threaded, blocking event loop.

When the event loop terminates because the connection to the FUSE kernel module has been closed, this function returns zero. This happens when the filesystem is unmounted regularly (by the filesystem owner or root running the umount(8) or fusermount(1) command), or if connection is explicitly severed by writing 1 to theabort file in /sys/fs/fuse/connections/NNN. The only way to distinguish between these two conditions is to check if the filesystem is still mounted after the session loop returns.

When some error occurs during request processing, the function returns a negated errno(3) value.

If the loop has been terminated because of a signal handler installed by fuse_set_signal_handlers(), this function returns the (positive) signal value that triggered the exit.

Parameters
sethe session
Returns
0, -errno, or a signal value

Definition at line 19 of file fuse_loop.c.

◆ fuse_session_mount()

int fuse_session_mount ( struct fuse_session *  se,
const char *  mountpoint 
)

Mount a FUSE file system.

Parameters
mountpointthe mount point path
sesession object
Returns
0 on success, -1 on failure.

Definition at line 3144 of file fuse_lowlevel.c.

◆ fuse_session_new()

struct fuse_session * fuse_session_new ( struct fuse_args args,
const struct fuse_lowlevel_ops op,
size_t  op_size,
void *  userdata 
)

Create a low level session.

Returns a session structure suitable for passing to fuse_session_mount() and fuse_session_loop().

This function accepts most file-system independent mount options (like context, nodev, ro - see mount(8)), as well as the general fuse mount options listed in mount.fuse(8) (e.g. -o allow_root and -o default_permissions, but not -o use_ino). Instead of -o debug, debugging may also enabled with -d or --debug.

If not all options are known, an error message is written to stderr and the function returns NULL.

Option parsing skips argv[0], which is assumed to contain the program name. To prevent accidentally passing an option in argv[0], this element must always be present (even if no options are specified). It may be set to the empty string ('\0') if no reasonable value can be provided.

Parameters
argsargument vector
opthe (low-level) filesystem operations
op_sizesizeof(struct fuse_lowlevel_ops)
userdatauser data
Returns
the fuse session on success, NULL on failure

Definition at line 3014 of file fuse_lowlevel.c.

◆ fuse_session_process_buf()

void fuse_session_process_buf ( struct fuse_session *  se,
const struct fuse_buf buf 
)

Process a raw request supplied in a generic buffer

The fuse_buf may contain a memory buffer or a pipe file descriptor.

Parameters
sethe session
bufthe fuse_buf containing the request

Definition at line 2640 of file fuse_lowlevel.c.

◆ fuse_session_receive_buf()

int fuse_session_receive_buf ( struct fuse_session *  se,
struct fuse_buf buf 
)

Read a raw request from the kernel into the supplied buffer.

Depending on file system options, system capabilities, and request size the request is either read into a memory buffer or spliced into a temporary pipe.

Parameters
sethe session
bufthe fuse_buf to store the request in
Returns
the actual size of the raw request, or -errno on error

Definition at line 2842 of file fuse_lowlevel.c.

◆ fuse_session_reset()

void fuse_session_reset ( struct fuse_session *  se)

Reset the terminated flag of a session

Parameters
sethe session

◆ fuse_session_unmount()

void fuse_session_unmount ( struct fuse_session *  se)

Ensure that file system is unmounted.

In regular operation, the file system is typically unmounted by the user calling umount(8) or fusermount(1), which then terminates the FUSE session loop. However, the session loop may also terminate as a result of an explicit call to fuse_session_exit() (e.g. by a signal handler installed by fuse_set_signal_handler()). In this case the filesystem remains mounted, but any attempt to access it will block (while the filesystem process is still running) or give an ESHUTDOWN error (after the filesystem process has terminated).

If the communication channel with the FUSE kernel module is still open (i.e., if the session loop was terminated by an explicit call to fuse_session_exit()), this function will close it and unmount the filesystem. If the communication channel has been closed by the kernel, this method will do (almost) nothing.

NOTE: The above semantics mean that if the connection to the kernel is terminated via the /sys/fs/fuse/connections/NNN/abort file, this method will not unmount the filesystem.

Parameters
sethe session

Definition at line 3199 of file fuse_lowlevel.c.