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
1b65aaf8
Commit
1b65aaf8
authored
Mar 02, 2015
by
Aaron Jacobs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored invariant checking.
parent
a0a0963c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
12 deletions
+37
-12
samples/memfs/fs.go
samples/memfs/fs.go
+21
-12
samples/memfs/inode.go
samples/memfs/inode.go
+16
-0
No files found.
samples/memfs/fs.go
View file @
1b65aaf8
...
@@ -5,7 +5,6 @@ package memfs
...
@@ -5,7 +5,6 @@ package memfs
import
(
import
(
"fmt"
"fmt"
"reflect"
"github.com/jacobsa/fuse"
"github.com/jacobsa/fuse"
"github.com/jacobsa/fuse/fuseutil"
"github.com/jacobsa/fuse/fuseutil"
...
@@ -58,6 +57,11 @@ func NewMemFS(
...
@@ -58,6 +57,11 @@ func NewMemFS(
}
}
func
(
fs
*
memFS
)
checkInvariants
()
{
func
(
fs
*
memFS
)
checkInvariants
()
{
// Check general inode invariants.
for
i
:=
range
fs
.
inodes
{
fs
.
inodes
[
i
]
.
checkInvariants
()
}
// Check reserved inodes.
// Check reserved inodes.
for
i
:=
0
;
i
<
fuse
.
RootInodeID
;
i
++
{
for
i
:=
0
;
i
<
fuse
.
RootInodeID
;
i
++
{
var
inode
*
inode
=
&
fs
.
inodes
[
i
]
var
inode
*
inode
=
&
fs
.
inodes
[
i
]
...
@@ -67,27 +71,32 @@ func (fs *memFS) checkInvariants() {
...
@@ -67,27 +71,32 @@ func (fs *memFS) checkInvariants() {
}
}
// Check the root inode.
// Check the root inode.
fs
.
inodes
[
fuse
.
RootInodeID
]
.
impl
.
(
*
d
ir
)
_
=
fs
.
inodes
[
fuse
.
RootInodeID
]
.
impl
.
(
*
memD
ir
)
// Check inodes, building our own set of free IDs.
// Check inodes, building our own set of free IDs.
freeIDsEncountered
:=
make
(
map
[
fuse
.
InodeID
]
struct
{})
freeIDsEncountered
:=
make
(
map
[
fuse
.
InodeID
]
struct
{})
for
i
:=
range
fs
.
inodes
{
for
i
:=
fuse
.
RootInodeID
+
1
;
i
<
len
(
fs
.
inodes
);
i
++
{
var
inode
*
inode
=
&
fs
.
inodes
[
i
]
var
inode
*
inode
=
&
fs
.
inodes
[
i
]
if
inode
.
impl
==
nil
{
if
inode
.
impl
==
nil
{
freeIDsEncountered
[
i
]
=
struct
{}{}
freeIDsEncountered
[
fuse
.
InodeID
(
i
)
]
=
struct
{}{}
continue
continue
}
}
// Check for known types.
switch
inode
.
impl
.
(
type
)
{
case
*
memFile
:
case
*
memDir
:
default
:
panic
(
fmt
.
Sprintf
(
"Unknown inode type: %v"
,
reflect
.
TypeOf
(
inode
.
impl
)))
}
}
// Check fs.freeInodes.
if
len
(
fs
.
freeInodes
)
!=
len
(
freeIDsEncountered
)
{
panic
(
fmt
.
Sprintf
(
"Length mismatch: %v vs. %v"
,
len
(
fs
.
freeInodes
),
len
(
freeIDsEncountered
)))
}
}
panic
(
"TODO"
)
for
_
,
id
:=
range
fs
.
freeInodes
{
if
_
,
ok
:=
freeIDsEncountered
[
id
];
!
ok
{
panic
(
fmt
.
Sprintf
(
"Unexected free inode ID: %v"
,
id
))
}
}
}
}
func
(
fs
*
memFS
)
Init
(
func
(
fs
*
memFS
)
Init
(
...
...
samples/memfs/inode.go
View file @
1b65aaf8
...
@@ -3,6 +3,11 @@
...
@@ -3,6 +3,11 @@
package
memfs
package
memfs
import
(
"fmt"
"reflect"
)
// Common attributes for files and directories.
// Common attributes for files and directories.
//
//
// TODO(jacobsa): Add tests for interacting with a file/directory after it has
// TODO(jacobsa): Add tests for interacting with a file/directory after it has
...
@@ -15,3 +20,14 @@ type inode struct {
...
@@ -15,3 +20,14 @@ type inode struct {
// INVARIANT: impl is nil, or of type *memFile or *memDir
// INVARIANT: impl is nil, or of type *memFile or *memDir
impl
interface
{}
impl
interface
{}
}
}
func
(
inode
*
inode
)
checkInvariants
()
{
switch
inode
.
impl
.
(
type
)
{
case
nil
:
case
*
memFile
:
case
*
memDir
:
default
:
panic
(
fmt
.
Sprintf
(
"Unexpected inode impl type: %v"
,
reflect
.
TypeOf
(
inode
.
impl
)))
}
}
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