Switched to an array of inodes for memfs, like a real file system.

geesefs-0-30-9
Aaron Jacobs 2015-03-02 14:06:32 +11:00
parent 23b398bc83
commit 3379842d1e
2 changed files with 25 additions and 11 deletions

View File

@ -25,20 +25,21 @@ type memFS struct {
mu syncutil.InvariantMutex
// The next inode to issue.
// The collection of all inodes that have ever been created, indexed by inode
// ID. Some inodes are not in use if they have been unlinked, and no inode
// with ID less than fuse.RootInodeID is ever used.
//
// INVARIANT: nextInode > 0
nextInode fuse.InodeID // GUARDED_BY(mu)
// INVARIANT: len(inodes) > fuse.RootInodeID
// INVARIANT: For all i < fuse.RootInodeID, inodes[i].impl == nil
// INVARIANT: inodes[fuse.RootInodeID].impl is of type *memDir
inodes []inode // GUARDED_BY(mu)
// A map from inode number to file or directory with that inode.
// A list of inode IDs within inodes available for reuse, not including the
// reserved IDs less than fuse.RootInodeID.
//
// INVARIANT: inodeIndex[fuse.RootInodeID] != nil
// INVARIANT: For all keys k, k > 0
// INVARIANT: For all keys k, k < nextInode
// INVARIANT: For all keys k, inodeIndex[k] is *memFile or *memDir
// INVARIANT: For all keys k, inodeIndex[k].inode == k
// INVARIANT: For all dirs d, all of d's children are in the map.
inodeIndex map[fuse.InodeID]interface{} // GUARDED_BY(mu)
// INVARIANT: This is all and only indices i of inodes such that i >
// fuse.RootInodeID and inodes[i].impl == nil
freeInodes []fuse.InodeID // GUARDED_BY(mu)
}
// Create a file system that stores data and metadata in memory.

13
samples/memfs/inode.go Normal file
View File

@ -0,0 +1,13 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Author: jacobsa@google.com (Aaron Jacobs)
package memfs
// Common attributes for files and directories.
type inode struct {
// The *memFile or *memDir for this inode, or nil if the inode is available
// for reuse.
//
// INVARIANT: impl is nil, or of type *memFile or *memDir
impl interface{}
}