Categorygithub.com/blacknon/go-nfs-sshlib
modulepackage
0.0.3
Repository: https://github.com/blacknon/go-nfs-sshlib.git
Documentation: pkg.go.dev

# README

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 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 a net.Listener to export a file system to NFS clients. Usage is structured similarly to many other golang network servers.

package main

import (
	"fmt"
	"log"
	"net"

	"github.com/go-git/go-billy/v5/memfs"
	nfs "github.com/willscott/go-nfs"
	nfshelper "github.com/willscott/go-nfs/helpers"
)

func main() {
	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")
}

func panicOnErr(err error, desc ...interface{}) {
	if err == 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 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

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

ReadSetFileAttributes reads an sattr3 xdr stream into a go struct.
RegisterMessageHandler registers a handler for a specific XDR procedure.
Serve is a singleton listener paralleling http.Serve.
No description provided by the author
ToFileAttribute creates an NFS fattr3 struct from an OS.FileInfo.
ToNFSTime generates the nfs 64bit time format from a golang time.
WritePostOpAttrs writes the `post_op_attr` representation of a files attributes.
WriteWcc writes the `wcc_data` representation of an object.

# Constants

AuthFlavor Codes.
AuthFlavor Codes.
AuthFlavor Codes.
AuthFlavor Codes.
AuthStat Codes.
AuthStat Codes.
AuthStat Codes.
AuthStat Codes.
AuthStat Codes.
AuthStat Codes.
AuthStat Codes.
AuthStat Codes.
AuthStat Codes.
AuthStat Codes.
AuthStat Codes.
AuthStat Codes.
AuthStat Codes.
AuthStat Codes.
AuthStat Codes.
CheckRead is a size where - if a request to read is larger than this, the server will stat the file to learn it's actual size before allocating a buffer to read into.
No description provided by the author
No description provided by the author
No description provided by the author
FHSize is the maximum size of a FileHandle.
Enumeration of NFS FileTypes.
Enumeration of NFS FileTypes.
Enumeration of NFS FileTypes.
Enumeration of NFS FileTypes.
Enumeration of NFS FileTypes.
Enumeration of NFS FileTypes.
Enumeration of NFS FileTypes.
FSInfoPropertyCanSetTime can the FS support setting access/mod times?.
FSInfoPropertyHomogeneous does the FS need PATHCONF calls for each file.
FSInfoPropertyLink does the FS support hard links?.
FSInfoPropertySymlink does the FS support soft links?.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
MaxRead is the advertised largest buffer the server is willing to read.
MNTNameLen is the maximum size of a mount name.
MntPathLen is the maximum size of a mount path.
MountProcedure Codes.
MountProcedure Codes.
MountProcedure Codes.
MountProcedure Codes.
MountProcedure Codes.
MountProcedure Codes.
MountStatus Codes.
MountStatus Codes.
MountStatus Codes.
MountStatus Codes.
MountStatus Codes.
MountStatus Codes.
MountStatus Codes.
MountStatus Codes.
MountStatus Codes.
MountStatus Codes.
NfsProcedure Codes.
NfsProcedure Codes.
NfsProcedure Codes.
NfsProcedure Codes.
NfsProcedure Codes.
NfsProcedure Codes.
NfsProcedure Codes.
NfsProcedure Codes.
NfsProcedure Codes.
NfsProcedure Codes.
NfsProcedure Codes.
NfsProcedure Codes.
NfsProcedure Codes.
NfsProcedure Codes.
NfsProcedure Codes.
NfsProcedure Codes.
NfsProcedure Codes.
NfsProcedure Codes.
NfsProcedure Codes.
NfsProcedure Codes.
NfsProcedure Codes.
NfsProcedure Codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
NFSStatus codes.
No description provided by the author
PathNameMax is the maximum length for a file name.
ResponseCode Codes.
ResponseCode Codes.
ResponseCode Codes.
ResponseCode Codes.
ResponseCode Codes.
ResponseCode Codes.
ResponseCode Codes.
No description provided by the author
No description provided by the author

# Variables

ErrAlreadySent is returned when writing a header/status multiple times.
ErrInputInvalid is returned when input cannot be parsed.
No description provided by the author

# Structs

AuthError is an RPCError.
No description provided by the author
DirOpArg is a common serialization used for referencing an object in a directory.
FileAttribute holds metadata about a filesystem object.
FileCacheAttribute is the subset of FileAttribute used by wcc_attr.
FileTime is the NFS wire time format This is equivalent to go-nfs-client/nfs.NFS3Time.
FSStat returns metadata about a file system.
MountRequest contains the format of a client request to open a mount.
MountResponse is the server's response with status `MountStatusOk`.
NFSStatusError represents an error at the NFS level.
ResponseCodeProcUnavailableError is an RPCError.
ResponseCodeSystemError is an RPCError.
RPCMismatchError is an RPCError.
Server is a handle to the listening NFS server.
SetFileAttributes represents a command to update some metadata about a file.
StatusErrorWithBody is an NFS error with a payload.

# Interfaces

CachingHandler represents the optional caching work that a user may wish to over-ride with their own implementations, but which can be otherwise provided through defaults.
Handler represents the interface of the file system / vfs being exposed over NFS.
No description provided by the author
RPCError provides the error interface for errors thrown by procedures to be transmitted over the XDR RPC channel.
UnixChange extends the billy `Change` interface with support for special files.

# Type aliases

AuthFlavor is a form of authentication, per rfc1057 section 7.2.
AuthStat is an enumeration of why authentication ahs failed.
FileHandle maps to a fhandle3.
FileType represents a NFS File Type.
HandleFunc represents a handler for a specific protocol message.
No description provided by the author
MountProcedure is the valid RPC calls for the mount service.
MountStatus defines the response to the Mount Procedure.
NFSProcedure is the valid RPC calls for the nfs service.
NFSStatus (nfsstat3) is a result code for nfs rpc calls.
ResponseCode is a combination of accept_stat and reject_stat.