fusebox

package module
v0.0.0-...-6667b10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2018 License: BSD-3-Clause-Clear Imports: 10 Imported by: 1

README

FUSEBox

A golang library for exposing variables through a FUSE filesystem.

Why?

This was taken from https://github.com/danielthatcher/proxyfs in case it's ever useful again.

Status

This is currently in early development, and may change significantly.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEmptyFS

func NewEmptyFS() (*FS, *Dir)

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) AddNode

func (d *Dir) AddNode(name string, node fs.Node) error

AddNode adds a node to the directory.

func (*Dir) Attr

func (d *Dir) Attr(ctx context.Context, attr *fuse.Attr) error

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) Node

func (d *Dir) Node() VarNode

Node is implemented to implement the VarNodeable interface.

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

func (d *Dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error)

ReadDirAll returns a []fuse.Dirent representing all nodes in the Dir.

func (*Dir) Remove

func (d *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) error

Remove handles a request from the filesystem to remove a given node, passing the request through to the Dir's element

func (*Dir) RemoveNode

func (d *Dir) RemoveNode(k string) bool

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.

func (*FS) Mount

func (f *FS) Mount(path string) error

Mount mounts the filesystem at the given path.

Unmounting can be done with fuse.Unmount.

func (*FS) Root

func (f *FS) Root() (fs.Node, error)

Root returns the root directory of the filesystem

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

func NewBoolFile(b *bool) *File

NewBoolFile returns a File based on a FileElement which reads and writes to the given bool pointer.

func NewBytePipeFile

func NewBytePipeFile(c chan []byte) *File

NewBytePipeFile returns a File that has an element which reads and writes bytes to a channel with blocking.

func NewChanFile

func NewChanFile(c chan int) *File

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

func NewInt64File(i *int64) *File

NewInt64File returns a new File which has an element that reads and updates the given int64 pointer appropriately.

func NewIntFile

func NewIntFile(i *int) *File

NewIntFile returns a new file with an Element which reads and updates the given int pointer.

func NewRegexpFile

func NewRegexpFile(r *regexp.Regexp) *File

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

func NewStringFile(s *string) *File

NewStringFile returns a File which has an element that reads from and writes to the given string pointer.

func NewURLFile

func NewURLFile(u *url.URL) *File

NewURLFile returns a File which has an element that reads from and updats the given url.URL pointer appropriately.

func (*File) Attr

func (f *File) Attr(ctx context.Context, attr *fuse.Attr) error

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) Fsync

func (*File) Fsync(ctx context.Context, req *fuse.FsyncRequest) error

Fsync is implemented to implement the fs.NodeFsyncer interface

func (*File) Node

func (f *File) Node() VarNode

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL