Commit 10a8a773 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Put user-serviceable types in api.go, and document.

parent 490d393c
......@@ -3,7 +3,8 @@ include $(GOROOT)/src/Make.inc
TARG=github.com/hanwen/go-fuse/fuse
GOFILES=misc.go\
GOFILES=api.go \
misc.go\
request.go \
fuse.go\
direntry.go\
......
package fuse
// Types for users to implement.
// A filesystem API that uses paths rather than inodes. A minimal
// file system should have at least a functional GetAttr method.
// Typically, each call happens in its own goroutine, so take care to
// make the file system thread-safe.
//
// Include DefaultFileSystem to provide default null implementation of
// required methods.
type FileSystem interface {
// Attributes
GetAttr(name string) (*Attr, Status)
Chmod(name string, mode uint32) (code Status)
Chown(name string, uid uint32, gid uint32) (code Status)
Utimens(name string, AtimeNs uint64, CtimeNs uint64) (code Status)
Truncate(name string, offset uint64) (code Status)
Access(name string, mode uint32) (code Status)
// Tree structure
Link(oldName string, newName string) (code Status)
Mkdir(name string, mode uint32) Status
Mknod(name string, mode uint32, dev uint32) Status
Rename(oldName string, newName string) (code Status)
Rmdir(name string) (code Status)
Unlink(name string) (code Status)
// Extended attributes.
GetXAttr(name string, attribute string) (data []byte, code Status)
ListXAttr(name string) (attributes []string, code Status)
RemoveXAttr(name string, attr string) Status
SetXAttr(name string, attr string, data []byte, flags int) Status
// Called after mount.
Mount(connector *FileSystemConnector) Status
Unmount()
// File handling
Open(name string, flags uint32) (file File, code Status)
Create(name string, flags uint32, mode uint32) (file File, code Status)
// Directory handling
OpenDir(name string) (stream chan DirEntry, code Status)
// Symlinks.
Symlink(value string, linkName string) (code Status)
Readlink(name string) (string, Status)
}
// A File object should be returned from FileSystem.Open and
// FileSystem.Create. Include DefaultFile into the struct to inherit
// a default null implementation.
//
// TODO - should File be thread safe?
type File interface {
Read(*ReadIn, *BufferPool) ([]byte, Status)
Write(*WriteIn, []byte) (written uint32, code Status)
Flush() Status
Release()
Fsync(*FsyncIn) (code Status)
GetAttr() (*Attr, Status)
Chown(uid uint32, gid uint32) Status
Chmod(perms uint32) Status
Utimens(atimeNs uint64, mtimeNs uint64) Status
Truncate(size uint64) Status
}
// MountOptions contains time out options for a FileSystem. The
// default copied from libfuse and set in NewMountOptions() is
// (1s,1s,0s).
type MountOptions struct {
EntryTimeout float64
AttrTimeout float64
NegativeTimeout float64
}
// DefaultFileSystem implements a FileSystem that returns ENOSYS for every operation.
type DefaultFileSystem struct{}
// DefaultFile returns ENOSYS for every operation.
type DefaultFile struct{}
// RawFileSystem is an interface closer to the FUSE wire protocol.
//
// Unless you really know what you are doing, you should not implement
// this, but rather the FileSystem interface; the details of getting
// interactions with open files, renames, and threading right etc. are
// somewhat tricky and not very interesting.
//
// Include DefaultRawFileSystem to inherit a null implementation.
type RawFileSystem interface {
Destroy(h *InHeader, input *InitIn)
Lookup(header *InHeader, name string) (out *EntryOut, status Status)
Forget(header *InHeader, input *ForgetIn)
// Attributes.
GetAttr(header *InHeader, input *GetAttrIn) (out *AttrOut, code Status)
SetAttr(header *InHeader, input *SetAttrIn) (out *AttrOut, code Status)
// Modifying structure.
Mknod(header *InHeader, input *MknodIn, name string) (out *EntryOut, code Status)
Mkdir(header *InHeader, input *MkdirIn, name string) (out *EntryOut, code Status)
Unlink(header *InHeader, name string) (code Status)
Rmdir(header *InHeader, name string) (code Status)
Rename(header *InHeader, input *RenameIn, oldName string, newName string) (code Status)
Link(header *InHeader, input *LinkIn, filename string) (out *EntryOut, code Status)
Symlink(header *InHeader, pointedTo string, linkName string) (out *EntryOut, code Status)
Readlink(header *InHeader) (out []byte, code Status)
Access(header *InHeader, input *AccessIn) (code Status)
// Extended attributes.
GetXAttr(header *InHeader, attr string) (data []byte, code Status)
ListXAttr(header *InHeader) (attributes []byte, code Status)
SetXAttr(header *InHeader, input *SetXAttrIn, attr string, data []byte) Status
RemoveXAttr(header *InHeader, attr string) (code Status)
// File handling.
Create(header *InHeader, input *CreateIn, name string) (flags uint32, handle uint64, out *EntryOut, code Status)
Open(header *InHeader, input *OpenIn) (flags uint32, handle uint64, status Status)
Read(*ReadIn, *BufferPool) ([]byte, Status)
Release(header *InHeader, input *ReleaseIn)
Write(*WriteIn, []byte) (written uint32, code Status)
Flush(*FlushIn) Status
Fsync(*FsyncIn) (code Status)
// Directory handling
OpenDir(header *InHeader, input *OpenIn) (flags uint32, handle uint64, status Status)
ReadDir(header *InHeader, input *ReadIn) (*DirEntryList, Status)
ReleaseDir(header *InHeader, input *ReleaseIn)
FsyncDir(header *InHeader, input *FsyncIn) (code Status)
}
// DefaultRawFileSystem returns ENOSYS for every operation.
type DefaultRawFileSystem struct{}
......@@ -249,9 +249,14 @@ func (me *FileSystemConnector) decodeFileHandle(h uint64) (interface{}, *mountDa
return b.Iface, b.mountData
}
func (me *FileSystemConnector) getDir(h uint64) (RawDir, *mountData) {
type rawDir interface {
ReadDir(input *ReadIn) (*DirEntryList, Status)
Release()
}
func (me *FileSystemConnector) getDir(h uint64) (rawDir, *mountData) {
f, m := me.decodeFileHandle(h)
return f.(RawDir), m
return f.(rawDir), m
}
func (me *FileSystemConnector) getFile(h uint64) (File, *mountData) {
......
......@@ -381,7 +381,7 @@ func (me *FileSystemConnector) Release(header *InHeader, input *ReleaseIn) {
func (me *FileSystemConnector) ReleaseDir(header *InHeader, input *ReleaseIn) {
node := me.getInodeData(header.NodeId)
d := me.unregisterFile(node, input.Fh).(RawDir)
d := me.unregisterFile(node, input.Fh).(rawDir)
d.Release()
me.considerDropInode(node)
}
......
......@@ -454,134 +454,3 @@ type NotifyInvalEntryOut struct {
}
////////////////////////////////////////////////////////////////
// Types for users to implement.
// This is the interface to the file system, mirroring the interface from
//
// /usr/include/fuse/fuse_lowlevel.h
//
// Typically, each call happens in its own goroutine, so any global
// data should be made thread-safe. Unless you really know what you
// are doing, you should not implement this, but FileSystem below;
// the details of getting interactions with open files, renames, and
// threading right etc. are somewhat tricky and not very interesting.
type RawFileSystem interface {
Destroy(h *InHeader, input *InitIn)
Lookup(header *InHeader, name string) (out *EntryOut, status Status)
Forget(header *InHeader, input *ForgetIn)
GetAttr(header *InHeader, input *GetAttrIn) (out *AttrOut, code Status)
SetAttr(header *InHeader, input *SetAttrIn) (out *AttrOut, code Status)
Readlink(header *InHeader) (out []byte, code Status)
Mknod(header *InHeader, input *MknodIn, name string) (out *EntryOut, code Status)
Mkdir(header *InHeader, input *MkdirIn, name string) (out *EntryOut, code Status)
Unlink(header *InHeader, name string) (code Status)
Rmdir(header *InHeader, name string) (code Status)
Symlink(header *InHeader, pointedTo string, linkName string) (out *EntryOut, code Status)
Rename(header *InHeader, input *RenameIn, oldName string, newName string) (code Status)
Link(header *InHeader, input *LinkIn, filename string) (out *EntryOut, code Status)
GetXAttr(header *InHeader, attr string) (data []byte, code Status)
ListXAttr(header *InHeader) (attributes []byte, code Status)
SetXAttr(header *InHeader, input *SetXAttrIn, attr string, data []byte) Status
RemoveXAttr(header *InHeader, attr string) (code Status)
Access(header *InHeader, input *AccessIn) (code Status)
Create(header *InHeader, input *CreateIn, name string) (flags uint32, handle uint64, out *EntryOut, code Status)
/*
// unimplemented.
Bmap(header *InHeader, input *BmapIn) (out *BmapOut, code Status)
Ioctl(header *InHeader, input *IoctlIn) (out *IoctlOut, code Status)
Poll(header *InHeader, input *PollIn) (out *PollOut, code Status)
*/
// File handling.
Open(header *InHeader, input *OpenIn) (flags uint32, handle uint64, status Status)
Read(*ReadIn, *BufferPool) ([]byte, Status)
Release(header *InHeader, input *ReleaseIn)
Write(*WriteIn, []byte) (written uint32, code Status)
Flush(*FlushIn) Status
Fsync(*FsyncIn) (code Status)
// Directory handling
OpenDir(header *InHeader, input *OpenIn) (flags uint32, handle uint64, status Status)
ReadDir(header *InHeader, input *ReadIn) (*DirEntryList, Status)
ReleaseDir(header *InHeader, input *ReleaseIn)
FsyncDir(header *InHeader, input *FsyncIn) (code Status)
}
type File interface {
Read(*ReadIn, *BufferPool) ([]byte, Status)
// u32 <-> u64 ?
Write(*WriteIn, []byte) (written uint32, code Status)
Flush() Status
Release()
Fsync(*FsyncIn) (code Status)
GetAttr() (*Attr, Status)
Chown(uid uint32, gid uint32) Status
Chmod(perms uint32) Status
Utimens(atimeNs uint64, mtimeNs uint64) Status
Truncate(size uint64) Status
}
type RawDir interface {
ReadDir(input *ReadIn) (*DirEntryList, Status)
Release()
}
type FileSystem interface {
GetAttr(name string) (*Attr, Status)
Readlink(name string) (string, Status)
Mknod(name string, mode uint32, dev uint32) Status
Mkdir(name string, mode uint32) Status
Unlink(name string) (code Status)
Rmdir(name string) (code Status)
Symlink(value string, linkName string) (code Status)
Rename(oldName string, newName string) (code Status)
Link(oldName string, newName string) (code Status)
Chmod(name string, mode uint32) (code Status)
Chown(name string, uid uint32, gid uint32) (code Status)
Truncate(name string, offset uint64) (code Status)
Open(name string, flags uint32) (file File, code Status)
GetXAttr(name string, attribute string) (data []byte, code Status)
SetXAttr(name string, attr string, data []byte, flags int) Status
ListXAttr(name string) (attributes []string, code Status)
RemoveXAttr(name string, attr string) Status
// Where to hook up statfs?
OpenDir(name string) (stream chan DirEntry, code Status)
// TODO - what is a good interface?
Mount(connector *FileSystemConnector) Status
Unmount()
Access(name string, mode uint32) (code Status)
Create(name string, flags uint32, mode uint32) (file File, code Status)
Utimens(name string, AtimeNs uint64, CtimeNs uint64) (code Status)
// unimplemented: poll, ioctl, bmap.
}
// MountOptions contains time out options for a FileSystem. The
// default copied from libfuse and set in NewMountOptions() is
// (1s,1s,0s).
type MountOptions struct {
EntryTimeout float64
AttrTimeout float64
NegativeTimeout float64
}
// Include these structs in your implementation to inherit default nop
// implementations.
type DefaultFileSystem struct{}
type DefaultFile struct{}
type DefaultRawFileSystem struct{}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment