Fuse::FileSystem
Inherits Reference < Object
Base class for a FUSE filesystem. Subclass it and override the operations
you care about; anything you leave alone returns a sensible default
(-ENOENT for lookups, -ENOSYS for write operations on a read-only fs).
Reference it as Fuse::FileSystem, or via the short alias
Fuse::FS.
Most operations come in two flavors: an ergonomic default that returns a
Crystal value (FileAttr, Array(String), Bytes, …) and, where it
matters, a lower-level "escape hatch" overload that hands you the raw
buffer/pointer for zero-copy or full control. Override whichever you need;
the escape-hatch forms delegate to the friendly ones by default. Any
operation can also return a negative Errno value to signal failure,
e.g. -Errno::ENOENT.value.
Instance methods
Check access permissions for path. Return 0 to allow.
Map a logical file block to a device block (for block-backed filesystems). idx is in/out: the requested block in, the mapped block out.
Server-side copy of size bytes between two open files. Return the number of bytes copied, or a negative errno.
Same as create but with the FileInfo (settable file handle).
Create and open a new file at path with the given mode.
Preallocate or punch holes in a file's space (see fallocate(2) mode).
BSD-style whole-file advisory lock (op is LOCK_SH / LOCK_EX / LOCK_UN …).
Called on each close(2) of a descriptor (may fire more than once, or
not at all). Return an error to surface it to close.
Sync a file's contents to storage. datasync true → flush data only.
Sync a directory. datasync true → flush data only, not metadata.
Raw escape hatch: fill the kernel's struct stat (stat) directly and
return 0, or a negative errno. Use this when you need a field FileAttr
doesn't model. By default it calls the friendly FileAttr-returning form
and marshals the result, so override one or the other.
Attributes for the file at path (the stat(2) of FUSE).
Return the value of extended attribute name, or a negative errno
(e.g. -Errno::ENODATA.value when it doesn't exist).
Device-style ioctl; arg/data are raw pointers per the ioctl protocol.
Create a hard link at link_path referring to the existing file target.
Return the names of path's extended attributes.
POSIX (fcntl) advisory lock. cmd is F_GETLK / F_SETLK / F_SETLKW; lock
points at a LibC::Flock to read and (for F_GETLK) write back.
Reposition the read/write offset; mainly SEEK_DATA/SEEK_HOLE for sparse files. Return the resulting offset, or a negative errno.
Create a filesystem node (regular file, FIFO, socket, device, …) at path. rdev matters only for device nodes.
Mount this filesystem, handing args (argv-style) straight to libfuse. Don't override this.
Same as open but with the FileInfo (open flags + a settable file
handle). Override this instead of open for handle/flag-aware behavior;
by default it just delegates to the path-only form.
Called when a directory is opened. Set fi.fh for a directory handle.
Poll for I/O readiness; set the ready events into reventsp. ph is an opaque poll handle for later notification.
Same as read but with the FileInfo (file handle set in open).
Buffer-filling escape hatch: write up to buffer.size bytes directly into
buffer (the kernel's own read buffer) starting at offset, and return
the number of bytes written, or a negative errno.
This avoids the allocate-and-copy of the Bytes-returning form, which is
worth it for filesystems streaming large files. Override this or the
Bytes form — by default this one calls the Bytes form and copies its
result into buffer.
Read up to size bytes from path starting at offset.
Streaming escape hatch: push entries into filler (filler << name) as
you discover them and return 0, or a negative errno. Avoids materializing
the whole listing into an Array(String) — worth it for directories with
very many entries. By default it calls the Array(String)-returning form
and streams its result, so override one or the other.
Same as readdir but with the FileInfo (the handle set in opendir).
Entries contained in the directory at path. Include "." and "..".
Called once when the last open reference to a file is released. Free any
handle/state you allocated in open/create here.
Rename/move path to new_path.
Set extended attribute name to value. flags may be XATTR_CREATE
(1, fail if it exists) or XATTR_REPLACE (2, fail if it doesn't).
Create a symbolic link at link_path pointing to target.
Set the access and/or modification times of path. Either may be nil,
meaning "leave that timestamp unchanged" (FUSE's UTIME_OMIT).
Same as write but with the FileInfo (file handle set in open).
Write data to path at offset. Return the number of bytes written.