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

Rename PassThroughFuse to LoopbackFileSystem.

parent 249e144f
...@@ -23,7 +23,7 @@ func main() { ...@@ -23,7 +23,7 @@ func main() {
} }
orig := flag.Arg(0) orig := flag.Arg(0)
fs := examplelib.NewPassThroughFuse(orig) fs := examplelib.NewLoopbackFileSystem(orig)
conn := fuse.NewPathFileSystemConnector(fs) conn := fuse.NewPathFileSystemConnector(fs)
state := fuse.NewMountState(conn) state := fuse.NewMountState(conn)
state.Debug = *debug state.Debug = *debug
......
...@@ -5,7 +5,7 @@ TARG=github.com/hanwen/go-fuse/examplelib ...@@ -5,7 +5,7 @@ TARG=github.com/hanwen/go-fuse/examplelib
DEPS=../fuse DEPS=../fuse
GOFILES=passthrough.go \ GOFILES=loopback.go \
stackfs.go \ stackfs.go \
zipfs.go \ zipfs.go \
multizip.go \ multizip.go \
......
...@@ -14,24 +14,24 @@ import ( ...@@ -14,24 +14,24 @@ import (
var _ = fmt.Println var _ = fmt.Println
type PassThroughFuse struct { type LoopbackFileSystem struct {
root string root string
fuse.DefaultPathFilesystem fuse.DefaultPathFilesystem
} }
func NewPassThroughFuse(root string) (out *PassThroughFuse) { func NewLoopbackFileSystem(root string) (out *LoopbackFileSystem) {
out = new(PassThroughFuse) out = new(LoopbackFileSystem)
out.root = root out.root = root
return out return out
} }
func (me *PassThroughFuse) GetPath(relPath string) string { func (me *LoopbackFileSystem) GetPath(relPath string) string {
return path.Join(me.root, relPath) return path.Join(me.root, relPath)
} }
func (me *PassThroughFuse) GetAttr(name string) (*fuse.Attr, fuse.Status) { func (me *LoopbackFileSystem) GetAttr(name string) (*fuse.Attr, fuse.Status) {
fullPath := me.GetPath(name) fullPath := me.GetPath(name)
fi, err := os.Lstat(fullPath) fi, err := os.Lstat(fullPath)
if err != nil { if err != nil {
...@@ -43,7 +43,7 @@ func (me *PassThroughFuse) GetAttr(name string) (*fuse.Attr, fuse.Status) { ...@@ -43,7 +43,7 @@ func (me *PassThroughFuse) GetAttr(name string) (*fuse.Attr, fuse.Status) {
return out, fuse.OK return out, fuse.OK
} }
func (me *PassThroughFuse) OpenDir(name string) (stream chan fuse.DirEntry, status fuse.Status) { func (me *LoopbackFileSystem) 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(me.GetPath(name), os.O_RDONLY, 0) f, err := os.Open(me.GetPath(name), os.O_RDONLY, 0)
...@@ -76,75 +76,75 @@ func (me *PassThroughFuse) OpenDir(name string) (stream chan fuse.DirEntry, stat ...@@ -76,75 +76,75 @@ func (me *PassThroughFuse) OpenDir(name string) (stream chan fuse.DirEntry, stat
return output, fuse.OK return output, fuse.OK
} }
func (me *PassThroughFuse) Open(name string, flags uint32) (fuseFile fuse.RawFuseFile, status fuse.Status) { func (me *LoopbackFileSystem) Open(name string, flags uint32) (fuseFile fuse.RawFuseFile, status fuse.Status) {
f, err := os.Open(me.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 &LoopbackFile{file: f}, fuse.OK
} }
func (me *PassThroughFuse) Chmod(path string, mode uint32) (code fuse.Status) { func (me *LoopbackFileSystem) Chmod(path string, mode uint32) (code fuse.Status) {
err := os.Chmod(me.GetPath(path), mode) err := os.Chmod(me.GetPath(path), mode)
return fuse.OsErrorToFuseError(err) return fuse.OsErrorToFuseError(err)
} }
func (me *PassThroughFuse) Chown(path string, uid uint32, gid uint32) (code fuse.Status) { func (me *LoopbackFileSystem) Chown(path string, uid uint32, gid uint32) (code fuse.Status) {
return fuse.OsErrorToFuseError(os.Chown(me.GetPath(path), int(uid), int(gid))) return fuse.OsErrorToFuseError(os.Chown(me.GetPath(path), int(uid), int(gid)))
} }
func (me *PassThroughFuse) Truncate(path string, offset uint64) (code fuse.Status) { func (me *LoopbackFileSystem) Truncate(path string, offset uint64) (code fuse.Status) {
return fuse.OsErrorToFuseError(os.Truncate(me.GetPath(path), int64(offset))) return fuse.OsErrorToFuseError(os.Truncate(me.GetPath(path), int64(offset)))
} }
func (me *PassThroughFuse) Utimens(path string, AtimeNs uint64, MtimeNs uint64) (code fuse.Status) { func (me *LoopbackFileSystem) Utimens(path string, AtimeNs uint64, MtimeNs uint64) (code fuse.Status) {
return fuse.OsErrorToFuseError(os.Chtimes(me.GetPath(path), int64(AtimeNs), int64(MtimeNs))) return fuse.OsErrorToFuseError(os.Chtimes(me.GetPath(path), int64(AtimeNs), int64(MtimeNs)))
} }
func (me *PassThroughFuse) Readlink(name string) (out string, code fuse.Status) { func (me *LoopbackFileSystem) Readlink(name string) (out string, code fuse.Status) {
f, err := os.Readlink(me.GetPath(name)) f, err := os.Readlink(me.GetPath(name))
return f, fuse.OsErrorToFuseError(err) return f, fuse.OsErrorToFuseError(err)
} }
func (me *PassThroughFuse) Mknod(name string, mode uint32, dev uint32) (code fuse.Status) { func (me *LoopbackFileSystem) Mknod(name string, mode uint32, dev uint32) (code fuse.Status) {
return fuse.Status(syscall.Mknod(me.GetPath(name), mode, int(dev))) return fuse.Status(syscall.Mknod(me.GetPath(name), mode, int(dev)))
} }
func (me *PassThroughFuse) Mkdir(path string, mode uint32) (code fuse.Status) { func (me *LoopbackFileSystem) Mkdir(path string, mode uint32) (code fuse.Status) {
return fuse.OsErrorToFuseError(os.Mkdir(me.GetPath(path), mode)) return fuse.OsErrorToFuseError(os.Mkdir(me.GetPath(path), mode))
} }
func (me *PassThroughFuse) Unlink(name string) (code fuse.Status) { func (me *LoopbackFileSystem) Unlink(name string) (code fuse.Status) {
return fuse.OsErrorToFuseError(os.Remove(me.GetPath(name))) return fuse.OsErrorToFuseError(os.Remove(me.GetPath(name)))
} }
func (me *PassThroughFuse) Rmdir(name string) (code fuse.Status) { func (me *LoopbackFileSystem) Rmdir(name string) (code fuse.Status) {
return fuse.OsErrorToFuseError(os.Remove(me.GetPath(name))) return fuse.OsErrorToFuseError(os.Remove(me.GetPath(name)))
} }
func (me *PassThroughFuse) Symlink(pointedTo string, linkName string) (code fuse.Status) { func (me *LoopbackFileSystem) Symlink(pointedTo string, linkName string) (code fuse.Status) {
return fuse.OsErrorToFuseError(os.Symlink(pointedTo, me.GetPath(linkName))) return fuse.OsErrorToFuseError(os.Symlink(pointedTo, me.GetPath(linkName)))
} }
func (me *PassThroughFuse) Rename(oldPath string, newPath string) (code fuse.Status) { func (me *LoopbackFileSystem) Rename(oldPath string, newPath string) (code fuse.Status) {
err := os.Rename(me.GetPath(oldPath), me.GetPath(newPath)) err := os.Rename(me.GetPath(oldPath), me.GetPath(newPath))
return fuse.OsErrorToFuseError(err) return fuse.OsErrorToFuseError(err)
} }
func (me *PassThroughFuse) Link(orig string, newName string) (code fuse.Status) { func (me *LoopbackFileSystem) Link(orig string, newName string) (code fuse.Status) {
return fuse.OsErrorToFuseError(os.Link(me.GetPath(orig), me.GetPath(newName))) return fuse.OsErrorToFuseError(os.Link(me.GetPath(orig), me.GetPath(newName)))
} }
func (me *PassThroughFuse) Access(name string, mode uint32) (code fuse.Status) { func (me *LoopbackFileSystem) Access(name string, mode uint32) (code fuse.Status) {
return fuse.Status(syscall.Access(me.GetPath(name), mode)) return fuse.Status(syscall.Access(me.GetPath(name), mode))
} }
func (me *PassThroughFuse) Create(path string, flags uint32, mode uint32) (fuseFile fuse.RawFuseFile, code fuse.Status) { func (me *LoopbackFileSystem) Create(path string, flags uint32, mode uint32) (fuseFile fuse.RawFuseFile, code fuse.Status) {
f, err := os.Open(me.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 &LoopbackFile{file: f}, fuse.OsErrorToFuseError(err)
} }
func (me *PassThroughFuse) SetOptions(options *fuse.PathFileSystemConnectorOptions) { func (me *LoopbackFileSystem) 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
...@@ -152,13 +152,13 @@ func (me *PassThroughFuse) SetOptions(options *fuse.PathFileSystemConnectorOptio ...@@ -152,13 +152,13 @@ func (me *PassThroughFuse) SetOptions(options *fuse.PathFileSystemConnectorOptio
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
type PassThroughFile struct { type LoopbackFile struct {
file *os.File file *os.File
fuse.DefaultRawFuseFile fuse.DefaultRawFuseFile
} }
func (me *PassThroughFile) Read(input *fuse.ReadIn, buffers *fuse.BufferPool) ([]byte, fuse.Status) { func (me *LoopbackFile) Read(input *fuse.ReadIn, buffers *fuse.BufferPool) ([]byte, fuse.Status) {
slice := buffers.AllocBuffer(input.Size) slice := buffers.AllocBuffer(input.Size)
n, err := me.file.ReadAt(slice, int64(input.Offset)) n, err := me.file.ReadAt(slice, int64(input.Offset))
...@@ -169,49 +169,15 @@ func (me *PassThroughFile) Read(input *fuse.ReadIn, buffers *fuse.BufferPool) ([ ...@@ -169,49 +169,15 @@ func (me *PassThroughFile) Read(input *fuse.ReadIn, buffers *fuse.BufferPool) ([
return slice[:n], fuse.OsErrorToFuseError(err) return slice[:n], fuse.OsErrorToFuseError(err)
} }
func (me *PassThroughFile) Write(input *fuse.WriteIn, data []byte) (uint32, fuse.Status) { func (me *LoopbackFile) Write(input *fuse.WriteIn, data []byte) (uint32, fuse.Status) {
n, err := me.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 (me *PassThroughFile) Release() { func (me *LoopbackFile) Release() {
me.file.Close() me.file.Close()
} }
func (me *PassThroughFile) Fsync(*fuse.FsyncIn) (code fuse.Status) { func (me *LoopbackFile) Fsync(*fuse.FsyncIn) (code fuse.Status) {
return fuse.Status(syscall.Fsync(me.file.Fd())) return fuse.Status(syscall.Fsync(me.file.Fd()))
} }
////////////////////////////////////////////////////////////////
type PassThroughDir struct {
directoryChannel chan *os.FileInfo
directoryError os.Error
shipped int
exported int
leftOver *os.FileInfo
}
func NewPassThroughDir(file *os.File) *PassThroughDir {
me := new(PassThroughDir)
me.directoryChannel = make(chan *os.FileInfo, 500)
go func() {
for {
want := 500
infos, err := file.Readdir(want)
for i, _ := range infos {
me.directoryChannel <- &infos[i]
}
if len(infos) < want {
break
}
if err != nil {
me.directoryError = err
break
}
}
close(me.directoryChannel)
file.Close()
}()
return me
}
...@@ -54,7 +54,7 @@ func (me *testCase) Setup(t *testing.T) { ...@@ -54,7 +54,7 @@ func (me *testCase) Setup(t *testing.T) {
me.origSubdir = path.Join(me.origDir, subdir) me.origSubdir = path.Join(me.origDir, subdir)
me.origSubfile = path.Join(me.origSubdir, "subfile") me.origSubfile = path.Join(me.origSubdir, "subfile")
pfs := NewPassThroughFuse(me.origDir) pfs := NewLoopbackFileSystem(me.origDir)
me.connector = fuse.NewPathFileSystemConnector(pfs) me.connector = fuse.NewPathFileSystemConnector(pfs)
me.connector.Debug = true me.connector.Debug = true
me.state = fuse.NewMountState(me.connector) me.state = fuse.NewMountState(me.connector)
...@@ -530,7 +530,7 @@ func TestRecursiveMount(t *testing.T) { ...@@ -530,7 +530,7 @@ func TestRecursiveMount(t *testing.T) {
f.WriteString("bla") f.WriteString("bla")
f.Close() f.Close()
pfs2 := NewPassThroughFuse(ts.origDir) pfs2 := NewLoopbackFileSystem(ts.origDir)
code := ts.connector.Mount("/hello.txt", pfs2) code := ts.connector.Mount("/hello.txt", pfs2)
if code != fuse.EINVAL { if code != fuse.EINVAL {
t.Error("expect EINVAL", code) t.Error("expect EINVAL", code)
......
...@@ -41,8 +41,8 @@ func (me *stackFsTestCase) Setup(t *testing.T) { ...@@ -41,8 +41,8 @@ func (me *stackFsTestCase) Setup(t *testing.T) {
os.Mkdir(me.origDir2, 0700) os.Mkdir(me.origDir2, 0700)
os.Mkdir(me.mountDir, 0700) os.Mkdir(me.mountDir, 0700)
fs1 := fuse.NewPathFileSystemConnector(NewPassThroughFuse(me.origDir1)) fs1 := fuse.NewPathFileSystemConnector(NewLoopbackFileSystem(me.origDir1))
fs2 := fuse.NewPathFileSystemConnector(NewPassThroughFuse(me.origDir2)) fs2 := fuse.NewPathFileSystemConnector(NewLoopbackFileSystem(me.origDir2))
me.fs = NewSubmountFileSystem() me.fs = NewSubmountFileSystem()
...@@ -154,7 +154,7 @@ func (me *stackFsTestCase) testAddRemove() { ...@@ -154,7 +154,7 @@ func (me *stackFsTestCase) testAddRemove() {
Mode: 0755, Mode: 0755,
} }
conn := fuse.NewPathFileSystemConnector(NewPassThroughFuse(me.origDir1)) conn := fuse.NewPathFileSystemConnector(NewLoopbackFileSystem(me.origDir1))
ok := me.fs.AddFileSystem("sub1", conn, attr) ok := me.fs.AddFileSystem("sub1", conn, attr)
if ok { if ok {
me.tester.Errorf("AddFileSystem should fail") me.tester.Errorf("AddFileSystem should fail")
......
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