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

Fixes for base FUSE library:

* Lookup a directory before trying to mount it.

* Cleanup stream closing for PathFileSystemConnector.
parent 655a5066
......@@ -69,7 +69,7 @@ func (self *PassThroughFuse) OpenDir(name string) (stream chan fuse.DirEntry, st
break
}
}
close(output)
output <- fuse.DirEntry{}
f.Close()
}()
......
......@@ -73,6 +73,7 @@ func (me *ZipDirTree) FindDir(name string) *ZipDirTree {
type ZipFileFuse struct {
zipReader *zip.Reader
tree *ZipDirTree
ZipFileName string
fuse.DefaultPathFilesystem
}
......@@ -99,17 +100,23 @@ func zipFilesToTree(files []*zip.File) *ZipDirTree {
return t
}
func NewZipFileFuse(name string) *ZipFileFuse {
z := new(ZipFileFuse)
r, err := zip.OpenReader(name)
if err != nil {
panic("zip open error")
// TODO - return os.Error instead.
log.Println("NewZipFileFuse(): " + err.String())
return nil
}
z.ZipFileName = name
z.zipReader = r
z.tree = zipFilesToTree(r.File)
return z
}
const zip_DIRMODE uint32 = fuse.S_IFDIR | 0700
const zip_FILEMODE uint32 = fuse.S_IFREG | 0600
......@@ -160,8 +167,7 @@ func (self *ZipFileFuse) OpenDir(name string) (stream chan fuse.DirEntry, code f
Mode: zip_DIRMODE,
}
}
close(stream)
stream <- fuse.DirEntry{}
}()
return stream, fuse.OK
}
......
package fuse
import (
"log"
)
var _ = log.Println
func (self *DefaultRawFuseFileSystem) Init(h *InHeader, input *InitIn) (*InitOut, Status) {
return new(InitOut), OK
}
......
......@@ -82,6 +82,10 @@ func (me *FuseDir) inode(name string) uint64 {
}
func (me *FuseDir) ReadDir(input *ReadIn) (*DirEntryList, Status) {
if me.stream == nil {
return nil, OK
}
list := NewDirEntryList(int(input.Size))
if me.leftOver.Name != "" {
......@@ -97,6 +101,8 @@ func (me *FuseDir) ReadDir(input *ReadIn) (*DirEntryList, Status) {
for {
d := <-me.stream
if d.Name == "" {
close(me.stream)
me.stream = nil
break
}
i := me.inode(d.Name)
......@@ -110,6 +116,5 @@ func (me *FuseDir) ReadDir(input *ReadIn) (*DirEntryList, Status) {
}
func (me *FuseDir) ReleaseDir() {
// TODO - should close ?
}
......@@ -33,6 +33,7 @@ type inodeData struct {
LookupCount int
Type uint32
// Number of inodeData that have this as parent.
RefCount int
......@@ -310,14 +311,23 @@ func (self *PathFileSystemConnector) SetOptions(opts PathFileSystemConnectorOpti
}
func (self *PathFileSystemConnector) Mount(path string, fs PathFilesystem) Status {
node := self.findInode(path)
func (self *PathFileSystemConnector) Mount(mountPoint string, fs PathFilesystem) Status {
var node *inodeData
if mountPoint != "/" {
dirParent, base := path.Split(mountPoint)
dirParentNode := self.findInode(dirParent)
// Make sure we know the mount point.
attr, _ := self.internalLookup(dirParentNode.NodeId, base, 0)
}
node = self.findInode(mountPoint)
// TODO - check that fs was not mounted elsewhere.
if node.RefCount > 0 {
return EBUSY
}
if node.Type&ModeToType(S_IFDIR) == 0 {
return EINVAL
}
......@@ -325,13 +335,13 @@ func (self *PathFileSystemConnector) Mount(path string, fs PathFilesystem) Statu
code := fs.Mount(self)
if code != OK {
if self.Debug {
log.Println("Mount error: ", path, code)
log.Println("Mount error: ", mountPoint, code)
}
return code
}
if self.Debug {
log.Println("Mount: ", fs, "on", path, node)
log.Println("Mount: ", fs, "on", mountPoint, node)
}
// TODO - this is technically a race-condition?
......@@ -392,7 +402,11 @@ func (self *PathFileSystemConnector) Destroy(h *InHeader, input *InitIn) {
}
func (self *PathFileSystemConnector) Lookup(header *InHeader, name string) (out *EntryOut, status Status) {
parent := self.getInodeData(header.NodeId)
return self.internalLookup(header.NodeId, name, 1)
}
func (self *PathFileSystemConnector) internalLookup(nodeid uint64, name string, lookupCount int) (out *EntryOut, status Status) {
parent := self.getInodeData(nodeid)
// TODO - fuse.c has special case code for name == "." and
// "..", those lookups happen if FUSE_EXPORT_SUPPORT is set in
......@@ -413,8 +427,8 @@ func (self *PathFileSystemConnector) Lookup(header *InHeader, name string) (out
return nil, err
}
data := self.lookupUpdate(header.NodeId, name)
data.LookupCount++
data := self.lookupUpdate(nodeid, name)
data.LookupCount += lookupCount
data.Type = ModeToType(attr.Mode)
out = new(EntryOut)
......
......@@ -539,7 +539,7 @@ type RawFileSystem interface {
type RawFuseFile interface {
Read(*ReadIn, *BufferPool) ([]byte, Status)
// u32 <-> u64 ?
Write(*WriteIn, []byte) (uint32, Status)
Write(*WriteIn, []byte) (written uint32, code Status)
Flush() Status
Release()
Fsync(*FsyncIn) (code Status)
......
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