Commit f2ebdfe7 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Hide DefaultNodeFileSystem and DefaultFsNode to reduce API clutter.

parent 4ed8a459
...@@ -43,7 +43,8 @@ type NodeFileSystem interface { ...@@ -43,7 +43,8 @@ type NodeFileSystem interface {
type FsNode interface { type FsNode interface {
// Inode and SetInode are basic getter/setters. They are // Inode and SetInode are basic getter/setters. They are
// called by the FileSystemConnector. You get them for free by // called by the FileSystemConnector. You get them for free by
// embedding DefaultFsNode. // embedding the result of NewDefaultFsNode() in your node
// struct.
Inode() *Inode Inode() *Inode
SetInode(node *Inode) SetInode(node *Inode)
......
package fuse package fuse
import ( import (
"log"
"time" "time"
"github.com/hanwen/go-fuse/raw" "github.com/hanwen/go-fuse/raw"
) )
var _ = log.Println
var _ = (File)((*defaultFile)(nil))
type defaultFile struct{} type defaultFile struct{}
// DefaultFile returns ENOSYS for every operation. // NewDefaultFile returns a File instance that returns ENOSYS for
// every operation.
func NewDefaultFile() File { func NewDefaultFile() File {
return &defaultFile{} return (*defaultFile)(nil)
} }
func (f *defaultFile) SetInode(*Inode) { func (f *defaultFile) SetInode(*Inode) {
......
package fuse package fuse
import ( import (
"log"
"time" "time"
) )
var _ = log.Println // NewDefaultNodeFileSystem returns a dummy implementation of
// NodeFileSystem, for embedding in structs.
func NewDefaultNodeFileSystem() NodeFileSystem {
return (*defaultNodeFileSystem)(nil)
}
type DefaultNodeFileSystem struct { type defaultNodeFileSystem struct {
} }
func (fs *DefaultNodeFileSystem) OnUnmount() { func (fs *defaultNodeFileSystem) OnUnmount() {
} }
func (fs *DefaultNodeFileSystem) OnMount(conn *FileSystemConnector) { func (fs *defaultNodeFileSystem) OnMount(conn *FileSystemConnector) {
} }
func (fs *DefaultNodeFileSystem) Root() FsNode { func (fs *defaultNodeFileSystem) Root() FsNode {
return new(DefaultFsNode) return NewDefaultFsNode()
} }
func (fs *DefaultNodeFileSystem) String() string { func (fs *defaultNodeFileSystem) String() string {
return "DefaultNodeFileSystem" return "defaultNodeFileSystem"
} }
func (fs *DefaultNodeFileSystem) SetDebug(dbg bool) { func (fs *defaultNodeFileSystem) SetDebug(dbg bool) {
} }
// NewDefaultFsNode returns an implementation of FsNode that returns
// ENOSYS for all operations.
func NewDefaultFsNode() FsNode {
return &defaultFsNode{}
}
//////////////////////////////////////////////////////////////// type defaultFsNode struct {
// FsNode default
type DefaultFsNode struct {
inode *Inode inode *Inode
} }
var _ = FsNode((*DefaultFsNode)(nil)) func (n *defaultFsNode) StatFs() *StatfsOut {
func (n *DefaultFsNode) StatFs() *StatfsOut {
return nil return nil
} }
func (n *DefaultFsNode) SetInode(node *Inode) { func (n *defaultFsNode) SetInode(node *Inode) {
n.inode = node n.inode = node
} }
func (n *DefaultFsNode) Deletable() bool { func (n *defaultFsNode) Deletable() bool {
return true return true
} }
func (n *DefaultFsNode) Inode() *Inode { func (n *defaultFsNode) Inode() *Inode {
return n.inode return n.inode
} }
func (n *DefaultFsNode) OnForget() { func (n *defaultFsNode) OnForget() {
} }
func (n *DefaultFsNode) Lookup(out *Attr, name string, context *Context) (node FsNode, code Status) { func (n *defaultFsNode) Lookup(out *Attr, name string, context *Context) (node FsNode, code Status) {
return nil, ENOENT return nil, ENOENT
} }
func (n *DefaultFsNode) Access(mode uint32, context *Context) (code Status) { func (n *defaultFsNode) Access(mode uint32, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (n *DefaultFsNode) Readlink(c *Context) ([]byte, Status) { func (n *defaultFsNode) Readlink(c *Context) ([]byte, Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (n *DefaultFsNode) Mknod(name string, mode uint32, dev uint32, context *Context) (newNode FsNode, code Status) { func (n *defaultFsNode) Mknod(name string, mode uint32, dev uint32, context *Context) (newNode FsNode, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (n *DefaultFsNode) Mkdir(name string, mode uint32, context *Context) (newNode FsNode, code Status) { func (n *defaultFsNode) Mkdir(name string, mode uint32, context *Context) (newNode FsNode, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (n *DefaultFsNode) Unlink(name string, context *Context) (code Status) { func (n *defaultFsNode) Unlink(name string, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (n *DefaultFsNode) Rmdir(name string, context *Context) (code Status) { func (n *defaultFsNode) Rmdir(name string, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (n *DefaultFsNode) Symlink(name string, content string, context *Context) (newNode FsNode, code Status) { func (n *defaultFsNode) Symlink(name string, content string, context *Context) (newNode FsNode, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (n *DefaultFsNode) Rename(oldName string, newParent FsNode, newName string, context *Context) (code Status) { func (n *defaultFsNode) Rename(oldName string, newParent FsNode, newName string, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (n *DefaultFsNode) Link(name string, existing FsNode, context *Context) (newNode FsNode, code Status) { func (n *defaultFsNode) Link(name string, existing FsNode, context *Context) (newNode FsNode, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (n *DefaultFsNode) Create(name string, flags uint32, mode uint32, context *Context) (file File, newNode FsNode, code Status) { func (n *defaultFsNode) Create(name string, flags uint32, mode uint32, context *Context) (file File, newNode FsNode, code Status) {
return nil, nil, ENOSYS return nil, nil, ENOSYS
} }
func (n *DefaultFsNode) Open(flags uint32, context *Context) (file File, code Status) { func (n *defaultFsNode) Open(flags uint32, context *Context) (file File, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (n *DefaultFsNode) Flush(file File, openFlags uint32, context *Context) (code Status) { func (n *defaultFsNode) Flush(file File, openFlags uint32, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (n *DefaultFsNode) OpenDir(context *Context) ([]DirEntry, Status) { func (n *defaultFsNode) OpenDir(context *Context) ([]DirEntry, Status) {
ch := n.Inode().Children() ch := n.Inode().Children()
s := make([]DirEntry, 0, len(ch)) s := make([]DirEntry, 0, len(ch))
for name, child := range ch { for name, child := range ch {
...@@ -118,23 +121,23 @@ func (n *DefaultFsNode) OpenDir(context *Context) ([]DirEntry, Status) { ...@@ -118,23 +121,23 @@ func (n *DefaultFsNode) OpenDir(context *Context) ([]DirEntry, Status) {
return s, OK return s, OK
} }
func (n *DefaultFsNode) GetXAttr(attribute string, context *Context) (data []byte, code Status) { func (n *defaultFsNode) GetXAttr(attribute string, context *Context) (data []byte, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (n *DefaultFsNode) RemoveXAttr(attr string, context *Context) Status { func (n *defaultFsNode) RemoveXAttr(attr string, context *Context) Status {
return ENOSYS return ENOSYS
} }
func (n *DefaultFsNode) SetXAttr(attr string, data []byte, flags int, context *Context) Status { func (n *defaultFsNode) SetXAttr(attr string, data []byte, flags int, context *Context) Status {
return ENOSYS return ENOSYS
} }
func (n *DefaultFsNode) ListXAttr(context *Context) (attrs []string, code Status) { func (n *defaultFsNode) ListXAttr(context *Context) (attrs []string, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (n *DefaultFsNode) GetAttr(out *Attr, file File, context *Context) (code Status) { func (n *defaultFsNode) GetAttr(out *Attr, file File, context *Context) (code Status) {
if n.Inode().IsDir() { if n.Inode().IsDir() {
out.Mode = S_IFDIR | 0755 out.Mode = S_IFDIR | 0755
} else { } else {
...@@ -143,22 +146,22 @@ func (n *DefaultFsNode) GetAttr(out *Attr, file File, context *Context) (code St ...@@ -143,22 +146,22 @@ func (n *DefaultFsNode) GetAttr(out *Attr, file File, context *Context) (code St
return OK return OK
} }
func (n *DefaultFsNode) Chmod(file File, perms uint32, context *Context) (code Status) { func (n *defaultFsNode) Chmod(file File, perms uint32, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (n *DefaultFsNode) Chown(file File, uid uint32, gid uint32, context *Context) (code Status) { func (n *defaultFsNode) Chown(file File, uid uint32, gid uint32, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (n *DefaultFsNode) Truncate(file File, size uint64, context *Context) (code Status) { func (n *defaultFsNode) Truncate(file File, size uint64, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (n *DefaultFsNode) Utimens(file File, atime *time.Time, mtime *time.Time, context *Context) (code Status) { func (n *defaultFsNode) Utimens(file File, atime *time.Time, mtime *time.Time, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (n *DefaultFsNode) Fallocate(file File, off uint64, size uint64, mode uint32, context *Context) (code Status) { func (n *defaultFsNode) Fallocate(file File, off uint64, size uint64, mode uint32, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
// NewDefaultRawFileSystem returns ENOSYS (not implemented) for all // NewDefaultRawFileSystem returns ENOSYS (not implemented) for all
// operations. // operations.
func NewDefaultRawFileSystem() RawFileSystem { func NewDefaultRawFileSystem() RawFileSystem {
return &defaultRawFileSystem{} return (*defaultRawFileSystem)(nil)
} }
type defaultRawFileSystem struct{} type defaultRawFileSystem struct{}
......
...@@ -56,8 +56,6 @@ type devNullFile struct { ...@@ -56,8 +56,6 @@ type devNullFile struct {
File File
} }
var _ = (File)((*devNullFile)(nil))
// NewDevNullFile returns a file that accepts any write, and always // NewDevNullFile returns a file that accepts any write, and always
// returns EOF for reads. // returns EOF for reads.
func NewDevNullFile() *devNullFile { func NewDevNullFile() *devNullFile {
......
...@@ -12,7 +12,6 @@ import ( ...@@ -12,7 +12,6 @@ import (
var _ = log.Println var _ = log.Println
type MemNodeFs struct { type MemNodeFs struct {
DefaultNodeFileSystem
backingStorePrefix string backingStorePrefix string
root *memNode root *memNode
...@@ -28,9 +27,19 @@ func (fs *MemNodeFs) Root() FsNode { ...@@ -28,9 +27,19 @@ func (fs *MemNodeFs) Root() FsNode {
return fs.root return fs.root
} }
func (fs *MemNodeFs) SetDebug(bool) {
}
func (fs *MemNodeFs) OnMount(*FileSystemConnector) {
}
func (fs *MemNodeFs) OnUnmount() {
}
func (fs *MemNodeFs) newNode() *memNode { func (fs *MemNodeFs) newNode() *memNode {
fs.mutex.Lock() fs.mutex.Lock()
n := &memNode{ n := &memNode{
FsNode: NewDefaultFsNode(),
fs: fs, fs: fs,
id: fs.nextFree, id: fs.nextFree,
} }
...@@ -43,8 +52,9 @@ func (fs *MemNodeFs) newNode() *memNode { ...@@ -43,8 +52,9 @@ func (fs *MemNodeFs) newNode() *memNode {
} }
func NewMemNodeFs(prefix string) *MemNodeFs { func NewMemNodeFs(prefix string) *MemNodeFs {
me := &MemNodeFs{} me := &MemNodeFs{
me.backingStorePrefix = prefix backingStorePrefix: prefix,
}
me.root = me.newNode() me.root = me.newNode()
return me return me
} }
...@@ -55,7 +65,7 @@ func (fs *MemNodeFs) Filename(n *Inode) string { ...@@ -55,7 +65,7 @@ func (fs *MemNodeFs) Filename(n *Inode) string {
} }
type memNode struct { type memNode struct {
DefaultFsNode FsNode
fs *MemNodeFs fs *MemNodeFs
id int id int
......
...@@ -199,8 +199,7 @@ type pathInode struct { ...@@ -199,8 +199,7 @@ type pathInode struct {
// This is to correctly resolve hardlinks of the underlying // This is to correctly resolve hardlinks of the underlying
// real filesystem. // real filesystem.
clientInode uint64 clientInode uint64
inode *fuse.Inode
fuse.DefaultFsNode
} }
// Drop all known client inodes. Must have the treeLock. // Drop all known client inodes. Must have the treeLock.
...@@ -211,6 +210,18 @@ func (n *pathInode) forgetClientInodes() { ...@@ -211,6 +210,18 @@ func (n *pathInode) forgetClientInodes() {
} }
} }
func (fs *pathInode) Deletable() bool {
return true
}
func (n *pathInode) Inode() *fuse.Inode {
return n.inode
}
func (n *pathInode) SetInode(node *fuse.Inode) {
n.inode = node
}
// Reread all client nodes below this node. Must run outside the treeLock. // Reread all client nodes below this node. Must run outside the treeLock.
func (n *pathInode) updateClientInodes() { func (n *pathInode) updateClientInodes() {
n.GetAttr(&fuse.Attr{}, nil, nil) n.GetAttr(&fuse.Attr{}, nil, nil)
......
...@@ -19,7 +19,7 @@ func TestMountOnExisting(t *testing.T) { ...@@ -19,7 +19,7 @@ func TestMountOnExisting(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Mkdir failed: %v", err) t.Fatalf("Mkdir failed: %v", err)
} }
nfs := &fuse.DefaultNodeFileSystem{} nfs := fuse.NewDefaultNodeFileSystem()
code := ts.connector.Mount(ts.rootNode(), "mnt", nfs, nil) code := ts.connector.Mount(ts.rootNode(), "mnt", nfs, nil)
if code != fuse.EBUSY { if code != fuse.EBUSY {
t.Fatal("expect EBUSY:", code) t.Fatal("expect EBUSY:", code)
......
...@@ -2,8 +2,9 @@ package zipfs ...@@ -2,8 +2,9 @@ package zipfs
import ( import (
"fmt" "fmt"
"github.com/hanwen/go-fuse/fuse"
"strings" "strings"
"github.com/hanwen/go-fuse/fuse"
) )
type MemFile interface { type MemFile interface {
...@@ -12,7 +13,7 @@ type MemFile interface { ...@@ -12,7 +13,7 @@ type MemFile interface {
} }
type memNode struct { type memNode struct {
fuse.DefaultFsNode fuse.FsNode
file MemFile file MemFile
} }
...@@ -20,15 +21,17 @@ type memNode struct { ...@@ -20,15 +21,17 @@ type memNode struct {
// loaded in memory completely at startup, it does not need to inode // loaded in memory completely at startup, it does not need to inode
// discovery through Lookup() at serve time. // discovery through Lookup() at serve time.
type MemTreeFs struct { type MemTreeFs struct {
fuse.DefaultNodeFileSystem fuse.NodeFileSystem
root memNode root memNode
files map[string]MemFile files map[string]MemFile
Name string Name string
} }
func NewMemTreeFs() *MemTreeFs { func NewMemTreeFs() *MemTreeFs {
d := new(MemTreeFs) return &MemTreeFs{
return d NodeFileSystem: fuse.NewDefaultNodeFileSystem(),
root: memNode{FsNode: fuse.NewDefaultFsNode()},
}
} }
func (fs *MemTreeFs) String() string { func (fs *MemTreeFs) String() string {
...@@ -110,7 +113,7 @@ func (n *MemTreeFs) addFile(name string, f MemFile) { ...@@ -110,7 +113,7 @@ func (n *MemTreeFs) addFile(name string, f MemFile) {
for i, c := range comps { for i, c := range comps {
child := node.GetChild(c) child := node.GetChild(c)
if child == nil { if child == nil {
fsnode := &memNode{} fsnode := &memNode{FsNode: fuse.NewDefaultFsNode()}
if i == len(comps)-1 { if i == len(comps)-1 {
fsnode.file = f fsnode.file = f
} }
......
...@@ -61,9 +61,8 @@ func NewZipTree(name string) (map[string]MemFile, error) { ...@@ -61,9 +61,8 @@ func NewZipTree(name string) (map[string]MemFile, error) {
} }
func NewArchiveFileSystem(name string) (mfs *MemTreeFs, err error) { func NewArchiveFileSystem(name string) (mfs *MemTreeFs, err error) {
mfs = &MemTreeFs{ mfs = NewMemTreeFs()
Name: fmt.Sprintf("fs(%s)", name), mfs.Name = fmt.Sprintf("fs(%s)", name)
}
if strings.HasSuffix(name, ".zip") { if strings.HasSuffix(name, ".zip") {
mfs.files, err = NewZipTree(name) mfs.files, err = NewZipTree(name)
......
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