Cross-platform FUSE library for Go
Cgofuse is a cross-platform FUSE library for Go. It is supported on multiple platforms and can be ported to any platform that has a FUSE implementation. It has [cgo](https://golang.org/cmd/cgo/) and [!cgo](https://github.com/golang/go/wiki/WindowsDLLs) ("nocgo") variants depending on the platform.
| |Windows
[](https://ci.appveyor.com/project/billziss-gh/cgofuse)|macOS
[](https://travis-ci.org/billziss-gh/cgofuse)|Linux
[](https://travis-ci.org/billziss-gh/cgofuse)|FreeBSD
[](https://cirrus-ci.com/github/billziss-gh/cgofuse)|NetBSD*
|OpenBSD*
|XGO
[](https://hub.docker.com/r/billziss/xgo-cgofuse)|
|:-----:|:------:|:------:|:------:|:------:|:------:|:------:|:------:|
| cgo |✓|✓|✓|✓|✓|✓|✓|
| !cgo |✓| | | | | | |
**\*** NetBSD and OpenBSD support is experimental. There are known issues that stem from the differences in the NetBSD [librefuse](https://github.com/NetBSD/src/tree/bbc46b99bff565d75f55fb23b51eff511068b183/lib/librefuse) and OpenBSD [libfuse](https://github.com/openbsd/src/tree/dae5ffec5618b0b660e9064e3b0991bb4ab1b1e8/lib/libfuse) implementations from the reference [libfuse](https://github.com/libfuse/libfuse) implementation
## How to build
**Windows cgo**
- Prerequisites: [WinFsp](https://github.com/billziss-gh/winfsp), gcc (e.g. from [Mingw-builds](http://mingw-w64.org/doku.php/download))
- Build:
```
> cd cgofuse
> set CPATH=C:\Program Files (x86)\WinFsp\inc\fuse
> go install -v ./fuse ./examples/memfs
```
**Windows !cgo**
- Prerequisites: [WinFsp](https://github.com/billziss-gh/winfsp)
- Build:
```
> cd cgofuse
> set CGO_ENABLED=0
> go install -v ./fuse ./examples/memfs
```
**macOS**
- Prerequisites: [FUSE for macOS](https://osxfuse.github.io), [command line tools](https://developer.apple.com/library/content/technotes/tn2339/_index.html)
- Build:
```
$ cd cgofuse
$ go install -v ./fuse ./examples/memfs ./examples/passthrough
```
**Linux**
- Prerequisites: libfuse-dev, gcc
- Build:
```
$ cd cgofuse
$ go install -v ./fuse ./examples/memfs ./examples/passthrough
```
**FreeBSD**
- Prerequisites: fusefs-libs
- Build:
```
$ cd cgofuse
$ go install -v ./fuse ./examples/memfs ./examples/passthrough
# You may also need the following in order to run FUSE file systems.
# Commands must be run as root.
$ vi /boot/loader.conf # add: fuse_load="YES"
$ sysctl vfs.usermount=1 # allow user mounts
$ pw usermod USERNAME -G operator # allow user to open /dev/fuse
```
**NetBSD**
- Prerequisites: NONE
- Build:
```
$ cd cgofuse
$ go install -v ./fuse ./examples/memfs ./examples/passthrough
# You may also need the following in order to run FUSE file systems.
# Commands must be run as root.
$ chmod go+rw /dev/puffs
$ sysctl -w vfs.generic.usermount=1
```
**OpenBSD**
- Prerequisites: NONE
- Build:
```
$ cd cgofuse
$ go install -v ./fuse ./examples/memfs ./examples/passthrough
```
- **NOTE**: OpenBSD 6 removed the `kern.usermount` option, which allowed non-root users to mount file systems [[link](https://undeadly.org/cgi?action=article&sid=20160715125022&mode=expanded&count=0)]. Therefore you must be root in order to use FUSE and cgofuse.
## How to cross-compile your project using xgo
You can easily cross-compile your project using [xgo](https://github.com/karalabe/xgo) and the [billziss/xgo-cgofuse](https://hub.docker.com/r/billziss/xgo-cgofuse/) docker image.
- Prerequisites: [docker](https://www.docker.com), [xgo](https://github.com/karalabe/xgo)
- Build:
```
$ docker pull billziss/xgo-cgofuse
$ go get -u github.com/karalabe/xgo
$ cd YOUR-PROJECT-THAT-USES-CGOFUSE
$ xgo --image=billziss/xgo-cgofuse \
--targets=darwin/386,darwin/amd64,linux/386,linux/amd64,windows/386,windows/amd64 .
```
Cross-compilation only works for Windows, macOS and Linux.
## How to use
User mode file systems are expected to implement `fuse.FileSystemInterface`. To make implementation simpler a file system can embed ("inherit") a `fuse.FileSystemBase` which provides default implementations for all operations. To mount a file system one must instantiate a `fuse.FileSystemHost` using `fuse.NewFileSystemHost`.
The full documentation is available at GoDoc.org: [package fuse](https://godoc.org/github.com/billziss-gh/cgofuse/fuse)
There are currently three example file systems:
- [Hellofs](examples/hellofs/hellofs.go) is an extremely simple file system. Runs on all OS'es.
- [Memfs](examples/memfs/memfs.go) is an in memory file system. Runs on all OS'es.
- [Passthrough](examples/passthrough/passthrough.go) is a file system that passes all operations to the underlying file system. Runs on all OS'es except Windows.
## How it is tested
Cgofuse is regularly built and tested on [Travis CI](https://travis-ci.org/billziss-gh/cgofuse), [AppVeyor](https://ci.appveyor.com/project/billziss-gh/cgofuse) and [DockerHub](https://hub.docker.com/r/billziss/xgo-cgofuse). The following software is being used to test cgofuse.
**Windows (cgo and !cgo)**
- [winfsp-tests](https://github.com/billziss-gh/winfsp/tree/master/tst/winfsp-tests)
- [fsx](https://github.com/billziss-gh/secfs.test/tree/master/fstools/src/fsx)
**macOS**
- [fstest](https://github.com/billziss-gh/secfs.test/tree/master/fstest/ntfs-3g-pjd-fstest-8af5670)
- [fsx](https://github.com/billziss-gh/secfs.test/tree/master/fstools/src/fsx)
**Linux**
- [fstest](https://github.com/billziss-gh/secfs.test/tree/master/fstest/ntfs-3g-pjd-fstest-8af5670)
- [fsx](https://github.com/billziss-gh/secfs.test/tree/master/fstools/src/fsx)
**FreeBSD**
- [fsx](https://github.com/billziss-gh/secfs.test/tree/master/fstools/src/fsx)
## Contributors
- Bill Zissimopoulos \
- Nick Craig-Wood \
- Fredrik Medley