Documentation ¶
Index ¶
- func NewEmptyFS() (*FS, *Dir)
- type Dir
- func (d *Dir) AddNode(name string, node fs.Node) error
- func (d *Dir) Attr(ctx context.Context, attr *fuse.Attr) error
- func (*Dir) DirentType() fuse.DirentType
- func (d *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.LookupResponse) (fs.Node, error)
- func (d *Dir) Node() VarNode
- func (d *Dir) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error)
- func (*Dir) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error
- func (d *Dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error)
- func (d *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) error
- func (d *Dir) RemoveNode(k string) bool
- func (*Dir) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error
- type DirElement
- type FS
- type File
- func NewBoolFile(b *bool) *File
- func NewBytePipeFile(c chan []byte) *File
- func NewChanFile(c chan int) *File
- func NewFile(e FileElement) *File
- func NewInt64File(i *int64) *File
- func NewIntFile(i *int) *File
- func NewRegexpFile(r *regexp.Regexp) *File
- func NewStringFile(s *string) *File
- func NewURLFile(u *url.URL) *File
- func (f *File) Attr(ctx context.Context, attr *fuse.Attr) error
- func (f *File) DirentType() fuse.DirentType
- func (*File) Fsync(ctx context.Context, req *fuse.FsyncRequest) error
- func (f *File) Node() VarNode
- func (f *File) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error)
- func (f *File) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error
- func (f *File) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error
- type FileElement
- type VarNode
- type VarNodeable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewEmptyFS ¶
NewEmptyFS returns a FS and the empty dir that is its root node. The resulting filesystem is the same as the one returned by NewFS(NewEmptyDir())
Types ¶
type Dir ¶
type Dir struct { // The directory's mode Mode os.FileMode // The flags used for in the response for fs.Open OpenFlags fuse.OpenResponseFlags Element DirElement // contains filtered or unexported fields }
Dir represents a directory in the filesystem. It contains subnodes of type fs.Node, usually Dir or VarNode.
func NewDir ¶
func NewDir(e DirElement) *Dir
NewDir creates a new directoy based on the given DirElement. This DirElement is used to provide information on the contained nodes.
func NewEmptyDir ¶
func NewEmptyDir() *Dir
NewEmptyDir returns an empty directory. This is equivalent to calling NewMapDir with an empty map.
func NewMapDir ¶
func NewMapDir(nodes map[string]VarNodeable) *Dir
NewMapDir returns a Dir which takes its nodes names and values from the keys and elements of the given map.
When adding a node, if it the given name already exists in the map, it will be overwritten.
func NewSliceDir ¶
func NewSliceDir(nodes *[]VarNodeable) *Dir
NewSliceDir a new Dir containing elements from the given slice. Elements are denoted by index in the list.
When adding a node to the returned Dir, if the given name is empty then the node is appended to the slice, otherwise if it is a string containing an integer, it will overwrite the element at that index.
func (*Dir) Attr ¶
Attr is implemented to comply with the fs.Node interface. It sets the mode in the filesystem to the value of Dir.Mode
func (*Dir) DirentType ¶
func (*Dir) DirentType() fuse.DirentType
DirentType indcates that this is a directory.
func (*Dir) Lookup ¶
func (d *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.LookupResponse) (fs.Node, error)
Lookup returns the node corresponding to the given name if it exists.
func (*Dir) Open ¶
func (d *Dir) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error)
Open returns the Dir as the handle, setting the response flags with Dir.OpenFlags
func (*Dir) Read ¶
func (*Dir) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error
Read returns fuse.EPERM for Dir.
func (*Dir) ReadDirAll ¶
ReadDirAll returns a []fuse.Dirent representing all nodes in the Dir.
func (*Dir) Remove ¶
Remove handles a request from the filesystem to remove a given node, passing the request through to the Dir's element
func (*Dir) RemoveNode ¶
RemoveNode removes a node from the dir, and returns whether the node originally existed.
func (*Dir) Write ¶
func (*Dir) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error
Cannot write directly to a directory.
type DirElement ¶
type DirElement interface { // GetNode should return a VarNode if the given key is valid, otherwise an // error that is passed in the return value to Dir.Lookup GetNode(ctx context.Context, k string) (VarNode, error) // Should return the dirent type for the node with the given key. If the key // is invalid, then an approriate error should be returned. GetDirentType(ctx context.Context, k string) (fuse.DirentType, error) // Should return a slice of all the valid keys GetKeys(ctx context.Context) []string // AddNode and RemoveNode should attempt to add and remove a node to the //given dir. If this fails, and error should be returned. AddNode(name string, node interface{}) error RemoveNode(name string) error }
The DirElement interface is used by a dir to interact with the underlying data.
type FS ¶
type FS struct { RootNode VarNodeable Name string // contains filtered or unexported fields }
FS represents a filesystem that can be mounted to expose its root directory.
func NewFS ¶
func NewFS(root VarNodeable) *FS
NewFS returns a new filesystem with the given root directory.
type File ¶
type File struct { // The file mode. Mode os.FileMode // The flages returned for Open OpenFlags fuse.OpenResponseFlags // A channel that is written to when the value is updated to notify of // a change. Change chan int // A lock used to synchronise reads/writes Lock *sync.RWMutex // The Element is used to interact with the underlying data. Element FileElement }
File represents a file in the virtualfilesystem. Reading and writing is handled by the ValRead and ValWrite functions, which normally read and write to an underlying go variable. It should be possible to read from the Change channel whenever the data is changed.
func NewBoolFile ¶
NewBoolFile returns a File based on a FileElement which reads and writes to the given bool pointer.
func NewBytePipeFile ¶
NewBytePipeFile returns a File that has an element which reads and writes bytes to a channel with blocking.
func NewChanFile ¶
NewChanFile returns a File which writes an arbitrary int down the given channel whenever it is written to.
func NewFile ¶
func NewFile(e FileElement) *File
NewFile returns a new file based on the given FileElement. This FileElement is used to read and write data from.
func NewInt64File ¶
NewInt64File returns a new File which has an element that reads and updates the given int64 pointer appropriately.
func NewIntFile ¶
NewIntFile returns a new file with an Element which reads and updates the given int pointer.
func NewRegexpFile ¶
NewRegexpFile returns a File which has an element that displays the given regexp.Regexp as a string on reads, and attempts to compile and modify it upon writes
func NewStringFile ¶
NewStringFile returns a File which has an element that reads from and writes to the given string pointer.
func NewURLFile ¶
NewURLFile returns a File which has an element that reads from and updats the given url.URL pointer appropriately.
func (*File) Attr ¶
Attr returns the attributes of the file. These are displayed to the filesystem, and should usually be enforced. This is implemented to implement the fs.Node interface.
func (*File) DirentType ¶
func (f *File) DirentType() fuse.DirentType
DirentType will return fuse.DT_File for File. This is implemented to implement the VarNode interface.
func (*File) Node ¶
Node returns the File itself. It is implemented to implement the VarNodeable interface.
func (*File) Open ¶
func (f *File) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error)
Open returns the File as the handle, as well as setting and OpenFlags in the response.
func (*File) Read ¶
func (f *File) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error
Read returns all the data from the File's element by calling its ValRead function. This function also makes a RLock and RUnlock calls to the Lock, as well as checking the permissions from the value of Mode.
func (*File) Write ¶
func (f *File) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error
Write writes the data to the File's element by calling its ValWrite function. If the Change channel is not empty, a value is sent through it to signal a change in the data to any listening routines. This function also makes Lock and Unlock calls to the Lock, as well as checking permissions from the value of Mode.
type FileElement ¶
type FileElement interface { // ValRead should return the value of the underlying data converted to // []byte, and any errors. ctx is passed in from Read, and the return // value is used as the return value of Read. // // This function is intended to be masked by any struct that embeds File. ValRead(ctx context.Context) ([]byte, error) // ValWrite should modify the underlying data from the data given in req, as // well as setting resp.Size to reflect how much data was written. The // arguments are passed in from Write, and the return value is used as the // return value of Write. // // This function is intended to be masked by any structs that embed File. ValWrite(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error // Size should return the length of the underlyig data in the format in // which it will be displayted Size(ctx context.Context) (uint64, error) }
The FileElement interface is used by File to interact with the underlying data.
type VarNode ¶
type VarNode interface { fs.Node fs.HandleReader fs.HandleWriter }
VarNode represent a node in the filesystem which expose a variable. These can be any kind of node in the filesystem.
type VarNodeable ¶
type VarNodeable interface { // Node should return a VarNode that can be mounted in the filesystem and used // to expose the underlying data. Node() VarNode // DirentType should return a fuse.DirentType representing how the VarNode // returned from Node() should be represented in the filesystem. DirentType() fuse.DirentType }
VarNodeable exposes a Node and DirentType functions to return a VarNode and the type of this node in the filesystem respectively.