go-nfs

golang NFSv3 server

Github星跟蹤圖

Golang Network File Server

NFSv3 protocol implementation in pure Golang.

Current Status:

  • Minimally tested
  • Mounts, read-only and read-write support

Usage

The most interesting demo is currently in example/osview.

Start the server
go run ./example/osview ..

The local folder at . will be the initial view in the mount. mutations to metadata or contents
will be stored purely in memory and not written back to the OS. When run, this
demo will print the port it is listening on.

The mount can be accessed using a command similar to
mount -o port=<n>,mountport=<n> -t nfs localohst:/mount <mountpoint>.

API

The NFS server runs on a net.Listener to export a file system to NFS clients.
Usage is structured similarly to many other golang network servers.

import (
   	"github.com/go-git/go-billy/v5/memfs"

	nfs "github.com/willscott/go-nfs"
	nfshelper "github.com/willscott/go-nfs/helpers"
)

listener, _ := net.Listen("tcp", ":0")
fmt.Printf("Server running at %s\n", listener.Addr())

mem := memfs.New()
f, err := mem.Create("hello.txt")
f.Write([]byte("hello world"))
f.Close()

handler := nfshelper.NewNullAuthHandler(mem)
cacheHelper := nfshelper.NewCachingHandler(handler)
nfs.Serve(listener, cacheHelper)

Notes

  • Ports are typically determined through portmap. The need for running portmap
    (which is the only part that needs a privileged listening port) can be avoided
    through specific mount options. e.g.
    mount -o port=n,mountport=n -t nfs host:/mount /localmount

  • This server currently uses billy to
    provide a file system abstraction layer. There are some edges of the NFS protocol
    which do not translate to this abstraction.

    • NFS expects access to an inode or equivalent unique identifier to reference
      files in a file system. These are considered opaque identifiers here, which
      means they will not work as expected in cases of hard linking.
    • The billy abstraction layer does not extend to exposing uid and gid
      ownership of files. If ownership is important to your file system, you
      will need to ensure that the os.FileInfo meets additional constraints.
      In particular, the Sys() escape hatch is queried by this library, and
      if your file system populates a syscall.Stat_t
      concrete struct, the ownership specified in that object will be used.
  • Relevant RFCS:
    5531 - RPC protocol,
    1813 - NFSv3,
    1094 - NFS

主要指標

概覽
名稱與所有者willscott/go-nfs
主編程語言Go
編程語言Go (語言數: 1)
平台
許可證Apache License 2.0
所有者活动
創建於2020-04-25 17:58:20
推送於2025-02-06 10:48:52
最后一次提交2025-02-06 12:45:01
發布數3
最新版本名稱v0.0.3 (發布於 2025-02-06 11:46:42)
第一版名稱v0.0.1 (發布於 )
用户参与
星數732
關注者數10
派生數78
提交數192
已啟用問題?
問題數49
打開的問題數4
拉請求數69
打開的拉請求數5
關閉的拉請求數16
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?