Movatterモバイル変換


[0]ホーム

URL:


fuse

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:18Imported by:337

Details

Repository

github.com/hanwen/go-fuse

Links

Documentation

Overview

Package fuse provides APIs to implement filesystems inuserspace in terms of raw FUSE protocol.

A filesystem is implemented by implementing its server that provides aRawFileSystem interface. Typically the server embedsNewDefaultRawFileSystem() and implements only subset of filesystem methods:

type MyFS struct {fuse.RawFileSystem...}func NewMyFS() *MyFS {return &MyFS{RawFileSystem: fuse.NewDefaultRawFileSystem(),...}}// Mkdir implements "mkdir" request handler.//// For other requests - not explicitly implemented by MyFS - ENOSYS// will be typically returned to client.func (fs *MyFS) Mkdir(...) {...}

Then the filesystem can be mounted and served to a client (typically OSkernel) by creating Server:

fs := NewMyFS() // implements RawFileSystemfssrv, err := fuse.NewServer(fs, mountpoint, &fuse.MountOptions{...})if err != nil {...}

and letting the server do its work:

// either synchronously - .Serve() blocks until the filesystem is unmounted.fssrv.Serve()// or in the background - .Serve() is spawned in another goroutine, but// before interacting with fssrv from current context we have to wait// until the filesystem mounting is complete.go fssrv.Serve()err = fssrv.WaitMount()if err != nil {...}

The server will serve clients by dispatching their requests to thefilesystem implementation and conveying responses back. For example "mkdir"FUSE request dispatches to call

fs.Mkdir(*MkdirIn, ..., *EntryOut)

"stat" to call

fs.GetAttr(*GetAttrIn, *AttrOut)

etc. Please refer to RawFileSystem documentation for details.

Typically, each call of the API happens in its owngoroutine, so take care to make the file system thread-safe.

Higher level interfaces

As said above this packages provides way to implement filesystems in terms ofraw FUSE protocol. Additionally packages nodefs and pathfs provide ways toimplement filesystem at higher levels:

Package github.com/hanwen/go-fuse/fuse/nodefs provides way to implementfilesystems in terms of inodes. This resembles kernel's idea of what afilesystem looks like.

Package github.com/hanwen/go-fuse/fuse/pathfs provides way to implementfilesystems in terms of path names. Working with path names is somewhateasier compared to inodes, however renames can be racy. Do not use pathfs ifyou care about correctness.

Index

Constants

View Source
const (FUSE_ROOT_ID = 1FUSE_UNKNOWN_INO = 0xffffffffCUSE_UNRESTRICTED_IOCTL = (1 << 0)FUSE_LK_FLOCK = (1 << 0)FUSE_IOCTL_MAX_IOV = 256FUSE_POLL_SCHEDULE_NOTIFY = (1 << 0)CUSE_INIT_INFO_MAX = 4096S_IFDIR =syscall.S_IFDIRS_IFREG =syscall.S_IFREGS_IFLNK =syscall.S_IFLNKS_IFIFO =syscall.S_IFIFOCUSE_INIT = 4096O_ANYWRITE =uint32(os.O_WRONLY |os.O_RDWR |os.O_APPEND |os.O_CREATE |os.O_TRUNC))
View Source
const (OK =Status(0)// EACCESS Permission deniedEACCES =Status(syscall.EACCES)// EBUSY Device or resource busyEBUSY =Status(syscall.EBUSY)// EAGAIN Resource temporarily unavailableEAGAIN =Status(syscall.EAGAIN)// EINTR Call was interruptedEINTR =Status(syscall.EINTR)// EINVAL Invalid argumentEINVAL =Status(syscall.EINVAL)// EIO I/O errorEIO =Status(syscall.EIO)// ENOENT No such file or directoryENOENT =Status(syscall.ENOENT)// ENOSYS Function not implementedENOSYS =Status(syscall.ENOSYS)// ENODATA No data availableENODATA =Status(syscall.ENODATA)// ENOTDIR Not a directoryENOTDIR =Status(syscall.ENOTDIR)// ENOTSUP Not supportedENOTSUP =Status(syscall.ENOTSUP)// EISDIR Is a directoryEISDIR =Status(syscall.EISDIR)// EPERM Operation not permittedEPERM =Status(syscall.EPERM)// ERANGE Math result not representableERANGE =Status(syscall.ERANGE)// EXDEV Cross-device linkEXDEV =Status(syscall.EXDEV)// EBADF Bad file numberEBADF =Status(syscall.EBADF)// ENODEV No such deviceENODEV =Status(syscall.ENODEV)// EROFS Read-only file systemEROFS =Status(syscall.EROFS))
View Source
const (FATTR_MODE      = (1 << 0)FATTR_UID       = (1 << 1)FATTR_GID       = (1 << 2)FATTR_SIZE      = (1 << 3)FATTR_ATIME     = (1 << 4)FATTR_MTIME     = (1 << 5)FATTR_FH        = (1 << 6)FATTR_ATIME_NOW = (1 << 7)FATTR_MTIME_NOW = (1 << 8)FATTR_LOCKOWNER = (1 << 9)FATTR_CTIME     = (1 << 10))
View Source
const (// OpenOut.FlagsFOPEN_DIRECT_IO   = (1 << 0)FOPEN_KEEP_CACHE  = (1 << 1)FOPEN_NONSEEKABLE = (1 << 2)FOPEN_CACHE_DIR   = (1 << 3)FOPEN_STREAM      = (1 << 4))
View Source
const (CAP_ASYNC_READ          = (1 << 0)CAP_POSIX_LOCKS         = (1 << 1)CAP_FILE_OPS            = (1 << 2)CAP_ATOMIC_O_TRUNC      = (1 << 3)CAP_EXPORT_SUPPORT      = (1 << 4)CAP_BIG_WRITES          = (1 << 5)CAP_DONT_MASK           = (1 << 6)CAP_SPLICE_WRITE        = (1 << 7)CAP_SPLICE_MOVE         = (1 << 8)CAP_SPLICE_READ         = (1 << 9)CAP_FLOCK_LOCKS         = (1 << 10)CAP_IOCTL_DIR           = (1 << 11)CAP_AUTO_INVAL_DATA     = (1 << 12)CAP_READDIRPLUS         = (1 << 13)CAP_READDIRPLUS_AUTO    = (1 << 14)CAP_ASYNC_DIO           = (1 << 15)CAP_WRITEBACK_CACHE     = (1 << 16)CAP_NO_OPEN_SUPPORT     = (1 << 17)CAP_PARALLEL_DIROPS     = (1 << 18)CAP_HANDLE_KILLPRIV     = (1 << 19)CAP_POSIX_ACL           = (1 << 20)CAP_ABORT_ERROR         = (1 << 21)CAP_MAX_PAGES           = (1 << 22)CAP_CACHE_SYMLINKS      = (1 << 23)CAP_NO_OPENDIR_SUPPORT  = (1 << 24)CAP_EXPLICIT_INVAL_DATA = (1 << 25))

To be set in InitIn/InitOut.Flags.

View Source
const (FUSE_IOCTL_COMPAT       = (1 << 0)FUSE_IOCTL_UNRESTRICTED = (1 << 1)FUSE_IOCTL_RETRY        = (1 << 2))
View Source
const (X_OK = 1W_OK = 2R_OK = 4F_OK = 0)

For AccessIn.Mask.

View Source
const (//NOTIFY_POLL         = -1 // notify kernel that a poll waiting for IO on a file handle should wake upNOTIFY_INVAL_INODE    = -2// notify kernel that an inode should be invalidatedNOTIFY_INVAL_ENTRY    = -3// notify kernel that a directory entry should be invalidatedNOTIFY_STORE_CACHE    = -4// store data into kernel cache of an inodeNOTIFY_RETRIEVE_CACHE = -5// retrieve data from kernel cache of an inodeNOTIFY_DELETE         = -6// notify kernel that a directory entry has been deleted)
View Source
const (WRITE_CACHE     = (1 << 0)WRITE_LOCKOWNER = (1 << 1))
View Source
const (ENOATTR =Status(syscall.ENODATA)// On Linux, ENOATTR is an alias for ENODATA.// EREMOTEIO Remote I/O errorEREMOTEIO =Status(syscall.EREMOTEIO))
View Source
const (// Mask for GetAttrIn.Flags. If set, GetAttrIn has a file handle set.FUSE_GETATTR_FH = (1 << 0))
View Source
const (// The kernel caps writes at 128k.MAX_KERNEL_WRITE = 128 * 1024)
View Source
const (READ_LOCKOWNER = (1 << 1))
View Source
const RELEASE_FLUSH = (1 << 0)

Variables

This section is empty.

Functions

funcNewContext

func NewContext(ctxcontext.Context, caller *Caller)context.Context

funcPrint

func Print(obj interface{})string

Print pretty prints FUSE data types for kernel communication

funcToStatT

func ToStatT(fos.FileInfo) *syscall.Stat_t

funcUtimeToTimespec

func UtimeToTimespec(t *time.Time) (tssyscall.Timespec)

UtimeToTimespec converts a "Time" pointer as passed to Utimens to a"Timespec" that can be passed to the utimensat syscall.A nil pointer is converted to the special UTIME_OMIT value.

Types

typeAccessIn

type AccessIn struct {InHeaderMaskuint32Paddinguint32}

typeAttr

type Attr struct {Inouint64Sizeuint64// Blocks is the number of 512-byte blocks that the file occupies on disk.Blocksuint64Atimeuint64Mtimeuint64Ctimeuint64Atimensecuint32Mtimensecuint32Ctimensecuint32Modeuint32Nlinkuint32OwnerRdevuint32// Blksize is the preferred size for file system operations.Blksizeuint32Paddinguint32}

funcToAttr

func ToAttr(fos.FileInfo) *Attr

func (*Attr)AccessTime

func (a *Attr) AccessTime()time.Time

func (*Attr)ChangeTime

func (a *Attr) ChangeTime()time.Time

func (*Attr)FromStat

func (a *Attr) FromStat(s *syscall.Stat_t)

func (*Attr)IsBlock

func (a *Attr) IsBlock()bool

IsBlock reports whether the FileInfo describes a block special file.

func (*Attr)IsChar

func (a *Attr) IsChar()bool

IsChar reports whether the FileInfo describes a character special file.

func (*Attr)IsDir

func (a *Attr) IsDir()bool

IsDir reports whether the FileInfo describes a directory.

func (*Attr)IsFifo

func (a *Attr) IsFifo()bool

func (*Attr)IsRegular

func (a *Attr) IsRegular()bool

IsRegular reports whether the FileInfo describes a regular file.

func (*Attr)IsSocket

func (a *Attr) IsSocket()bool

IsSocket reports whether the FileInfo describes a socket.

func (*Attr)IsSymlink

func (a *Attr) IsSymlink()bool

IsSymlink reports whether the FileInfo describes a symbolic link.

func (*Attr)ModTime

func (a *Attr) ModTime()time.Time

func (*Attr)SetTimes

func (a *Attr) SetTimes(access *time.Time, mod *time.Time, chstatus *time.Time)

func (*Attr)String

func (a *Attr) String()string

typeAttrOut

type AttrOut struct {AttrValiduint64AttrValidNsecuint32Dummyuint32Attr}

func (*AttrOut)SetTimeout

func (o *AttrOut) SetTimeout(dttime.Duration)

func (*AttrOut)Timeout

func (o *AttrOut) Timeout()time.Duration

typeCaller

type Caller struct {OwnerPiduint32}

Caller has data on the process making the FS call.

The UID and GID are effective UID/GID, except for the ACCESSopcode, where UID and GID are the real UIDs

funcFromContext

func FromContext(ctxcontext.Context) (*Caller,bool)

typeContext

type Context struct {CallerCancel <-chan struct{}}

Context passes along cancelation signal and request data (PID, GID,UID). The name of this class predates the standard "context"package from Go, but it does implement the context.Contextinterface.

When a FUSE request is canceled, the API routine should respond byreturning the EINTR status code.

func (*Context)Deadline

func (c *Context) Deadline() (time.Time,bool)

func (*Context)Done

func (c *Context) Done() <-chan struct{}

func (*Context)Err

func (c *Context) Err()error

func (*Context)Value

func (c *Context) Value(key interface{}) interface{}

typeCopyFileRangeIn

type CopyFileRangeIn struct {InHeaderFhInuint64OffInuint64NodeIdOutuint64FhOutuint64OffOutuint64Lenuint64Flagsuint64}

typeCreateIn

type CreateIn struct {InHeaderFlagsuint32// Mode for the new file; already takes Umask into account.Modeuint32// Umask used for this create call.Umaskuint32Paddinguint32}

typeCreateOut

type CreateOut struct {EntryOutOpenOut}

typeDirEntry

type DirEntry struct {// Mode is the file's mode. Only the high bits (eg. S_IFDIR)// are considered.Modeuint32// Name is the basename of the file in the directory.Namestring// Ino is the inode number.Inouint64}

DirEntry is a type for PathFileSystem and NodeFileSystem to returndirectory contents in.

func (DirEntry)String

func (dDirEntry) String()string

typeDirEntryList

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

DirEntryList holds the return value for READDIR and READDIRPLUSopcodes.

funcNewDirEntryList

func NewDirEntryList(data []byte, offuint64) *DirEntryList

NewDirEntryList creates a DirEntryList with the given data bufferand offset.

func (*DirEntryList)Add

func (l *DirEntryList) Add(prefixint, namestring, inodeuint64, modeuint32)bool

Add adds a direntry to the DirEntryList, returning whether itsucceeded.

func (*DirEntryList)AddDirEntry

func (l *DirEntryList) AddDirEntry(eDirEntry)bool

AddDirEntry tries to add an entry, and reports whether itsucceeded.

func (*DirEntryList)AddDirLookupEntry

func (l *DirEntryList) AddDirLookupEntry(eDirEntry) *EntryOut

AddDirLookupEntry is used for ReadDirPlus. If reserves and zeroizes spacefor an EntryOut struct and serializes a DirEntry.On success, it returns pointers to both structs.If not enough space was left, it returns two nil pointers.

The resulting READDIRPLUS output buffer looks like this in memory:1) EntryOut{}2) _Dirent{}3) Name (null-terminated)4) Padding to align to 8 bytes[repeat]

func (*DirEntryList)FixModeadded inv2.0.3

func (l *DirEntryList) FixMode(modeuint32)

FixMode overrides the file mode of the last direntry that was added. This canbe needed when a directory changes while READDIRPLUS is running.Only the file type bits of mode are considered, the rest is masked out.

typeEntryOut

type EntryOut struct {NodeIduint64Generationuint64EntryValiduint64AttrValiduint64EntryValidNsecuint32AttrValidNsecuint32Attr}

EntryOut holds the result of a (directory,name) lookup. It has twoTTLs, one for the (directory, name) lookup itself, and one for theattributes (eg. size, mode). The entry TTL also applies if thelookup result is ENOENT ("negative entry lookup")

func (*EntryOut)AttrTimeout

func (o *EntryOut) AttrTimeout()time.Duration

func (*EntryOut)EntryTimeout

func (o *EntryOut) EntryTimeout()time.Duration

EntryTimeout returns entry timeout currently

func (*EntryOut)SetAttrTimeout

func (o *EntryOut) SetAttrTimeout(dttime.Duration)

func (*EntryOut)SetEntryTimeout

func (o *EntryOut) SetEntryTimeout(dttime.Duration)

typeFallocateIn

type FallocateIn struct {InHeaderFhuint64Offsetuint64Lengthuint64Modeuint32Paddinguint32}

typeFileLock

type FileLock struct {Startuint64Enduint64Typuint32Piduint32}

func (*FileLock)FromFlockT

func (lk *FileLock) FromFlockT(flockT *syscall.Flock_t)

func (*FileLock)ToFlockT

func (lk *FileLock) ToFlockT(flockT *syscall.Flock_t)

typeFlushIn

type FlushIn struct {InHeaderFhuint64Unuseduint32Paddinguint32LockOwneruint64}

typeForgetIn

type ForgetIn struct {InHeaderNlookupuint64}

typeFsyncIn

type FsyncIn struct {InHeaderFhuint64FsyncFlagsuint32Paddinguint32}

typeGetAttrIn

type GetAttrIn struct {InHeaderFlags_uint32Dummyuint32Fh_uint64}

func (*GetAttrIn)Fh

func (g *GetAttrIn) Fh()uint64

Fh accesses the file handle. This is a method, because OSXFuse does nothave GetAttrIn flags.

func (*GetAttrIn)Flags

func (g *GetAttrIn) Flags()uint32

Flags accesses the flags. This is a method, because OSXFuse does nothave GetAttrIn flags.

typeGetXAttrIn

type GetXAttrIn struct {InHeaderSizeuint32Paddinguint32}

typeGetXAttrOut

type GetXAttrOut struct {Sizeuint32Paddinguint32}

typeInHeader

type InHeader struct {Lengthuint32Opcodeuint32Uniqueuint64NodeIduint64CallerPaddinguint32}

typeInitIn

type InitIn struct {InHeaderMajoruint32Minoruint32MaxReadAheaduint32Flagsuint32}

func (*InitIn)SupportsNotify

func (in *InitIn) SupportsNotify(notifyTypeint)bool

SupportsNotify returns whether a certain notification type issupported. Pass any of the NOTIFY_* types as argument.

func (*InitIn)SupportsVersion

func (in *InitIn) SupportsVersion(maj, minuint32)bool

SupportsVersion returns true if the kernel supports the givenprotocol version or newer.

typeInitOut

type InitOut struct {Majoruint32Minoruint32MaxReadAheaduint32Flagsuint32MaxBackgrounduint16CongestionThresholduint16MaxWriteuint32TimeGranuint32MaxPagesuint16Paddinguint16Unused              [8]uint32}

typeInterruptIn

type InterruptIn struct {InHeaderUniqueuint64}

typeLatencyMap

type LatencyMap interface {Add(namestring, dttime.Duration)}

This type may be provided for recording latencies of each FUSEoperation.

typeLinkIn

type LinkIn struct {InHeaderOldnodeiduint64}

typeLkIn

type LkIn struct {InHeaderFhuint64Owneruint64LkFileLockLkFlagsuint32Paddinguint32}

typeLkOut

type LkOut struct {LkFileLock}

typeLseekIn

type LseekIn struct {InHeaderFhuint64Offsetuint64Whenceuint32Paddinguint32}

typeLseekOut

type LseekOut struct {Offsetuint64}

typeMkdirIn

type MkdirIn struct {InHeader// The mode for the new directory. The calling process' umask// is already factored into the mode.Modeuint32Umaskuint32}

typeMknodIn

type MknodIn struct {InHeader// Mode to use, including the Umask valueModeuint32Rdevuint32Umaskuint32Paddinguint32}

typeMountOptions

type MountOptions struct {AllowOtherbool// Options are passed as -o string to fusermount.Options []string// Default is _DEFAULT_BACKGROUND_TASKS, 12.  This numbers// controls the allowed number of requests that relate to// async I/O.  Concurrency for synchronous I/O is not limited.MaxBackgroundint// Write size to use.  If 0, use default. This number is// capped at the kernel maximum.MaxWriteint// Max read ahead to use.  If 0, use default. This number is// capped at the kernel maximum.MaxReadAheadint// If IgnoreSecurityLabels is set, all security related xattr// requests will return NO_DATA without passing through the// user defined filesystem.  You should only set this if you// file system implements extended attributes, and you are not// interested in security labels.IgnoreSecurityLabelsbool// ignoring labels should be provided as a fusermount mount option.// If RememberInodes is set, we will never forget inodes.// This may be useful for NFS.RememberInodesbool// Values shown in "df -T" and friends// First column, "Filesystem"FsNamestring// Second column, "Type", will be shown as "fuse." + NameNamestring// If set, wrap the file system in a single-threaded locking wrapper.SingleThreadedbool// If set, return ENOSYS for Getxattr calls, so the kernel does not issue any// Xattr operations at all.DisableXAttrsbool// If set, print debugging information.Debugbool// If set, ask kernel to forward file locks to FUSE. If using,// you must implement the GetLk/SetLk/SetLkw methods.EnableLocksbool// If set, ask kernel not to do automatic data cache invalidation.// The filesystem is fully responsible for invalidating data cache.ExplicitDataCacheControlbool// If set, fuse will first attempt to use syscall.Mount instead of// fusermount to mount the filesystem. This will not update /etc/mtab// but might be needed if fusermount is not available.DirectMountbool// Options passed to syscall.Mount, the default value used by fusermount// is syscall.MS_NOSUID|syscall.MS_NODEVDirectMountFlagsuintptr}

typeNotifyInvalDeleteOut

type NotifyInvalDeleteOut struct {Parentuint64Childuint64NameLenuint32Paddinguint32}

typeNotifyInvalEntryOut

type NotifyInvalEntryOut struct {Parentuint64NameLenuint32Paddinguint32}

typeNotifyInvalInodeOut

type NotifyInvalInodeOut struct {Inouint64Offint64Lengthint64}

typeNotifyRetrieveIn

type NotifyRetrieveIn struct {InHeaderDummy1uint64Offsetuint64Sizeuint32Dummy2uint32Dummy3uint64Dummy4uint64}

typeNotifyRetrieveOut

type NotifyRetrieveOut struct {NotifyUniqueuint64Nodeiduint64Offsetuint64Sizeuint32Paddinguint32}

typeNotifyStoreOut

type NotifyStoreOut struct {Nodeiduint64Offsetuint64Sizeuint32Paddinguint32}

typeOpenIn

type OpenIn struct {InHeaderFlagsuint32Modeuint32}

typeOpenOut

type OpenOut struct {Fhuint64OpenFlagsuint32Paddinguint32}

typeOutHeader

type OutHeader struct {Lengthuint32Statusint32Uniqueuint64}

typeOwner

type Owner struct {Uiduint32Giduint32}

funcCurrentOwner

func CurrentOwner() *Owner

typeRawFileSystem

type RawFileSystem interface {String()string// If called, provide debug output through the log package.SetDebug(debugbool)// Lookup is called by the kernel when the VFS wants to know// about a file inside a directory. Many lookup calls can// occur in parallel, but only one call happens for each (dir,// name) pair.Lookup(cancel <-chan struct{}, header *InHeader, namestring, out *EntryOut) (statusStatus)// Forget is called when the kernel discards entries from its// dentry cache. This happens on unmount, and when the kernel// is short on memory. Since it is not guaranteed to occur at// any moment, and since there is no return value, Forget// should not do I/O, as there is no channel to report back// I/O errors.Forget(nodeid, nlookupuint64)// Attributes.GetAttr(cancel <-chan struct{}, input *GetAttrIn, out *AttrOut) (codeStatus)SetAttr(cancel <-chan struct{}, input *SetAttrIn, out *AttrOut) (codeStatus)// Modifying structure.Mknod(cancel <-chan struct{}, input *MknodIn, namestring, out *EntryOut) (codeStatus)Mkdir(cancel <-chan struct{}, input *MkdirIn, namestring, out *EntryOut) (codeStatus)Unlink(cancel <-chan struct{}, header *InHeader, namestring) (codeStatus)Rmdir(cancel <-chan struct{}, header *InHeader, namestring) (codeStatus)Rename(cancel <-chan struct{}, input *RenameIn, oldNamestring, newNamestring) (codeStatus)Link(cancel <-chan struct{}, input *LinkIn, filenamestring, out *EntryOut) (codeStatus)Symlink(cancel <-chan struct{}, header *InHeader, pointedTostring, linkNamestring, out *EntryOut) (codeStatus)Readlink(cancel <-chan struct{}, header *InHeader) (out []byte, codeStatus)Access(cancel <-chan struct{}, input *AccessIn) (codeStatus)// GetXAttr reads an extended attribute, and should return the// number of bytes. If the buffer is too small, return ERANGE,// with the required buffer size.GetXAttr(cancel <-chan struct{}, header *InHeader, attrstring, dest []byte) (szuint32, codeStatus)// ListXAttr lists extended attributes as '\0' delimited byte// slice, and return the number of bytes. If the buffer is too// small, return ERANGE, with the required buffer size.ListXAttr(cancel <-chan struct{}, header *InHeader, dest []byte) (uint32,Status)// SetAttr writes an extended attribute.SetXAttr(cancel <-chan struct{}, input *SetXAttrIn, attrstring, data []byte)Status// RemoveXAttr removes an extended attribute.RemoveXAttr(cancel <-chan struct{}, header *InHeader, attrstring) (codeStatus)// File handling.Create(cancel <-chan struct{}, input *CreateIn, namestring, out *CreateOut) (codeStatus)Open(cancel <-chan struct{}, input *OpenIn, out *OpenOut) (statusStatus)Read(cancel <-chan struct{}, input *ReadIn, buf []byte) (ReadResult,Status)Lseek(cancel <-chan struct{}, in *LseekIn, out *LseekOut)Status// File lockingGetLk(cancel <-chan struct{}, input *LkIn, out *LkOut) (codeStatus)SetLk(cancel <-chan struct{}, input *LkIn) (codeStatus)SetLkw(cancel <-chan struct{}, input *LkIn) (codeStatus)Release(cancel <-chan struct{}, input *ReleaseIn)Write(cancel <-chan struct{}, input *WriteIn, data []byte) (writtenuint32, codeStatus)CopyFileRange(cancel <-chan struct{}, input *CopyFileRangeIn) (writtenuint32, codeStatus)Flush(cancel <-chan struct{}, input *FlushIn)StatusFsync(cancel <-chan struct{}, input *FsyncIn) (codeStatus)Fallocate(cancel <-chan struct{}, input *FallocateIn) (codeStatus)// Directory handlingOpenDir(cancel <-chan struct{}, input *OpenIn, out *OpenOut) (statusStatus)ReadDir(cancel <-chan struct{}, input *ReadIn, out *DirEntryList)StatusReadDirPlus(cancel <-chan struct{}, input *ReadIn, out *DirEntryList)StatusReleaseDir(input *ReleaseIn)FsyncDir(cancel <-chan struct{}, input *FsyncIn) (codeStatus)StatFs(cancel <-chan struct{}, input *InHeader, out *StatfsOut) (codeStatus)// This is called on processing the first request. The// filesystem implementation can use the server argument to// talk back to the kernel (through notify methods).Init(*Server)}

RawFileSystem is an interface close to the FUSE wire protocol.

Unless you really know what you are doing, you should not implementthis, but rather the nodefs.Node or pathfs.FileSystem interfaces; thedetails of getting interactions with open files, renames, and threadingright etc. are somewhat tricky and not very interesting.

Each FUSE request results in a corresponding method called by Server.Several calls may be made simultaneously, because the server typically callseach method in separate goroutine.

A null implementation is provided by NewDefaultRawFileSystem.

After a successful FUSE API call returns, you may not read input orwrite output data: for performance reasons, memory is reused forfollowing requests, and reading/writing the request data will leadto race conditions. If you spawn a background routine from a FUSEAPI call, any incoming request data it wants to reference should becopied over.

If a FUSE API call is canceled (which is signaled by closing the`cancel` channel), the API call should return EINTR. In this case,the outstanding request data is not reused, so the API call mayreturn EINTR without ensuring that child contexts have successfullycompleted.

funcNewDefaultRawFileSystem

func NewDefaultRawFileSystem()RawFileSystem

NewDefaultRawFileSystem returns ENOSYS (not implemented) for alloperations.

typeReadIn

type ReadIn struct {InHeaderFhuint64Offsetuint64Sizeuint32ReadFlagsuint32LockOwneruint64Flagsuint32Paddinguint32}

typeReadResult

type ReadResult interface {// Returns the raw bytes for the read, possibly using the// passed buffer. The buffer should be larger than the return// value from Size.Bytes(buf []byte) ([]byte,Status)// Size returns how many bytes this return value takes at most.Size()int// Done() is called after sending the data to the kernel.Done()}

The result of Read is an array of bytes, but for performancereasons, we can also return data as a file-descriptor/offset/sizetuple. If the backing store for a file is another filesystem, thisreduces the amount of copying between the kernel and the FUSEserver. The ReadResult interface captures both cases.

funcReadResultData

func ReadResultData(b []byte)ReadResult

funcReadResultFd

func ReadResultFd(fduintptr, offint64, szint)ReadResult

typeReleaseIn

type ReleaseIn struct {InHeaderFhuint64Flagsuint32ReleaseFlagsuint32LockOwneruint64}

typeRename1In

type Rename1In struct {InHeaderNewdiruint64}

typeRenameIn

type RenameIn struct {InHeaderNewdiruint64Flagsuint32Paddinguint32}

typeServer

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

Server contains the logic for reading from the FUSE device andtranslating it to RawFileSystem interface calls.

funcNewServer

func NewServer(fsRawFileSystem, mountPointstring, opts *MountOptions) (*Server,error)

NewServer creates a server and attaches it to the given directory.

func (*Server)DebugData

func (ms *Server) DebugData()string

DebugData returns internal status information for debuggingpurposes.

func (*Server)DeleteNotify

func (ms *Server) DeleteNotify(parentuint64, childuint64, namestring)Status

DeleteNotify notifies the kernel that an entry is removed from adirectory. In many cases, this is equivalent to EntryNotify,except when the directory is in use, eg. as working directory ofsome process. You should not hold any FUSE filesystem locks, as thatcan lead to deadlock.

func (*Server)EntryNotify

func (ms *Server) EntryNotify(parentuint64, namestring)Status

EntryNotify should be used if the existence status of an entrywithin a directory changes. You should not hold any FUSE filesystemlocks, as that can lead to deadlock.

func (*Server)InodeNotify

func (ms *Server) InodeNotify(nodeuint64, offint64, lengthint64)Status

InodeNotify invalidates the information associated with the inode(ie. data cache, attributes, etc.)

func (*Server)InodeNotifyStoreCache

func (ms *Server) InodeNotifyStoreCache(nodeuint64, offsetint64, data []byte)Status

InodeNotifyStoreCache tells kernel to store data into inode's cache.

This call is similar to InodeNotify, but instead of only invalidating a dataregion, it gives updated data directly to the kernel.

func (*Server)InodeRetrieveCache

func (ms *Server) InodeRetrieveCache(nodeuint64, offsetint64, dest []byte) (nint, stStatus)

InodeRetrieveCache retrieves data from kernel's inode cache.

InodeRetrieveCache asks kernel to return data from its cache for inode at[offset:offset+len(dest)) and waits for corresponding reply. If kernel cachehas fewer consecutive data starting at offset, that fewer amount is returned.In particular if inode data at offset is not cached (0, OK) is returned.

The kernel returns ENOENT if it does not currently have entry for this inodein its dentry cache.

func (*Server)KernelSettings

func (ms *Server) KernelSettings() *InitIn

KernelSettings returns the Init message from the kernel, sofilesystems can adapt to availability of features of the kerneldriver. The message should not be altered.

func (*Server)RecordLatencies

func (ms *Server) RecordLatencies(lLatencyMap)

RecordLatencies switches on collection of timing for each requestcoming from the kernel.P assing a nil argument switches off the

func (*Server)Serve

func (ms *Server) Serve()

Serve initiates the FUSE loop. Normally, callers should run Serve()and wait for it to exit, but tests will want to run this in agoroutine.

Each filesystem operation executes in a separate goroutine.

func (*Server)SetDebug

func (ms *Server) SetDebug(dbgbool)

SetDebug is deprecated. Use MountOptions.Debug instead.

func (*Server)Unmount

func (ms *Server) Unmount() (errerror)

Unmount calls fusermount -u on the mount. This has the effect ofshutting down the filesystem. After the Server is unmounted, itshould be discarded.

func (*Server)Wait

func (ms *Server) Wait()

Wait waits for the serve loop to exit. This should only be calledafter Serve has been called, or it will hang indefinitely.

func (*Server)WaitMount

func (ms *Server) WaitMount()error

WaitMount waits for the first request to be served. Use this toavoid racing between accessing the (empty or not yet mounted)mountpoint, and the OS trying to setup the user-space mount.

typeSetAttrIn

type SetAttrIn struct {SetAttrInCommon}

typeSetAttrInCommon

type SetAttrInCommon struct {InHeaderValiduint32Paddinguint32Fhuint64Sizeuint64LockOwneruint64Atimeuint64Mtimeuint64Ctimeuint64Atimensecuint32Mtimensecuint32Ctimensecuint32Modeuint32Unused4uint32OwnerUnused5uint32}

func (*SetAttrInCommon)GetATime

func (s *SetAttrInCommon) GetATime() (time.Time,bool)

func (*SetAttrInCommon)GetCTime

func (s *SetAttrInCommon) GetCTime() (time.Time,bool)

func (*SetAttrInCommon)GetFh

func (s *SetAttrInCommon) GetFh() (uint64,bool)

GetFh returns the file handle if available, or 0 if undefined.

func (*SetAttrInCommon)GetGID

func (s *SetAttrInCommon) GetGID() (uint32,bool)

func (*SetAttrInCommon)GetMTime

func (s *SetAttrInCommon) GetMTime() (time.Time,bool)

func (*SetAttrInCommon)GetMode

func (s *SetAttrInCommon) GetMode() (uint32,bool)

func (*SetAttrInCommon)GetSize

func (s *SetAttrInCommon) GetSize() (uint64,bool)

func (*SetAttrInCommon)GetUID

func (s *SetAttrInCommon) GetUID() (uint32,bool)

typeSetXAttrIn

type SetXAttrIn struct {InHeaderSizeuint32Flagsuint32}

typeStatfsOut

type StatfsOut struct {Blocksuint64Bfreeuint64Bavailuint64Filesuint64Ffreeuint64Bsizeuint32NameLenuint32Frsizeuint32Paddinguint32Spare   [6]uint32}

func (*StatfsOut)FromStatfsT

func (s *StatfsOut) FromStatfsT(statfs *syscall.Statfs_t)

typeStatus

type Statusint32

Status is the errno number that a FUSE call returns to the kernel.

funcToStatus

func ToStatus(errerror)Status

ToStatus extracts an errno number from Go error objects. If itfails, it logs an error and returns ENOSYS.

func (Status)Ok

func (codeStatus) Ok()bool

func (Status)String

func (codeStatus) String()string

typeWriteIn

type WriteIn struct {InHeaderFhuint64Offsetuint64Sizeuint32WriteFlagsuint32LockOwneruint64Flagsuint32Paddinguint32}

typeWriteOut

type WriteOut struct {Sizeuint32Paddinguint32}

Source Files

View all Source files

Directories

PathSynopsis
This package is deprecated.
This package is deprecated.
This package is deprecated.
This package is deprecated.
Package test holds the tests for Go-FUSE and is not for end-user consumption.
Package test holds the tests for Go-FUSE and is not for end-user consumption.

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