Commit 8c22b3ff authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

nodefs: split the dual function of OperationStubs

Provide InodeLink/InodeEmbed which implements linking machinery.
parent e6ec0065
...@@ -64,12 +64,9 @@ import ( ...@@ -64,12 +64,9 @@ import (
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
) )
// Operations is the interface that implements the filesystem inode. // InodeLink provides the machinery to connect Operations (user
// Each Operations instance must embed OperationStubs. All error // defined methods) to Inode (a node in the filesystem tree).
// reporting must use the syscall.Errno type. The value 0 (`OK`) type InodeLink interface {
// should be used to indicate success. The method names are inspired
// on the system call names, so we have Listxattr rather than ListXAttr.
type Operations interface {
// populateInode and inode are used by nodefs internally to // populateInode and inode are used by nodefs internally to
// link Inode to a Node. // link Inode to a Node.
// //
...@@ -82,6 +79,16 @@ type Operations interface { ...@@ -82,6 +79,16 @@ type Operations interface {
// the lifetime of the node object. Inode() is provided by // the lifetime of the node object. Inode() is provided by
// OperationStubs, and should not be reimplemented. // OperationStubs, and should not be reimplemented.
Inode() *Inode Inode() *Inode
}
// Operations is the interface that implements the filesystem inode.
// Each Operations instance must embed OperationStubs. All error
// reporting must use the syscall.Errno type. The value 0 (`OK`)
// should be used to indicate success. The method names are inspired
// on the system call names, so we have Listxattr rather than
// ListXAttr.
type Operations interface {
InodeLink
// Statfs implements statistics for the filesystem that holds // Statfs implements statistics for the filesystem that holds
// this Inode. // this Inode.
......
...@@ -12,27 +12,20 @@ import ( ...@@ -12,27 +12,20 @@ import (
"github.com/hanwen/go-fuse/internal" "github.com/hanwen/go-fuse/internal"
) )
// OperationStubs provides no-operation default implementations for // InodeEmbed embeds the Inode into a filesystem node. It is the only
// all the XxxOperations interfaces. The stubs provide useful defaults // type that implements the InodeLink interface, and hence, it must be
// for implementing a read-only filesystem whose tree is constructed // part of any implementation of Operations.
// beforehand in the OnAdd method of the root. A example is in type InodeEmbed struct {
// zip_test.go
//
// It must be embedded in any Operations implementation.
type OperationStubs struct {
inode_ Inode inode_ Inode
} }
// check that we have implemented all interface methods var _ = (InodeLink)((*InodeEmbed)(nil))
var _ DirOperations = &OperationStubs{}
var _ FileOperations = &OperationStubs{}
var _ LockOperations = &OperationStubs{}
func (n *OperationStubs) inode() *Inode { func (n *InodeEmbed) inode() *Inode {
return &n.inode_ return &n.inode_
} }
func (n *OperationStubs) init(ops Operations, attr NodeAttr, bridge *rawBridge, persistent bool) { func (n *InodeEmbed) init(ops Operations, attr NodeAttr, bridge *rawBridge, persistent bool) {
n.inode_ = Inode{ n.inode_ = Inode{
ops: ops, ops: ops,
nodeAttr: attr, nodeAttr: attr,
...@@ -46,10 +39,27 @@ func (n *OperationStubs) init(ops Operations, attr NodeAttr, bridge *rawBridge, ...@@ -46,10 +39,27 @@ func (n *OperationStubs) init(ops Operations, attr NodeAttr, bridge *rawBridge,
} }
// Inode returns the Inode for this Operations // Inode returns the Inode for this Operations
func (n *OperationStubs) Inode() *Inode { func (n *InodeEmbed) Inode() *Inode {
return &n.inode_ return &n.inode_
} }
// OperationStubs provides no-operation default implementations for
// all the XxxOperations interfaces. The stubs provide useful defaults
// for implementing a read-only filesystem whose tree is constructed
// beforehand in the OnAdd method of the root. A example is in
// zip_test.go
//
// It is recommended to embed this in any Operations implementation,
// as it is the means by new operations are supported.
type OperationStubs struct {
InodeEmbed
}
// check that we have implemented all interface methods
var _ DirOperations = &OperationStubs{}
var _ FileOperations = &OperationStubs{}
var _ LockOperations = &OperationStubs{}
// StatFs zeroes the out argument and returns OK. This is because OSX // StatFs zeroes the out argument and returns OK. This is because OSX
// filesystems must define this, or the mount will not work. // filesystems must define this, or the mount will not work.
func (n *OperationStubs) Statfs(ctx context.Context, out *fuse.StatfsOut) syscall.Errno { func (n *OperationStubs) Statfs(ctx context.Context, out *fuse.StatfsOut) syscall.Errno {
......
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