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
d0a8174e
Commit
d0a8174e
authored
Mar 31, 2015
by
Aaron Jacobs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fsImpl.LookUpInode.
parent
541223bb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
8 deletions
+65
-8
samples/forgetfs/forget_fs.go
samples/forgetfs/forget_fs.go
+65
-8
No files found.
samples/forgetfs/forget_fs.go
View file @
d0a8174e
...
...
@@ -136,6 +136,10 @@ type inode struct {
lookupCount
int
}
////////////////////////////////////////////////////////////////////////
// Helpers
////////////////////////////////////////////////////////////////////////
// LOCKS_REQUIRED(fs.mu)
func
(
fs
*
fsImpl
)
checkInvariants
()
{
// INVARIANT: For each v in inodes, v.lookupCount >= 0
...
...
@@ -165,6 +169,26 @@ func (fs *fsImpl) Check() {
}
}
// Look up the inode and verify it hasn't been forgotten.
//
// LOCKS_REQUIRED(fs.mu)
func
(
fs
*
fsImpl
)
findInodeByID
(
id
fuseops
.
InodeID
)
(
in
*
inode
)
{
in
=
fs
.
inodes
[
id
]
if
in
==
nil
{
panic
(
fmt
.
Sprintf
(
"Unknown inode: %v"
,
id
))
}
if
in
.
lookupCount
<=
0
{
panic
(
fmt
.
Sprintf
(
"Forgotten inode: %v"
,
id
))
}
return
}
////////////////////////////////////////////////////////////////////////
// FileSystem methods
////////////////////////////////////////////////////////////////////////
func
(
fs
*
fsImpl
)
Init
(
op
*
fuseops
.
InitOp
)
{
var
err
error
...
...
@@ -173,24 +197,57 @@ func (fs *fsImpl) Init(
return
}
func
(
fs
*
fsImpl
)
GetInodeAttributes
(
op
*
fuseops
.
GetInodeAttributes
Op
)
{
func
(
fs
*
fsImpl
)
LookUpInode
(
op
*
fuseops
.
LookUpInode
Op
)
{
var
err
error
defer
fuseutil
.
RespondToOp
(
op
,
&
err
)
fs
.
mu
.
Lock
()
defer
fs
.
mu
.
Unlock
()
// Find the inode, verifying that it has not been forgotten.
in
:=
fs
.
inodes
[
op
.
Inode
]
if
in
==
nil
{
panic
(
fmt
.
Sprintf
(
"Unknown inode: %v"
,
op
.
Inode
))
// Make sure the parent exists and has not been forgotten.
_
=
fs
.
findInodeByID
(
op
.
Parent
)
// Handle the names we support.
var
childID
fuseops
.
InodeID
switch
{
case
op
.
Parent
==
cannedID_Root
&&
op
.
Name
==
"foo"
:
childID
=
cannedID_Foo
case
op
.
Parent
==
cannedID_Root
&&
op
.
Name
==
"bar"
:
childID
=
cannedID_Bar
default
:
err
=
fuse
.
ENOENT
return
}
if
in
.
lookupCount
<=
0
{
panic
(
fmt
.
Sprintf
(
"Forgotten inode: %v"
,
op
.
Inode
))
// Find the child.
child
:=
fs
.
findInodeByID
(
childID
)
// Increment the child's lookup count.
child
.
lookupCount
++
// Return an appropriate entry.
op
.
Entry
=
fuseops
.
ChildInodeEntry
{
Child
:
childID
,
Attributes
:
child
.
attributes
,
}
return
}
func
(
fs
*
fsImpl
)
GetInodeAttributes
(
op
*
fuseops
.
GetInodeAttributesOp
)
{
var
err
error
defer
fuseutil
.
RespondToOp
(
op
,
&
err
)
fs
.
mu
.
Lock
()
defer
fs
.
mu
.
Unlock
()
// Find the inode, verifying that it has not been forgotten.
in
:=
fs
.
findInodeByID
(
op
.
Inode
)
// Return appropriate attributes.
op
.
Attributes
=
in
.
attributes
...
...
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