pub trait Filesystem {
Show 33 methods
// Provided methods
fn init(&self, req: RequestInfo, config: &mut KernelConfig) -> ResultEmpty { ... }
fn destroy(&self) { ... }
fn getattr(
&self,
req: RequestInfo,
path: &EntryRef,
fh: Option<u64>,
) -> ResultEntry { ... }
fn chmod(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: Option<u64>,
mode: u32,
) -> ResultEmpty { ... }
fn chown(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: Option<u64>,
uid: Option<u32>,
gid: Option<u32>,
) -> ResultEmpty { ... }
fn truncate(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: Option<u64>,
size: u64,
) -> ResultEmpty { ... }
fn utimens(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: Option<u64>,
atime: Option<SystemTime>,
mtime: Option<SystemTime>,
) -> ResultEmpty { ... }
fn utimens_macos(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: Option<u64>,
crtime: Option<SystemTime>,
chgtime: Option<SystemTime>,
bkuptime: Option<SystemTime>,
flags: Option<u32>,
) -> ResultEmpty { ... }
fn readlink(&self, req: RequestInfo, path: &ResolvedPath) -> ResultData { ... }
fn mknod(
&self,
req: RequestInfo,
entry: &EntryName,
mode: u32,
rdev: u32,
) -> ResultEntry { ... }
fn mkdir(
&self,
req: RequestInfo,
entry: &EntryName,
mode: u32,
) -> ResultEntry { ... }
fn unlink(&self, req: RequestInfo, entry: &EntryName) -> ResultEmpty { ... }
fn rmdir(&self, req: RequestInfo, entry: &EntryName) -> ResultEmpty { ... }
fn symlink(
&self,
req: RequestInfo,
entry: &EntryName,
target: &Path,
) -> ResultEntry { ... }
fn rename(
&self,
req: RequestInfo,
entry: &EntryName,
new_entry: &EntryName,
) -> ResultEmpty { ... }
fn link(
&self,
req: RequestInfo,
path: &ResolvedPath,
new_entry: &EntryName,
) -> ResultEntry { ... }
fn open(
&self,
req: RequestInfo,
path: &ResolvedPath,
flags: u32,
) -> ResultOpen { ... }
fn read(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: u64,
offset: u64,
size: u32,
callback: impl FnOnce(ResultSlice<'_>) -> CallbackResult,
) -> CallbackResult { ... }
fn write(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: u64,
offset: u64,
data: Vec<u8>,
flags: u32,
) -> ResultWrite { ... }
fn flush(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: u64,
lock_owner: u64,
) -> ResultEmpty { ... }
fn release(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: u64,
flags: u32,
lock_owner: u64,
flush: bool,
) -> ResultEmpty { ... }
fn fsync(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: u64,
datasync: bool,
) -> ResultEmpty { ... }
fn opendir(
&self,
req: RequestInfo,
path: &ResolvedPath,
flags: u32,
) -> ResultOpen { ... }
fn readdir(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: u64,
) -> ResultReaddir { ... }
fn releasedir(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: u64,
flags: u32,
) -> ResultEmpty { ... }
fn fsyncdir(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: u64,
datasync: bool,
) -> ResultEmpty { ... }
fn statfs(&self, req: RequestInfo, path: &ResolvedPath) -> ResultStatfs { ... }
fn setxattr(
&self,
req: RequestInfo,
path: &ResolvedPath,
name: &OsStr,
value: &[u8],
flags: u32,
position: u32,
) -> ResultEmpty { ... }
fn getxattr(
&self,
req: RequestInfo,
path: &ResolvedPath,
name: &OsStr,
size: u32,
) -> ResultXattr { ... }
fn listxattr(
&self,
req: RequestInfo,
path: &ResolvedPath,
size: u32,
) -> ResultXattr { ... }
fn removexattr(
&self,
req: RequestInfo,
path: &ResolvedPath,
name: &OsStr,
) -> ResultEmpty { ... }
fn access(
&self,
req: RequestInfo,
path: &ResolvedPath,
mask: u32,
) -> ResultEmpty { ... }
fn create(
&self,
req: RequestInfo,
path: &ResolvedPath,
mode: u32,
flags: u32,
) -> ResultCreate { ... }
}Expand description
This trait must be implemented to implement a filesystem with FuserNG.
Methods have default ENOSYS implementations, so a filesystem can implement only the operations it supports.
use std::io;
use std::time::{Duration, SystemTime};
use fuser_ng::{EntryRef, FileAttr, FileType, Filesystem, RequestInfo, ResultEntry};
struct RootOnly;
impl Filesystem for RootOnly {
fn getattr(&self, _req: RequestInfo, path: &EntryRef, _fh: Option<u64>) -> ResultEntry {
if path.full_path() != std::path::Path::new("/") {
return Err(io::Error::from_raw_os_error(libc::ENOENT));
}
let now = SystemTime::now();
Ok((
Duration::from_secs(1),
FileAttr {
size: 0,
blocks: 0,
atime: now,
mtime: now,
ctime: now,
crtime: now,
kind: FileType::Directory,
perm: 0o755,
nlink: 2,
uid: 0,
gid: 0,
rdev: 0,
blksize: 512,
flags: 0,
},
))
}
}Provided Methods§
Sourcefn init(&self, req: RequestInfo, config: &mut KernelConfig) -> ResultEmpty
fn init(&self, req: RequestInfo, config: &mut KernelConfig) -> ResultEmpty
Called on mount, before any other function.
Sourcefn getattr(
&self,
req: RequestInfo,
path: &EntryRef,
fh: Option<u64>,
) -> ResultEntry
fn getattr( &self, req: RequestInfo, path: &EntryRef, fh: Option<u64>, ) -> ResultEntry
Get the attributes of a filesystem entry.
fh: a file handle if this is called on an open file.
Sourcefn chmod(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: Option<u64>,
mode: u32,
) -> ResultEmpty
fn chmod( &self, req: RequestInfo, path: &ResolvedPath, fh: Option<u64>, mode: u32, ) -> ResultEmpty
Change the mode of a filesystem entry.
fh: a file handle if this is called on an open file.mode: the mode to change the file to.
Sourcefn chown(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: Option<u64>,
uid: Option<u32>,
gid: Option<u32>,
) -> ResultEmpty
fn chown( &self, req: RequestInfo, path: &ResolvedPath, fh: Option<u64>, uid: Option<u32>, gid: Option<u32>, ) -> ResultEmpty
Change the owner UID and/or group GID of a filesystem entry.
fh: a file handle if this is called on an open file.uid: user ID to change the file’s owner to. IfNone, leave the UID unchanged.gid: group ID to change the file’s group to. IfNone, leave the GID unchanged.
Sourcefn truncate(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: Option<u64>,
size: u64,
) -> ResultEmpty
fn truncate( &self, req: RequestInfo, path: &ResolvedPath, fh: Option<u64>, size: u64, ) -> ResultEmpty
Set the length of a file.
fh: a file handle if this is called on an open file.size: size in bytes to set as the file’s length.
Sourcefn utimens(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: Option<u64>,
atime: Option<SystemTime>,
mtime: Option<SystemTime>,
) -> ResultEmpty
fn utimens( &self, req: RequestInfo, path: &ResolvedPath, fh: Option<u64>, atime: Option<SystemTime>, mtime: Option<SystemTime>, ) -> ResultEmpty
Set timestamps of a filesystem entry.
fh: a file handle if this is called on an open file.atime: the time of last access.mtime: the time of last modification.
Sourcefn utimens_macos(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: Option<u64>,
crtime: Option<SystemTime>,
chgtime: Option<SystemTime>,
bkuptime: Option<SystemTime>,
flags: Option<u32>,
) -> ResultEmpty
fn utimens_macos( &self, req: RequestInfo, path: &ResolvedPath, fh: Option<u64>, crtime: Option<SystemTime>, chgtime: Option<SystemTime>, bkuptime: Option<SystemTime>, flags: Option<u32>, ) -> ResultEmpty
Set timestamps of a filesystem entry (with extra options only used on MacOS).
Sourcefn readlink(&self, req: RequestInfo, path: &ResolvedPath) -> ResultData
fn readlink(&self, req: RequestInfo, path: &ResolvedPath) -> ResultData
Read a symbolic link.
Sourcefn mknod(
&self,
req: RequestInfo,
entry: &EntryName,
mode: u32,
rdev: u32,
) -> ResultEntry
fn mknod( &self, req: RequestInfo, entry: &EntryName, mode: u32, rdev: u32, ) -> ResultEntry
Create a special file.
parent: path to the directory to make the entry under.name: name of the entry.mode: mode for the new entry.rdev: if mode has the bitsS_IFCHRorS_IFBLKset, this is the major and minor numbers for the device file. Otherwise it should be ignored.
Sourcefn mkdir(&self, req: RequestInfo, entry: &EntryName, mode: u32) -> ResultEntry
fn mkdir(&self, req: RequestInfo, entry: &EntryName, mode: u32) -> ResultEntry
Create a directory.
parent: path to the directory to make the directory under.name: name of the directory.mode: permissions for the new directory.
Sourcefn unlink(&self, req: RequestInfo, entry: &EntryName) -> ResultEmpty
fn unlink(&self, req: RequestInfo, entry: &EntryName) -> ResultEmpty
Remove a file.
parent: path to the directory containing the file to delete.name: name of the file to delete.
Sourcefn rmdir(&self, req: RequestInfo, entry: &EntryName) -> ResultEmpty
fn rmdir(&self, req: RequestInfo, entry: &EntryName) -> ResultEmpty
Remove a directory.
parent: path to the directory containing the directory to delete.name: name of the directory to delete.
Sourcefn symlink(
&self,
req: RequestInfo,
entry: &EntryName,
target: &Path,
) -> ResultEntry
fn symlink( &self, req: RequestInfo, entry: &EntryName, target: &Path, ) -> ResultEntry
Create a symbolic link.
parent: path to the directory to make the link in.name: name of the symbolic link.target: path (may be relative or absolute) to the target of the link.
Sourcefn rename(
&self,
req: RequestInfo,
entry: &EntryName,
new_entry: &EntryName,
) -> ResultEmpty
fn rename( &self, req: RequestInfo, entry: &EntryName, new_entry: &EntryName, ) -> ResultEmpty
Rename a filesystem entry.
parent: path to the directory containing the existing entry.name: name of the existing entry.newparent: path to the directory it should be renamed into (may be the same asparent).newname: name of the new entry.
Sourcefn link(
&self,
req: RequestInfo,
path: &ResolvedPath,
new_entry: &EntryName,
) -> ResultEntry
fn link( &self, req: RequestInfo, path: &ResolvedPath, new_entry: &EntryName, ) -> ResultEntry
Create a hard link.
path: path to an existing file.newparent: path to the directory for the new link.newname: name for the new link.
Sourcefn open(&self, req: RequestInfo, path: &ResolvedPath, flags: u32) -> ResultOpen
fn open(&self, req: RequestInfo, path: &ResolvedPath, flags: u32) -> ResultOpen
Open a file.
path: path to the file.flags: one ofO_RDONLY,O_WRONLY, orO_RDWR, plus maybe additional flags.
Return a tuple of (file handle, flags). The file handle will be passed to any subsequent calls that operate on the file, and can be any value you choose, though it should allow your filesystem to identify the file opened even without any path info.
Sourcefn read(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: u64,
offset: u64,
size: u32,
callback: impl FnOnce(ResultSlice<'_>) -> CallbackResult,
) -> CallbackResult
fn read( &self, req: RequestInfo, path: &ResolvedPath, fh: u64, offset: u64, size: u32, callback: impl FnOnce(ResultSlice<'_>) -> CallbackResult, ) -> CallbackResult
Read from a file.
Note that it is not an error for this call to request to read past the end of the file, and you should only return data up to the end of the file (i.e. the number of bytes returned will be fewer than requested; possibly even zero). Do not extend the file in this case.
path: path to the file.fh: file handle returned from theopencall.offset: offset into the file to start reading.size: number of bytes to read.callback: a callback that must be invoked to return the result of the operation: either the result data as a slice, or an error code.
Return the return value from the callback function.
Sourcefn write(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: u64,
offset: u64,
data: Vec<u8>,
flags: u32,
) -> ResultWrite
fn write( &self, req: RequestInfo, path: &ResolvedPath, fh: u64, offset: u64, data: Vec<u8>, flags: u32, ) -> ResultWrite
Write to a file.
path: path to the file.fh: file handle returned from theopencall.offset: offset into the file to start writing.data: the data to writeflags:
Return the number of bytes written.
Sourcefn flush(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: u64,
lock_owner: u64,
) -> ResultEmpty
fn flush( &self, req: RequestInfo, path: &ResolvedPath, fh: u64, lock_owner: u64, ) -> ResultEmpty
Called each time a program calls close on an open file.
Note that because file descriptors can be duplicated (by dup, dup2, fork) this may be
called multiple times for a given file handle. The main use of this function is if the
filesystem would like to return an error to the close call. Note that most programs
ignore the return value of close, though.
path: path to the file.fh: file handle returned from theopencall.lock_owner: if the filesystem supports locking (setlk,getlk), remove all locks belonging to this lock owner.
Sourcefn release(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: u64,
flags: u32,
lock_owner: u64,
flush: bool,
) -> ResultEmpty
fn release( &self, req: RequestInfo, path: &ResolvedPath, fh: u64, flags: u32, lock_owner: u64, flush: bool, ) -> ResultEmpty
Called when an open file is closed.
There will be one of these for each open call. After release, no more calls will be
made with the given file handle.
path: path to the file.fh: file handle returned from theopencall.flags: the flags passed when the file was opened.lock_owner: if the filesystem supports locking (setlk,getlk), remove all locks belonging to this lock owner.flush: whether pending data must be flushed or not.
Sourcefn fsync(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: u64,
datasync: bool,
) -> ResultEmpty
fn fsync( &self, req: RequestInfo, path: &ResolvedPath, fh: u64, datasync: bool, ) -> ResultEmpty
Write out any pending changes of a file.
When this returns, data should be written to persistent storage.
path: path to the file.fh: file handle returned from theopencall.datasync: iffalse, also write metadata, otherwise just write file data.
Sourcefn opendir(
&self,
req: RequestInfo,
path: &ResolvedPath,
flags: u32,
) -> ResultOpen
fn opendir( &self, req: RequestInfo, path: &ResolvedPath, flags: u32, ) -> ResultOpen
Open a directory.
Analogous to the opend call.
path: path to the directory.flags: file access flags. Will containO_DIRECTORYat least.
Return a tuple of (file handle, flags). The file handle will be passed to any subsequent calls that operate on the directory, and can be any value you choose, though it should allow your filesystem to identify the directory opened even without any path info.
Sourcefn readdir(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: u64,
) -> ResultReaddir
fn readdir( &self, req: RequestInfo, path: &ResolvedPath, fh: u64, ) -> ResultReaddir
Get the entries of a directory.
path: path to the directory.fh: file handle returned from theopendircall.
Return all the entries of the directory.
Sourcefn releasedir(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: u64,
flags: u32,
) -> ResultEmpty
fn releasedir( &self, req: RequestInfo, path: &ResolvedPath, fh: u64, flags: u32, ) -> ResultEmpty
Close an open directory.
This will be called exactly once for each opendir call.
path: path to the directory.fh: file handle returned from theopendircall.flags: the file access flags passed to theopendircall.
Sourcefn fsyncdir(
&self,
req: RequestInfo,
path: &ResolvedPath,
fh: u64,
datasync: bool,
) -> ResultEmpty
fn fsyncdir( &self, req: RequestInfo, path: &ResolvedPath, fh: u64, datasync: bool, ) -> ResultEmpty
Write out any pending changes to a directory.
Analogous to the fsync call.
Sourcefn statfs(&self, req: RequestInfo, path: &ResolvedPath) -> ResultStatfs
fn statfs(&self, req: RequestInfo, path: &ResolvedPath) -> ResultStatfs
Get filesystem statistics.
path: path to some folder in the filesystem.
See the Statfs struct for more details.
Sourcefn setxattr(
&self,
req: RequestInfo,
path: &ResolvedPath,
name: &OsStr,
value: &[u8],
flags: u32,
position: u32,
) -> ResultEmpty
fn setxattr( &self, req: RequestInfo, path: &ResolvedPath, name: &OsStr, value: &[u8], flags: u32, position: u32, ) -> ResultEmpty
Set a file extended attribute.
path: path to the file.name: attribute name.value: the data to set the value to.flags: can be eitherXATTR_CREATEorXATTR_REPLACE.position: offset into the attribute value to write data.
Sourcefn getxattr(
&self,
req: RequestInfo,
path: &ResolvedPath,
name: &OsStr,
size: u32,
) -> ResultXattr
fn getxattr( &self, req: RequestInfo, path: &ResolvedPath, name: &OsStr, size: u32, ) -> ResultXattr
Get a file extended attribute.
path: path to the filename: attribute name.size: the maximum number of bytes to read.
If size is 0, return Xattr::Size(n) where n is the size of the attribute data.
Otherwise, return Xattr::Data(data) with the requested data.
Sourcefn listxattr(
&self,
req: RequestInfo,
path: &ResolvedPath,
size: u32,
) -> ResultXattr
fn listxattr( &self, req: RequestInfo, path: &ResolvedPath, size: u32, ) -> ResultXattr
List extended attributes for a file.
path: path to the file.size: maximum number of bytes to return.
If size is 0, return Xattr::Size(n) where n is the size required for the list of
attribute names.
Otherwise, return Xattr::Data(data) where data is all the null-terminated attribute
names.
Sourcefn removexattr(
&self,
req: RequestInfo,
path: &ResolvedPath,
name: &OsStr,
) -> ResultEmpty
fn removexattr( &self, req: RequestInfo, path: &ResolvedPath, name: &OsStr, ) -> ResultEmpty
Remove an extended attribute for a file.
path: path to the file.name: name of the attribute to remove.
Sourcefn access(
&self,
req: RequestInfo,
path: &ResolvedPath,
mask: u32,
) -> ResultEmpty
fn access( &self, req: RequestInfo, path: &ResolvedPath, mask: u32, ) -> ResultEmpty
Check for access to a file.
path: path to the file.mask: mode bits to check for access to.
Return Ok(()) if all requested permissions are allowed, otherwise return Err(EACCES)
or other error code as appropriate (e.g. ENOENT if the file doesn’t exist).
Sourcefn create(
&self,
req: RequestInfo,
path: &ResolvedPath,
mode: u32,
flags: u32,
) -> ResultCreate
fn create( &self, req: RequestInfo, path: &ResolvedPath, mode: u32, flags: u32, ) -> ResultCreate
Create and open a new file.
parent: path to the directory to create the file in.name: name of the file to be created.mode: the mode to set on the new file.flags: flags like would be passed toopen.
Return a CreatedEntry (which contains the new file’s attributes as well as a file handle
– see documentation on open for more info on that).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".