Commit 088ea6ab authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

fuse: make locking filesystem inner members available.

parent 2db031aa
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
type LockingFileSystem struct { type LockingFileSystem struct {
// Should be public so people reusing can access the wrapped // Should be public so people reusing can access the wrapped
// FS. // FS.
fs FileSystem FS FileSystem
lock sync.Mutex lock sync.Mutex
} }
...@@ -22,18 +22,18 @@ var _ = ((FileSystem)((*LockingFileSystem)(nil))) ...@@ -22,18 +22,18 @@ var _ = ((FileSystem)((*LockingFileSystem)(nil)))
func NewLockingFileSystem(pfs FileSystem) *LockingFileSystem { func NewLockingFileSystem(pfs FileSystem) *LockingFileSystem {
l := new(LockingFileSystem) l := new(LockingFileSystem)
l.fs = pfs l.FS = pfs
return l return l
} }
func (fs *LockingFileSystem) String() string { func (fs *LockingFileSystem) String() string {
defer fs.locked()() defer fs.locked()()
return fs.fs.String() return fs.FS.String()
} }
func (fs *LockingFileSystem) StatFs(name string) *StatfsOut { func (fs *LockingFileSystem) StatFs(name string) *StatfsOut {
defer fs.locked()() defer fs.locked()()
return fs.fs.StatFs(name) return fs.FS.StatFs(name)
} }
func (fs *LockingFileSystem) locked() func() { func (fs *LockingFileSystem) locked() func() {
...@@ -43,123 +43,123 @@ func (fs *LockingFileSystem) locked() func() { ...@@ -43,123 +43,123 @@ func (fs *LockingFileSystem) locked() func() {
func (fs *LockingFileSystem) GetAttr(name string, context *Context) (*Attr, Status) { func (fs *LockingFileSystem) GetAttr(name string, context *Context) (*Attr, Status) {
defer fs.locked()() defer fs.locked()()
return fs.fs.GetAttr(name, context) return fs.FS.GetAttr(name, context)
} }
func (fs *LockingFileSystem) Readlink(name string, context *Context) (string, Status) { func (fs *LockingFileSystem) Readlink(name string, context *Context) (string, Status) {
defer fs.locked()() defer fs.locked()()
return fs.fs.Readlink(name, context) return fs.FS.Readlink(name, context)
} }
func (fs *LockingFileSystem) Mknod(name string, mode uint32, dev uint32, context *Context) Status { func (fs *LockingFileSystem) Mknod(name string, mode uint32, dev uint32, context *Context) Status {
defer fs.locked()() defer fs.locked()()
return fs.fs.Mknod(name, mode, dev, context) return fs.FS.Mknod(name, mode, dev, context)
} }
func (fs *LockingFileSystem) Mkdir(name string, mode uint32, context *Context) Status { func (fs *LockingFileSystem) Mkdir(name string, mode uint32, context *Context) Status {
defer fs.locked()() defer fs.locked()()
return fs.fs.Mkdir(name, mode, context) return fs.FS.Mkdir(name, mode, context)
} }
func (fs *LockingFileSystem) Unlink(name string, context *Context) (code Status) { func (fs *LockingFileSystem) Unlink(name string, context *Context) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.fs.Unlink(name, context) return fs.FS.Unlink(name, context)
} }
func (fs *LockingFileSystem) Rmdir(name string, context *Context) (code Status) { func (fs *LockingFileSystem) Rmdir(name string, context *Context) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.fs.Rmdir(name, context) return fs.FS.Rmdir(name, context)
} }
func (fs *LockingFileSystem) Symlink(value string, linkName string, context *Context) (code Status) { func (fs *LockingFileSystem) Symlink(value string, linkName string, context *Context) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.fs.Symlink(value, linkName, context) return fs.FS.Symlink(value, linkName, context)
} }
func (fs *LockingFileSystem) Rename(oldName string, newName string, context *Context) (code Status) { func (fs *LockingFileSystem) Rename(oldName string, newName string, context *Context) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.fs.Rename(oldName, newName, context) return fs.FS.Rename(oldName, newName, context)
} }
func (fs *LockingFileSystem) Link(oldName string, newName string, context *Context) (code Status) { func (fs *LockingFileSystem) Link(oldName string, newName string, context *Context) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.fs.Link(oldName, newName, context) return fs.FS.Link(oldName, newName, context)
} }
func (fs *LockingFileSystem) Chmod(name string, mode uint32, context *Context) (code Status) { func (fs *LockingFileSystem) Chmod(name string, mode uint32, context *Context) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.fs.Chmod(name, mode, context) return fs.FS.Chmod(name, mode, context)
} }
func (fs *LockingFileSystem) Chown(name string, uid uint32, gid uint32, context *Context) (code Status) { func (fs *LockingFileSystem) Chown(name string, uid uint32, gid uint32, context *Context) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.fs.Chown(name, uid, gid, context) return fs.FS.Chown(name, uid, gid, context)
} }
func (fs *LockingFileSystem) Truncate(name string, offset uint64, context *Context) (code Status) { func (fs *LockingFileSystem) Truncate(name string, offset uint64, context *Context) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.fs.Truncate(name, offset, context) return fs.FS.Truncate(name, offset, context)
} }
func (fs *LockingFileSystem) Open(name string, flags uint32, context *Context) (file File, code Status) { func (fs *LockingFileSystem) Open(name string, flags uint32, context *Context) (file File, code Status) {
return fs.fs.Open(name, flags, context) return fs.FS.Open(name, flags, context)
} }
func (fs *LockingFileSystem) OpenDir(name string, context *Context) (stream []DirEntry, status Status) { func (fs *LockingFileSystem) OpenDir(name string, context *Context) (stream []DirEntry, status Status) {
defer fs.locked()() defer fs.locked()()
return fs.fs.OpenDir(name, context) return fs.FS.OpenDir(name, context)
} }
func (fs *LockingFileSystem) OnMount(nodeFs *PathNodeFs) { func (fs *LockingFileSystem) OnMount(nodeFs *PathNodeFs) {
defer fs.locked()() defer fs.locked()()
fs.fs.OnMount(nodeFs) fs.FS.OnMount(nodeFs)
} }
func (fs *LockingFileSystem) OnUnmount() { func (fs *LockingFileSystem) OnUnmount() {
defer fs.locked()() defer fs.locked()()
fs.fs.OnUnmount() fs.FS.OnUnmount()
} }
func (fs *LockingFileSystem) Access(name string, mode uint32, context *Context) (code Status) { func (fs *LockingFileSystem) Access(name string, mode uint32, context *Context) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.fs.Access(name, mode, context) return fs.FS.Access(name, mode, context)
} }
func (fs *LockingFileSystem) Create(name string, flags uint32, mode uint32, context *Context) (file File, code Status) { func (fs *LockingFileSystem) Create(name string, flags uint32, mode uint32, context *Context) (file File, code Status) {
defer fs.locked()() defer fs.locked()()
return fs.fs.Create(name, flags, mode, context) return fs.FS.Create(name, flags, mode, context)
} }
func (fs *LockingFileSystem) Utimens(name string, Atime *time.Time, Mtime *time.Time, context *Context) (code Status) { func (fs *LockingFileSystem) Utimens(name string, Atime *time.Time, Mtime *time.Time, context *Context) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.fs.Utimens(name, Atime, Mtime, context) return fs.FS.Utimens(name, Atime, Mtime, context)
} }
func (fs *LockingFileSystem) GetXAttr(name string, attr string, context *Context) ([]byte, Status) { func (fs *LockingFileSystem) GetXAttr(name string, attr string, context *Context) ([]byte, Status) {
defer fs.locked()() defer fs.locked()()
return fs.fs.GetXAttr(name, attr, context) return fs.FS.GetXAttr(name, attr, context)
} }
func (fs *LockingFileSystem) SetXAttr(name string, attr string, data []byte, flags int, context *Context) Status { func (fs *LockingFileSystem) SetXAttr(name string, attr string, data []byte, flags int, context *Context) Status {
defer fs.locked()() defer fs.locked()()
return fs.fs.SetXAttr(name, attr, data, flags, context) return fs.FS.SetXAttr(name, attr, data, flags, context)
} }
func (fs *LockingFileSystem) ListXAttr(name string, context *Context) ([]string, Status) { func (fs *LockingFileSystem) ListXAttr(name string, context *Context) ([]string, Status) {
defer fs.locked()() defer fs.locked()()
return fs.fs.ListXAttr(name, context) return fs.FS.ListXAttr(name, context)
} }
func (fs *LockingFileSystem) RemoveXAttr(name string, attr string, context *Context) Status { func (fs *LockingFileSystem) RemoveXAttr(name string, attr string, context *Context) Status {
defer fs.locked()() defer fs.locked()()
return fs.fs.RemoveXAttr(name, attr, context) return fs.FS.RemoveXAttr(name, attr, context)
} }
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// Locking raw FS. // Locking raw FS.
type LockingRawFileSystem struct { type LockingRawFileSystem struct {
raw RawFileSystem RawFS RawFileSystem
lock sync.Mutex lock sync.Mutex
} }
...@@ -172,167 +172,167 @@ func (fs *LockingRawFileSystem) locked() func() { ...@@ -172,167 +172,167 @@ func (fs *LockingRawFileSystem) locked() func() {
func NewLockingRawFileSystem(rfs RawFileSystem) *LockingRawFileSystem { func NewLockingRawFileSystem(rfs RawFileSystem) *LockingRawFileSystem {
l := &LockingRawFileSystem{} l := &LockingRawFileSystem{}
l.raw = rfs l.RawFS = rfs
return l return l
} }
func (fs *LockingRawFileSystem) Lookup(out *raw.EntryOut, h *Context, name string) (code Status) { func (fs *LockingRawFileSystem) Lookup(out *raw.EntryOut, h *Context, name string) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.Lookup(out, h, name) return fs.RawFS.Lookup(out, h, name)
} }
func (fs *LockingRawFileSystem) Forget(nodeID uint64, nlookup uint64) { func (fs *LockingRawFileSystem) Forget(nodeID uint64, nlookup uint64) {
defer fs.locked()() defer fs.locked()()
fs.raw.Forget(nodeID, nlookup) fs.RawFS.Forget(nodeID, nlookup)
} }
func (fs *LockingRawFileSystem) GetAttr(out *raw.AttrOut, header *Context, input *raw.GetAttrIn) (code Status) { func (fs *LockingRawFileSystem) GetAttr(out *raw.AttrOut, header *Context, input *raw.GetAttrIn) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.GetAttr(out, header, input) return fs.RawFS.GetAttr(out, header, input)
} }
func (fs *LockingRawFileSystem) Open(out *raw.OpenOut, header *Context, input *raw.OpenIn) (status Status) { func (fs *LockingRawFileSystem) Open(out *raw.OpenOut, header *Context, input *raw.OpenIn) (status Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.Open(out, header, input) return fs.RawFS.Open(out, header, input)
} }
func (fs *LockingRawFileSystem) SetAttr(out *raw.AttrOut, header *Context, input *raw.SetAttrIn) (code Status) { func (fs *LockingRawFileSystem) SetAttr(out *raw.AttrOut, header *Context, input *raw.SetAttrIn) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.SetAttr(out, header, input) return fs.RawFS.SetAttr(out, header, input)
} }
func (fs *LockingRawFileSystem) Readlink(header *Context) (out []byte, code Status) { func (fs *LockingRawFileSystem) Readlink(header *Context) (out []byte, code Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.Readlink(header) return fs.RawFS.Readlink(header)
} }
func (fs *LockingRawFileSystem) Mknod(out *raw.EntryOut, header *Context, input *raw.MknodIn, name string) (code Status) { func (fs *LockingRawFileSystem) Mknod(out *raw.EntryOut, header *Context, input *raw.MknodIn, name string) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.Mknod(out, header, input, name) return fs.RawFS.Mknod(out, header, input, name)
} }
func (fs *LockingRawFileSystem) Mkdir(out *raw.EntryOut, header *Context, input *raw.MkdirIn, name string) (code Status) { func (fs *LockingRawFileSystem) Mkdir(out *raw.EntryOut, header *Context, input *raw.MkdirIn, name string) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.Mkdir(out, header, input, name) return fs.RawFS.Mkdir(out, header, input, name)
} }
func (fs *LockingRawFileSystem) Unlink(header *Context, name string) (code Status) { func (fs *LockingRawFileSystem) Unlink(header *Context, name string) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.Unlink(header, name) return fs.RawFS.Unlink(header, name)
} }
func (fs *LockingRawFileSystem) Rmdir(header *Context, name string) (code Status) { func (fs *LockingRawFileSystem) Rmdir(header *Context, name string) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.Rmdir(header, name) return fs.RawFS.Rmdir(header, name)
} }
func (fs *LockingRawFileSystem) Symlink(out *raw.EntryOut, header *Context, pointedTo string, linkName string) (code Status) { func (fs *LockingRawFileSystem) Symlink(out *raw.EntryOut, header *Context, pointedTo string, linkName string) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.Symlink(out, header, pointedTo, linkName) return fs.RawFS.Symlink(out, header, pointedTo, linkName)
} }
func (fs *LockingRawFileSystem) Rename(header *Context, input *raw.RenameIn, oldName string, newName string) (code Status) { func (fs *LockingRawFileSystem) Rename(header *Context, input *raw.RenameIn, oldName string, newName string) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.Rename(header, input, oldName, newName) return fs.RawFS.Rename(header, input, oldName, newName)
} }
func (fs *LockingRawFileSystem) Link(out *raw.EntryOut, header *Context, input *raw.LinkIn, name string) (code Status) { func (fs *LockingRawFileSystem) Link(out *raw.EntryOut, header *Context, input *raw.LinkIn, name string) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.Link(out, header, input, name) return fs.RawFS.Link(out, header, input, name)
} }
func (fs *LockingRawFileSystem) SetXAttr(header *Context, input *raw.SetXAttrIn, attr string, data []byte) Status { func (fs *LockingRawFileSystem) SetXAttr(header *Context, input *raw.SetXAttrIn, attr string, data []byte) Status {
defer fs.locked()() defer fs.locked()()
return fs.raw.SetXAttr(header, input, attr, data) return fs.RawFS.SetXAttr(header, input, attr, data)
} }
func (fs *LockingRawFileSystem) GetXAttrData(header *Context, attr string) (data []byte, code Status) { func (fs *LockingRawFileSystem) GetXAttrData(header *Context, attr string) (data []byte, code Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.GetXAttrData(header, attr) return fs.RawFS.GetXAttrData(header, attr)
} }
func (fs *LockingRawFileSystem) GetXAttrSize(header *Context, attr string) (sz int, code Status) { func (fs *LockingRawFileSystem) GetXAttrSize(header *Context, attr string) (sz int, code Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.GetXAttrSize(header, attr) return fs.RawFS.GetXAttrSize(header, attr)
} }
func (fs *LockingRawFileSystem) ListXAttr(header *Context) (data []byte, code Status) { func (fs *LockingRawFileSystem) ListXAttr(header *Context) (data []byte, code Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.ListXAttr(header) return fs.RawFS.ListXAttr(header)
} }
func (fs *LockingRawFileSystem) RemoveXAttr(header *Context, attr string) Status { func (fs *LockingRawFileSystem) RemoveXAttr(header *Context, attr string) Status {
defer fs.locked()() defer fs.locked()()
return fs.raw.RemoveXAttr(header, attr) return fs.RawFS.RemoveXAttr(header, attr)
} }
func (fs *LockingRawFileSystem) Access(header *Context, input *raw.AccessIn) (code Status) { func (fs *LockingRawFileSystem) Access(header *Context, input *raw.AccessIn) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.Access(header, input) return fs.RawFS.Access(header, input)
} }
func (fs *LockingRawFileSystem) Create(out *raw.CreateOut, header *Context, input *raw.CreateIn, name string) (code Status) { func (fs *LockingRawFileSystem) Create(out *raw.CreateOut, header *Context, input *raw.CreateIn, name string) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.Create(out, header, input, name) return fs.RawFS.Create(out, header, input, name)
} }
func (fs *LockingRawFileSystem) OpenDir(out *raw.OpenOut, header *Context, input *raw.OpenIn) (status Status) { func (fs *LockingRawFileSystem) OpenDir(out *raw.OpenOut, header *Context, input *raw.OpenIn) (status Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.OpenDir(out, header, input) return fs.RawFS.OpenDir(out, header, input)
} }
func (fs *LockingRawFileSystem) Release(header *Context, input *raw.ReleaseIn) { func (fs *LockingRawFileSystem) Release(header *Context, input *raw.ReleaseIn) {
defer fs.locked()() defer fs.locked()()
fs.raw.Release(header, input) fs.RawFS.Release(header, input)
} }
func (fs *LockingRawFileSystem) ReleaseDir(header *Context, h *raw.ReleaseIn) { func (fs *LockingRawFileSystem) ReleaseDir(header *Context, h *raw.ReleaseIn) {
defer fs.locked()() defer fs.locked()()
fs.raw.ReleaseDir(header, h) fs.RawFS.ReleaseDir(header, h)
} }
func (fs *LockingRawFileSystem) Read(header *Context, input *raw.ReadIn, buf []byte) (ReadResult, Status) { func (fs *LockingRawFileSystem) Read(header *Context, input *raw.ReadIn, buf []byte) (ReadResult, Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.Read(header, input, buf) return fs.RawFS.Read(header, input, buf)
} }
func (fs *LockingRawFileSystem) Write(header *Context, input *raw.WriteIn, data []byte) (written uint32, code Status) { func (fs *LockingRawFileSystem) Write(header *Context, input *raw.WriteIn, data []byte) (written uint32, code Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.Write(header, input, data) return fs.RawFS.Write(header, input, data)
} }
func (fs *LockingRawFileSystem) Flush(header *Context, input *raw.FlushIn) Status { func (fs *LockingRawFileSystem) Flush(header *Context, input *raw.FlushIn) Status {
defer fs.locked()() defer fs.locked()()
return fs.raw.Flush(header, input) return fs.RawFS.Flush(header, input)
} }
func (fs *LockingRawFileSystem) Fsync(header *Context, input *raw.FsyncIn) (code Status) { func (fs *LockingRawFileSystem) Fsync(header *Context, input *raw.FsyncIn) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.Fsync(header, input) return fs.RawFS.Fsync(header, input)
} }
func (fs *LockingRawFileSystem) ReadDir(out *DirEntryList, header *Context, input *raw.ReadIn) Status { func (fs *LockingRawFileSystem) ReadDir(out *DirEntryList, header *Context, input *raw.ReadIn) Status {
defer fs.locked()() defer fs.locked()()
return fs.raw.ReadDir(out, header, input) return fs.RawFS.ReadDir(out, header, input)
} }
func (fs *LockingRawFileSystem) FsyncDir(header *Context, input *raw.FsyncIn) (code Status) { func (fs *LockingRawFileSystem) FsyncDir(header *Context, input *raw.FsyncIn) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.FsyncDir(header, input) return fs.RawFS.FsyncDir(header, input)
} }
func (fs *LockingRawFileSystem) Init(params *RawFsInit) { func (fs *LockingRawFileSystem) Init(params *RawFsInit) {
defer fs.locked()() defer fs.locked()()
fs.raw.Init(params) fs.RawFS.Init(params)
} }
func (fs *LockingRawFileSystem) StatFs(out *StatfsOut, context *Context) (code Status) { func (fs *LockingRawFileSystem) StatFs(out *StatfsOut, context *Context) (code Status) {
defer fs.locked()() defer fs.locked()()
return fs.raw.StatFs(out, context) return fs.RawFS.StatFs(out, context)
} }
func (fs *LockingRawFileSystem) String() string { func (fs *LockingRawFileSystem) String() string {
defer fs.locked()() defer fs.locked()()
return fmt.Sprintf("Locked(%s)", fs.raw.String()) return fmt.Sprintf("Locked(%s)", fs.RawFS.String())
} }
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