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 (
"github.com/hanwen/go-fuse/fuse"
)
// 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 provides the machinery to connect Operations (user
// defined methods) to Inode (a node in the filesystem tree).
type InodeLink interface {
// populateInode and inode are used by nodefs internally to
// link Inode to a Node.
//
......@@ -82,6 +79,16 @@ type Operations interface {
// the lifetime of the node object. Inode() is provided by
// OperationStubs, and should not be reimplemented.
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
// this Inode.
......
......@@ -12,27 +12,20 @@ import (
"github.com/hanwen/go-fuse/internal"
)
// 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 must be embedded in any Operations implementation.
type OperationStubs struct {
// InodeEmbed embeds the Inode into a filesystem node. It is the only
// type that implements the InodeLink interface, and hence, it must be
// part of any implementation of Operations.
type InodeEmbed struct {
inode_ Inode
}
// check that we have implemented all interface methods
var _ DirOperations = &OperationStubs{}
var _ FileOperations = &OperationStubs{}
var _ LockOperations = &OperationStubs{}
var _ = (InodeLink)((*InodeEmbed)(nil))
func (n *OperationStubs) inode() *Inode {
func (n *InodeEmbed) inode() *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{
ops: ops,
nodeAttr: attr,
......@@ -46,10 +39,27 @@ func (n *OperationStubs) init(ops Operations, attr NodeAttr, bridge *rawBridge,
}
// Inode returns the Inode for this Operations
func (n *OperationStubs) Inode() *Inode {
func (n *InodeEmbed) Inode() *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
// filesystems must define this, or the mount will not work.
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