Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

golang NFSv3 server

License

NotificationsYou must be signed in to change notification settings

willscott/go-nfs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NFSv3 protocol implementation in pure Golang.

Current Status:

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

Usage

The most interesting demo is currently inexample/osview.

Start the servergo run ./example/osview ..

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

The mount can be accessed using a command similar tomount -o port=<n>,mountport=<n> -t nfs localhost:/mount <mountpoint> (For Mac users)

or

mount -o port=<n>,mountport=<n>,nfsvers=3,noacl,tcp -t nfs localhost:/mount <mountpoint> (For Linux users)

API

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

package mainimport ("fmt""log""net""github.com/go-git/go-billy/v5/memfs"nfs"github.com/willscott/go-nfs"nfshelper"github.com/willscott/go-nfs/helpers")funcmain() {listener,err:=net.Listen("tcp",":0")panicOnErr(err,"starting TCP listener")fmt.Printf("Server running at %s\n",listener.Addr())mem:=memfs.New()f,err:=mem.Create("hello.txt")panicOnErr(err,"creating file")_,err=f.Write([]byte("hello world"))panicOnErr(err,"writing data")f.Close()handler:=nfshelper.NewNullAuthHandler(mem)cacheHelper:=nfshelper.NewCachingHandler(handler,1)panicOnErr(nfs.Serve(listener,cacheHelper),"serving nfs")}funcpanicOnErr(errerror,desc...interface{}) {iferr==nil {return}log.Println(desc...)log.Panicln(err)}

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 avoidedthrough specific mount options. e.g.mount -o port=n,mountport=n -t nfs host:/mount /localmount

  • This server currently usesbilly toprovide a file system abstraction layer. There are some edges of the NFS protocolwhich do not translate to this abstraction.

    • NFS expects access to aninode or equivalent unique identifier to referencefiles in a file system. These are considered opaque identifiers here, whichmeans they will not work as expected in cases of hard linking.
    • The billy abstraction layer does not extend to exposinguid andgidownership of files. If ownership is important to your file system, youwill need to ensure that theos.FileInfo meets additional constraints.In particular, theSys() escape hatch is queried by this library, andif your file system populates asyscall.Stat_tconcrete struct, the ownership specified in that object will be used.You can also return afile.FileInfowhich doesn't vary between platforms so may be easier to deal with.
  • Relevant RFCS:5531 - RPC protocol,1813 - NFSv3,1094 - NFS


[8]ページ先頭

©2009-2025 Movatter.jp