From 7bb6fe37d2a1bd6753a7be2525f59490e94ffe13 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Thu, 5 Mar 2015 19:35:32 +1100 Subject: [PATCH] Added an invariant for inode size. --- samples/memfs/inode.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/samples/memfs/inode.go b/samples/memfs/inode.go index bfb2244..07583ab 100644 --- a/samples/memfs/inode.go +++ b/samples/memfs/inode.go @@ -54,6 +54,7 @@ type inode struct { // INVARIANT: No non-permission mode bits are set besides os.ModeDir // INVARIANT: If dir, then os.ModeDir is set // INVARIANT: If !dir, then os.ModeDir is not set + // INVARIANT: attributes.Size == len(contents) attributes fuse.InodeAttributes // GUARDED_BY(mu) // For directories, entries describing the children of the directory. Unused @@ -142,6 +143,15 @@ func (inode *inode) checkInvariants() { panic("Non-nil entries in a file.") } } + + // Check the size. + if inode.attributes.Size != uint64(len(inode.contents)) { + panic( + fmt.Sprintf( + "Unexpected size: %v vs. %v", + inode.attributes.Size, + len(inode.contents))) + } } // Return the index of the child within inode.entries, if it exists.