nodefs

package
v0.0.0-...-bc17f6b Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2013 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File interface {
	// Called upon registering the filehandle in the inode.
	SetInode(*Inode)

	// The String method is for debug printing.
	String() string

	// Wrappers around other File implementations, should return
	// the inner file here.
	InnerFile() File

	Read(dest []byte, off int64) (fuse.ReadResult, fuse.Status)
	Write(data []byte, off int64) (written uint32, code fuse.Status)
	Flush() fuse.Status
	Release()
	Fsync(flags int) (code fuse.Status)

	// The methods below may be called on closed files, due to
	// concurrency.  In that case, you should return EBADF.
	Truncate(size uint64) fuse.Status
	GetAttr(out *fuse.Attr) fuse.Status
	Chown(uid uint32, gid uint32) fuse.Status
	Chmod(perms uint32) fuse.Status
	Utimens(atime *time.Time, mtime *time.Time) fuse.Status
	Allocate(off uint64, size uint64, mode uint32) (code fuse.Status)
}

A File object should be returned from FileSystem.Open and FileSystem.Create. Include the NewDefaultFile return value into the struct to inherit a default null implementation.

func NewDataFile

func NewDataFile(data []byte) File

func NewDefaultFile

func NewDefaultFile() File

NewDefaultFile returns a File instance that returns ENOSYS for every operation.

func NewDevNullFile

func NewDevNullFile() File

NewDevNullFile returns a file that accepts any write, and always returns EOF for reads.

func NewLockingFile

func NewLockingFile(mu *sync.Mutex, f File) File

NewDefaultFile returns a File instance that returns ENOSYS for every operation.

func NewLoopbackFile

func NewLoopbackFile(f *os.File) File

LoopbackFile delegates all operations back to an underlying os.File.

func NewReadOnlyFile

func NewReadOnlyFile(f File) File

type FileSystem

type FileSystem interface {
	// OnUnmount is executed just before a submount is removed,
	// and when the process receives a forget for the FUSE root
	// node.
	OnUnmount()

	// OnMount is called just after a mount is executed, either
	// when the root is mounted, or when other filesystem are
	// mounted in-process. The passed-in FileSystemConnector gives
	// access to Notify methods and Debug settings.
	OnMount(conn *FileSystemConnector)

	// Root should return the inode for root of this file system.
	Root() Node

	// Used for debug outputs
	String() string

	// If called, provide debug output through the log package.
	SetDebug(debug bool)
}

FileSystem is a high level API that resembles the kernel's idea of what an FS looks like. FileSystems can have multiple hard-links to one file, for example. It is also suited if the data to represent fits in memory: you can construct Node at mount time, and the filesystem will be ready.

func NewDefaultFileSystem

func NewDefaultFileSystem() FileSystem

NewDefaultNodeFileSystem returns a dummy implementation of NodeFileSystem, for embedding in structs.

func NewMemNodeFs

func NewMemNodeFs(prefix string) FileSystem

NewMemNodeFs creates an in-memory node-based filesystem. Files are written into a backing store under the given prefix.

type FileSystemConnector

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

FilesystemConnector translates the raw FUSE protocol (serialized structs of uint32/uint64) to operations on Go objects representing files and directories.

func MountFileSystem

func MountFileSystem(mountpoint string, nodeFs FileSystem, opts *Options) (*fuse.Server, *FileSystemConnector, error)

func NewFileSystemConnector

func NewFileSystemConnector(nodeFs FileSystem, opts *Options) (c *FileSystemConnector)

NewFileSystemConnector creates a FileSystemConnector with the given options.

func (*FileSystemConnector) DeleteNotify

func (c *FileSystemConnector) DeleteNotify(dir *Inode, child *Inode, name string) fuse.Status

DeleteNotify signals to the kernel that the named entry in dir for the child disappeared.

func (*FileSystemConnector) EntryNotify

func (c *FileSystemConnector) EntryNotify(node *Inode, name string) fuse.Status

EntryNotify makes the kernel forget the entry data from the given name from a directory. After this call, the kernel will issue a new lookup request for the given name when necessary.

func (*FileSystemConnector) FileNotify

func (c *FileSystemConnector) FileNotify(node *Inode, off int64, length int64) fuse.Status

FileNotify notifies the kernel that data and metadata of this inode has changed. After this call completes, the kernel will issue a new GetAttr requests for metadata and new Read calls for content.

func (*FileSystemConnector) InodeHandleCount

func (c *FileSystemConnector) InodeHandleCount() int

InodeCount returns the number of inodes registered with the kernel.

func (*FileSystemConnector) LookupNode

func (c *FileSystemConnector) LookupNode(parent *Inode, path string) *Inode

Follows the path from the given parent, doing lookups as necesary. The path should be '/' separated without leading slash.

func (*FileSystemConnector) Mount

func (c *FileSystemConnector) Mount(parent *Inode, name string, nodeFs FileSystem, opts *Options) fuse.Status

Mount() generates a synthetic directory node, and mounts the file system there. If opts is nil, the mount options of the root file system are inherited. The encompassing filesystem should pretend the mount point does not exist.

It returns ENOENT if the directory containing the mount point does not exist, and EBUSY if the intended mount point already exists.

func (*FileSystemConnector) Node

func (c *FileSystemConnector) Node(parent *Inode, fullPath string) (*Inode, []string)

Finds a node within the currently known inodes, returns the last known node and the remaining unknown path components. If parent is nil, start from FUSE mountpoint.

func (*FileSystemConnector) RawFS

Returns the RawFileSystem so it can be mounted.

func (*FileSystemConnector) Server

func (c *FileSystemConnector) Server() *fuse.Server

Server returns the fuse.Server that talking to the kernel.

func (*FileSystemConnector) SetDebug

func (c *FileSystemConnector) SetDebug(debug bool)

SetDebug toggles printing of debug information.

func (*FileSystemConnector) Unmount

func (c *FileSystemConnector) Unmount(node *Inode) fuse.Status

Unmount() tries to unmount the given inode. It returns EINVAL if the path does not exist, or is not a mount point, and EBUSY if there are open files or submounts below this node.

type Inode

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

The inode reflects the kernel's idea of the inode. Inodes may be created automatically when the kernel does lookups inode, or by explicitly by calling Inode.New().

func (*Inode) AddChild

func (n *Inode) AddChild(name string, child *Inode)

func (*Inode) AnyFile

func (n *Inode) AnyFile() (file File)

Returns any open file, preferably a r/w one.

func (*Inode) Children

func (n *Inode) Children() (out map[string]*Inode)

func (*Inode) Files

func (n *Inode) Files(mask uint32) (files []WithFlags)

Files() returns an opens file that have bits in common with the give mask. Use mask==0 to return all files.

func (*Inode) FsChildren

func (n *Inode) FsChildren() (out map[string]*Inode)

FsChildren returns all the children from the same filesystem. It will skip mountpoints.

func (*Inode) GetChild

func (n *Inode) GetChild(name string) (child *Inode)

func (*Inode) IsDir

func (n *Inode) IsDir() bool

func (*Inode) New

func (n *Inode) New(isDir bool, fsi Node) *Inode

func (*Inode) Node

func (n *Inode) Node() Node

func (*Inode) RmChild

func (n *Inode) RmChild(name string) (ch *Inode)

type Node

type Node interface {
	// Inode and SetInode are basic getter/setters.  They are
	// called by the FileSystemConnector. You get them for free by
	// embedding the result of NewDefaultNode() in your node
	// struct.
	Inode() *Inode
	SetInode(node *Inode)

	// Lookup finds a child node to this node; it is only called
	// for directory Nodes.
	Lookup(out *fuse.Attr, name string, context *fuse.Context) (node Node, code fuse.Status)

	// Deletable() should return true if this inode may be
	// discarded from the children list. This will be called from
	// within the treeLock critical section, so you cannot look at
	// other inodes.
	Deletable() bool

	// OnForget is called when the reference to this inode is
	// dropped from the tree.
	OnForget()

	// Misc.
	Access(mode uint32, context *fuse.Context) (code fuse.Status)
	Readlink(c *fuse.Context) ([]byte, fuse.Status)

	// Namespace operations; these are only called on directory Nodes.
	Mknod(name string, mode uint32, dev uint32, context *fuse.Context) (newNode Node, code fuse.Status)
	Mkdir(name string, mode uint32, context *fuse.Context) (newNode Node, code fuse.Status)
	Unlink(name string, context *fuse.Context) (code fuse.Status)
	Rmdir(name string, context *fuse.Context) (code fuse.Status)
	Symlink(name string, content string, context *fuse.Context) (newNode Node, code fuse.Status)
	Rename(oldName string, newParent Node, newName string, context *fuse.Context) (code fuse.Status)
	Link(name string, existing Node, context *fuse.Context) (newNode Node, code fuse.Status)

	// Files
	Create(name string, flags uint32, mode uint32, context *fuse.Context) (file File, newNode Node, code fuse.Status)
	Open(flags uint32, context *fuse.Context) (file File, code fuse.Status)
	OpenDir(context *fuse.Context) ([]fuse.DirEntry, fuse.Status)

	// XAttrs
	GetXAttr(attribute string, context *fuse.Context) (data []byte, code fuse.Status)
	RemoveXAttr(attr string, context *fuse.Context) fuse.Status
	SetXAttr(attr string, data []byte, flags int, context *fuse.Context) fuse.Status
	ListXAttr(context *fuse.Context) (attrs []string, code fuse.Status)

	// Attributes
	GetAttr(out *fuse.Attr, file File, context *fuse.Context) (code fuse.Status)
	Chmod(file File, perms uint32, context *fuse.Context) (code fuse.Status)
	Chown(file File, uid uint32, gid uint32, context *fuse.Context) (code fuse.Status)
	Truncate(file File, size uint64, context *fuse.Context) (code fuse.Status)
	Utimens(file File, atime *time.Time, mtime *time.Time, context *fuse.Context) (code fuse.Status)
	Fallocate(file File, off uint64, size uint64, mode uint32, context *fuse.Context) (code fuse.Status)

	StatFs() *fuse.StatfsOut
}

The Node implements the basic functionality of inodes; this is where the majority of the FS code for a typical filesystem will be.

func NewDefaultNode

func NewDefaultNode() Node

NewDefaultNode returns an implementation of Node that returns ENOSYS for all operations.

type Options

type Options struct {
	EntryTimeout    time.Duration
	AttrTimeout     time.Duration
	NegativeTimeout time.Duration

	// If set, replace all uids with given UID.
	// NewFileSystemOptions() will set this to the daemon's
	// uid/gid.
	*fuse.Owner

	// If set, use a more portable, but slower inode number
	// generation scheme.  This will make inode numbers (exported
	// back to callers) stay within int32, which is necessary for
	// making stat() succeed in 32-bit programs.
	PortableInodes bool
}

Options contains time out options for a node FileSystem. The default copied from libfuse and set in NewMountOptions() is (1s,1s,0s).

func NewOptions

func NewOptions() *Options

NewOptions generates FUSE options that correspond to libfuse's defaults.

type WithFlags

type WithFlags struct {
	File

	// For debugging.
	Description string

	// Put FOPEN_* flags here.
	FuseFlags uint32

	// O_RDWR, O_TRUNCATE, etc.
	OpenFlags uint32
}

Wrap a File return in this to set FUSE flags. Also used internally to store open file data.

func (*WithFlags) String

func (me *WithFlags) String() string

Jump to

Keyboard shortcuts

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