Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jacobsa-fuse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
jacobsa-fuse
Commits
c03718ca
Commit
c03718ca
authored
Feb 27, 2015
by
Aaron Jacobs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Started on an in-memory file system.
parent
e06c8f77
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
0 deletions
+92
-0
samples/mem_fs.go
samples/mem_fs.go
+92
-0
No files found.
samples/mem_fs.go
0 → 100644
View file @
c03718ca
// Copyright 2015 Google Inc. All Rights Reserved.
// Author: jacobsa@google.com (Aaron Jacobs)
package
samples
import
(
"sync"
"github.com/jacobsa/fuse"
"github.com/jacobsa/fuse/fuseutil"
"github.com/jacobsa/gcloud/syncutil"
"github.com/jacobsa/gcsfuse/timeutil"
)
// Create a file system that stores data and metadata in memory.
func
NewMemFS
(
clock
timeutil
.
Clock
)
fuse
.
FileSystem
type
memFS
struct
{
fuseutil
.
NotImplementedFileSystem
/////////////////////////
// Dependencies
/////////////////////////
clock
timeutil
.
Clock
/////////////////////////
// Mutable state
/////////////////////////
mu
syncutil
.
InvariantMutex
// The next inode to issue.
//
// INVARIANT: nextInode > 0
nextInode
fuse
.
InodeID
// GUARDED_BY(mu)
// A map from inode number to file or directory with that inode.
//
// 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)
}
type
memFile
struct
{
/////////////////////////
// Constant data
/////////////////////////
inode
fuse
.
InodeID
/////////////////////////
// Mutable state
/////////////////////////
mu
sync
.
RWMutex
// The current contents of the file.
contents
[]
byte
// GUARDED_BY(mu)
}
// TODO(jacobsa): Add a test that various WriteAt calls with a real on-disk
// file to verify what the behavior should be here, particularly when starting
// a write well beyond EOF. Leave the test around for documentation purposes.
func
(
f
*
memFile
)
WriteAt
(
p
[]
byte
,
off
int64
)
(
n
int
,
err
error
)
type
memDir
struct
{
/////////////////////////
// Constant data
/////////////////////////
inode
fuse
.
InodeID
/////////////////////////
// Mutable state
/////////////////////////
mu
syncutil
.
InvariantMutex
// The contents of the directory. An entry with inode zero is unused.
//
// 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.
entries
[]
fuseutil
.
Dirent
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment