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

Add String() to the File API.

parent 0c88a201
...@@ -143,6 +143,9 @@ type File interface { ...@@ -143,6 +143,9 @@ type File interface {
// Called upon registering the filehandle in the inode. // Called upon registering the filehandle in the inode.
SetInode(*Inode) SetInode(*Inode)
// The String method is for debug printing.
String() string
// Wrappers around other File implementations, should return // Wrappers around other File implementations, should return
// the inner file here. // the inner file here.
InnerFile() File InnerFile() File
......
...@@ -14,6 +14,10 @@ func (me *DefaultFile) InnerFile() File { ...@@ -14,6 +14,10 @@ func (me *DefaultFile) InnerFile() File {
return nil return nil
} }
func (me *DefaultFile) String() string {
return "DefaultFile"
}
func (me *DefaultFile) Read(*ReadIn, BufferPool) ([]byte, Status) { func (me *DefaultFile) Read(*ReadIn, BufferPool) ([]byte, Status) {
return []byte(""), ENOSYS return []byte(""), ENOSYS
} }
......
...@@ -42,6 +42,11 @@ func NewDevNullFile() *DevNullFile { ...@@ -42,6 +42,11 @@ func NewDevNullFile() *DevNullFile {
return new(DevNullFile) return new(DevNullFile)
} }
func (me *DevNullFile) String() string {
return "DevNullFile"
}
func (me *DevNullFile) Read(input *ReadIn, bp BufferPool) ([]byte, Status) { func (me *DevNullFile) Read(input *ReadIn, bp BufferPool) ([]byte, Status) {
return []byte{}, OK return []byte{}, OK
} }
...@@ -71,6 +76,10 @@ type LoopbackFile struct { ...@@ -71,6 +76,10 @@ type LoopbackFile struct {
DefaultFile DefaultFile
} }
func (me *LoopbackFile) String() string {
return fmt.Sprintf("LoopbackFile(%s)", me.File.Name())
}
func (me *LoopbackFile) Read(input *ReadIn, buffers BufferPool) ([]byte, Status) { func (me *LoopbackFile) Read(input *ReadIn, buffers BufferPool) ([]byte, Status) {
slice := buffers.AllocBuffer(input.Size) slice := buffers.AllocBuffer(input.Size)
...@@ -124,6 +133,10 @@ type ReadOnlyFile struct { ...@@ -124,6 +133,10 @@ type ReadOnlyFile struct {
File File
} }
func (me *ReadOnlyFile) String() string {
return fmt.Sprintf("ReadOnlyFile(%s)", me.File.String())
}
func (me *ReadOnlyFile) Write(input *WriteIn, data []byte) (uint32, Status) { func (me *ReadOnlyFile) Write(input *WriteIn, data []byte) (uint32, Status) {
return 0, EPERM return 0, EPERM
} }
......
...@@ -140,6 +140,10 @@ type memNodeFile struct { ...@@ -140,6 +140,10 @@ type memNodeFile struct {
node *memNode node *memNode
} }
func (me *memNodeFile) String() string {
return fmt.Sprintf("memNodeFile(%s)", me.LoopbackFile.String())
}
func (me *memNodeFile) InnerFile() File { func (me *memNodeFile) InnerFile() File {
return &me.LoopbackFile return &me.LoopbackFile
} }
......
...@@ -23,7 +23,7 @@ type MemUnionFs struct { ...@@ -23,7 +23,7 @@ type MemUnionFs struct {
mutex sync.RWMutex mutex sync.RWMutex
cond *sync.Cond cond *sync.Cond
nextFree int nextFree int
readonly fuse.FileSystem readonly fuse.FileSystem
openWritable int openWritable int
...@@ -99,9 +99,9 @@ func (me *MemUnionFs) Reap() map[string]*Result { ...@@ -99,9 +99,9 @@ func (me *MemUnionFs) Reap() map[string]*Result {
for me.openWritable > 0 { for me.openWritable > 0 {
me.cond.Wait() me.cond.Wait()
} }
m := map[string]*Result{} m := map[string]*Result{}
for name, _ := range me.deleted { for name, _ := range me.deleted {
fi, code := me.readonly.GetAttr(name, nil) fi, code := me.readonly.GetAttr(name, nil)
...@@ -112,13 +112,13 @@ func (me *MemUnionFs) Reap() map[string]*Result { ...@@ -112,13 +112,13 @@ func (me *MemUnionFs) Reap() map[string]*Result {
if !fi.IsDirectory() { if !fi.IsDirectory() {
continue continue
} }
todo := []string{name} todo := []string{name}
for len(todo) > 0 { for len(todo) > 0 {
l := len(todo)-1 l := len(todo)-1
n := todo[l] n := todo[l]
todo = todo[:l] todo = todo[:l]
s, _ := me.readonly.OpenDir(n, nil) s, _ := me.readonly.OpenDir(n, nil)
for e := range s { for e := range s {
full := filepath.Join(n, e.Name) full := filepath.Join(n, e.Name)
...@@ -161,16 +161,16 @@ func (me *MemUnionFs) Update(results map[string]*Result) { ...@@ -161,16 +161,16 @@ func (me *MemUnionFs) Update(results map[string]*Result) {
if len(rest) > 0 { if len(rest) > 0 {
continue continue
} }
dirNode.RmChild(base) dirNode.RmChild(base)
me.connector.EntryNotify(dirNode, base) me.connector.EntryNotify(dirNode, base)
} }
me.mutex.Lock() me.mutex.Lock()
notifyNodes := []*fuse.Inode{} notifyNodes := []*fuse.Inode{}
enotifyNodes := []*fuse.Inode{} enotifyNodes := []*fuse.Inode{}
enotifyNames := []string{} enotifyNames := []string{}
sort.Strings(add) sort.Strings(add)
for _, n := range add { for _, n := range add {
node, rest := me.connector.Node(me.root.Inode(), n) node, rest := me.connector.Node(me.root.Inode(), n)
...@@ -189,7 +189,7 @@ func (me *MemUnionFs) Update(results map[string]*Result) { ...@@ -189,7 +189,7 @@ func (me *MemUnionFs) Update(results map[string]*Result) {
mn.link = r.Link mn.link = r.Link
} }
me.mutex.Unlock() me.mutex.Unlock()
for _, n := range notifyNodes { for _, n := range notifyNodes {
me.connector.FileNotify(n, 0, 0) me.connector.FileNotify(n, 0, 0)
} }
...@@ -202,7 +202,7 @@ func (me *MemUnionFs) getFilename() string { ...@@ -202,7 +202,7 @@ func (me *MemUnionFs) getFilename() string {
id := me.nextFree id := me.nextFree
me.nextFree++ me.nextFree++
if me.nextFree % 1000 == 0 { if me.nextFree % 1000 == 0 {
go me.gc() // go me.gc()
} }
return fmt.Sprintf("%s/%d", me.backingStore, id) return fmt.Sprintf("%s/%d", me.backingStore, id)
} }
...@@ -236,7 +236,7 @@ func NewMemUnionFs(backingStore string, roFs fuse.FileSystem) *MemUnionFs { ...@@ -236,7 +236,7 @@ func NewMemUnionFs(backingStore string, roFs fuse.FileSystem) *MemUnionFs {
me.root = me.newNode(true) me.root = me.newNode(true)
me.root.info.Mode = fuse.S_IFDIR | 0755 me.root.info.Mode = fuse.S_IFDIR | 0755
me.cond = sync.NewCond(&me.mutex) me.cond = sync.NewCond(&me.mutex)
return me return me
} }
...@@ -282,7 +282,7 @@ func (me *memNode) lookup(name string, context *fuse.Context) (fi *os.FileInfo, ...@@ -282,7 +282,7 @@ func (me *memNode) lookup(name string, context *fuse.Context) (fi *os.FileInfo,
if _, del := me.fs.deleted[fn]; del { if _, del := me.fs.deleted[fn]; del {
return nil, nil, fuse.ENOENT return nil, nil, fuse.ENOENT
} }
fi, code = me.fs.readonly.GetAttr(fn, context) fi, code = me.fs.readonly.GetAttr(fn, context)
if !code.Ok() { if !code.Ok() {
return nil, nil, code return nil, nil, code
...@@ -386,7 +386,7 @@ func (me *memNode) Rename(oldName string, newParent fuse.FsNode, newName string, ...@@ -386,7 +386,7 @@ func (me *memNode) Rename(oldName string, newParent fuse.FsNode, newName string,
mn.materialize() mn.materialize()
mn.markChanged() mn.markChanged()
} }
newParent.Inode().RmChild(newName) newParent.Inode().RmChild(newName)
newParent.Inode().AddChild(newName, ch) newParent.Inode().AddChild(newName, ch)
me.touch() me.touch()
...@@ -435,6 +435,10 @@ type memNodeFile struct { ...@@ -435,6 +435,10 @@ type memNodeFile struct {
node *memNode node *memNode
} }
func (me *memNodeFile) String() string {
return fmt.Sprintf("memUfsFile(%s)", me.File.String())
}
func (me *memNodeFile) InnerFile() fuse.File { func (me *memNodeFile) InnerFile() fuse.File {
return me.File return me.File
} }
...@@ -593,7 +597,7 @@ func (me *memNode) OpenDir(context *fuse.Context) (stream chan fuse.DirEntry, co ...@@ -593,7 +597,7 @@ func (me *memNode) OpenDir(context *fuse.Context) (stream chan fuse.DirEntry, co
} }
} }
} }
for k, n := range me.Inode().FsChildren() { for k, n := range me.Inode().FsChildren() {
ch[k] = n.FsNode().(*memNode).info.Mode ch[k] = n.FsNode().(*memNode).info.Mode
} }
...@@ -632,7 +636,7 @@ func (me *memNode) markUsed(seen map[string]bool) { ...@@ -632,7 +636,7 @@ func (me *memNode) markUsed(seen map[string]bool) {
ch.FsNode().(*memNode).markUsed(seen) ch.FsNode().(*memNode).markUsed(seen)
} }
} }
func (me *memNode) Clear(path string) { func (me *memNode) Clear(path string) {
me.original = path me.original = path
me.changed = false me.changed = false
...@@ -643,4 +647,4 @@ func (me *memNode) Clear(path string) { ...@@ -643,4 +647,4 @@ func (me *memNode) Clear(path string) {
mn.Clear(p) mn.Clear(p)
} }
} }
...@@ -971,6 +971,10 @@ type unionFsFile struct { ...@@ -971,6 +971,10 @@ type unionFsFile struct {
layer int layer int
} }
func (me *unionFsFile) String() string {
return fmt.Sprintf("unionFsFile(%s)", me.File.String())
}
func (me *UnionFs) newUnionFsFile(f fuse.File, branch int) *unionFsFile { func (me *UnionFs) newUnionFsFile(f fuse.File, branch int) *unionFsFile {
return &unionFsFile{ return &unionFsFile{
File: f, File: f,
......
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