vfs: Add SetSys() methods to Node to allow caching stuff on a node

This commit is contained in:
Nick Craig-Wood
2020-05-01 18:30:06 +01:00
parent 7f8d74e903
commit cfcdc85b26
5 changed files with 31 additions and 2 deletions

View File

@@ -52,6 +52,7 @@ type File struct {
pendingModTime time.Time // will be applied once o becomes available, i.e. after file was written
pendingRenameFun func(ctx context.Context) error // will be run/renamed after all writers close
appendMode bool // file was opened with O_APPEND
sys interface{} // user defined info to be attached here
muRW sync.Mutex // synchonize RWFileHandle.openPending(), RWFileHandle.close() and File.Remove
}
@@ -130,7 +131,16 @@ func (f *File) osPath() string {
// Sys returns underlying data source (can be nil) - satisfies Node interface
func (f *File) Sys() interface{} {
return nil
f.mu.RLock()
defer f.mu.RUnlock()
return f.sys
}
// SetSys sets the underlying data source (can be nil) - satisfies Node interface
func (f *File) SetSys(x interface{}) {
f.mu.Lock()
f.sys = x
f.mu.Unlock()
}
// Inode returns the inode number - satisfies Node interface