cgofuse

repository·master·Indexed 20 days ago

https://github.com/winfsp/cgofuse

A cross-platform FUSE (Filesystem in Userspace) library for Go that allows developers to implement custom file systems mountable on Windows, macOS, Linux, and BSDs. It provides the fuse.FileSystemInterface for implementation and fuse.FileSystemHost for mounting, with support for both cgo and non-cgo builds on Windows.

Tokens
1.1K
Snippets
6
Records
8
Agent score
21%

What's inside cgofuse

  1. How to implement a file system with cgofuse

    master

    To create a user-mode file system in cgofuse, follow these steps:

    1. Implement the interface: Your file system must implement the fuse.FileSystemInterface.
    2. Simplify with embedding: To avoid implementing every method manually, embed fuse.FileSystemBase in your struct. This provides default implementations for all operations.
    3. Mount the file system: Instantiate a fuse.FileSystemHost using fuse.NewFileSystemHost to handle the mounting process.
  2. Build cgofuse on OpenBSD

    master

    Prerequisites: None.

    Note: Support is experimental. Because OpenBSD 6 removed the kern.usermount option, you must run as root to use FUSE and cgofuse. Known issues may exist due to differences in the OpenBSD libfuse implementation.

    go install -v ./fuse ./examples/memfs ./examples/passthrough
  3. Build cgofuse on NetBSD

    master

    Prerequisites: None.

    Note: Support is experimental. Due to differences in NetBSD's librefuse implementation compared to the reference libfuse, known issues may exist. To run a file system, you may need to run these commands as root:

    1. chmod go+rw /dev/puffs
    2. sysctl -w vfs.generic.usermount=1
    go install -v ./fuse ./examples/memfs ./examples/passthrough
  4. Build cgofuse on Linux

    master

    Prerequisites: libfuse-dev, libfuse3-dev, and gcc.

    You can build against the standard FUSE implementation or specifically target FUSE3 using the -tags=fuse3 build tag.

    # Build FUSE
    go install -v ./fuse ./examples/memfs ./examples/passthrough
    
    # Build FUSE3
    go install -tags=fuse3 -v ./fuse ./examples/memfs ./examples/passthrough
  5. Build cgofuse on Windows

    master

    To build cgofuse on Windows, you need WinFsp and a gcc environment (such as Mingw-builds).

    Build with cgo

    Use this method if you want to leverage cgo for performance or specific features. You must set the CPATH to point to the WinFsp fuse include directory.

    Build without cgo (!cgo)

    Use this method by disabling CGO via the CGO_ENABLED=0 environment variable.

    # Build cgo
    set CPATH=C:\Program Files (x86)\WinFsp\inc\fuse
    go install -v ./fuse ./examples/memfs
    
    # Build !cgo
    set CGO_ENABLED=0
    go install -v ./fuse ./examples/memfs
  6. Build cgofuse on FreeBSD

    master

    Prerequisites: fusefs-libs and fusefs-libs3.

    You can build against FUSE or FUSE3 using the -tags=fuse3 build tag.

    Note: To run the resulting file system, you may need to perform the following root-level configuration:

    1. Add fuse_load="YES" to /boot/loader.conf.
    2. Set sysctl vfs.usermount=1 to allow user mounts.
    3. Add your user to the operator group (pw usermod USERNAME -G operator) to allow opening /dev/fuse.
    # Build FUSE
    go install -v ./fuse ./examples/memfs ./examples/passthrough
    
    # Build FUSE3
    go install -tags=fuse3 -v ./fuse ./examples/memfs ./examples/passthrough
  7. Available cgofuse example file systems

    master

    The repository includes several example implementations to demonstrate different capabilities:

    • Hellofs: An extremely simple file system that runs on all operating systems.
    • Memfs: An in-memory file system that runs on all operating systems.
    • Passthrough: A file system that passes all operations to the underlying file system. Runs on all OS'es except Windows.
    • Notifyfs: A file system capable of issuing file change notifications. Runs on Windows only.