Commit 30bc3e19 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

nodefs: drop InodeOf

parent 8ada39b5
...@@ -64,31 +64,22 @@ import ( ...@@ -64,31 +64,22 @@ import (
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
) )
// InodeOf returns index-node associated with filesystem node.
//
// The identity of the Inode does not change over the lifetime of
// the node object.
func InodeOf(node Operations) *Inode {
return node.inode()
}
// Operations is the interface that implements the filesystem inode. // Operations is the interface that implements the filesystem inode.
// Each Operations instance must embed DefaultNode. All error // Each Operations instance must embed DefaultNode. All error
// reporting must use the syscall.Errno type. The value 0 (`OK`) // reporting must use the syscall.Errno type. The value 0 (`OK`)
// should be used to indicate success. // should be used to indicate success.
type Operations interface { type Operations interface {
// setInode and inode are used by nodefs internally to link Inode to a Node. // populateInode and inode are used by nodefs internally to
// // link Inode to a Node.
// When a new Node instance is created, e.g. on Lookup, it has nil Inode.
// Nodefs infrastructure will notice this and associate created Node with new Inode.
// //
// See InodeOf for public API to retrieve an inode from Node. // See Inode() for the public API to retrieve an inode from Node.
inode() *Inode inode() *Inode
init(ops Operations, attr NodeAttr, bridge *rawBridge, persistent bool) init(ops Operations, attr NodeAttr, bridge *rawBridge, persistent bool)
// Inode() is a convenience method, and is equivalent to // Inode returns the *Inode associated with this Operations
// InodeOf(ops) It is provided by DefaultOperations, and // instance. The identity of the Inode does not change over
// should not be reimplemented. // the lifetime of the node object. Inode() is provided by
// DefaultOperations, and should not be reimplemented.
Inode() *Inode Inode() *Inode
// StatFs implements statistics for the filesystem that holds // StatFs implements statistics for the filesystem that holds
......
...@@ -68,7 +68,7 @@ type keepCacheRoot struct { ...@@ -68,7 +68,7 @@ type keepCacheRoot struct {
} }
func (r *keepCacheRoot) OnAdd(ctx context.Context) { func (r *keepCacheRoot) OnAdd(ctx context.Context) {
i := InodeOf(r) i := r.Inode()
r.keep = &keepCacheFile{ r.keep = &keepCacheFile{
keepCache: true, keepCache: true,
...@@ -113,7 +113,7 @@ func TestKeepCache(t *testing.T) { ...@@ -113,7 +113,7 @@ func TestKeepCache(t *testing.T) {
t.Errorf("keep read 2 got %q want read 1 %q", c2, c1) t.Errorf("keep read 2 got %q want read 1 %q", c2, c1)
} }
if s := InodeOf(root.keep).NotifyContent(0, 100); s != OK { if s := root.keep.Inode().NotifyContent(0, 100); s != OK {
t.Errorf("NotifyContent: %v", s) t.Errorf("NotifyContent: %v", s)
} }
......
...@@ -43,7 +43,7 @@ func (n *DefaultOperations) init(ops Operations, attr NodeAttr, bridge *rawBridg ...@@ -43,7 +43,7 @@ func (n *DefaultOperations) init(ops Operations, attr NodeAttr, bridge *rawBridg
} }
} }
// Inode is syntactic sugar for InodeOf(ops). // Inode returns the Inode for this Operations
func (n *DefaultOperations) Inode() *Inode { func (n *DefaultOperations) Inode() *Inode {
return &n.inode_ return &n.inode_
} }
...@@ -79,7 +79,7 @@ func (n *DefaultOperations) Access(ctx context.Context, mask uint32) syscall.Err ...@@ -79,7 +79,7 @@ func (n *DefaultOperations) Access(ctx context.Context, mask uint32) syscall.Err
} }
var out fuse.AttrOut var out fuse.AttrOut
if s := InodeOf(n).Operations().GetAttr(ctx, &out); s != 0 { if s := n.inode().Operations().GetAttr(ctx, &out); s != 0 {
return s return s
} }
...@@ -102,7 +102,7 @@ func (n *DefaultOperations) FSetAttr(ctx context.Context, f FileHandle, in *fuse ...@@ -102,7 +102,7 @@ func (n *DefaultOperations) FSetAttr(ctx context.Context, f FileHandle, in *fuse
// The Lookup method on the DefaultOperations type looks for an // The Lookup method on the DefaultOperations type looks for an
// existing child with the given name, or returns ENOENT. // existing child with the given name, or returns ENOENT.
func (n *DefaultOperations) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*Inode, syscall.Errno) { func (n *DefaultOperations) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*Inode, syscall.Errno) {
ch := InodeOf(n).GetChild(name) ch := n.inode().GetChild(name)
if ch == nil { if ch == nil {
return nil, syscall.ENOENT return nil, syscall.ENOENT
} }
...@@ -141,7 +141,7 @@ func (n *DefaultOperations) OpenDir(ctx context.Context) syscall.Errno { ...@@ -141,7 +141,7 @@ func (n *DefaultOperations) OpenDir(ctx context.Context) syscall.Errno {
// The default ReadDir returns the list of children from the tree // The default ReadDir returns the list of children from the tree
func (n *DefaultOperations) ReadDir(ctx context.Context) (DirStream, syscall.Errno) { func (n *DefaultOperations) ReadDir(ctx context.Context) (DirStream, syscall.Errno) {
r := []fuse.DirEntry{} r := []fuse.DirEntry{}
for k, ch := range InodeOf(n).Children() { for k, ch := range n.inode().Children() {
r = append(r, fuse.DirEntry{Mode: ch.Mode(), r = append(r, fuse.DirEntry{Mode: ch.Mode(),
Name: k, Name: k,
Ino: ch.NodeAttr().Ino}) Ino: ch.NodeAttr().Ino})
......
...@@ -30,7 +30,7 @@ func (r *interruptRoot) Lookup(ctx context.Context, name string, out *fuse.Entry ...@@ -30,7 +30,7 @@ func (r *interruptRoot) Lookup(ctx context.Context, name string, out *fuse.Entry
if name != "file" { if name != "file" {
return nil, syscall.ENOENT return nil, syscall.ENOENT
} }
ch := InodeOf(r).NewInode(ctx, &r.child, NodeAttr{ ch := r.Inode().NewInode(ctx, &r.child, NodeAttr{
Ino: 2, Ino: 2,
Gen: 1}) Gen: 1})
......
...@@ -54,7 +54,7 @@ type loopbackNode struct { ...@@ -54,7 +54,7 @@ type loopbackNode struct {
} }
func (n *loopbackNode) path() string { func (n *loopbackNode) path() string {
path := InodeOf(n).Path(nil) path := n.Inode().Path(nil)
return filepath.Join(n.rootNode.root, path) return filepath.Join(n.rootNode.root, path)
} }
......
...@@ -47,13 +47,13 @@ func (n *loopbackNode) renameExchange(name string, newparent *loopbackNode, newN ...@@ -47,13 +47,13 @@ func (n *loopbackNode) renameExchange(name string, newparent *loopbackNode, newN
if err := syscall.Fstat(fd1, &st); err != nil { if err := syscall.Fstat(fd1, &st); err != nil {
return ToErrno(err) return ToErrno(err)
} }
if !n.Inode().IsRoot() && InodeOf(n).NodeAttr().Ino != n.rootNode.idFromStat(&st).Ino { if !n.Inode().IsRoot() && n.Inode().NodeAttr().Ino != n.rootNode.idFromStat(&st).Ino {
return syscall.EBUSY return syscall.EBUSY
} }
if err := syscall.Fstat(fd2, &st); err != nil { if err := syscall.Fstat(fd2, &st); err != nil {
return ToErrno(err) return ToErrno(err)
} }
if !newparent.Inode().IsRoot() && InodeOf(newparent).NodeAttr().Ino != n.rootNode.idFromStat(&st).Ino { if !newparent.Inode().IsRoot() && newparent.Inode().NodeAttr().Ino != n.rootNode.idFromStat(&st).Ino {
return syscall.EBUSY return syscall.EBUSY
} }
......
...@@ -170,7 +170,7 @@ func (zr *zipRoot) OnAdd(ctx context.Context) { ...@@ -170,7 +170,7 @@ func (zr *zipRoot) OnAdd(ctx context.Context) {
for _, f := range zr.r.File { for _, f := range zr.r.File {
dir, base := filepath.Split(f.Name) dir, base := filepath.Split(f.Name)
p := InodeOf(zr) p := zr.Inode()
for _, component := range strings.Split(dir, "/") { for _, component := range strings.Split(dir, "/") {
if len(component) == 0 { if len(component) == 0 {
continue continue
......
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