Commit 18e0e322 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

nodefs: more method documentation

parent 2f9c4b1d
...@@ -85,3 +85,4 @@ or ...@@ -85,3 +85,4 @@ or
* Merge Fsync/FsyncDir? * Merge Fsync/FsyncDir?
* OnMount in Operations or in Options? Or argument to NewNodeFS ?
...@@ -67,8 +67,8 @@ func InodeOf(node Operations) *Inode { ...@@ -67,8 +67,8 @@ func InodeOf(node Operations) *Inode {
return node.inode() return node.inode()
} }
// Operations is the interface that implements the filesystem. Each // Operations is the interface that implements the filesystem inode.
// Operations instance must embed DefaultNode. // Each Operations instance must embed DefaultNode.
type Operations interface { type Operations interface {
// setInode and inode are used by nodefs internally to link Inode to a Node. // setInode and inode are used by nodefs internally to link Inode to a Node.
// //
...@@ -293,7 +293,6 @@ type FileHandle interface { ...@@ -293,7 +293,6 @@ type FileHandle interface {
// Options sets options for the entire filesystem // Options sets options for the entire filesystem
type Options struct { type Options struct {
// Debug toggles debug output // Debug toggles debug output
Debug bool Debug bool
......
...@@ -13,9 +13,10 @@ import ( ...@@ -13,9 +13,10 @@ import (
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
) )
// DefaultOperations provides stubs that return ENOSYS for all functions // DefaultOperations provides stubs that return ENOENT for almost all
// functions.
// //
// It must be embedded in any Node implementation. // It must be embedded in any Operations implementation.
type DefaultOperations struct { type DefaultOperations struct {
inode_ *Inode inode_ *Inode
} }
...@@ -51,6 +52,8 @@ func (n *DefaultOperations) inode() *Inode { ...@@ -51,6 +52,8 @@ func (n *DefaultOperations) inode() *Inode {
(*unsafe.Pointer)(unsafe.Pointer(&n.inode_)))) (*unsafe.Pointer)(unsafe.Pointer(&n.inode_))))
} }
// StatFs zeroes the out argument and returns OK. This is because OSX
// filesystems must define this, or the mount will not work.
func (n *DefaultOperations) StatFs(ctx context.Context, out *fuse.StatfsOut) fuse.Status { func (n *DefaultOperations) StatFs(ctx context.Context, out *fuse.StatfsOut) fuse.Status {
// this should be defined on OSX, or the FS won't mount // this should be defined on OSX, or the FS won't mount
*out = fuse.StatfsOut{} *out = fuse.StatfsOut{}
...@@ -58,78 +61,78 @@ func (n *DefaultOperations) StatFs(ctx context.Context, out *fuse.StatfsOut) fus ...@@ -58,78 +61,78 @@ func (n *DefaultOperations) StatFs(ctx context.Context, out *fuse.StatfsOut) fus
} }
func (n *DefaultOperations) GetAttr(ctx context.Context, out *fuse.AttrOut) fuse.Status { func (n *DefaultOperations) GetAttr(ctx context.Context, out *fuse.AttrOut) fuse.Status {
return fuse.ENOSYS return fuse.ENOENT
} }
func (n *DefaultOperations) SetAttr(ctx context.Context, in *fuse.SetAttrIn, out *fuse.AttrOut) fuse.Status { func (n *DefaultOperations) SetAttr(ctx context.Context, in *fuse.SetAttrIn, out *fuse.AttrOut) fuse.Status {
return fuse.ENOSYS return fuse.ENOENT
} }
func (n *DefaultOperations) Access(ctx context.Context, mask uint32) fuse.Status { func (n *DefaultOperations) Access(ctx context.Context, mask uint32) fuse.Status {
return fuse.ENOSYS return fuse.ENOENT
} }
// **************************************************************** // FSetAttr delegates to the FileHandle's if f is not nil, or else to the
// Inode's SetAttr method.
func (n *DefaultOperations) FSetAttr(ctx context.Context, f FileHandle, in *fuse.SetAttrIn, out *fuse.AttrOut) fuse.Status { func (n *DefaultOperations) FSetAttr(ctx context.Context, f FileHandle, in *fuse.SetAttrIn, out *fuse.AttrOut) fuse.Status {
if f != nil { if f != nil {
return f.SetAttr(ctx, in, out) return f.SetAttr(ctx, in, out)
} }
return fuse.ENOSYS return n.inode_.Operations().SetAttr(ctx, in, out)
} }
func (n *DefaultOperations) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*Inode, fuse.Status) { func (n *DefaultOperations) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*Inode, fuse.Status) {
return nil, fuse.ENOSYS return nil, fuse.ENOENT
} }
func (n *DefaultOperations) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.EntryOut) (*Inode, fuse.Status) { func (n *DefaultOperations) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.EntryOut) (*Inode, fuse.Status) {
return nil, fuse.ENOSYS return nil, fuse.ENOENT
} }
func (n *DefaultOperations) Mknod(ctx context.Context, name string, mode uint32, dev uint32, out *fuse.EntryOut) (*Inode, fuse.Status) { func (n *DefaultOperations) Mknod(ctx context.Context, name string, mode uint32, dev uint32, out *fuse.EntryOut) (*Inode, fuse.Status) {
return nil, fuse.ENOSYS return nil, fuse.ENOENT
} }
func (n *DefaultOperations) Rmdir(ctx context.Context, name string) fuse.Status { func (n *DefaultOperations) Rmdir(ctx context.Context, name string) fuse.Status {
return fuse.ENOSYS return fuse.ENOENT
} }
func (n *DefaultOperations) Unlink(ctx context.Context, name string) fuse.Status { func (n *DefaultOperations) Unlink(ctx context.Context, name string) fuse.Status {
return fuse.ENOSYS return fuse.ENOENT
} }
func (n *DefaultOperations) OpenDir(ctx context.Context) fuse.Status { func (n *DefaultOperations) OpenDir(ctx context.Context) fuse.Status {
return fuse.ENOSYS return fuse.ENOENT
} }
func (n *DefaultOperations) ReadDir(ctx context.Context) (DirStream, fuse.Status) { func (n *DefaultOperations) ReadDir(ctx context.Context) (DirStream, fuse.Status) {
return nil, fuse.ENOSYS return nil, fuse.ENOENT
} }
func (n *DefaultOperations) Rename(ctx context.Context, name string, newParent Operations, newName string, flags uint32) fuse.Status { func (n *DefaultOperations) Rename(ctx context.Context, name string, newParent Operations, newName string, flags uint32) fuse.Status {
return fuse.ENOSYS return fuse.ENOENT
} }
func (n *DefaultOperations) Read(ctx context.Context, f FileHandle, dest []byte, off int64) (fuse.ReadResult, fuse.Status) { func (n *DefaultOperations) Read(ctx context.Context, f FileHandle, dest []byte, off int64) (fuse.ReadResult, fuse.Status) {
if f != nil { if f != nil {
return f.Read(ctx, dest, off) return f.Read(ctx, dest, off)
} }
return nil, fuse.ENOSYS return nil, fuse.ENOENT
} }
func (n *DefaultOperations) Symlink(ctx context.Context, target, name string, out *fuse.EntryOut) (node *Inode, status fuse.Status) { func (n *DefaultOperations) Symlink(ctx context.Context, target, name string, out *fuse.EntryOut) (node *Inode, status fuse.Status) {
log.Println("defsyml") log.Println("defsyml")
return nil, fuse.ENOSYS return nil, fuse.ENOENT
} }
func (n *DefaultOperations) Readlink(ctx context.Context) (string, fuse.Status) { func (n *DefaultOperations) Readlink(ctx context.Context) (string, fuse.Status) {
return "", fuse.ENOSYS return "", fuse.ENOENT
} }
func (n *DefaultOperations) Fsync(ctx context.Context, f FileHandle, flags uint32) fuse.Status { func (n *DefaultOperations) Fsync(ctx context.Context, f FileHandle, flags uint32) fuse.Status {
if f != nil { if f != nil {
return f.Fsync(ctx, flags) return f.Fsync(ctx, flags)
} }
return fuse.ENOSYS return fuse.ENOENT
} }
func (n *DefaultOperations) Write(ctx context.Context, f FileHandle, data []byte, off int64) (written uint32, status fuse.Status) { func (n *DefaultOperations) Write(ctx context.Context, f FileHandle, data []byte, off int64) (written uint32, status fuse.Status) {
...@@ -137,7 +140,7 @@ func (n *DefaultOperations) Write(ctx context.Context, f FileHandle, data []byte ...@@ -137,7 +140,7 @@ func (n *DefaultOperations) Write(ctx context.Context, f FileHandle, data []byte
return f.Write(ctx, data, off) return f.Write(ctx, data, off)
} }
return 0, fuse.ENOSYS return 0, fuse.ENOENT
} }
func (n *DefaultOperations) GetLk(ctx context.Context, f FileHandle, owner uint64, lk *fuse.FileLock, flags uint32, out *fuse.FileLock) (status fuse.Status) { func (n *DefaultOperations) GetLk(ctx context.Context, f FileHandle, owner uint64, lk *fuse.FileLock, flags uint32, out *fuse.FileLock) (status fuse.Status) {
...@@ -145,7 +148,7 @@ func (n *DefaultOperations) GetLk(ctx context.Context, f FileHandle, owner uint6 ...@@ -145,7 +148,7 @@ func (n *DefaultOperations) GetLk(ctx context.Context, f FileHandle, owner uint6
return f.GetLk(ctx, owner, lk, flags, out) return f.GetLk(ctx, owner, lk, flags, out)
} }
return fuse.ENOSYS return fuse.ENOENT
} }
func (n *DefaultOperations) SetLk(ctx context.Context, f FileHandle, owner uint64, lk *fuse.FileLock, flags uint32) (status fuse.Status) { func (n *DefaultOperations) SetLk(ctx context.Context, f FileHandle, owner uint64, lk *fuse.FileLock, flags uint32) (status fuse.Status) {
...@@ -153,7 +156,7 @@ func (n *DefaultOperations) SetLk(ctx context.Context, f FileHandle, owner uint6 ...@@ -153,7 +156,7 @@ func (n *DefaultOperations) SetLk(ctx context.Context, f FileHandle, owner uint6
return f.SetLk(ctx, owner, lk, flags) return f.SetLk(ctx, owner, lk, flags)
} }
return fuse.ENOSYS return fuse.ENOENT
} }
func (n *DefaultOperations) SetLkw(ctx context.Context, f FileHandle, owner uint64, lk *fuse.FileLock, flags uint32) (status fuse.Status) { func (n *DefaultOperations) SetLkw(ctx context.Context, f FileHandle, owner uint64, lk *fuse.FileLock, flags uint32) (status fuse.Status) {
...@@ -161,21 +164,21 @@ func (n *DefaultOperations) SetLkw(ctx context.Context, f FileHandle, owner uint ...@@ -161,21 +164,21 @@ func (n *DefaultOperations) SetLkw(ctx context.Context, f FileHandle, owner uint
return f.SetLkw(ctx, owner, lk, flags) return f.SetLkw(ctx, owner, lk, flags)
} }
return fuse.ENOSYS return fuse.ENOENT
} }
func (n *DefaultOperations) Flush(ctx context.Context, f FileHandle) fuse.Status { func (n *DefaultOperations) Flush(ctx context.Context, f FileHandle) fuse.Status {
if f != nil { if f != nil {
return f.Flush(ctx) return f.Flush(ctx)
} }
return fuse.ENOSYS return fuse.ENOENT
} }
func (n *DefaultOperations) Release(ctx context.Context, f FileHandle) fuse.Status { func (n *DefaultOperations) Release(ctx context.Context, f FileHandle) fuse.Status {
if f != nil { if f != nil {
return f.Release(ctx) return f.Release(ctx)
} }
return fuse.ENOSYS return fuse.ENOENT
} }
func (n *DefaultOperations) Allocate(ctx context.Context, f FileHandle, off uint64, size uint64, mode uint32) (status fuse.Status) { func (n *DefaultOperations) Allocate(ctx context.Context, f FileHandle, off uint64, size uint64, mode uint32) (status fuse.Status) {
...@@ -183,88 +186,92 @@ func (n *DefaultOperations) Allocate(ctx context.Context, f FileHandle, off uint ...@@ -183,88 +186,92 @@ func (n *DefaultOperations) Allocate(ctx context.Context, f FileHandle, off uint
return f.Allocate(ctx, off, size, mode) return f.Allocate(ctx, off, size, mode)
} }
return fuse.ENOSYS return fuse.ENOENT
} }
// FGetAttr delegates to the FileHandle's if f is not nil, or else to the
// Inode's GetAttr method.
func (n *DefaultOperations) FGetAttr(ctx context.Context, f FileHandle, out *fuse.AttrOut) fuse.Status { func (n *DefaultOperations) FGetAttr(ctx context.Context, f FileHandle, out *fuse.AttrOut) fuse.Status {
if f != nil { if f != nil {
f.GetAttr(ctx, out) f.GetAttr(ctx, out)
} }
return fuse.ENOSYS return n.inode_.ops.GetAttr(ctx, out)
} }
func (n *DefaultOperations) Open(ctx context.Context, flags uint32) (fh FileHandle, fuseFlags uint32, status fuse.Status) { func (n *DefaultOperations) Open(ctx context.Context, flags uint32) (fh FileHandle, fuseFlags uint32, status fuse.Status) {
return nil, 0, fuse.ENOSYS return nil, 0, fuse.ENOENT
} }
func (n *DefaultOperations) Create(ctx context.Context, name string, flags uint32, mode uint32) (node *Inode, fh FileHandle, fuseFlags uint32, status fuse.Status) { func (n *DefaultOperations) Create(ctx context.Context, name string, flags uint32, mode uint32) (node *Inode, fh FileHandle, fuseFlags uint32, status fuse.Status) {
return nil, nil, 0, fuse.ENOSYS return nil, nil, 0, fuse.ENOENT
} }
func (n *DefaultOperations) Link(ctx context.Context, target Operations, name string, out *fuse.EntryOut) (node *Inode, status fuse.Status) { func (n *DefaultOperations) Link(ctx context.Context, target Operations, name string, out *fuse.EntryOut) (node *Inode, status fuse.Status) {
return nil, fuse.ENOSYS return nil, fuse.ENOENT
} }
func (n *DefaultOperations) GetXAttr(ctx context.Context, attr string, dest []byte) (uint32, fuse.Status) { func (n *DefaultOperations) GetXAttr(ctx context.Context, attr string, dest []byte) (uint32, fuse.Status) {
return 0, fuse.ENOATTR return 0, fuse.ENOENT
} }
func (n *DefaultOperations) SetXAttr(ctx context.Context, attr string, data []byte, flags uint32) fuse.Status { func (n *DefaultOperations) SetXAttr(ctx context.Context, attr string, data []byte, flags uint32) fuse.Status {
return fuse.ENOATTR return fuse.ENOENT
} }
func (n *DefaultOperations) RemoveXAttr(ctx context.Context, attr string) fuse.Status { func (n *DefaultOperations) RemoveXAttr(ctx context.Context, attr string) fuse.Status {
return fuse.ENOATTR return fuse.ENOENT
} }
func (n *DefaultOperations) ListXAttr(ctx context.Context, dest []byte) (uint32, fuse.Status) { func (n *DefaultOperations) ListXAttr(ctx context.Context, dest []byte) (uint32, fuse.Status) {
return 0, fuse.OK return 0, fuse.OK
} }
type DefaultFile struct { // DefaultFileHandle satisfies the FileHandle interface, and provides
// stub methods that return ENOENT for all operations.
type DefaultFileHandle struct {
} }
var _ = FileHandle((*DefaultFile)(nil)) var _ = FileHandle((*DefaultFileHandle)(nil))
func (f *DefaultFile) Read(ctx context.Context, dest []byte, off int64) (fuse.ReadResult, fuse.Status) { func (f *DefaultFileHandle) Read(ctx context.Context, dest []byte, off int64) (fuse.ReadResult, fuse.Status) {
return nil, fuse.ENOSYS return nil, fuse.ENOENT
} }
func (f *DefaultFile) Write(ctx context.Context, data []byte, off int64) (written uint32, status fuse.Status) { func (f *DefaultFileHandle) Write(ctx context.Context, data []byte, off int64) (written uint32, status fuse.Status) {
return 0, fuse.ENOSYS return 0, fuse.ENOENT
} }
func (f *DefaultFile) GetLk(ctx context.Context, owner uint64, lk *fuse.FileLock, flags uint32, out *fuse.FileLock) (status fuse.Status) { func (f *DefaultFileHandle) GetLk(ctx context.Context, owner uint64, lk *fuse.FileLock, flags uint32, out *fuse.FileLock) (status fuse.Status) {
return fuse.ENOSYS return fuse.ENOENT
} }
func (f *DefaultFile) SetLk(ctx context.Context, owner uint64, lk *fuse.FileLock, flags uint32) (status fuse.Status) { func (f *DefaultFileHandle) SetLk(ctx context.Context, owner uint64, lk *fuse.FileLock, flags uint32) (status fuse.Status) {
return fuse.ENOSYS return fuse.ENOENT
} }
func (f *DefaultFile) SetLkw(ctx context.Context, owner uint64, lk *fuse.FileLock, flags uint32) (status fuse.Status) { func (f *DefaultFileHandle) SetLkw(ctx context.Context, owner uint64, lk *fuse.FileLock, flags uint32) (status fuse.Status) {
return fuse.ENOSYS return fuse.ENOENT
} }
func (f *DefaultFile) Flush(ctx context.Context) fuse.Status { func (f *DefaultFileHandle) Flush(ctx context.Context) fuse.Status {
return fuse.ENOSYS return fuse.ENOENT
} }
func (f *DefaultFile) Release(ctx context.Context) fuse.Status { func (f *DefaultFileHandle) Release(ctx context.Context) fuse.Status {
return fuse.ENOSYS return fuse.ENOENT
} }
func (f *DefaultFile) GetAttr(ctx context.Context, out *fuse.AttrOut) fuse.Status { func (f *DefaultFileHandle) GetAttr(ctx context.Context, out *fuse.AttrOut) fuse.Status {
return fuse.ENOSYS return fuse.ENOENT
} }
func (f *DefaultFile) SetAttr(ctx context.Context, in *fuse.SetAttrIn, out *fuse.AttrOut) fuse.Status { func (f *DefaultFileHandle) SetAttr(ctx context.Context, in *fuse.SetAttrIn, out *fuse.AttrOut) fuse.Status {
return fuse.ENOSYS return fuse.ENOENT
} }
func (f *DefaultFile) Allocate(ctx context.Context, off uint64, size uint64, mode uint32) (status fuse.Status) { func (f *DefaultFileHandle) Allocate(ctx context.Context, off uint64, size uint64, mode uint32) (status fuse.Status) {
return fuse.ENOSYS return fuse.ENOENT
} }
func (f *DefaultFile) Fsync(ctx context.Context, flags uint32) (status fuse.Status) { func (f *DefaultFileHandle) Fsync(ctx context.Context, flags uint32) (status fuse.Status) {
return fuse.ENOSYS return fuse.ENOENT
} }
...@@ -17,6 +17,7 @@ type loopbackDirStream struct { ...@@ -17,6 +17,7 @@ type loopbackDirStream struct {
fd int fd int
} }
// NewLoopbackDirStream open a directory for reading as a DirStream
func NewLoopbackDirStream(name string) (DirStream, fuse.Status) { func NewLoopbackDirStream(name string) (DirStream, fuse.Status) {
fd, err := syscall.Open(name, syscall.O_DIRECTORY, 0755) fd, err := syscall.Open(name, syscall.O_DIRECTORY, 0755)
if err != nil { if err != nil {
......
...@@ -14,11 +14,12 @@ import ( ...@@ -14,11 +14,12 @@ import (
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
) )
func newLoopbackFile(fd int) *loopbackFile { // NewLoopbackFile creates a FileHandle out of a file descriptor. All
// operations are implemented.
func NewLoopbackFile(fd int) FileHandle {
return &loopbackFile{fd: fd} return &loopbackFile{fd: fd}
} }
// loopbackFile delegates all operations back to an underlying file.
type loopbackFile struct { type loopbackFile struct {
fd int fd int
......
...@@ -95,7 +95,6 @@ func (n *loopbackNode) Mknod(ctx context.Context, name string, mode, rdev uint32 ...@@ -95,7 +95,6 @@ func (n *loopbackNode) Mknod(ctx context.Context, name string, mode, rdev uint32
} }
func (n *loopbackNode) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.EntryOut) (*Inode, fuse.Status) { func (n *loopbackNode) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.EntryOut) (*Inode, fuse.Status) {
// NOSUBMIT what about umask
p := filepath.Join(n.path(), name) p := filepath.Join(n.path(), name)
err := os.Mkdir(p, os.FileMode(mode)) err := os.Mkdir(p, os.FileMode(mode))
if err != nil { if err != nil {
...@@ -172,7 +171,7 @@ func (n *loopbackNode) Create(ctx context.Context, name string, flags uint32, mo ...@@ -172,7 +171,7 @@ func (n *loopbackNode) Create(ctx context.Context, name string, flags uint32, mo
node := n.rootNode.newLoopbackNode() node := n.rootNode.newLoopbackNode()
ch := n.inode().NewInode(node, uint32(st.Mode), idFromStat(&st)) ch := n.inode().NewInode(node, uint32(st.Mode), idFromStat(&st))
lf := newLoopbackFile(fd) lf := NewLoopbackFile(fd)
return ch, lf, 0, fuse.OK return ch, lf, 0, fuse.OK
} }
...@@ -236,7 +235,7 @@ func (n *loopbackNode) Open(ctx context.Context, flags uint32) (fh FileHandle, f ...@@ -236,7 +235,7 @@ func (n *loopbackNode) Open(ctx context.Context, flags uint32) (fh FileHandle, f
if err != nil { if err != nil {
return nil, 0, fuse.ToStatus(err) return nil, 0, fuse.ToStatus(err)
} }
lf := newLoopbackFile(f) lf := NewLoopbackFile(f)
return lf, 0, fuse.OK return lf, 0, fuse.OK
} }
......
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