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