Documentation
¶
Index ¶
- Constants
- Variables
- func RegisterMessageHandler(protocol uint32, proc uint32, handler HandleFunc) error
- func Serve(l net.Listener, handler Handler) error
- func SetLogger(logger Logger)
- func WritePostOpAttrs(writer io.Writer, post *FileAttribute) error
- func WriteWcc(writer io.Writer, pre *FileCacheAttribute, post *FileAttribute) error
- type AuthError
- type AuthFlavor
- type AuthStat
- type CachingHandler
- type DefaultLogger
- func (l *DefaultLogger) Debug(args ...interface{})
- func (l *DefaultLogger) Debugf(format string, args ...interface{})
- func (l *DefaultLogger) Error(args ...interface{})
- func (l *DefaultLogger) Errorf(format string, args ...interface{})
- func (l *DefaultLogger) Fatal(args ...interface{})
- func (l *DefaultLogger) Fatalf(format string, args ...interface{})
- func (l *DefaultLogger) GetLevel() LogLevel
- func (l *DefaultLogger) Info(args ...interface{})
- func (l *DefaultLogger) Infof(format string, args ...interface{})
- func (l *DefaultLogger) Panic(args ...interface{})
- func (l *DefaultLogger) Panicf(format string, args ...interface{})
- func (l *DefaultLogger) ParseLevel(level string) (LogLevel, error)
- func (l *DefaultLogger) Print(args ...interface{})
- func (l *DefaultLogger) Printf(format string, args ...interface{})
- func (l *DefaultLogger) SetLevel(level LogLevel)
- func (l *DefaultLogger) Trace(args ...interface{})
- func (l *DefaultLogger) Tracef(format string, args ...interface{})
- func (l *DefaultLogger) Warn(args ...interface{})
- func (l *DefaultLogger) Warnf(format string, args ...interface{})
- type DirOpArg
- type FSStat
- type FileAttribute
- type FileCacheAttribute
- type FileHandle
- type FileTime
- type FileType
- type HandleFunc
- type Handler
- type LogLevel
- type Logger
- type MountProcedure
- type MountRequest
- type MountResponse
- type MountStatus
- type NFSProcedure
- type NFSStatus
- type NFSStatusError
- type RPCError
- type RPCMismatchError
- type ReadDirStreamer
- type ResponseCode
- type ResponseCodeProcUnavailableError
- type ResponseCodeSystemError
- type Server
- type SetFileAttributes
- type StatusErrorWithBody
- type UnixChange
Constants ¶
const ( // FSInfoPropertyLink does the FS support hard links? FSInfoPropertyLink = 0x0001 // FSInfoPropertySymlink does the FS support soft links? FSInfoPropertySymlink = 0x0002 // FSInfoPropertyHomogeneous does the FS need PATHCONF calls for each file FSInfoPropertyHomogeneous = 0x0008 // FSInfoPropertyCanSetTime can the FS support setting access/mod times? FSInfoPropertyCanSetTime = 0x0010 )
const ( FTYPE_NF3REG nfs_ftype = 1 FTYPE_NF3DIR nfs_ftype = 2 FTYPE_NF3BLK nfs_ftype = 3 FTYPE_NF3CHR nfs_ftype = 4 FTYPE_NF3LNK nfs_ftype = 5 FTYPE_NF3SOCK nfs_ftype = 6 FTYPE_NF3FIFO nfs_ftype = 7 )
const CheckRead = 1 << 15
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.
const FHSize = 64
FHSize is the maximum size of a FileHandle
const MNTNameLen = 255
MNTNameLen is the maximum size of a mount name
const MaxRead = 1 << 24
MaxRead is the advertised largest buffer the server is willing to read
const MntPathLen = 1024
MntPathLen is the maximum size of a mount path
const PathNameMax = 255
PathNameMax is the maximum length for a file name
Variables ¶
var ( // ErrInputInvalid is returned when input cannot be parsed ErrInputInvalid = errors.New("invalid input") // ErrAlreadySent is returned when writing a header/status multiple times ErrAlreadySent = errors.New("response already started") )
Functions ¶
func RegisterMessageHandler ¶
func RegisterMessageHandler(protocol uint32, proc uint32, handler HandleFunc) error
RegisterMessageHandler registers a handler for a specific XDR procedure.
func WritePostOpAttrs ¶
func WritePostOpAttrs(writer io.Writer, post *FileAttribute) error
WritePostOpAttrs writes the `post_op_attr` representation of a files attributes
func WriteWcc ¶
func WriteWcc(writer io.Writer, pre *FileCacheAttribute, post *FileAttribute) error
WriteWcc writes the `wcc_data` representation of an object.
Types ¶
type AuthError ¶
type AuthError struct {
AuthStat
}
AuthError is an RPCError
func (*AuthError) Code ¶
func (a *AuthError) Code() ResponseCode
Code for AuthErrors is ResponseCodeAuthError
func (*AuthError) MarshalBinary ¶
MarshalBinary sends the specific auth status
type AuthFlavor ¶
type AuthFlavor uint32
AuthFlavor is a form of authentication, per rfc1057 section 7.2
const ( AuthFlavorNull AuthFlavor = 0 AuthFlavorUnix AuthFlavor = 1 AuthFlavorShort AuthFlavor = 2 AuthFlavorDES AuthFlavor = 3 )
AuthFlavor Codes
type AuthStat ¶
type AuthStat uint32
AuthStat is an enumeration of why authentication ahs failed
const ( AuthStatOK AuthStat = iota AuthStatBadCred AuthStatRejectedCred AuthStatBadVerifier AuthStatRejectedVerfier AuthStatTooWeak AuthStatInvalidResponse AuthStatFailed AuthStatKerbGeneric AuthStatTimeExpire AuthStatTktFile AuthStatDecode AuthStatNetAddr AuthStatRPCGSSCredProblem AuthStatRPCGSSCTXProblem )
AuthStat Codes
type CachingHandler ¶
type CachingHandler interface {
VerifierFor(path string, contents []fs.FileInfo) uint64
// fs.FileInfo needs to be sorted by Name(), nil in case of a cache-miss
DataForVerifier(path string, verifier uint64) []fs.FileInfo
}
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.
type DefaultLogger ¶
type DefaultLogger struct {
Level LogLevel
}
func (*DefaultLogger) Debug ¶
func (l *DefaultLogger) Debug(args ...interface{})
func (*DefaultLogger) Debugf ¶
func (l *DefaultLogger) Debugf(format string, args ...interface{})
func (*DefaultLogger) Error ¶
func (l *DefaultLogger) Error(args ...interface{})
func (*DefaultLogger) Errorf ¶
func (l *DefaultLogger) Errorf(format string, args ...interface{})
func (*DefaultLogger) Fatal ¶
func (l *DefaultLogger) Fatal(args ...interface{})
func (*DefaultLogger) Fatalf ¶
func (l *DefaultLogger) Fatalf(format string, args ...interface{})
func (*DefaultLogger) GetLevel ¶
func (l *DefaultLogger) GetLevel() LogLevel
func (*DefaultLogger) Info ¶
func (l *DefaultLogger) Info(args ...interface{})
func (*DefaultLogger) Infof ¶
func (l *DefaultLogger) Infof(format string, args ...interface{})
func (*DefaultLogger) Panic ¶
func (l *DefaultLogger) Panic(args ...interface{})
func (*DefaultLogger) Panicf ¶
func (l *DefaultLogger) Panicf(format string, args ...interface{})
func (*DefaultLogger) ParseLevel ¶
func (l *DefaultLogger) ParseLevel(level string) (LogLevel, error)
func (*DefaultLogger) Print ¶
func (l *DefaultLogger) Print(args ...interface{})
func (*DefaultLogger) Printf ¶
func (l *DefaultLogger) Printf(format string, args ...interface{})
func (*DefaultLogger) SetLevel ¶
func (l *DefaultLogger) SetLevel(level LogLevel)
func (*DefaultLogger) Trace ¶
func (l *DefaultLogger) Trace(args ...interface{})
func (*DefaultLogger) Tracef ¶
func (l *DefaultLogger) Tracef(format string, args ...interface{})
func (*DefaultLogger) Warn ¶
func (l *DefaultLogger) Warn(args ...interface{})
func (*DefaultLogger) Warnf ¶
func (l *DefaultLogger) Warnf(format string, args ...interface{})
type FSStat ¶
type FSStat struct {
TotalSize uint64
FreeSize uint64
AvailableSize uint64
TotalFiles uint64
FreeFiles uint64
AvailableFiles uint64
// CacheHint is called "invarsec" in the nfs standard
CacheHint time.Duration
}
FSStat returns metadata about a file system
type FileAttribute ¶
type FileAttribute struct {
Type FileType
FileMode uint32
Nlink uint32
UID uint32
GID uint32
Filesize uint64
Used uint64
SpecData [2]uint32
FSID uint64
Fileid uint64
Atime, Mtime, Ctime FileTime
}
FileAttribute holds metadata about a filesystem object
func ToFileAttribute ¶
func ToFileAttribute(info os.FileInfo, filePath string) *FileAttribute
ToFileAttribute creates an NFS fattr3 struct from an OS.FileInfo
func (FileAttribute) AsCache ¶
func (f FileAttribute) AsCache() *FileCacheAttribute
AsCache provides the wcc view of the file attributes
func (*FileAttribute) Mode ¶
func (f *FileAttribute) Mode() os.FileMode
Mode provides the OS interpreted mode of the file attributes
type FileCacheAttribute ¶
FileCacheAttribute is the subset of FileAttribute used by wcc_attr
type FileTime ¶
FileTime is the NFS wire time format This is equivalent to go-nfs-client/nfs.NFS3Time
func (FileTime) EqualTimespec ¶
EqualTimespec returns if this time is equal to a local time spec
type FileType ¶
type FileType uint32
FileType represents a NFS File Type
type HandleFunc ¶
HandleFunc represents a handler for a specific protocol message.
type Handler ¶
type Handler interface {
Mount(context.Context, net.Conn, MountRequest) (MountStatus, billy.Filesystem, []AuthFlavor)
// Change can return 'nil' if filesystem is read-only
// If the returned value can be cast to `UnixChange`, mknod and link RPCs will be available.
Change(billy.Filesystem) billy.Change
// Fill in information about a file system's free space.
FSStat(context.Context, billy.Filesystem, *FSStat) error
// represent file objects as opaque references
// Can be safely implemented via helpers/cachinghandler.
ToHandle(fs billy.Filesystem, path []string) []byte
FromHandle(fh []byte) (billy.Filesystem, []string, error)
InvalidateHandle(billy.Filesystem, []byte) error
// How many handles can be safely maintained by the handler.
HandleLimit() int
}
Handler represents the interface of the file system / vfs being exposed over NFS
type Logger ¶
type Logger interface {
SetLevel(level LogLevel)
GetLevel() LogLevel
ParseLevel(level string) (LogLevel, error)
Panic(args ...interface{})
Fatal(args ...interface{})
Error(args ...interface{})
Warn(args ...interface{})
Info(args ...interface{})
Debug(args ...interface{})
Trace(args ...interface{})
Print(args ...interface{})
Panicf(format string, args ...interface{})
Fatalf(format string, args ...interface{})
Errorf(format string, args ...interface{})
Warnf(format string, args ...interface{})
Infof(format string, args ...interface{})
Debugf(format string, args ...interface{})
Tracef(format string, args ...interface{})
Printf(format string, args ...interface{})
}
var (
Log Logger = &DefaultLogger{}
)
type MountProcedure ¶
type MountProcedure uint32
MountProcedure is the valid RPC calls for the mount service.
const ( MountProcNull MountProcedure = iota MountProcMount MountProcDump MountProcUmnt MountProcUmntAll MountProcExport )
MountProcedure Codes
func (MountProcedure) String ¶
func (m MountProcedure) String() string
type MountRequest ¶
MountRequest contains the format of a client request to open a mount.
type MountResponse ¶
type MountResponse struct {
rpc.Header
FileHandle
AuthFlavors []int
}
MountResponse is the server's response with status `MountStatusOk`
type MountStatus ¶
type MountStatus uint32
MountStatus defines the response to the Mount Procedure
const ( MountStatusOk MountStatus = 0 MountStatusErrPerm MountStatus = 1 MountStatusErrNoEnt MountStatus = 2 MountStatusErrIO MountStatus = 5 MountStatusErrAcces MountStatus = 13 MountStatusErrNotDir MountStatus = 20 MountStatusErrInval MountStatus = 22 MountStatusErrNameTooLong MountStatus = 63 MountStatusErrNotSupp MountStatus = 10004 MountStatusErrServerFault MountStatus = 10006 )
MountStatus Codes
type NFSProcedure ¶
type NFSProcedure uint32
NFSProcedure is the valid RPC calls for the nfs service.
const ( NFSProcedureNull NFSProcedure = iota NFSProcedureGetAttr NFSProcedureSetAttr NFSProcedureLookup NFSProcedureAccess NFSProcedureReadlink NFSProcedureRead NFSProcedureWrite NFSProcedureCreate NFSProcedureMkDir NFSProcedureSymlink NFSProcedureMkNod NFSProcedureRemove NFSProcedureRmDir NFSProcedureRename NFSProcedureLink NFSProcedureReadDir NFSProcedureReadDirPlus NFSProcedureFSStat NFSProcedureFSInfo NFSProcedurePathConf NFSProcedureCommit )
NfsProcedure Codes
func (NFSProcedure) String ¶
func (n NFSProcedure) String() string
type NFSStatus ¶
type NFSStatus uint32
NFSStatus (nfsstat3) is a result code for nfs rpc calls
const ( NFSStatusOk NFSStatus = 0 NFSStatusPerm NFSStatus = 1 NFSStatusNoEnt NFSStatus = 2 NFSStatusIO NFSStatus = 5 NFSStatusNXIO NFSStatus = 6 NFSStatusAccess NFSStatus = 13 NFSStatusExist NFSStatus = 17 NFSStatusXDev NFSStatus = 18 NFSStatusNoDev NFSStatus = 19 NFSStatusNotDir NFSStatus = 20 NFSStatusIsDir NFSStatus = 21 NFSStatusInval NFSStatus = 22 NFSStatusFBig NFSStatus = 27 NFSStatusNoSPC NFSStatus = 28 NFSStatusROFS NFSStatus = 30 NFSStatusMlink NFSStatus = 31 NFSStatusNameTooLong NFSStatus = 63 NFSStatusNotEmpty NFSStatus = 66 NFSStatusDQuot NFSStatus = 69 NFSStatusStale NFSStatus = 70 NFSStatusRemote NFSStatus = 71 NFSStatusBadHandle NFSStatus = 10001 NFSStatusNotSync NFSStatus = 10002 NFSStatusBadCookie NFSStatus = 10003 NFSStatusNotSupp NFSStatus = 10004 NFSStatusTooSmall NFSStatus = 10005 NFSStatusServerFault NFSStatus = 10006 NFSStatusBadType NFSStatus = 10007 NFSStatusJukebox NFSStatus = 10008 )
NFSStatus codes
type NFSStatusError ¶
NFSStatusError represents an error at the NFS level.
func (*NFSStatusError) Code ¶
func (s *NFSStatusError) Code() ResponseCode
Code for NFS issues are successful RPC responses
func (*NFSStatusError) MarshalBinary ¶
func (s *NFSStatusError) MarshalBinary() (data []byte, err error)
MarshalBinary - The binary form of the code.
func (*NFSStatusError) Unwrap ¶
func (s *NFSStatusError) Unwrap() error
Unwrap unpacks wrapped errors
type RPCError ¶
type RPCError interface {
// An RPCError is an `error` with this method
Error() string
// Code is the RPC Response code to send
Code() ResponseCode
// BinaryMarshaler is the on-wire representation of this error
encoding.BinaryMarshaler
}
RPCError provides the error interface for errors thrown by procedures to be transmitted over the XDR RPC channel
type RPCMismatchError ¶
RPCMismatchError is an RPCError
func (*RPCMismatchError) Code ¶
func (r *RPCMismatchError) Code() ResponseCode
Code for RPCMismatchError is ResponseCodeRPCMismatch
func (*RPCMismatchError) Error ¶
func (r *RPCMismatchError) Error() string
func (*RPCMismatchError) MarshalBinary ¶
func (r *RPCMismatchError) MarshalBinary() (data []byte, err error)
MarshalBinary sends the specific rpc mismatch range
type ReadDirStreamer ¶
type ReadDirStreamer interface {
// ReadDirStream returns a page of directory entries for the given path.
//
// Parameters:
// - fs: The billy.Filesystem for this mount
// - path: Directory path components (e.g., ["dir", "subdir"])
// - cookie: Opaque pagination token from previous call (0 for first request)
// - count: Suggested maximum entries to return
//
// Returns:
// - entries: Directory entries for this page (may be fewer than count)
// - verifier: Cookie verifier for directory change detection (0 to disable)
// - nextCookie: Token for next page (0 indicates this is the last page)
// - err: Any error encountered
//
// Cookie semantics:
// - Cookie 0 always means "start from beginning"
// - Cookie values are opaque to go-nfs but must be less than 2^63
// (bit 63 is reserved internally for synthetic NFS cookies)
// - Returning nextCookie=0 signals end of directory (EOF)
//
// When cookie is 0, go-nfs will prepend "." and ".." entries automatically.
// Implementations should NOT include "." and ".." in their returned entries.
//
// Error handling:
// - Return &NFSStatusError{NFSStatusBadCookie, err} if cookie is invalid/stale
// - Return &NFSStatusError{NFSStatusIO, err} for backend errors
// - Return &NFSStatusError{NFSStatusNoEnt, err} if directory doesn't exist
//
// Ordering note: go-nfs calls ReadDirStream before validating the cookie
// verifier (because the verifier comes from this method's return value).
// If the verifier check then fails, the response is discarded. This means
// any state consumed during the call (e.g., continuation tokens) is lost.
// Implementations should make state consumption recoverable — for example,
// by deferring deletion of continuation tokens until after the page is
// successfully served, or by allowing tokens to be re-fetched.
ReadDirStream(
fs billy.Filesystem,
path []string,
cookie uint64,
count int,
) (entries []os.FileInfo, verifier uint64, nextCookie uint64, err error)
}
ReadDirStreamer is an optional interface that handlers can implement to support paginated directory listing. When implemented, go-nfs will use this instead of billy.Filesystem.ReadDir() for READDIR and READDIRPLUS operations.
This enables efficient handling of directories with millions of files by streaming entries directly from the backend (e.g., S3 ListObjectsV2) without buffering the entire listing in memory.
Handlers that do not implement this interface will continue to use the existing behavior of calling ReadDir() and paginating in memory.
type ResponseCode ¶
type ResponseCode uint32
ResponseCode is a combination of accept_stat and reject_stat.
const ( ResponseCodeSuccess ResponseCode = iota ResponseCodeGarbageArgs ResponseCodeSystemErr ResponseCodeRPCMismatch ResponseCodeAuthError )
ResponseCode Codes
type ResponseCodeProcUnavailableError ¶
type ResponseCodeProcUnavailableError struct {
}
ResponseCodeProcUnavailableError is an RPCError
func (*ResponseCodeProcUnavailableError) Code ¶
func (r *ResponseCodeProcUnavailableError) Code() ResponseCode
Code for ResponseCodeProcUnavailableError
func (*ResponseCodeProcUnavailableError) Error ¶
func (r *ResponseCodeProcUnavailableError) Error() string
func (*ResponseCodeProcUnavailableError) MarshalBinary ¶
func (r *ResponseCodeProcUnavailableError) MarshalBinary() (data []byte, err error)
MarshalBinary - this error has no associated body
type ResponseCodeSystemError ¶
type ResponseCodeSystemError struct {
}
ResponseCodeSystemError is an RPCError
func (*ResponseCodeSystemError) Code ¶
func (r *ResponseCodeSystemError) Code() ResponseCode
Code for ResponseCodeSystemError
func (*ResponseCodeSystemError) Error ¶
func (r *ResponseCodeSystemError) Error() string
func (*ResponseCodeSystemError) MarshalBinary ¶
func (r *ResponseCodeSystemError) MarshalBinary() (data []byte, err error)
MarshalBinary - this error has no associated body
type SetFileAttributes ¶
type SetFileAttributes struct {
SetMode *uint32
SetUID *uint32
SetGID *uint32
SetSize *uint64
SetAtime *time.Time
SetMtime *time.Time
}
SetFileAttributes represents a command to update some metadata about a file.
func ReadSetFileAttributes ¶
func ReadSetFileAttributes(r io.Reader) (*SetFileAttributes, error)
ReadSetFileAttributes reads an sattr3 xdr stream into a go struct.
func (*SetFileAttributes) Apply ¶
func (s *SetFileAttributes) Apply(changer billy.Change, fs billy.Filesystem, file string) error
Apply uses a `Change` implementation to set defined attributes on a provided file.
type StatusErrorWithBody ¶
type StatusErrorWithBody struct {
NFSStatusError
Body []byte
}
StatusErrorWithBody is an NFS error with a payload.
func (*StatusErrorWithBody) MarshalBinary ¶
func (s *StatusErrorWithBody) MarshalBinary() (data []byte, err error)
MarshalBinary provides the wire format of the error response
type UnixChange ¶
type UnixChange interface {
billy.Change
Mknod(path string, mode uint32, major uint32, minor uint32) error
Mkfifo(path string, mode uint32) error
Socket(path string) error
Link(path string, link string) error
}
UnixChange extends the billy `Change` interface with support for special files.
Source Files
¶
- conn.go
- errors.go
- file.go
- filesystem.go
- handler.go
- log.go
- mount.go
- mountinterface.go
- nfs.go
- nfs_onaccess.go
- nfs_oncommit.go
- nfs_oncreate.go
- nfs_onfsinfo.go
- nfs_onfsstat.go
- nfs_ongetattr.go
- nfs_onlink.go
- nfs_onlookup.go
- nfs_onmkdir.go
- nfs_onmknod.go
- nfs_onpathconf.go
- nfs_onread.go
- nfs_onreaddir.go
- nfs_onreaddirplus.go
- nfs_onreadlink.go
- nfs_onremove.go
- nfs_onrename.go
- nfs_onrmdir.go
- nfs_onsetattr.go
- nfs_onsymlink.go
- nfs_onwrite.go
- nfsinterface.go
- server.go
- streaming.go
- time.go