Documentation
¶
Overview ¶
Package nfs is a read-only NFSv2 server over UDP with the portmap and mount protocols beside it, aimed at clients no modern server still speaks to: an SGI PROM miniroot mounts its install distribution over NFSv2/UDP. No memory-safe userspace NFS-over-UDP server exists, so this is written from the RPCs up. Read only - every write path is refused - which makes it stateless and small.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("no such file") ErrNotDir = errors.New("not a directory") ErrStale = errors.New("stale handle") ErrIO = errors.New("io error") )
Errors an FS returns; each maps to an NFS status code.
Functions ¶
This section is empty.
Types ¶
type Describer ¶
type Describer interface {
Describe() string
}
Describer is optionally implemented by a Node that can render its own path and backing image, for the per-open log line nfsLookup emits when the resolved node is a regular file. An FS whose Node doesn't back onto named media (a test double, say) need not implement it; that log line is simply skipped.
type FS ¶
type FS interface {
// MountRoot resolves a mount path to its root node. A client mounts
// one export; the path chooses which.
MountRoot(path string) (Node, error)
NodeByID(id uint64) (Node, error)
Lookup(dir Node, name string) (Node, error)
ReadDir(dir Node) ([]DirEntry, error)
ReadAt(n Node, p []byte, off int64) (int, error)
Readlink(n Node) (string, error)
}
FS is the tree the server exports. All methods are read-only. Node IDs must be unique across everything the FS can mount, since the ID is the filehandle the client keeps.
type Node ¶
Node is one filesystem object. ID must be stable for the lifetime of the server: it is the filehandle. Mode is a Unix mode with type bits.
type Server ¶
type Server struct {
FS FS
// AllowIP filters clients; nil allows everyone.
AllowIP func(netip.Addr) bool
// Logger, when set, receives leveled log output: DEBUG for every
// RPC call (program, procedure, caller), INFO for a mount and each
// regular file opened (once per LOOKUP that resolves to one, not
// per read/getattr against an already-open handle), WARN for a
// call refused by the client filter. A nil Logger is silent.
Logger *logging.Logger
// contains filtered or unexported fields
}
Server serves the portmap, mount, and NFS protocols over one FS.
func (*Server) ServeMount ¶
func (s *Server) ServeMount(pc net.PacketConn) error
ServeMount answers the mount protocol. Conventionally bound to UDP 635.
func (*Server) ServeNFS ¶
func (s *Server) ServeNFS(pc net.PacketConn) error
ServeNFS answers NFSv2. Conventionally bound to UDP 2049.
func (*Server) ServePortmap ¶
func (s *Server) ServePortmap(pc net.PacketConn) error
ServePortmap answers portmap GETPORT so a client can find mountd and nfsd. Conventionally bound to UDP 111.