Request Handlers

(You can use the Index to directly jump to a specific handler).

class llfuse.Operations

This class defines the general and request handler methods that an LLFUSE file system may implement. If a particular request handler has not been implemented, it must raise FUSEError with an errorcode of errno.ENOSYS.

It has recommended that file systems are derived from this class and only overwrite the handlers that they actually implement. (The default implementations defined in this class all just raise the not-implemented exception).

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.

access(inode, mode, ctx)

Check if requesting process has mode rights on inode.

ctx will be a RequestContext instance. The method must return a boolean value.

If the default_permissions mount option is given, this method is not called.

create(inode_parent, name, mode, ctx)

Create a file with permissions mode and open it

ctx will be a RequestContext instance.

The method must return a tuple of the form (fh, attr), where fh is a file handle like the one returned by open and attr is an EntryAttributes instance with the attributes of the newly created directory entry.

destroy()

Clean up operations.

This method will be called after the last request has been received and when the file system is about to be unmounted. It must not raise any exceptions (including FUSEError, since this method is not handling a particular syscall).

flush(fh)

Handle close() syscall.

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).

If the file system implements locking, this method must clear all locks belonging to the file handle’s owner.

forget(inode, nlookup)

Notify about inode being removed from the kernel cache

This method is called when the kernel removes inode from its internal caches. nlookup is the number of times that lookup has been called for this inode.

Once the file system has received a forget call for an inode, no other request handlers will be called for this inode without a prior lookup call.

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).

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).

getattr(inode)

Get attributes for inode

This method should return an EntryAttributes instance with the attributes of inode. The entry_timeout attribute is ignored in this context.

getxattr(inode, name)

Return extended attribute value

If the attribute does not exist, the method must raise FUSEError with an error code of ENOATTR.

handle_exc(fn, exc)

Handle exceptions that occured during request processing.

This method will be called when things went seriously wrong. This includes e.g. bugs in LLFUSE itself or request handlers raising exceptions other than FUSEError, but not problems with sending the reply once the request has been processed.

The type of the request that failed is passed in fn.

init()

Initialize operations

This function will be called just before the file system starts handling requests. It must not raise any exceptions (including FUSEError, since this method is not handling a particular syscall).

Create a hard link.

The method must return an EntryAttributes instance with the attributes of the newly created directory entry.

listxattr(inode)

Get list of extended attribute names

lookup(parent_inode, name)

Look up a directory entry by name and get its attributes.

If the entry does not exist, this method must raise FUSEError with an errno of errno.ENOENT. Otherwise it must return an EntryAttributes instance.

The file system must be able to handle lookups for . and .., no matter if these entries are returned by readdir or not.

mkdir(parent_inode, name, mode, ctx)

Create a directory

ctx will be a RequestContext instance. The method must return an EntryAttributes instance with the attributes of the newly created directory entry.

mknod(parent_inode, name, mode, rdev, ctx)

Create (possibly special) file

ctx will be a RequestContext instance. The method must return an EntryAttributes instance with the attributes of the newly created directory entry.

open(inode, flags)

Open a file.

flags will be a bitwise or of the open flags described in the open(2) manpage and defined in the os module (with the exception of O_CREAT, O_EXCL, O_NOCTTY and O_TRUNC)

This method should return an integer file handle. The file handle will be passed to the read, write, flush, fsync and release methods to identify the open file.

opendir(inode)

Open a directory.

This method should return an integer file handle. The file handle will be passed to the readdir, fsyncdir and releasedir methods to identify the directory.

read(fh, off, size)

Read size bytes from fh at position off

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.

readdir(fh, off)

Read directory entries

This method should return an iterator over the contents of directory fh, starting at the entry identified by off.

The iterator must yield tuples of the form (name, attr, next_), where attr is an EntryAttributes instance and next_ gives an offset that can be passed as off to start a successive readdir call at the right position.

Iteration may be stopped as soon as enough elements have been retrieved. The method should be prepared for this case.

If entries are added or removed during a readdir cycle, 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.

Return target of symbolic link

release(fh)

Release open file

This method will be called when the last file descriptor of fh has been closed. Therefore it will be called exactly once for each open call.

releasedir(fh)

Release open directory

This method must be called exactly once for each opendir call.

removexattr(inode, name)

Remove extended attribute

If the attribute does not exist, the method must raise FUSEError with an error code of ENOATTR.

rename(inode_parent_old, name_old, inode_parent_new, name_new)

Rename a directory entry

rmdir(inode_parent, name)

Remove a directory

setattr(inode, attr)

Change attributes of inode

attr is an EntryAttributes instance with the new attributes. Only the attributes st_size, st_mode, st_uid, st_gid, st_atime and st_mtime are relevant. Unchanged attributes will have a value None.

The method should return a new EntryAttributes instance with the updated attributes (i.e., all attributes except for entry_timeout should be set).

setxattr(inode, name, value)

Set an extended attribute.

The attribute may or may not exist already.

stacktrace()

Asynchronous debugging

This method will be called when the fuse_stacktrace extended attribute is set on the mountpoint. It will be called without holding the global lock. The default implementation logs the current stack trace of every running Python thread. This can be quite useful to debug file system deadlocks.

statfs()

Get file system statistics

The method is expected to return an appropriately filled StatvfsData instance.

Create a symbolic link

ctx will be a RequestContext instance. The method must return an EntryAttributes instance with the attributes of the newly created directory entry.

Remove a (possibly special) file

If the file is currently opened, the file system must defer removing the actual file contents and metadata until the file is no longer opened by any application.

Note that an unlinked file may also appear again if it gets a new directory entry by the link method.

write(fh, off, buf)

Write buf into fh at off

This method should return the number of bytes written. If no error occured, this should be exactly len(buf).

Table Of Contents

Previous topic

The global lock

Next topic

Example File System