Commit c3298a7a authored by Aaron Jacobs's avatar Aaron Jacobs

Added an inode invariant.

parent e612c866
...@@ -50,6 +50,7 @@ type inode struct { ...@@ -50,6 +50,7 @@ type inode struct {
// //
// INVARIANT: If dir is false, this is nil. // INVARIANT: If dir is false, this is nil.
// INVARIANT: For each i, entries[i].Offset == i+1 // INVARIANT: For each i, entries[i].Offset == i+1
// INVARIANT: Contains no duplicate names.
entries []fuseutil.Dirent // GUARDED_BY(mu) entries []fuseutil.Dirent // GUARDED_BY(mu)
// For files, the current contents of the file. // For files, the current contents of the file.
...@@ -91,10 +92,17 @@ func (inode *inode) checkInvariants() { ...@@ -91,10 +92,17 @@ func (inode *inode) checkInvariants() {
panic("Non-nil contents in a directory.") panic("Non-nil contents in a directory.")
} }
childNames := make(map[string]struct{})
for i, e := range inode.entries { for i, e := range inode.entries {
if e.Offset != fuse.DirOffset(i+1) { if e.Offset != fuse.DirOffset(i+1) {
panic(fmt.Sprintf("Unexpected offset: %v", e.Offset)) panic(fmt.Sprintf("Unexpected offset: %v", e.Offset))
} }
if _, ok := childNames[e.Name]; ok {
panic(fmt.Sprintf("Duplicate name: %s", e.Name))
}
childNames[e.Name] = struct{}{}
} }
} }
......
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