Getting started
Install FSK, implement a read-only filesystem, and mount it as a native volume.
Mount a read-only volume with five methods. The filesystem below exposes one file,
hello.txt, in the root directory.
You need Rust 1.85 or later, and the platform component from
Platform setup: FSK.app on macOS, FUSE on Linux, or the Projected File
System feature on Windows.
Install
The crate is a single dependency. It re-exports the trait, the data model, the error type and
the platform MountSession, so a backend needs no platform-specific imports.
Check the platform
Mounting depends on host software that Cargo cannot install. Check it before you build anything:
ensure_authorization() never installs anything. NotInstalled returns
io::ErrorKind::NotFound; NeedsApproval opens the platform UI and returns
io::ErrorKind::PermissionDenied. That error is the instruction to run again, not a bug.
On targets other than macOS, Linux and Windows, authorization_status() returns
io::ErrorKind::Unsupported.
Implement a filesystem
Five methods are required: statfs, metadata, lookup, read_directory and read.
Every mutation has a default that returns ENOTSUP.
Each method answers one question from the kernel:
statfsreports capacity and inode counts for the volume display. Values are advisory.metadatareturns the attributes for an inode the kernel has already seen, with or without a preceding lookup.lookupresolves one name inside one directory to an inode and its kind.read_directorystreams the entries of one directory starting at a cookie.readfills the buffer from the file at an offset and returns how many bytes it wrote.
The type must be Send + Sync + 'static. Methods are called concurrently, so shared state
needs interior mutability and locks.
Mount it
MountSession::mount takes the backend by value, mounts it, and returns a session that serves
requests from the calling process. It is synchronous and returns once the mount exists. The
mount directory is created if it is missing.
The session owns the mount. Drop it to unmount; there is no handle back to the backend. A real program usually waits on a signal instead of parking forever, as the examples do.
What works out of the box
With only the five methods, you get a mountable read-only volume:
- Directory browsing in Finder, Explorer and Linux file managers.
ls,statandcatthrough the kernel.dfreporting the values fromstatfs(except on Windows, which never callsstatfs).- A working
fsync, becausesynchronizedefaults to a successful no-op.
Everything that would change state returns ENOTSUP:
That is the intended posture. Leaving the default is better than accepting an operation and doing nothing, because the kernel assumes success.
Continue building
- Core concepts explains inodes, names and errors before you write a real backend.
- Implementing a filesystem covers every optional method.
- Mounting and lifecycle covers options, unmounting and running from an app.
- Examples has a complete writable in-memory backend to copy from.
