Commit 7c3c1e41 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Uniformize receiver names to 'me'.

parent 1fe92061
...@@ -27,12 +27,12 @@ func NewPassThroughFuse(root string) (out *PassThroughFuse) { ...@@ -27,12 +27,12 @@ func NewPassThroughFuse(root string) (out *PassThroughFuse) {
return out return out
} }
func (self *PassThroughFuse) GetPath(relPath string) string { func (me *PassThroughFuse) GetPath(relPath string) string {
return path.Join(self.root, relPath) return path.Join(me.root, relPath)
} }
func (self *PassThroughFuse) GetAttr(name string) (*fuse.Attr, fuse.Status) { func (me *PassThroughFuse) GetAttr(name string) (*fuse.Attr, fuse.Status) {
fullPath := self.GetPath(name) fullPath := me.GetPath(name)
fi, err := os.Lstat(fullPath) fi, err := os.Lstat(fullPath)
if err != nil { if err != nil {
return nil, fuse.ENOENT return nil, fuse.ENOENT
...@@ -43,10 +43,10 @@ func (self *PassThroughFuse) GetAttr(name string) (*fuse.Attr, fuse.Status) { ...@@ -43,10 +43,10 @@ func (self *PassThroughFuse) GetAttr(name string) (*fuse.Attr, fuse.Status) {
return out, fuse.OK return out, fuse.OK
} }
func (self *PassThroughFuse) OpenDir(name string) (stream chan fuse.DirEntry, status fuse.Status) { func (me *PassThroughFuse) OpenDir(name string) (stream chan fuse.DirEntry, status fuse.Status) {
// What other ways beyond O_RDONLY are there to open // What other ways beyond O_RDONLY are there to open
// directories? // directories?
f, err := os.Open(self.GetPath(name), os.O_RDONLY, 0) f, err := os.Open(me.GetPath(name), os.O_RDONLY, 0)
if err != nil { if err != nil {
return nil, fuse.OsErrorToFuseError(err) return nil, fuse.OsErrorToFuseError(err)
} }
...@@ -76,75 +76,75 @@ func (self *PassThroughFuse) OpenDir(name string) (stream chan fuse.DirEntry, st ...@@ -76,75 +76,75 @@ func (self *PassThroughFuse) OpenDir(name string) (stream chan fuse.DirEntry, st
return output, fuse.OK return output, fuse.OK
} }
func (self *PassThroughFuse) Open(name string, flags uint32) (fuseFile fuse.RawFuseFile, status fuse.Status) { func (me *PassThroughFuse) Open(name string, flags uint32) (fuseFile fuse.RawFuseFile, status fuse.Status) {
f, err := os.Open(self.GetPath(name), int(flags), 0) f, err := os.Open(me.GetPath(name), int(flags), 0)
if err != nil { if err != nil {
return nil, fuse.OsErrorToFuseError(err) return nil, fuse.OsErrorToFuseError(err)
} }
return &PassThroughFile{file: f}, fuse.OK return &PassThroughFile{file: f}, fuse.OK
} }
func (self *PassThroughFuse) Chmod(path string, mode uint32) (code fuse.Status) { func (me *PassThroughFuse) Chmod(path string, mode uint32) (code fuse.Status) {
err := os.Chmod(self.GetPath(path), mode) err := os.Chmod(me.GetPath(path), mode)
return fuse.OsErrorToFuseError(err) return fuse.OsErrorToFuseError(err)
} }
func (self *PassThroughFuse) Chown(path string, uid uint32, gid uint32) (code fuse.Status) { func (me *PassThroughFuse) Chown(path string, uid uint32, gid uint32) (code fuse.Status) {
return fuse.OsErrorToFuseError(os.Chown(self.GetPath(path), int(uid), int(gid))) return fuse.OsErrorToFuseError(os.Chown(me.GetPath(path), int(uid), int(gid)))
} }
func (self *PassThroughFuse) Truncate(path string, offset uint64) (code fuse.Status) { func (me *PassThroughFuse) Truncate(path string, offset uint64) (code fuse.Status) {
return fuse.OsErrorToFuseError(os.Truncate(self.GetPath(path), int64(offset))) return fuse.OsErrorToFuseError(os.Truncate(me.GetPath(path), int64(offset)))
} }
func (self *PassThroughFuse) Utimens(path string, AtimeNs uint64, MtimeNs uint64) (code fuse.Status) { func (me *PassThroughFuse) Utimens(path string, AtimeNs uint64, MtimeNs uint64) (code fuse.Status) {
return fuse.OsErrorToFuseError(os.Chtimes(self.GetPath(path), int64(AtimeNs), int64(MtimeNs))) return fuse.OsErrorToFuseError(os.Chtimes(me.GetPath(path), int64(AtimeNs), int64(MtimeNs)))
} }
func (self *PassThroughFuse) Readlink(name string) (out string, code fuse.Status) { func (me *PassThroughFuse) Readlink(name string) (out string, code fuse.Status) {
f, err := os.Readlink(self.GetPath(name)) f, err := os.Readlink(me.GetPath(name))
return f, fuse.OsErrorToFuseError(err) return f, fuse.OsErrorToFuseError(err)
} }
func (self *PassThroughFuse) Mknod(name string, mode uint32, dev uint32) (code fuse.Status) { func (me *PassThroughFuse) Mknod(name string, mode uint32, dev uint32) (code fuse.Status) {
return fuse.Status(syscall.Mknod(self.GetPath(name), mode, int(dev))) return fuse.Status(syscall.Mknod(me.GetPath(name), mode, int(dev)))
} }
func (self *PassThroughFuse) Mkdir(path string, mode uint32) (code fuse.Status) { func (me *PassThroughFuse) Mkdir(path string, mode uint32) (code fuse.Status) {
return fuse.OsErrorToFuseError(os.Mkdir(self.GetPath(path), mode)) return fuse.OsErrorToFuseError(os.Mkdir(me.GetPath(path), mode))
} }
func (self *PassThroughFuse) Unlink(name string) (code fuse.Status) { func (me *PassThroughFuse) Unlink(name string) (code fuse.Status) {
return fuse.OsErrorToFuseError(os.Remove(self.GetPath(name))) return fuse.OsErrorToFuseError(os.Remove(me.GetPath(name)))
} }
func (self *PassThroughFuse) Rmdir(name string) (code fuse.Status) { func (me *PassThroughFuse) Rmdir(name string) (code fuse.Status) {
return fuse.OsErrorToFuseError(os.Remove(self.GetPath(name))) return fuse.OsErrorToFuseError(os.Remove(me.GetPath(name)))
} }
func (self *PassThroughFuse) Symlink(pointedTo string, linkName string) (code fuse.Status) { func (me *PassThroughFuse) Symlink(pointedTo string, linkName string) (code fuse.Status) {
return fuse.OsErrorToFuseError(os.Symlink(pointedTo, self.GetPath(linkName))) return fuse.OsErrorToFuseError(os.Symlink(pointedTo, me.GetPath(linkName)))
} }
func (self *PassThroughFuse) Rename(oldPath string, newPath string) (code fuse.Status) { func (me *PassThroughFuse) Rename(oldPath string, newPath string) (code fuse.Status) {
err := os.Rename(self.GetPath(oldPath), self.GetPath(newPath)) err := os.Rename(me.GetPath(oldPath), me.GetPath(newPath))
return fuse.OsErrorToFuseError(err) return fuse.OsErrorToFuseError(err)
} }
func (self *PassThroughFuse) Link(orig string, newName string) (code fuse.Status) { func (me *PassThroughFuse) Link(orig string, newName string) (code fuse.Status) {
return fuse.OsErrorToFuseError(os.Link(self.GetPath(orig), self.GetPath(newName))) return fuse.OsErrorToFuseError(os.Link(me.GetPath(orig), me.GetPath(newName)))
} }
func (self *PassThroughFuse) Access(name string, mode uint32) (code fuse.Status) { func (me *PassThroughFuse) Access(name string, mode uint32) (code fuse.Status) {
return fuse.Status(syscall.Access(self.GetPath(name), mode)) return fuse.Status(syscall.Access(me.GetPath(name), mode))
} }
func (self *PassThroughFuse) Create(path string, flags uint32, mode uint32) (fuseFile fuse.RawFuseFile, code fuse.Status) { func (me *PassThroughFuse) Create(path string, flags uint32, mode uint32) (fuseFile fuse.RawFuseFile, code fuse.Status) {
f, err := os.Open(self.GetPath(path), int(flags)|os.O_CREAT, mode) f, err := os.Open(me.GetPath(path), int(flags)|os.O_CREAT, mode)
return &PassThroughFile{file: f}, fuse.OsErrorToFuseError(err) return &PassThroughFile{file: f}, fuse.OsErrorToFuseError(err)
} }
func (self *PassThroughFuse) SetOptions(options *fuse.PathFileSystemConnectorOptions) { func (me *PassThroughFuse) SetOptions(options *fuse.PathFileSystemConnectorOptions) {
options.NegativeTimeout = 100.0 options.NegativeTimeout = 100.0
options.AttrTimeout = 100.0 options.AttrTimeout = 100.0
options.EntryTimeout = 100.0 options.EntryTimeout = 100.0
...@@ -158,10 +158,10 @@ type PassThroughFile struct { ...@@ -158,10 +158,10 @@ type PassThroughFile struct {
fuse.DefaultRawFuseFile fuse.DefaultRawFuseFile
} }
func (self *PassThroughFile) Read(input *fuse.ReadIn, buffers *fuse.BufferPool) ([]byte, fuse.Status) { func (me *PassThroughFile) Read(input *fuse.ReadIn, buffers *fuse.BufferPool) ([]byte, fuse.Status) {
slice := buffers.AllocBuffer(input.Size) slice := buffers.AllocBuffer(input.Size)
n, err := self.file.ReadAt(slice, int64(input.Offset)) n, err := me.file.ReadAt(slice, int64(input.Offset))
if err == os.EOF { if err == os.EOF {
// TODO - how to signal EOF? // TODO - how to signal EOF?
return slice[:n], fuse.OK return slice[:n], fuse.OK
...@@ -169,17 +169,17 @@ func (self *PassThroughFile) Read(input *fuse.ReadIn, buffers *fuse.BufferPool) ...@@ -169,17 +169,17 @@ func (self *PassThroughFile) Read(input *fuse.ReadIn, buffers *fuse.BufferPool)
return slice[:n], fuse.OsErrorToFuseError(err) return slice[:n], fuse.OsErrorToFuseError(err)
} }
func (self *PassThroughFile) Write(input *fuse.WriteIn, data []byte) (uint32, fuse.Status) { func (me *PassThroughFile) Write(input *fuse.WriteIn, data []byte) (uint32, fuse.Status) {
n, err := self.file.WriteAt(data, int64(input.Offset)) n, err := me.file.WriteAt(data, int64(input.Offset))
return uint32(n), fuse.OsErrorToFuseError(err) return uint32(n), fuse.OsErrorToFuseError(err)
} }
func (self *PassThroughFile) Release() { func (me *PassThroughFile) Release() {
self.file.Close() me.file.Close()
} }
func (self *PassThroughFile) Fsync(*fuse.FsyncIn) (code fuse.Status) { func (me *PassThroughFile) Fsync(*fuse.FsyncIn) (code fuse.Status) {
return fuse.Status(syscall.Fsync(self.file.Fd())) return fuse.Status(syscall.Fsync(me.file.Fd()))
} }
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
...@@ -193,25 +193,25 @@ type PassThroughDir struct { ...@@ -193,25 +193,25 @@ type PassThroughDir struct {
} }
func NewPassThroughDir(file *os.File) *PassThroughDir { func NewPassThroughDir(file *os.File) *PassThroughDir {
self := new(PassThroughDir) me := new(PassThroughDir)
self.directoryChannel = make(chan *os.FileInfo, 500) me.directoryChannel = make(chan *os.FileInfo, 500)
go func() { go func() {
for { for {
want := 500 want := 500
infos, err := file.Readdir(want) infos, err := file.Readdir(want)
for i, _ := range infos { for i, _ := range infos {
self.directoryChannel <- &infos[i] me.directoryChannel <- &infos[i]
} }
if len(infos) < want { if len(infos) < want {
break break
} }
if err != nil { if err != nil {
self.directoryError = err me.directoryError = err
break break
} }
} }
close(self.directoryChannel) close(me.directoryChannel)
file.Close() file.Close()
}() }()
return self return me
} }
This diff is collapsed.
This diff is collapsed.
...@@ -29,63 +29,63 @@ type stackFsTestCase struct { ...@@ -29,63 +29,63 @@ type stackFsTestCase struct {
state *fuse.MountState state *fuse.MountState
} }
func (self *stackFsTestCase) Setup(t *testing.T) { func (me *stackFsTestCase) Setup(t *testing.T) {
self.tester = t me.tester = t
self.testDir = fuse.MakeTempDir() me.testDir = fuse.MakeTempDir()
self.origDir1 = path.Join(self.testDir, "orig1") me.origDir1 = path.Join(me.testDir, "orig1")
self.origDir2 = path.Join(self.testDir, "orig2") me.origDir2 = path.Join(me.testDir, "orig2")
self.mountDir = path.Join(self.testDir, "mount") me.mountDir = path.Join(me.testDir, "mount")
os.Mkdir(self.origDir1, 0700) os.Mkdir(me.origDir1, 0700)
os.Mkdir(self.origDir2, 0700) os.Mkdir(me.origDir2, 0700)
os.Mkdir(self.mountDir, 0700) os.Mkdir(me.mountDir, 0700)
fs1 := fuse.NewPathFileSystemConnector(NewPassThroughFuse(self.origDir1)) fs1 := fuse.NewPathFileSystemConnector(NewPassThroughFuse(me.origDir1))
fs2 := fuse.NewPathFileSystemConnector(NewPassThroughFuse(self.origDir2)) fs2 := fuse.NewPathFileSystemConnector(NewPassThroughFuse(me.origDir2))
self.fs = NewSubmountFileSystem() me.fs = NewSubmountFileSystem()
attr := fuse.Attr{ attr := fuse.Attr{
Mode: uint32(magicMode), Mode: uint32(magicMode),
} }
self.fs.AddFileSystem("sub1", fs1, attr) me.fs.AddFileSystem("sub1", fs1, attr)
self.fs.AddFileSystem("sub2", fs2, attr) me.fs.AddFileSystem("sub2", fs2, attr)
self.state = fuse.NewMountState(self.fs) me.state = fuse.NewMountState(me.fs)
self.state.Mount(self.mountDir) me.state.Mount(me.mountDir)
self.state.Debug = true me.state.Debug = true
fmt.Println("tempdir: ", self.testDir) fmt.Println("tempdir: ", me.testDir)
// Unthreaded, but in background. // Unthreaded, but in background.
go self.state.Loop(false) go me.state.Loop(false)
} }
// Unmount and del. // Unmount and del.
func (self *stackFsTestCase) Cleanup() { func (me *stackFsTestCase) Cleanup() {
fmt.Println("Unmounting.") fmt.Println("Unmounting.")
err := self.state.Unmount() err := me.state.Unmount()
if err != nil { if err != nil {
self.tester.Errorf("Can't unmount a dir, err: %v", err) me.tester.Errorf("Can't unmount a dir, err: %v", err)
} }
os.RemoveAll(self.testDir) os.RemoveAll(me.testDir)
} }
//////////////// ////////////////
func (self *stackFsTestCase) testReaddir() { func (me *stackFsTestCase) testReaddir() {
fmt.Println("testReaddir... ") fmt.Println("testReaddir... ")
dir, err := os.Open(self.mountDir, os.O_RDONLY, 0) dir, err := os.Open(me.mountDir, os.O_RDONLY, 0)
if err != nil { if err != nil {
self.tester.Errorf("opendir err %v", err) me.tester.Errorf("opendir err %v", err)
return return
} }
infos, err := dir.Readdir(10) infos, err := dir.Readdir(10)
if err != nil { if err != nil {
self.tester.Errorf("readdir err %v", err) me.tester.Errorf("readdir err %v", err)
} }
wanted := map[string]bool{ wanted := map[string]bool{
...@@ -93,16 +93,16 @@ func (self *stackFsTestCase) testReaddir() { ...@@ -93,16 +93,16 @@ func (self *stackFsTestCase) testReaddir() {
"sub2": true, "sub2": true,
} }
if len(wanted) != len(infos) { if len(wanted) != len(infos) {
self.tester.Errorf("Length mismatch %v", infos) me.tester.Errorf("Length mismatch %v", infos)
} else { } else {
for _, v := range infos { for _, v := range infos {
_, ok := wanted[v.Name] _, ok := wanted[v.Name]
if !ok { if !ok {
self.tester.Errorf("Unexpected name %v", v.Name) me.tester.Errorf("Unexpected name %v", v.Name)
} }
if v.Mode&0777 != magicMode { if v.Mode&0777 != magicMode {
self.tester.Errorf("Unexpected mode %o, %v", v.Mode, v) me.tester.Errorf("Unexpected mode %o, %v", v.Mode, v)
} }
} }
} }
...@@ -111,11 +111,11 @@ func (self *stackFsTestCase) testReaddir() { ...@@ -111,11 +111,11 @@ func (self *stackFsTestCase) testReaddir() {
} }
func (self *stackFsTestCase) testSubFs() { func (me *stackFsTestCase) testSubFs() {
fmt.Println("testSubFs... ") fmt.Println("testSubFs... ")
for i := 1; i <= 2; i++ { for i := 1; i <= 2; i++ {
// orig := path.Join(self.testDir, fmt.Sprintf("orig%d", i)) // orig := path.Join(me.testDir, fmt.Sprintf("orig%d", i))
mount := path.Join(self.mountDir, fmt.Sprintf("sub%d", i)) mount := path.Join(me.mountDir, fmt.Sprintf("sub%d", i))
name := "testFile" name := "testFile"
...@@ -123,13 +123,13 @@ func (self *stackFsTestCase) testSubFs() { ...@@ -123,13 +123,13 @@ func (self *stackFsTestCase) testSubFs() {
f, err := os.Open(mountFile, os.O_WRONLY, 0) f, err := os.Open(mountFile, os.O_WRONLY, 0)
if err == nil { if err == nil {
self.tester.Errorf("Expected error for open write %v", name) me.tester.Errorf("Expected error for open write %v", name)
continue continue
} }
content1 := "booh!" content1 := "booh!"
f, err = os.Open(mountFile, os.O_WRONLY|os.O_CREATE, magicMode) f, err = os.Open(mountFile, os.O_WRONLY|os.O_CREATE, magicMode)
if err != nil { if err != nil {
self.tester.Errorf("Create %v", err) me.tester.Errorf("Create %v", err)
} }
f.Write([]byte(content1)) f.Write([]byte(content1))
...@@ -137,80 +137,80 @@ func (self *stackFsTestCase) testSubFs() { ...@@ -137,80 +137,80 @@ func (self *stackFsTestCase) testSubFs() {
err = os.Chmod(mountFile, magicMode) err = os.Chmod(mountFile, magicMode)
if err != nil { if err != nil {
self.tester.Errorf("chmod %v", err) me.tester.Errorf("chmod %v", err)
} }
fi, err := os.Lstat(mountFile) fi, err := os.Lstat(mountFile)
if err != nil { if err != nil {
self.tester.Errorf("Lstat %v", err) me.tester.Errorf("Lstat %v", err)
} else { } else {
if fi.Mode&0777 != magicMode { if fi.Mode&0777 != magicMode {
self.tester.Errorf("Mode %o", fi.Mode) me.tester.Errorf("Mode %o", fi.Mode)
} }
} }
g, err := os.Open(mountFile, os.O_RDONLY, 0) g, err := os.Open(mountFile, os.O_RDONLY, 0)
if err != nil { if err != nil {
self.tester.Errorf("Open %v", err) me.tester.Errorf("Open %v", err)
} else { } else {
buf := make([]byte, 1024) buf := make([]byte, 1024)
n, err := g.Read(buf) n, err := g.Read(buf)
if err != nil { if err != nil {
self.tester.Errorf("read err %v", err) me.tester.Errorf("read err %v", err)
} }
if string(buf[:n]) != content1 { if string(buf[:n]) != content1 {
self.tester.Errorf("content %v", buf[:n]) me.tester.Errorf("content %v", buf[:n])
} }
g.Close() g.Close()
} }
} }
} }
func (self *stackFsTestCase) testAddRemove() { func (me *stackFsTestCase) testAddRemove() {
self.tester.Log("testAddRemove") me.tester.Log("testAddRemove")
attr := fuse.Attr{ attr := fuse.Attr{
Mode: 0755, Mode: 0755,
} }
conn := fuse.NewPathFileSystemConnector(NewPassThroughFuse(self.origDir1)) conn := fuse.NewPathFileSystemConnector(NewPassThroughFuse(me.origDir1))
ok := self.fs.AddFileSystem("sub1", conn, attr) ok := me.fs.AddFileSystem("sub1", conn, attr)
if ok { if ok {
self.tester.Errorf("AddFileSystem should fail") me.tester.Errorf("AddFileSystem should fail")
return return
} }
ok = self.fs.AddFileSystem("third", conn, attr) ok = me.fs.AddFileSystem("third", conn, attr)
if !ok { if !ok {
self.tester.Errorf("AddFileSystem fail") me.tester.Errorf("AddFileSystem fail")
} }
conn.Init(new(fuse.InHeader), new(fuse.InitIn)) conn.Init(new(fuse.InHeader), new(fuse.InitIn))
fi, err := os.Lstat(path.Join(self.mountDir, "third")) fi, err := os.Lstat(path.Join(me.mountDir, "third"))
if err != nil { if err != nil {
self.tester.Errorf("third lstat err %v", err) me.tester.Errorf("third lstat err %v", err)
} else { } else {
if !fi.IsDirectory() { if !fi.IsDirectory() {
self.tester.Errorf("not a directory %v", fi) me.tester.Errorf("not a directory %v", fi)
} }
} }
fs := self.fs.RemoveFileSystem("third") fs := me.fs.RemoveFileSystem("third")
if fs == nil { if fs == nil {
self.tester.Errorf("remove fail") me.tester.Errorf("remove fail")
} }
dir, err := os.Open(self.mountDir, os.O_RDONLY, 0) dir, err := os.Open(me.mountDir, os.O_RDONLY, 0)
if err != nil { if err != nil {
self.tester.Errorf("opendir err %v", err) me.tester.Errorf("opendir err %v", err)
return return
} }
infos, err := dir.Readdir(10) infos, err := dir.Readdir(10)
if len(infos) != 2 { if len(infos) != 2 {
self.tester.Errorf("lstat expect 2 infos %v", infos) me.tester.Errorf("lstat expect 2 infos %v", infos)
} }
dir.Close() dir.Close()
_, err = os.Open(path.Join(self.mountDir, "third"), os.O_RDONLY, 0) _, err = os.Open(path.Join(me.mountDir, "third"), os.O_RDONLY, 0)
if err == nil { if err == nil {
self.tester.Errorf("expect enoent %v", err) me.tester.Errorf("expect enoent %v", err)
} }
} }
......
...@@ -119,8 +119,8 @@ func NewZipFileFuse(name string) *ZipFileFuse { ...@@ -119,8 +119,8 @@ func NewZipFileFuse(name string) *ZipFileFuse {
const zip_DIRMODE uint32 = fuse.S_IFDIR | 0700 const zip_DIRMODE uint32 = fuse.S_IFDIR | 0700
const zip_FILEMODE uint32 = fuse.S_IFREG | 0600 const zip_FILEMODE uint32 = fuse.S_IFREG | 0600
func (self *ZipFileFuse) GetAttr(name string) (*fuse.Attr, fuse.Status) { func (me *ZipFileFuse) GetAttr(name string) (*fuse.Attr, fuse.Status) {
dir, file := self.tree.Lookup(name) dir, file := me.tree.Lookup(name)
if dir == nil { if dir == nil {
return nil, fuse.ENOENT return nil, fuse.ENOENT
} }
...@@ -136,16 +136,16 @@ func (self *ZipFileFuse) GetAttr(name string) (*fuse.Attr, fuse.Status) { ...@@ -136,16 +136,16 @@ func (self *ZipFileFuse) GetAttr(name string) (*fuse.Attr, fuse.Status) {
return a, fuse.OK return a, fuse.OK
} }
func (self *ZipFileFuse) Open(name string, flags uint32) (file fuse.RawFuseFile, code fuse.Status) { func (me *ZipFileFuse) Open(name string, flags uint32) (file fuse.RawFuseFile, code fuse.Status) {
_, zfile := self.tree.Lookup(name) _, zfile := me.tree.Lookup(name)
if zfile == nil { if zfile == nil {
return nil, fuse.ENOENT return nil, fuse.ENOENT
} }
return NewZipFile(zfile), fuse.OK return NewZipFile(zfile), fuse.OK
} }
func (self *ZipFileFuse) OpenDir(name string) (stream chan fuse.DirEntry, code fuse.Status) { func (me *ZipFileFuse) OpenDir(name string) (stream chan fuse.DirEntry, code fuse.Status) {
zdir, file := self.tree.Lookup(name) zdir, file := me.tree.Lookup(name)
if file != nil { if file != nil {
return nil, fuse.ENOSYS return nil, fuse.ENOSYS
} }
......
...@@ -41,37 +41,37 @@ func NewBufferPool() *BufferPool { ...@@ -41,37 +41,37 @@ func NewBufferPool() *BufferPool {
return bp return bp
} }
func (self *BufferPool) String() string { func (me *BufferPool) String() string {
s := "" s := ""
for exp, bufs := range self.buffersByExponent { for exp, bufs := range me.buffersByExponent {
s = s + fmt.Sprintf("%d = %d\n", exp, len(bufs)) s = s + fmt.Sprintf("%d = %d\n", exp, len(bufs))
} }
return s return s
} }
func (self *BufferPool) getBuffer(exponent uint) []byte { func (me *BufferPool) getBuffer(exponent uint) []byte {
if len(self.buffersByExponent) <= int(exponent) { if len(me.buffersByExponent) <= int(exponent) {
return nil return nil
} }
bufferList := self.buffersByExponent[exponent] bufferList := me.buffersByExponent[exponent]
if len(bufferList) == 0 { if len(bufferList) == 0 {
return nil return nil
} }
result := bufferList[len(bufferList)-1] result := bufferList[len(bufferList)-1]
self.buffersByExponent[exponent] = self.buffersByExponent[exponent][:len(bufferList)-1] me.buffersByExponent[exponent] = me.buffersByExponent[exponent][:len(bufferList)-1]
return result return result
} }
func (self *BufferPool) addBuffer(slice []byte, exp uint) { func (me *BufferPool) addBuffer(slice []byte, exp uint) {
for len(self.buffersByExponent) <= int(exp) { for len(me.buffersByExponent) <= int(exp) {
self.buffersByExponent = append(self.buffersByExponent, make([][]byte, 0)) me.buffersByExponent = append(me.buffersByExponent, make([][]byte, 0))
} }
self.buffersByExponent[exp] = append(self.buffersByExponent[exp], slice) me.buffersByExponent[exp] = append(me.buffersByExponent[exp], slice)
} }
func (self *BufferPool) AllocBuffer(size uint32) []byte { func (me *BufferPool) AllocBuffer(size uint32) []byte {
sz := int(size) sz := int(size)
if sz < PAGESIZE { if sz < PAGESIZE {
sz = PAGESIZE sz = PAGESIZE
...@@ -82,10 +82,10 @@ func (self *BufferPool) AllocBuffer(size uint32) []byte { ...@@ -82,10 +82,10 @@ func (self *BufferPool) AllocBuffer(size uint32) []byte {
exp -= IntToExponent(PAGESIZE) exp -= IntToExponent(PAGESIZE)
self.lock.Lock() me.lock.Lock()
defer self.lock.Unlock() defer me.lock.Unlock()
b := self.getBuffer(exp) b := me.getBuffer(exp)
if b != nil { if b != nil {
b = b[:size] b = b[:size]
...@@ -93,24 +93,24 @@ func (self *BufferPool) AllocBuffer(size uint32) []byte { ...@@ -93,24 +93,24 @@ func (self *BufferPool) AllocBuffer(size uint32) []byte {
} }
b = make([]byte, size, rounded) b = make([]byte, size, rounded)
self.outstandingBuffers[uintptr(unsafe.Pointer(&b[0]))] = exp me.outstandingBuffers[uintptr(unsafe.Pointer(&b[0]))] = exp
return b return b
} }
// Takes back a buffer if it was allocated through AllocBuffer. It is // Takes back a buffer if it was allocated through AllocBuffer. It is
// not an error to call FreeBuffer() on a slice obtained elsewhere. // not an error to call FreeBuffer() on a slice obtained elsewhere.
func (self *BufferPool) FreeBuffer(slice []byte) { func (me *BufferPool) FreeBuffer(slice []byte) {
self.lock.Lock() me.lock.Lock()
defer self.lock.Unlock() defer me.lock.Unlock()
if cap(slice) < PAGESIZE { if cap(slice) < PAGESIZE {
return return
} }
key := uintptr(unsafe.Pointer(&slice[0])) key := uintptr(unsafe.Pointer(&slice[0]))
exp, ok := self.outstandingBuffers[key] exp, ok := me.outstandingBuffers[key]
if ok { if ok {
self.addBuffer(slice, exp) me.addBuffer(slice, exp)
self.outstandingBuffers[key] = 0, false me.outstandingBuffers[key] = 0, false
} }
} }
...@@ -14,11 +14,11 @@ func NewReadOnlyFile(data []byte) *ReadOnlyFile { ...@@ -14,11 +14,11 @@ func NewReadOnlyFile(data []byte) *ReadOnlyFile {
return f return f
} }
func (self *ReadOnlyFile) Read(input *ReadIn, bp *BufferPool) ([]byte, Status) { func (me *ReadOnlyFile) Read(input *ReadIn, bp *BufferPool) ([]byte, Status) {
end := int(input.Offset) + int(input.Size) end := int(input.Offset) + int(input.Size)
if end > len(self.data) { if end > len(me.data) {
end = len(self.data) end = len(me.data)
} }
return self.data[input.Offset:end], OK return me.data[input.Offset:end], OK
} }
This diff is collapsed.
...@@ -25,41 +25,41 @@ func NewDirEntryList(max int) *DirEntryList { ...@@ -25,41 +25,41 @@ func NewDirEntryList(max int) *DirEntryList {
return &DirEntryList{maxSize: max} return &DirEntryList{maxSize: max}
} }
func (de *DirEntryList) AddString(name string, inode uint64, mode uint32) bool { func (me *DirEntryList) AddString(name string, inode uint64, mode uint32) bool {
return de.Add([]byte(name), inode, mode) return me.Add([]byte(name), inode, mode)
} }
func (de *DirEntryList) Add(name []byte, inode uint64, mode uint32) bool { func (me *DirEntryList) Add(name []byte, inode uint64, mode uint32) bool {
lastLen := de.buf.Len() lastLen := me.buf.Len()
de.offset++ me.offset++
dirent := new(Dirent) dirent := new(Dirent)
dirent.Off = de.offset dirent.Off = me.offset
dirent.Ino = inode dirent.Ino = inode
dirent.NameLen = uint32(len(name)) dirent.NameLen = uint32(len(name))
dirent.Typ = ModeToType(mode) dirent.Typ = ModeToType(mode)
err := binary.Write(&de.buf, binary.LittleEndian, dirent) err := binary.Write(&me.buf, binary.LittleEndian, dirent)
if err != nil { if err != nil {
panic("Serialization of Dirent failed") panic("Serialization of Dirent failed")
} }
de.buf.Write(name) me.buf.Write(name)
padding := 8 - len(name)&7 padding := 8 - len(name)&7
if padding < 8 { if padding < 8 {
de.buf.Write(make([]byte, padding)) me.buf.Write(make([]byte, padding))
} }
if de.buf.Len() > de.maxSize { if me.buf.Len() > me.maxSize {
de.buf.Truncate(lastLen) me.buf.Truncate(lastLen)
de.offset-- me.offset--
return false return false
} }
return true return true
} }
func (de *DirEntryList) Bytes() []byte { func (me *DirEntryList) Bytes() []byte {
return de.buf.Bytes() return me.buf.Bytes()
} }
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
......
...@@ -60,47 +60,47 @@ type MountState struct { ...@@ -60,47 +60,47 @@ type MountState struct {
operationCounts *expvar.Map operationCounts *expvar.Map
} }
func (self *MountState) RegisterFile(file RawFuseFile) uint64 { func (me *MountState) RegisterFile(file RawFuseFile) uint64 {
self.openedFilesMutex.Lock() me.openedFilesMutex.Lock()
defer self.openedFilesMutex.Unlock() defer me.openedFilesMutex.Unlock()
// We will be screwed if nextFree ever wraps. // We will be screwed if nextFree ever wraps.
self.nextFreeFile++ me.nextFreeFile++
index := self.nextFreeFile index := me.nextFreeFile
self.openedFiles[index] = file me.openedFiles[index] = file
return index return index
} }
func (self *MountState) FindFile(index uint64) RawFuseFile { func (me *MountState) FindFile(index uint64) RawFuseFile {
self.openedFilesMutex.RLock() me.openedFilesMutex.RLock()
defer self.openedFilesMutex.RUnlock() defer me.openedFilesMutex.RUnlock()
return self.openedFiles[index] return me.openedFiles[index]
} }
func (self *MountState) UnregisterFile(handle uint64) { func (me *MountState) UnregisterFile(handle uint64) {
self.openedFilesMutex.Lock() me.openedFilesMutex.Lock()
defer self.openedFilesMutex.Unlock() defer me.openedFilesMutex.Unlock()
self.openedFiles[handle] = nil, false me.openedFiles[handle] = nil, false
} }
func (self *MountState) RegisterDir(dir RawFuseDir) uint64 { func (me *MountState) RegisterDir(dir RawFuseDir) uint64 {
self.openedDirsMutex.Lock() me.openedDirsMutex.Lock()
defer self.openedDirsMutex.Unlock() defer me.openedDirsMutex.Unlock()
self.nextFreeDir++ me.nextFreeDir++
index := self.nextFreeDir index := me.nextFreeDir
self.openedDirs[index] = dir me.openedDirs[index] = dir
return index return index
} }
func (self *MountState) FindDir(index uint64) RawFuseDir { func (me *MountState) FindDir(index uint64) RawFuseDir {
self.openedDirsMutex.RLock() me.openedDirsMutex.RLock()
defer self.openedDirsMutex.RUnlock() defer me.openedDirsMutex.RUnlock()
return self.openedDirs[index] return me.openedDirs[index]
} }
func (self *MountState) UnregisterDir(handle uint64) { func (me *MountState) UnregisterDir(handle uint64) {
self.openedDirsMutex.Lock() me.openedDirsMutex.Lock()
defer self.openedDirsMutex.Unlock() defer me.openedDirsMutex.Unlock()
self.openedDirs[handle] = nil, false me.openedDirs[handle] = nil, false
} }
// Mount filesystem on mountPoint. // Mount filesystem on mountPoint.
...@@ -110,48 +110,48 @@ func (self *MountState) UnregisterDir(handle uint64) { ...@@ -110,48 +110,48 @@ func (self *MountState) UnregisterDir(handle uint64) {
// using channels. // using channels.
// //
// TODO - error handling should perhaps be user-serviceable. // TODO - error handling should perhaps be user-serviceable.
func (self *MountState) Mount(mountPoint string) os.Error { func (me *MountState) Mount(mountPoint string) os.Error {
file, mp, err := mount(mountPoint) file, mp, err := mount(mountPoint)
if err != nil { if err != nil {
return err return err
} }
self.mountPoint = mp me.mountPoint = mp
self.mountFile = file me.mountFile = file
self.operationCounts = expvar.NewMap(fmt.Sprintf("mount(%v)", mountPoint)) me.operationCounts = expvar.NewMap(fmt.Sprintf("mount(%v)", mountPoint))
return nil return nil
} }
// Normally, callers should run loop() and wait for FUSE to exit, but // Normally, callers should run loop() and wait for FUSE to exit, but
// tests will want to run this in a goroutine. // tests will want to run this in a goroutine.
func (self *MountState) Loop(threaded bool) { func (me *MountState) Loop(threaded bool) {
self.threaded = threaded me.threaded = threaded
if self.threaded { if me.threaded {
self.outputChannel = make(chan [][]byte, 100) me.outputChannel = make(chan [][]byte, 100)
self.errorChannel = make(chan os.Error, 100) me.errorChannel = make(chan os.Error, 100)
go self.asyncWriterThread() go me.asyncWriterThread()
go self.DefaultErrorHandler() go me.DefaultErrorHandler()
} }
self.loop() me.loop()
if self.threaded { if me.threaded {
close(self.outputChannel) close(me.outputChannel)
close(self.errorChannel) close(me.errorChannel)
} }
} }
func (self *MountState) Unmount() os.Error { func (me *MountState) Unmount() os.Error {
// Todo: flush/release all files/dirs? // Todo: flush/release all files/dirs?
result := unmount(self.mountPoint) result := unmount(me.mountPoint)
if result == nil { if result == nil {
self.mountPoint = "" me.mountPoint = ""
} }
return result return result
} }
func (self *MountState) DefaultErrorHandler() { func (me *MountState) DefaultErrorHandler() {
for err := range self.errorChannel { for err := range me.errorChannel {
if err == os.EOF || err == nil { if err == os.EOF || err == nil {
break break
} }
...@@ -159,45 +159,45 @@ func (self *MountState) DefaultErrorHandler() { ...@@ -159,45 +159,45 @@ func (self *MountState) DefaultErrorHandler() {
} }
} }
func (self *MountState) Error(err os.Error) { func (me *MountState) Error(err os.Error) {
// It is safe to do errors unthreaded, since the logger is thread-safe. // It is safe to do errors unthreaded, since the logger is thread-safe.
if !self.threaded || self.Debug { if !me.threaded || me.Debug {
log.Println("error: ", err) log.Println("error: ", err)
} else { } else {
self.errorChannel <- err me.errorChannel <- err
} }
} }
func (self *MountState) Write(packet [][]byte) { func (me *MountState) Write(packet [][]byte) {
if packet == nil { if packet == nil {
return return
} }
if self.threaded { if me.threaded {
self.outputChannel <- packet me.outputChannel <- packet
} else { } else {
self.syncWrite(packet) me.syncWrite(packet)
} }
} }
func NewMountState(fs RawFileSystem) *MountState { func NewMountState(fs RawFileSystem) *MountState {
self := new(MountState) me := new(MountState)
self.openedDirs = make(map[uint64]RawFuseDir) me.openedDirs = make(map[uint64]RawFuseDir)
self.openedFiles = make(map[uint64]RawFuseFile) me.openedFiles = make(map[uint64]RawFuseFile)
self.mountPoint = "" me.mountPoint = ""
self.fileSystem = fs me.fileSystem = fs
self.buffers = NewBufferPool() me.buffers = NewBufferPool()
return self return me
} }
// TODO - have more statistics. // TODO - have more statistics.
func (self *MountState) Stats() string { func (me *MountState) Stats() string {
var lines []string var lines []string
// TODO - bufferpool should use expvar. // TODO - bufferpool should use expvar.
lines = append(lines, lines = append(lines,
fmt.Sprintf("buffers: %v", self.buffers.String())) fmt.Sprintf("buffers: %v", me.buffers.String()))
for v := range expvar.Iter() { for v := range expvar.Iter() {
if strings.HasPrefix(v.Key, "mount") { if strings.HasPrefix(v.Key, "mount") {
...@@ -210,19 +210,19 @@ func (self *MountState) Stats() string { ...@@ -210,19 +210,19 @@ func (self *MountState) Stats() string {
//////////////// ////////////////
// Private routines. // Private routines.
func (self *MountState) asyncWriterThread() { func (me *MountState) asyncWriterThread() {
for packet := range self.outputChannel { for packet := range me.outputChannel {
self.syncWrite(packet) me.syncWrite(packet)
} }
} }
func (self *MountState) syncWrite(packet [][]byte) { func (me *MountState) syncWrite(packet [][]byte) {
_, err := Writev(self.mountFile.Fd(), packet) _, err := Writev(me.mountFile.Fd(), packet)
if err != nil { if err != nil {
self.Error(os.NewError(fmt.Sprintf("writer: Writev %v failed, err: %v", packet, err))) me.Error(os.NewError(fmt.Sprintf("writer: Writev %v failed, err: %v", packet, err)))
} }
for _, v := range packet { for _, v := range packet {
self.buffers.FreeBuffer(v) me.buffers.FreeBuffer(v)
} }
} }
...@@ -230,11 +230,11 @@ func (self *MountState) syncWrite(packet [][]byte) { ...@@ -230,11 +230,11 @@ func (self *MountState) syncWrite(packet [][]byte) {
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// Logic for the control loop. // Logic for the control loop.
func (self *MountState) loop() { func (me *MountState) loop() {
// See fuse_kern_chan_receive() // See fuse_kern_chan_receive()
for { for {
buf := self.buffers.AllocBuffer(bufSize) buf := me.buffers.AllocBuffer(bufSize)
n, err := self.mountFile.Read(buf) n, err := me.mountFile.Read(buf)
if err != nil { if err != nil {
errNo := OsErrorToFuseError(err) errNo := OsErrorToFuseError(err)
...@@ -254,21 +254,21 @@ func (self *MountState) loop() { ...@@ -254,21 +254,21 @@ func (self *MountState) loop() {
} }
readErr := os.NewError(fmt.Sprintf("Failed to read from fuse conn: %v", err)) readErr := os.NewError(fmt.Sprintf("Failed to read from fuse conn: %v", err))
self.Error(readErr) me.Error(readErr)
break break
} }
if self.threaded { if me.threaded {
go self.handle(buf[0:n]) go me.handle(buf[0:n])
} else { } else {
self.handle(buf[0:n]) me.handle(buf[0:n])
} }
} }
self.mountFile.Close() me.mountFile.Close()
} }
func (self *MountState) handle(in_data []byte) { func (me *MountState) handle(in_data []byte) {
r := bytes.NewBuffer(in_data) r := bytes.NewBuffer(in_data)
header := new(InHeader) header := new(InHeader)
err := binary.Read(r, binary.LittleEndian, header) err := binary.Read(r, binary.LittleEndian, header)
...@@ -276,11 +276,11 @@ func (self *MountState) handle(in_data []byte) { ...@@ -276,11 +276,11 @@ func (self *MountState) handle(in_data []byte) {
err = os.NewError(fmt.Sprintf("MountPoint, handle: can't read a header, in_data: %v", in_data)) err = os.NewError(fmt.Sprintf("MountPoint, handle: can't read a header, in_data: %v", in_data))
} }
if err != nil { if err != nil {
self.Error(err) me.Error(err)
return return
} }
self.Write(dispatch(self, header, r)) me.Write(dispatch(me, header, r))
self.buffers.FreeBuffer(in_data) me.buffers.FreeBuffer(in_data)
} }
......
This diff is collapsed.
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