Movatterモバイル変換


[0]ホーム

URL:


nodefs

package
v2.0.3Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2020 License:BSD-3-ClauseImports:10Imported by:37

Details

Repository

github.com/hanwen/go-fuse

Links

Documentation

Overview

This package is deprecated. New projects should use the package"github.com/hanwen/go-fuse/v2/fs" instead.

The nodefs package offers a high level API that resembles thekernel's idea of what an FS looks like. File systems can havemultiple hard-links to one file, for example. It is also suited ifthe data to represent fits in memory: you can construct thecomplete file system tree at mount time

Index

Constants

View Source
const (F_OFD_GETLK  = 36F_OFD_SETLK  = 37F_OFD_SETLKW = 38)

Variables

This section is empty.

Functions

This section is empty.

Types

typeFile

type File interface {// Called upon registering the filehandle in the inode. This// is useful in that PathFS API, where Create/Open have no// access to the Inode at hand.SetInode(*Inode)// The String method is for debug printing.String()string// Wrappers around other File implementations, should return// the inner file here.InnerFile()FileRead(dest []byte, offint64) (fuse.ReadResult,fuse.Status)Write(data []byte, offint64) (writtenuint32, codefuse.Status)// File lockingGetLk(owneruint64, lk *fuse.FileLock, flagsuint32, out *fuse.FileLock) (codefuse.Status)SetLk(owneruint64, lk *fuse.FileLock, flagsuint32) (codefuse.Status)SetLkw(owneruint64, lk *fuse.FileLock, flagsuint32) (codefuse.Status)// Flush is called for close() call on a file descriptor. In// case of duplicated descriptor, it may be called more than// once for a file.Flush()fuse.Status// This is called to before the file handle is forgotten. This// method has no return value, so nothing can synchronizes on// the call. Any cleanup that requires specific synchronization or// could fail with I/O errors should happen in Flush instead.Release()Fsync(flagsint) (codefuse.Status)// The methods below may be called on closed files, due to// concurrency.  In that case, you should return EBADF.Truncate(sizeuint64)fuse.StatusGetAttr(out *fuse.Attr)fuse.StatusChown(uiduint32, giduint32)fuse.StatusChmod(permsuint32)fuse.StatusUtimens(atime *time.Time, mtime *time.Time)fuse.StatusAllocate(offuint64, sizeuint64, modeuint32) (codefuse.Status)}

A File object is returned from FileSystem.Open andFileSystem.Create. Include the NewDefaultFile return value intothe struct to inherit a null implementation.

funcNewDataFile

func NewDataFile(data []byte)File

funcNewDefaultFile

func NewDefaultFile()File

NewDefaultFile returns a File instance that returns ENOSYS forevery operation.

funcNewDevNullFile

func NewDevNullFile()File

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

funcNewLockingFile

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

NewLockingFile serializes operations an existing File.

funcNewLoopbackFile

func NewLoopbackFile(f *os.File)File

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

funcNewReadOnlyFile

func NewReadOnlyFile(fFile)File

NewReadOnlyFile wraps a File so all write operations are denied.

typeFileSystemConnector

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

FileSystemConnector translates the raw FUSE protocol (serializedstructs of uint32/uint64) to operations on Go objects representingfiles and directories.

funcMount

func Mount(mountpointstring, rootNode, mountOptions *fuse.MountOptions, nodefsOptions *Options) (*fuse.Server, *FileSystemConnector,error)

Mount mounts a filesystem with the given root node on the given directory.Convenience wrapper around fuse.NewServer

funcMountRoot

func MountRoot(mountpointstring, rootNode, opts *Options) (*fuse.Server, *FileSystemConnector,error)

MountRoot is like Mount but uses default fuse mount options.

funcNewFileSystemConnector

func NewFileSystemConnector(rootNode, opts *Options) (c *FileSystemConnector)

NewFileSystemConnector creates a FileSystemConnector with the givenoptions.

func (*FileSystemConnector)DeleteNotify

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

DeleteNotify signals to the kernel that the named entry in dir forthe child disappeared. No filesystem related locks should be heldwhen calling this.

func (*FileSystemConnector)EntryNotify

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

EntryNotify makes the kernel forget the entry data from the givenname from a directory. After this call, the kernel will issue anew lookup request for the given name when necessary. No filesystemrelated locks should be held when calling this.

func (*FileSystemConnector)FileNotify

func (c *FileSystemConnector) FileNotify(node *Inode, offint64, lengthint64)fuse.Status

FileNotify notifies the kernel that data and metadata of this inodehas changed. After this call completes, the kernel will issue anew GetAttr requests for metadata and new Read calls for content.Use negative offset for metadata-only invalidation, and zero-lengthfor invalidating all content.

func (*FileSystemConnector)FileNotifyStoreCache

func (c *FileSystemConnector) FileNotifyStoreCache(node *Inode, offint64, data []byte)fuse.Status

FileNotifyStoreCache notifies the kernel about changed data of the inode.

This call is similar to FileNotify, but instead of only invalidating a dataregion, it puts updated data directly to the kernel cache:

After this call completes, the kernel has put updated data into the inode's cache,and will use data from that cache for non direct-IO reads from the inodein corresponding data region. After kernel's cache data is evicted, the kernelwill have to issue new Read calls on user request to get data content.

ENOENT is returned if the kernel does not currently have entry for thisinode in its dentry cache.

func (*FileSystemConnector)FileRetrieveCache

func (c *FileSystemConnector) FileRetrieveCache(node *Inode, offint64, dest []byte) (nint, stfuse.Status)

FileRetrieveCache retrieves data from kernel's inode cache.

This call retrieves data from kernel's inode cache @ offset and up tolen(dest) bytes. If kernel cache has fewer consecutive data starting atoffset, that fewer amount is returned. In particular if inode data at offsetis not cached (0, OK) is returned.

If the kernel does not currently have entry for this inode in its dentrycache (0, OK) is still returned, pretending that the inode could be known tothe kernel, but kernel's inode cache is empty.

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, pathstring) *Inode

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

func (*FileSystemConnector)Mount

func (c *FileSystemConnector) Mount(parent *Inode, namestring, rootNode, opts *Options)fuse.Status

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

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

func (*FileSystemConnector)Node

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

Finds a node within the currently known inodes, returns the lastknown node and the remaining unknown path components. If parent isnil, 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(debugbool)

SetDebug toggles printing of debug information. This function isdeprecated. Set the Debug option in the Options struct instead.

func (*FileSystemConnector)Unmount

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

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

typeInode

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

An Inode reflects the kernel's idea of the inode. Inodes have IDsthat are communicated to the kernel, and they have a treestructure: a directory Inode may contain named children. EachInode object is paired with a Node object, which file systemimplementers should supply.

func (*Inode)AddChild

func (n *Inode) AddChild(namestring, child *Inode)

AddChild adds a child inode. The parent inode must be a directorynode.

func (*Inode)AnyFile

func (n *Inode) AnyFile() (fileFile)

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

func (*Inode)Children

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

Children returns all children of this inode.

func (*Inode)Files

func (n *Inode) Files(maskuint32) (files []WithFlags)

Files() returns an opens file that have bits in common with thegive 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. Itwill skip mountpoints.

func (*Inode)GetChild

func (n *Inode) GetChild(namestring) (child *Inode)

GetChild returns a child inode with the given name, or nil if itdoes not exist.

func (*Inode)IsDir

func (n *Inode) IsDir()bool

IsDir returns true if this is a directory.

func (*Inode)NewChild

func (n *Inode) NewChild(namestring, isDirbool, fsiNode) *Inode

NewChild adds a new child inode to this inode.

func (*Inode)Node

func (n *Inode) Node()Node

Node returns the file-system specific node.

func (*Inode)Parent

func (n *Inode) Parent() (parent *Inode, namestring)

Parent returns a random parent and the name this inode has under this parent.This function can be used to walk up the directory tree. It will not crosssub-mounts.

func (*Inode)RmChild

func (n *Inode) RmChild(namestring) (ch *Inode)

RmChild removes an inode by name, and returns it. It returns nil ifchild does not exist.

func (*Inode)String

func (n *Inode) String()string

Print the inode. The default print method may not be used fordebugging, as dumping the map requires synchronization.

typeNode

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() *InodeSetInode(node *Inode)// OnMount is called on the root node just after a mount is// executed, either when the actual root is mounted, or when a// filesystem is mounted in-process. The passed-in// FileSystemConnector gives access to Notify methods and// Debug settings.OnMount(conn *FileSystemConnector)// OnUnmount is executed just before a submount is removed,// and when the process receives a forget for the FUSE root// node.OnUnmount()// Lookup finds a child node to this node; it is only called// for directory Nodes. Lookup may be called on nodes that are// already known.Lookup(out *fuse.Attr, namestring, context *fuse.Context) (*Inode,fuse.Status)// Deletable() should return true if this node may be discarded once// the kernel forgets its reference.// If it returns false, OnForget will never get called for this node. This// is appropriate if the filesystem has no persistent backing store// (in-memory filesystems) where discarding the node loses the stored data.// Deletable will be called from within the treeLock critical section, so you// cannot look at other nodes.Deletable()bool// OnForget is called when the kernel forgets its reference to this node and// sends a FORGET request. It should perform cleanup and free memory as// appropriate for the filesystem.// OnForget is not called if the node is a directory and has children.// This is called from within a treeLock critical section.OnForget()// Misc.Access(modeuint32, context *fuse.Context) (codefuse.Status)Readlink(c *fuse.Context) ([]byte,fuse.Status)// Mknod should create the node, add it to the receiver's// inode, and return itMknod(namestring, modeuint32, devuint32, context *fuse.Context) (newNode *Inode, codefuse.Status)// Mkdir should create the directory Inode, add it to the// receiver's Inode, and return itMkdir(namestring, modeuint32, context *fuse.Context) (newNode *Inode, codefuse.Status)Unlink(namestring, context *fuse.Context) (codefuse.Status)Rmdir(namestring, context *fuse.Context) (codefuse.Status)// Symlink should create a child inode to the receiver, and// return it.Symlink(namestring, contentstring, context *fuse.Context) (*Inode,fuse.Status)Rename(oldNamestring, newParentNode, newNamestring, context *fuse.Context) (codefuse.Status)// Link should return the Inode of the resulting link. In// a POSIX conformant file system, this should add 'existing'// to the receiver, and return the Inode corresponding to// 'existing'.Link(namestring, existingNode, context *fuse.Context) (newNode *Inode, codefuse.Status)// Create should return an open file, and the Inode for that file.Create(namestring, flagsuint32, modeuint32, context *fuse.Context) (fileFile, child *Inode, codefuse.Status)// Open opens a file, and returns a File which is associated// with a file handle. It is OK to return (nil, OK) here. In// that case, the Node should implement Read or Write// directly.Open(flagsuint32, context *fuse.Context) (fileFile, codefuse.Status)OpenDir(context *fuse.Context) ([]fuse.DirEntry,fuse.Status)Read(fileFile, dest []byte, offint64, context *fuse.Context) (fuse.ReadResult,fuse.Status)Write(fileFile, data []byte, offint64, context *fuse.Context) (writtenuint32, codefuse.Status)// XAttrsGetXAttr(attributestring, context *fuse.Context) (data []byte, codefuse.Status)RemoveXAttr(attrstring, context *fuse.Context)fuse.StatusSetXAttr(attrstring, data []byte, flagsint, context *fuse.Context)fuse.StatusListXAttr(context *fuse.Context) (attrs []string, codefuse.Status)// File locking//// GetLk returns existing lock information for file.GetLk(fileFile, owneruint64, lk *fuse.FileLock, flagsuint32, out *fuse.FileLock, context *fuse.Context) (codefuse.Status)// Sets or clears the lock described by lk on file.SetLk(fileFile, owneruint64, lk *fuse.FileLock, flagsuint32, context *fuse.Context) (codefuse.Status)// Sets or clears the lock described by lk. This call blocks until the operation can be completed.SetLkw(fileFile, owneruint64, lk *fuse.FileLock, flagsuint32, context *fuse.Context) (codefuse.Status)// AttributesGetAttr(out *fuse.Attr, fileFile, context *fuse.Context) (codefuse.Status)Chmod(fileFile, permsuint32, context *fuse.Context) (codefuse.Status)Chown(fileFile, uiduint32, giduint32, context *fuse.Context) (codefuse.Status)Truncate(fileFile, sizeuint64, context *fuse.Context) (codefuse.Status)Utimens(fileFile, atime *time.Time, mtime *time.Time, context *fuse.Context) (codefuse.Status)Fallocate(fileFile, offuint64, sizeuint64, modeuint32, context *fuse.Context) (codefuse.Status)StatFs() *fuse.StatfsOut}

The Node interface implements the user-defined file systemfunctionality

funcNewDefaultNode

func NewDefaultNode()Node

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

funcNewMemNodeFSRoot

func NewMemNodeFSRoot(prefixstring)Node

NewMemNodeFSRoot creates an in-memory node-based filesystem. Filesare written into a backing store under the given prefix.

typeOptions

type Options struct {EntryTimeouttime.DurationAttrTimeouttime.DurationNegativeTimeouttime.Duration// If set, replace all uids with given UID.// NewOptions() will set this to the daemon's// uid/gid.*fuse.Owner// This option exists for compatibility and is ignored.PortableInodesbool// If set, print debug information.Debugbool// If set, issue Lookup rather than GetAttr calls for known// children. This allows the filesystem to update its inode// hierarchy in response to kernel calls.LookupKnownChildrenbool}

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

funcNewOptions

func NewOptions() *Options

NewOptions generates FUSE options that correspond to libfuse'sdefaults.

typeTreeWatcher

type TreeWatcher interface {OnAdd(parent *Inode, namestring)OnRemove(parent *Inode, namestring)}

TreeWatcher is an additional interface that Nodes can implement.If they do, the OnAdd and OnRemove are called for operations on thefile system tree. These functions run under a lock, so they shouldnot do blocking operations.

typeWithFlags

type WithFlags struct {File// For debugging.Descriptionstring// Put FOPEN_* flags here.FuseFlagsuint32// O_RDWR, O_TRUNCATE, etc.OpenFlagsuint32}

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

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp