Added an inode invariant.

geesefs-0-30-9
Aaron Jacobs 2015-03-02 16:12:54 +11:00
parent e612c866cb
commit c3298a7a6b
1 changed files with 8 additions and 0 deletions

View File

@ -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() {
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{}{}
} }
} }