Request Handlers¶
(You can use the Index to directly jump to a specific handler).
-
class
pyfuse3.Operations¶ This class defines the request handler methods that an pyfuse3 file system may implement. If a particular request handler has not been implemented, it must raise
FUSEErrorwith an errorcode oferrno.ENOSYS. Further requests of this type will then be handled directly by the FUSE kernel module without calling the handler again.The only exception that request handlers are allowed to raise is
FUSEError. This will cause the specified errno to be returned by the syscall that is being handled.It is recommended that file systems are derived from this class and only overwrite the handlers that they actually implement. (The methods defined in this class all just raise
FUSEError(ENOSYS)or do nothing).-
supports_dot_lookup = True If set, indicates that the filesystem supports lookup of the
.and..entries. This is required if the file system will be shared over NFS.
-
enable_writeback_cache = True Enables write-caching in the kernel if available. This means that individual write request may be buffered and merged in the kernel before they are send to the filesystem.
-
enable_acl = False Enable ACL support. When enabled, the kernel will cache and have responsibility for enforcing ACLs. ACL will be stored as xattrs and passed to userspace, which is responsible for updating the ACLs in the filesystem, keeping the file mode in sync with the ACL, and ensuring inheritance of default ACLs when new filesystem nodes are created. Note that this requires that the file system is able to parse and interpret the xattr representation of ACLs.
Enabling this feature implicitly turns on thedefault_permissionsoption.
-
coroutine
access(inode, mode, ctx)¶ Check if requesting process has mode rights on inode.
ctx will be a
RequestContextinstance.The method must return a boolean value.
If the
default_permissionsmount option is given, this method is not called.When implementing this method, the
get_sup_groupsfunction may be useful.
-
coroutine
create(parent_inode, name, mode, flags, ctx)¶ Create a file with permissions mode and open it with flags
ctx will be a
RequestContextinstance.The method must return a tuple of the form (fi, attr), where fi is a FileInfo instance handle like the one returned by
openand attr is anEntryAttributesinstance with the attributes of the newly created directory entry.(Successful) execution of this handler increases the lookup count for the returned inode by one.
-
coroutine
flush(fh)¶ Handle close() syscall.
fh will by an integer filehandle returned by a prior
openorcreatecall.This method is called whenever a file descriptor is closed. It may be called multiple times for the same open file (e.g. if the file handle has been duplicated).
-
coroutine
forget(inode_list)¶ Decrease lookup counts for inodes in inode_list
inode_list is a list of
(inode, nlookup)tuples. This method should reduce the lookup count for each inode by nlookup.If the lookup count reaches zero, the inode is currently not known to the kernel. In this case, the file system will typically check if there are still directory entries referring to this inode and, if not, remove the inode.
If the file system is unmounted, it may not have received
forgetcalls to bring all lookup counts to zero. The filesystem needs to take care to clean up inodes that at that point still have non-zero lookup count (e.g. by explicitly callingforgetwith the current lookup count for every such inode aftermainhas returned).This method must not raise any exceptions (not even
FUSEError), since it is not handling a particular client request.
-
coroutine
fsync(fh, datasync)¶ Flush buffers for open file fh
If datasync is true, only the file contents should be flushed (in contrast to the metadata about the file).
fh will by an integer filehandle returned by a prior
openorcreatecall.
-
coroutine
fsyncdir(fh, datasync)¶ Flush buffers for open directory fh
If datasync is true, only the directory contents should be flushed (in contrast to metadata about the directory itself).
-
coroutine
getattr(inode, ctx)¶ Get attributes for inode
ctx will be a
RequestContextinstance.This method should return an
EntryAttributesinstance with the attributes of inode. Theentry_timeoutattribute is ignored in this context.
-
coroutine
getxattr(inode, name, ctx)¶ Return extended attribute name of inode
ctx will be a
RequestContextinstance.If the attribute does not exist, the method must raise
FUSEErrorwith an error code ofENOATTR. name will be of typebytes, but is guaranteed not to contain zero-bytes (\0).
-
init()¶ Initialize operations
This method will be called just before the file system starts handling requests. It must not raise any exceptions (not even
FUSEError), since it is not handling a particular client request.
-
coroutine
link(inode, new_parent_inode, new_name, ctx)¶ Create directory entry name in parent_inode refering to inode.
ctx will be a
RequestContextinstance.The method must return an
EntryAttributesinstance with the attributes of the newly created directory entry.(Successful) execution of this handler increases the lookup count for the returned inode by one.
-
coroutine
listxattr(inode, ctx)¶ Get list of extended attributes for inode
ctx will be a
RequestContextinstance.This method must return a sequence of
bytesobjects. The objects must not include zero-bytes (\0).
-
coroutine
lookup(parent_inode, name, ctx)¶ Look up a directory entry by name and get its attributes.
This method should return an
EntryAttributesinstance for the directory entry name in the directory with inode parent_inode.If there is no such entry, the method should either return an
EntryAttributesinstance with zerost_inovalue (in which case the negative lookup will be cached as specified byentry_timeout), or it should raiseFUSEErrorwith an errno oferrno.ENOENT(in this case the negative result will not be cached).ctx will be a
RequestContextinstance.The file system must be able to handle lookups for
.and.., no matter if these entries are returned byreaddiror not.(Successful) execution of this handler increases the lookup count for the returned inode by one.
-
coroutine
mkdir(parent_inode, name, mode, ctx)¶ Create a directory
This method must create a new directory name with mode mode in the directory with inode parent_inode. ctx will be a
RequestContextinstance.This method must return an
EntryAttributesinstance with the attributes of the newly created directory entry.(Successful) execution of this handler increases the lookup count for the returned inode by one.
-
coroutine
mknod(parent_inode, name, mode, rdev, ctx)¶ Create (possibly special) file
This method must create a (special or regular) file name in the directory with inode parent_inode. Whether the file is special or regular is determined by its mode. If the file is neither a block nor character device, rdev can be ignored. ctx will be a
RequestContextinstance.The method must return an
EntryAttributesinstance with the attributes of the newly created directory entry.(Successful) execution of this handler increases the lookup count for the returned inode by one.
-
coroutine
open(inode, flags, ctx)¶ Open a inode inode with flags.
ctx will be a
RequestContextinstance.flags will be a bitwise or of the open flags described in the open(2) manpage and defined in the
osmodule (with the exception ofO_CREAT,O_EXCL,O_NOCTTYandO_TRUNC)This method must return a
FileInfoinstance. TheFileInfo.fhfield must contain an integer file handle, which will be passed to theread,write,flush,fsyncandreleasemethods to identify the open file. TheFileInfoinstance may also have relevant configuration attributes set; see theFileInfodocumentation for more information.
-
coroutine
opendir(inode, ctx)¶ Open the directory with inode inode
ctx will be a
RequestContextinstance.This method should return an integer file handle. The file handle will be passed to the
readdir,fsyncdirandreleasedirmethods to identify the directory.
-
coroutine
read(fh, off, size)¶ Read size bytes from fh at position off
fh will by an integer filehandle returned by a prior
openorcreatecall.This function should return exactly the number of bytes requested except on EOF or error, otherwise the rest of the data will be substituted with zeroes.
-
coroutine
readdir(fh, start_id, token)¶ Read entries in open directory fh.
This method should list the contents of directory fh (as returned by a prior
opendircall), starting at the entry identified by start_id.Instead of returning the directory entries directly, the method must call
readdir_replyfor each directory entry. Ifreaddir_replyreturns True, the file system must increase the lookup count for the provided directory entry by one and callreaddir_replyagain for the next entry (if any). Ifreaddir_replyreturns False, the lookup count must not be increased and the method should return without further calls toreaddir_reply.The start_id parameter will be either zero (in which case listing should begin with the first entry) or it will correspond to a value that was previously passed by the file system to the
readdir_replyfunction in the next_id parameter.If entries are added or removed during a
readdircycle, they may or may not be returned. However, they must not cause other entries to be skipped or returned more than once..and..entries may be included but are not required. However, if they are reported the filesystem must not increase the lookup count for the corresponding inodes (even ifreaddir_replyreturns True).
-
coroutine
readlink(inode, ctx)¶ Return target of symbolic link inode.
ctx will be a
RequestContextinstance.
-
coroutine
release(fh)¶ Release open file
This method will be called when the last file descriptor of fh has been closed, i.e. when the file is no longer opened by any client process.
fh will by an integer filehandle returned by a prior
openorcreatecall. Oncereleasehas been called, no future requests for fh will be received (until the value is re-used in the return value of anotheropenorcreatecall).This method may return an error by raising
FUSEError, but the error will be discarded because there is no corresponding client request.
-
coroutine
releasedir(fh)¶ Release open directory
This method will be called exactly once for each
opendircall. After fh has been released, no furtherreaddirrequests will be received for it (until it is opened again withopendir).
-
coroutine
removexattr(inode, name, ctx)¶ Remove extended attribute name of inode
ctx will be a
RequestContextinstance.If the attribute does not exist, the method must raise
FUSEErrorwith an error code ofENOATTR. name will be of typebytes, but is guaranteed not to contain zero-bytes (\0).
-
coroutine
rename(parent_inode_old, name_old, parent_inode_new, name_new, flags, ctx)¶ Rename a directory entry.
This method must rename name_old in the directory with inode parent_inode_old to name_new in the directory with inode parent_inode_new. If name_new already exists, it should be overwritten.
flags may be
RENAME_EXCHANGEorRENAME_NOREPLACE. IfRENAME_NOREPLACEis specified, the filesystem must not overwrite name_new if it exists and return an error instead. IfRENAME_EXCHANGEis specified, the filesystem must atomically exchange the two files, i.e. both must exist and neither may be deleted.ctx will be a
RequestContextinstance.Let the inode associated with name_old in parent_inode_old be inode_moved, and the inode associated with name_new in parent_inode_new (if it exists) be called inode_deref.
If inode_deref exists and has a non-zero lookup count, or if there are other directory entries referring to inode_deref), the file system must update only the directory entry for name_new to point to inode_moved instead of inode_deref. (Potential) removal of inode_deref (containing the previous contents of name_new) must be deferred to the
forgetmethod to be carried out when the lookup count reaches zero (and of course only if at that point there are no more directory entries associated with inode_deref either).
-
coroutine
rmdir(parent_inode, name, ctx)¶ Remove directory name
This method must remove the directory name from the direcory with inode parent_inode. ctx will be a
RequestContextinstance. If there are still entries in the directory, the method should raiseFUSEError(errno.ENOTEMPTY).If the inode associated with name (i.e., not the parent_inode) has a non-zero lookup count, the file system must remove only the directory entry (so that future calls to
readdirfor parent_inode will no longer include name, but e.g. calls togetattrfor file’s inode still succeed). Removal of the associated inode holding the directory contents and metadata must be deferred to theforgetmethod to be carried out when the lookup count reaches zero.(Since hard links to directories are not allowed by POSIX, this method is not required to check if there are still other directory entries refering to the same inode. This conveniently avoids the ambigiouties associated with the
.and..entries).
-
coroutine
setattr(inode, attr, fields, fh, ctx)¶ Change attributes of inode
fields will be an
SetattrFieldsinstance that specifies which attributes are to be updated. attr will be anEntryAttributesinstance for inode that contains the new values for changed attributes, and undefined values for all other attributes.Most file systems will additionally set the
st_ctime_nsattribute to the current time (to indicate that the inode metadata was changed).If the syscall that is being processed received a file descriptor argument (like e.g. ftruncate(2) or fchmod(2)), fh will be the file handle returned by the corresponding call to the
openhandler. If the syscall was path based (like e.g. truncate(2) or chmod(2)), fh will beNone.ctx will be a
RequestContextinstance.The method should return an
EntryAttributesinstance (containing both the changed and unchanged values).
-
coroutine
setxattr(inode, name, value, ctx)¶ Set extended attribute name of inode to value.
ctx will be a
RequestContextinstance.The attribute may or may not exist already. Both name and value will be of type
bytes. name is guaranteed not to contain zero-bytes (\0).
-
stacktrace()¶ Asynchronous debugging
This method will be called when the
fuse_stacktraceextended attribute is set on the mountpoint. The default implementation logs the current stack trace of every running Python thread. This can be quite useful to debug file system deadlocks.
-
coroutine
statfs(ctx)¶ Get file system statistics
ctx will be a
RequestContextinstance.The method must return an appropriately filled
StatvfsDatainstance.
-
coroutine
symlink(parent_inode, name, target, ctx)¶ Create a symbolic link
This method must create a symbolink link named name in the directory with inode parent_inode, pointing to target. ctx will be a
RequestContextinstance.The method must return an
EntryAttributesinstance with the attributes of the newly created directory entry.(Successful) execution of this handler increases the lookup count for the returned inode by one.
-
coroutine
unlink(parent_inode, name, ctx)¶ Remove a (possibly special) file
This method must remove the (special or regular) file name from the direcory with inode parent_inode. ctx will be a
RequestContextinstance.If the inode associated with file (i.e., not the parent_inode) has a non-zero lookup count, or if there are still other directory entries referring to this inode (due to hardlinks), the file system must remove only the directory entry (so that future calls to
readdirfor parent_inode will no longer include name, but e.g. calls togetattrfor file’s inode still succeed). (Potential) removal of the associated inode with the file contents and metadata must be deferred to theforgetmethod to be carried out when the lookup count reaches zero (and of course only if at that point there are no more directory entries associated with the inode either).
-
coroutine
write(fh, off, buf)¶ Write buf into fh at off
fh will by an integer filehandle returned by a prior
openorcreatecall.This method must return the number of bytes written. However, unless the file system has been mounted with the
direct_iooption, the file system must always write all the provided data (i.e., returnlen(buf)).
-