Documentation
¶
Index ¶
- Constants
- Variables
- func CapabilityCheck(fs Filesystem, cap billy.Capability) bool
- 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 Change
- 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 File
- type FileAttribute
- type FileCacheAttribute
- type FileHandle
- type FileTime
- type FileType
- type Filesystem
- 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 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 CapabilityCheck ¶
func CapabilityCheck(fs Filesystem, cap billy.Capability) bool
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 Change ¶
type Change interface { // Chmod changes the mode of the named file to mode. If the file is a // symbolic link, it changes the mode of the link's target. Chmod(ctx context.Context, name string, mode os.FileMode) error // Lchown changes the numeric uid and gid of the named file. If the file is // a symbolic link, it changes the uid and gid of the link itself. Lchown(ctx context.Context, name string, uid, gid int) error // Chtimes changes the access and modification times of the named file, // similar to the Unix utime() or utimes() functions. // // The underlying filesystem may truncate or round the values to a less // precise time unit. Chtimes(ctx context.Context, name string, atime time.Time, mtime time.Time) error }
Change abstract the FileInfo change related operations in a storage-agnostic interface as an extension to the Basic interface
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 Filesystem ¶
type Filesystem interface { // Create creates the named file with mode 0666 (before umask), truncating // it if it already exists. If successful, methods on the returned File can // be used for I/O; the associated file descriptor has mode O_RDWR. Create(ctx context.Context, filename string) (File, error) // OpenFile is the generalized open call; most users will use Open or Create // instead. It opens the named file with specified flag (O_RDONLY etc.) and // perm, (0666 etc.) if applicable. If successful, methods on the returned // File can be used for I/O. OpenFile(ctx context.Context, filename string, flag int, perm os.FileMode) (File, error) // Stat returns a FileInfo describing the named file. Stat(ctx context.Context, filename string) (os.FileInfo, error) // Rename renames (moves) oldpath to newpath. If newpath already exists and // is not a directory, Rename replaces it. OS-specific restrictions may // apply when oldpath and newpath are in different directories. Rename(ctx context.Context, oldpath, newpath string) error // Remove removes the named file or directory. Remove(ctx context.Context, filename string) error // Join joins any number of path elements into a single path, adding a // Separator if necessary. Join calls filepath.Clean on the result; in // particular, all empty strings are ignored. On Windows, the result is a // UNC path if and only if the first path element is a UNC path. Join(elem ...string) string // ReadDir reads the directory named by d(irname and returns a list of // directory entries sorted by filename. ReadDir(ctx context.Context, path string) ([]os.FileInfo, error) // MkdirAll creates a directory named path, along with any necessary // parents, and returns nil, or else returns an error. The permission bits // perm are used for all directories that MkdirAll creates. If path is/ // already a directory, MkdirAll does nothing and returns nil. MkdirAll(ctx context.Context, filename string, perm os.FileMode) error // Lstat returns a FileInfo describing the named file. If the file is a // symbolic link, the returned FileInfo describes the symbolic link. Lstat // makes no attempt to follow the link. Lstat(ctx context.Context, filename string) (os.FileInfo, error) // Symlink creates a symbolic-link from link to target. target may be an // absolute or relative path, and need not refer to an existing node. // Parent directories of link are created as necessary. Symlink(ctx context.Context, target, link string) error // Readlink returns the target path of link. Readlink(ctx context.Context, link string) (string, error) }
type HandleFunc ¶
HandleFunc represents a handler for a specific protocol message.
type Handler ¶
type Handler interface { Mount(context.Context, net.Conn, MountRequest) (MountStatus, 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(Filesystem) Change // Fill in information about a file system's free space. FSStat(context.Context, Filesystem, *FSStat) error // represent file objects as opaque references // Can be safely implemented via helpers/cachinghandler. ToHandle(ctx context.Context, fs Filesystem, path []string) []byte FromHandle(ctx context.Context, fh []byte) (Filesystem, []string, error) InvalidateHandle(context.Context, 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 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(ctx context.Context, changer Change, fs 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 { ctxbilly.Change Mknod(ctx context.Context, path string, mode uint32, major uint32, minor uint32) error Mkfifo(ctx context.Context, path string, mode uint32) error Socket(ctx context.Context, path string) error Link(ctx context.Context, path string, link string) error }
UnixChange extends the billy `Change` interface with support for special files.
Source Files
¶
- capability_check.go
- 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
- time.go