FuseSharp is a FUSE binding for macOS (macFUSE) written in modern C#. It provides a clean API designed specifically to enable the development of userspace filesystems in .NET applications.
Note: This fork is a complete rewrite of the original FuseSharp for .NET 10. It binds directly against macFUSE's FUSE 2.x compatibility library (
/usr/local/lib/libfuse.2.dylib) usingLibraryImportand[UnmanagedCallersOnly]function pointers. The original nativeAdaptorshim, theMono.Posixdependency, and the delegate-based marshaling layer have been removed entirely - no native components need to be built or shipped alongside the managed assembly, and bothosx-arm64andosx-x64are supported.
- macOS with macFUSE installed
- .NET 10 or later
Derive from FuseFileSystemBase and override the operations your filesystem supports. Only overridden
callbacks are registered with FUSE; everything else is reported to the kernel as not implemented.
usingFuseSharp;usingFuseSharp.Native;sealedclassMyFileSystem:FuseFileSystemBase{publicoverrideboolSupportsMultiThreading=>true;publicoverrideintGetAttr(ReadOnlySpan<byte>path,refStatstat,FuseFileInfoReffiRef){if(!path.SequenceEqual(RootPath))return-LibC.ENOENT;stat.st_mode=(ushort)(LibC.S_IFDIR|0x1ED);// drwxr-xr-xstat.st_nlink=2;return0;}publicoverrideintReadDir(ReadOnlySpan<byte>path,ulongoffset,DirectoryContentcontent,refFuseFileInfofi){content.AddEntry(".");content.AddEntry("..");return0;}}Mount and unmount:
if(!Fuse.CheckDependencies())thrownewInvalidOperationException("macFUSE is not installed.");IFuseMountmount=Fuse.Mount("/path/to/mountpoint",newMyFileSystem(),newMountOptions(){Options="default_permissions,volname=MyVolume"});// ... the filesystem is served on a background thread ...boolunmounted=awaitmount.UnmountAsync(force:true);| Component | Purpose |
|---|---|
FuseFileSystemBase | The abstract base class filesystem implementations derive from. Callbacks receive UTF-8 paths as spans and return 0 or a negated Darwin errno. |
Fuse | Static entry point: CheckDependencies, Mount, LazyUnmount. |
IFuseMount | A handle to a mounted filesystem with UnmountAsync. |
Native/LibFuse | LibraryImport bindings for libfuse.2.dylib (fuse_mount, fuse_new, fuse_loop_mt, ...). |
Native/LibC | Darwin libSystem bindings and POSIX constants (errno values, open flags, xattr, ...). |
Native/FuseOperations | A blittable mirror of macFUSE's struct fuse_operations (FUSE API 26), layout-verified against the installed headers. |
The MountOptions.Options string is passed to FUSE verbatim (comma-separated). Commonly useful options
(see the macFUSE mount options wiki):
| Option | Description |
|---|---|
volname=NAME | The volume name shown in Finder. |
fsname=NAME | The file system name reported by mount. |
default_permissions | Let the kernel enforce permissions based on GetAttr results. |
allow_other / allow_root | Allow other users (requires the allow_other macFUSE tunable). |
ro | Mount read-only. |
noappledouble | Do not create AppleDouble (._) companion files. |
iosize=N | I/O size in bytes (512 bytes - 32 MB, power of 2). |
debug | Print FUSE debugging output. |
See LICENSE. Based on FuseSharp by Códice Software / PlasticSCM.