fusego/samples/memfs/inode.go

61 lines
1.8 KiB
Go
Raw Normal View History

// Copyright 2015 Google Inc. All Rights Reserved.
// Author: jacobsa@google.com (Aaron Jacobs)
package memfs
2015-03-02 06:37:01 +03:00
import (
2015-03-02 07:18:23 +03:00
"github.com/jacobsa/fuse"
2015-03-02 07:35:12 +03:00
"github.com/jacobsa/fuse/fuseutil"
"github.com/jacobsa/gcloud/syncutil"
2015-03-02 06:37:01 +03:00
)
// Common attributes for files and directories.
2015-03-02 06:17:52 +03:00
//
// TODO(jacobsa): Add tests for interacting with a file/directory after it has
// been unlinked, including creating a new file. Make sure we don't screw up
2015-03-02 07:35:12 +03:00
// and reuse an inode ID while it is still in use.
type inode struct {
2015-03-02 07:35:12 +03:00
/////////////////////////
// Constant data
/////////////////////////
// Is this a directory? If not, it is a file.
2015-03-02 07:36:13 +03:00
dir bool
2015-03-02 07:35:12 +03:00
/////////////////////////
// Mutable state
/////////////////////////
mu syncutil.InvariantMutex
// The current attributes of this inode.
//
2015-03-02 07:35:12 +03:00
// 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
attributes fuse.InodeAttributes // GUARDED_BY(mu)
2015-03-02 06:37:01 +03:00
2015-03-02 07:35:12 +03:00
// For directories, entries describing the children of the directory.
//
// This array can never be shortened, nor can its elements be moved, because
// we use its indices for Dirent.Offset, which is exposed to the user who
// might be calling readdir in a loop while concurrently modifying the
// directory. Unused entries can, however, be reused.
//
// TODO(jacobsa): Add good tests exercising concurrent modifications while
// doing readdir, seekdir, etc. calls.
//
// INVARIANT: If dir is false, this is nil.
// INVARIANT: For each i, entries[i].Offset == i+1
entries []fuseutil.Dirent // GUARDED_BY(mu)
2015-03-02 07:18:23 +03:00
2015-03-02 07:35:12 +03:00
// For files, the current contents of the file.
//
// INVARIANT: If dir is true, this is nil.
contents []byte // GUARDED_BY(mu)
2015-03-02 07:20:29 +03:00
}
2015-03-02 07:35:12 +03:00
func newInode(dir bool) (inode *inode)
func (inode *inode) checkInvariants()