sisyphus

package module
v0.0.0-...-74fbc30 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

README

Gopherbrick

sisyphus provides tools to build a simple user FUSE-based sysfs-like interface

Build Status Coverage Status GoDoc

Documentation

Overview

Package sisyphus provides tools to build a simple user FUSE-based sysfs-like interface.

Index

Constants

This section is empty.

Variables

View Source
var ErrBadName = errors.New("sisyphus: base contains filepath separator")

ErrBadName is returned when a new Node is created with a base name that contains a filepath separator.

Functions

func Serve

func Serve(mnt string, filesys *FileSystem, config *fs.Config, mntopts ...fuse.MountOption) (io.Closer, error)

Serve starts a server for filesys mounted at the specified mount point. It is the responsibility of the caller to close the returned io.Closer when the server is no longer required.

Types

type Bytes

type Bytes []byte

Bytes is a ReadWriter backed by a byte slice.

func NewBytes

func NewBytes(data []byte) *Bytes

NewBytes returns a new Bytes backed by the provided data.

func (*Bytes) ReadAt

func (f *Bytes) ReadAt(b []byte, offset int64) (int, error)

ReadAt satisfies the io.ReaderAt interface.

func (*Bytes) Size

func (f *Bytes) Size() (int64, error)

Size returns the length of the backing data and a nil error.

func (*Bytes) Truncate

func (f *Bytes) Truncate(n int64) error

Truncate truncates the Bytes at n bytes from the beginning of the slice.

func (*Bytes) WriteAt

func (f *Bytes) WriteAt(b []byte, off int64) (int, error)

WriteAt satisfies the io.WriterAt interface.

type Dir

type Dir struct {
	// contains filtered or unexported fields
}

Dir is a directory node.

func MustNewDir

func MustNewDir(name string, mode os.FileMode) *Dir

MustNewDir returns a new Dir with the given name and file mode. It will panic if name contains a filepath separator unless name is "/".

func NewDir

func NewDir(name string, mode os.FileMode) (*Dir, error)

NewDir returns a new Dir with the given name and file mode.

func (*Dir) Attr

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

Attr satisfies the bazil.org/fuse/fs.Node interface.

func (*Dir) Invalidate

func (d *Dir) Invalidate() error

Invalidate invalidates the kernel cache of the directory.

func (*Dir) Lookup

func (d *Dir) Lookup(ctx context.Context, name string) (fs.Node, error)

Lookup satisfies the bazil.org/fuse/NodeStringLookuper.Node interface.

func (*Dir) Name

func (d *Dir) Name() string

Name returns the name of the directory.

func (*Dir) Own

func (d *Dir) Own(uid, gid uint32) *Dir

Own sets the uid and gid of the directory.

func (*Dir) ReadDirAll

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

ReadDirAll satisfies the bazil.org/fuse/HandleReadDirAller.Node interface.

func (*Dir) SetSys

func (d *Dir) SetSys(filesys *FileSystem)

SetSys sets the directory's containing file system.

func (*Dir) Sys

func (d *Dir) Sys() *FileSystem

Sys returns the directory's containing filesystem.

func (*Dir) With

func (d *Dir) With(nodes ...Node) Node

With adds nodes to the dirctory. If with is used the FileSystem Sync method should be called when all nodes have been added.

type FileSystem

type FileSystem struct {
	// contains filtered or unexported fields
}

FileSystem is a virtual file system.

func NewFileSystem

func NewFileSystem(mode os.FileMode, clock func() time.Time) *FileSystem

NewFileSystem returns a new file system setting the mode of the root and the clock.

func (*FileSystem) Bind

func (fs *FileSystem) Bind(dir string, n Node) error

Bind binds the node at the given directory path.

func (*FileSystem) Invalidate

func (fs *FileSystem) Invalidate(n Node) error

Invalidate invalidates the kernel cache of the given node.

func (*FileSystem) InvalidatePath

func (fs *FileSystem) InvalidatePath(path string) error

InvalidatePath invalidates the kernel cache of the node at the given path.

func (*FileSystem) Root

func (fs *FileSystem) Root() (fs.Node, error)

Root satisfies the bazil.org/fuse/fs.FS interface.

func (*FileSystem) Sync

func (fs *FileSystem) Sync() *FileSystem

Sync updates all internal data links within the file system. Sync must be called if a file system has been constructed using With.

func (*FileSystem) Unbind

func (fs *FileSystem) Unbind(path string) (Node, error)

Unbind unbinds to node at the given path, returning the node if successful.

func (*FileSystem) With

func (fs *FileSystem) With(nodes ...Node) *FileSystem

With adds nodes to the file system's root.

type Func

type Func func([]byte, int64) (int, error)

Func is a Writer backed by a user defined function.

func (Func) Size

func (f Func) Size() (int64, error)

Size returns zero and a nil error.

func (Func) Truncate

func (f Func) Truncate(_ int64) error

Truncate is a no-op.

func (Func) WriteAt

func (f Func) WriteAt(b []byte, off int64) (int, error)

WriteAt satisfies the io.WriterAt interface.

type Node

type Node interface {
	fs.Node

	// Name returns the name of the node.
	Name() string

	// Sys returns a pointer to the FileSystem
	// holding the Node.
	Sys() *FileSystem

	// SetSys sets the pointer to the FileSystem
	// holding the node. SetSys must accept a nil
	// parameter.
	SetSys(*FileSystem)
}

Node is a node in a FileSystem.

type RO

type RO struct {
	// contains filtered or unexported fields
}

RO is a read only file node.

func MustNewRO

func MustNewRO(name string, mode os.FileMode, dev Reader) *RO

MustNewRO returns a new RO with the given name and file mode. It will panic if name contains a filepath separator.

func MustNewROFlags

func MustNewROFlags(name string, mode os.FileMode, flags fuse.OpenResponseFlags, dev Reader) *RO

MustNewRO returns a new RO with the given name and file mode. It will panic if name contains a filepath separator. The provided flags are used when opening the RO node.

func NewRO

func NewRO(name string, mode os.FileMode, dev Reader) (*RO, error)

NewRO returns a new RO file with the given name and file mode.

func NewROFlags

func NewROFlags(name string, mode os.FileMode, flags fuse.OpenResponseFlags, dev Reader) (*RO, error)

NewRO returns a new RO file with the given name and file mode. The provided flags are used when opening the RO node.

func (*RO) Attr

func (f *RO) Attr(ctx context.Context, a *fuse.Attr) error

Attr satisfies the bazil.org/fuse/fs.Node interface.

func (*RO) Invalidate

func (f *RO) Invalidate() error

Invalidate invalidates the kernel cache of the file.

func (*RO) Name

func (f *RO) Name() string

Name returns the name of the file.

func (*RO) Open

func (f *RO) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error)

Open satisfies the bazil.org/fuse/fs.NodeOpener interface.

func (*RO) Own

func (f *RO) Own(uid, gid uint32) *RO

Own sets the uid and gid of the file.

func (*RO) Read

func (f *RO) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error

Read satisfies the bazil.org/fuse/fs.HandleReader interface.

func (*RO) Release

func (f *RO) Release(ctx context.Context, req *fuse.ReleaseRequest) error

Release satisfies the bazil.org/fuse/fs.HandleReleaser interface. If the RO Reader device is an io.Closer, its Close method is called.

func (*RO) SetSys

func (f *RO) SetSys(filesys *FileSystem)

SetSys sets the file's containing file system.

func (*RO) Sys

func (f *RO) Sys() *FileSystem

Sys returns the file's containing filesystem.

type RW

type RW struct {
	// contains filtered or unexported fields
}

RW is a read write file node.

func MustNewRW

func MustNewRW(name string, mode os.FileMode, dev ReadWriter) *RW

MustNewRW returns a new RW with the given name and file mode. It will panic if name contains a filepath separator.

func MustNewRWFlags

func MustNewRWFlags(name string, mode os.FileMode, flags fuse.OpenResponseFlags, dev ReadWriter) *RW

MustNewRWFlags returns a new RW with the given name and file mode. It will panic if name contains a filepath separator. The provided flags are used when opening the RW node.

func NewRW

func NewRW(name string, mode os.FileMode, dev ReadWriter) (*RW, error)

NewRW returns a new RW file with the given name and file mode.

func NewRWFlags

func NewRWFlags(name string, mode os.FileMode, flags fuse.OpenResponseFlags, dev ReadWriter) (*RW, error)

NewRWFlags returns a new RW file with the given name and file mode. The provided flags are used when opening the RW node.

func (*RW) Attr

func (f *RW) Attr(ctx context.Context, a *fuse.Attr) error

Attr satisfies the bazil.org/fuse/fs.Node interface.

func (*RW) Flush

func (f *RW) Flush(ctx context.Context, req *fuse.FlushRequest) error

Flush satisfies the bazil.org/fuse/fs.HandleFlusher interface.

func (*RW) Invalidate

func (f *RW) Invalidate() error

Invalidate invalidates the kernel cache of the file.

func (*RW) Name

func (f *RW) Name() string

Name returns the name of the file.

func (*RW) Open

func (f *RW) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error)

Open satisfies the bazil.org/fuse/fs.NodeOpener interface.

func (*RW) Own

func (f *RW) Own(uid, gid uint32) *RW

Own sets the uid and gid of the file.

func (*RW) Read

func (f *RW) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error

Read satisfies the bazil.org/fuse/fs.HandleReader interface.

func (*RW) Release

func (f *RW) Release(ctx context.Context, req *fuse.ReleaseRequest) error

Release satisfies the bazil.org/fuse/fs.HandleReleaser interface. If the RW ReadWriter device is an io.Closer, its Close method is called.

func (*RW) SetSys

func (f *RW) SetSys(filesys *FileSystem)

SetSys sets the file's containing file system.

func (*RW) Setattr

func (f *RW) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error

Setattr satisfies the bazil.org/fuse/fs.NodeSetattrer interface.

func (*RW) Sys

func (f *RW) Sys() *FileSystem

Sys returns the file's containing filesystem.

func (*RW) Write

func (f *RW) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error

Write satisfies the bazil.org/fuse/fs.HandleWriter interface.

type ReadWriter

type ReadWriter interface {
	io.ReaderAt
	io.WriterAt
	Truncate(int64) error
	Size() (int64, error)
}

ReadWriter is the data interface for a read write file.

type Reader

type Reader interface {
	io.ReaderAt
	Size() (int64, error)
}

Reader is the data interface for a read only file.

type String

type String string

String is a Reader backed by a string.

func (String) ReadAt

func (s String) ReadAt(b []byte, off int64) (int, error)

ReadAt satisfies the io.ReaderAt interface.

func (String) Size

func (s String) Size() (int64, error)

Size returns the length of the backing string and a nil error.

type WO

type WO struct {
	// contains filtered or unexported fields
}

WO is a write only file node.

func MustNewWO

func MustNewWO(name string, mode os.FileMode, dev Writer) *WO

MustNewWO returns a new WO with the given name and file mode. It will panic if name contains a filepath separator.

func MustNewWOFlags

func MustNewWOFlags(name string, mode os.FileMode, flags fuse.OpenResponseFlags, dev Writer) *WO

MustNewWOFlags returns a new WO with the given name and file mode. It will panic if name contains a filepath separator. The provided flags are used when opening the WO node.

func NewWO

func NewWO(name string, mode os.FileMode, dev Writer) (*WO, error)

NewWO returns a new WO file with the given name and file mode.

func NewWOFlags

func NewWOFlags(name string, mode os.FileMode, flags fuse.OpenResponseFlags, dev Writer) (*WO, error)

NewWOFlags returns a new WO file with the given name and file mode. The provided flags are used when opening the WO node.

func (*WO) Attr

func (f *WO) Attr(ctx context.Context, a *fuse.Attr) error

Attr satisfies the bazil.org/fuse/fs.Node interface.

func (*WO) Flush

func (f *WO) Flush(ctx context.Context, req *fuse.FlushRequest) error

Flush satisfies the bazil.org/fuse/fs.HandleFlusher interface.

func (*WO) Invalidate

func (f *WO) Invalidate() error

Invalidate invalidates the kernel cache of the file.

func (*WO) Name

func (f *WO) Name() string

Name returns the name of the file.

func (*WO) Open

func (f *WO) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error)

Open satisfies the bazil.org/fuse/fs.NodeOpener interface.

func (*WO) Own

func (f *WO) Own(uid, gid uint32) *WO

Own sets the uid and gid of the file.

func (*WO) Release

func (f *WO) Release(ctx context.Context, req *fuse.ReleaseRequest) error

Release satisfies the bazil.org/fuse/fs.HandleReleaser interface. If the WO Writer device is an io.Closer, its Close method is called.

func (*WO) SetSys

func (f *WO) SetSys(filesys *FileSystem)

SetSys sets the file's containing file system.

func (*WO) Setattr

func (f *WO) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error

Setattr satisfies the bazil.org/fuse/fs.NodeSetattrer interface.

func (*WO) Sys

func (f *WO) Sys() *FileSystem

Sys returns the file's containing filesystem.

func (*WO) Write

func (f *WO) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error

Write satisfies the bazil.org/fuse/fs.HandleWriter interface.

type Writer

type Writer interface {
	io.WriterAt
	Truncate(int64) error
	Size() (int64, error)
}

Writer is the data interface for a write only file.

Jump to

Keyboard shortcuts

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