From c38463a12226ba4906b311ab05f39f4b969b4347 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Mon, 2 Mar 2015 14:40:28 +1100 Subject: [PATCH] Fixed broken invariants at construction. --- samples/memfs/dir.go | 6 ++++++ samples/memfs/fs.go | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/samples/memfs/dir.go b/samples/memfs/dir.go index 7e59984..5272e67 100644 --- a/samples/memfs/dir.go +++ b/samples/memfs/dir.go @@ -31,5 +31,11 @@ type memDir struct { // // TODO(jacobsa): Add good tests exercising concurrent modifications while // doing readdir, seekdir, etc. calls. + // + // INVIARANT: For each i < len(entries)-1, entries[i].Offset = i+1 entries []fuseutil.Dirent } + +func newDir() *memDir + +func (d *memDir) checkInvariants() diff --git a/samples/memfs/fs.go b/samples/memfs/fs.go index 9193964..ce8ea18 100644 --- a/samples/memfs/fs.go +++ b/samples/memfs/fs.go @@ -47,13 +47,20 @@ type memFS struct { // Create a file system that stores data and metadata in memory. func NewMemFS( - clock timeutil.Clock) (fs fuse.FileSystem) { - fs = &memFS{ - clock: clock, + clock timeutil.Clock) fuse.FileSystem { + // Set up the basic struct. + fs := &memFS{ + clock: clock, + inodes: make([]inode, fuse.RootInodeID+1), } - fs.(*memFS).mu = syncutil.NewInvariantMutex(fs.(*memFS).checkInvariants) - return + // Set up the root inode. + fs.inodes[fuse.RootInodeID].impl = newDir() + + // Set up invariant checking. + fs.mu = syncutil.NewInvariantMutex(fs.checkInvariants) + + return fs } func (fs *memFS) checkInvariants() {