Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go-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
Levin Zimmermann
go-fuse
Commits
d415f3e7
Commit
d415f3e7
authored
Apr 22, 2011
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use memory addresses as node ids.
Saves a mutex and a map lookup.
parent
990f3c11
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
20 deletions
+19
-20
fuse/pathfilesystem.go
fuse/pathfilesystem.go
+19
-20
No files found.
fuse/pathfilesystem.go
View file @
d415f3e7
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"path/filepath"
"path/filepath"
"strings"
"strings"
"sync"
"sync"
"unsafe"
)
)
type
mountData
struct
{
type
mountData
struct
{
...
@@ -158,7 +159,7 @@ type FileSystemConnector struct {
...
@@ -158,7 +159,7 @@ type FileSystemConnector struct {
// Invariants: see the verify() method.
// Invariants: see the verify() method.
inodeMap
map
[
uint64
]
*
inode
inodeMap
map
[
uint64
]
*
inode
nextFreeInode
uint64
rootNode
*
inode
// Open files/directories.
// Open files/directories.
fileLock
sync
.
RWMutex
fileLock
sync
.
RWMutex
...
@@ -173,7 +174,7 @@ func (me *FileSystemConnector) DebugString() string {
...
@@ -173,7 +174,7 @@ func (me *FileSystemConnector) DebugString() string {
me
.
fileLock
.
RLock
()
me
.
fileLock
.
RLock
()
defer
me
.
fileLock
.
RUnlock
()
defer
me
.
fileLock
.
RUnlock
()
root
:=
me
.
inodeMap
[
FUSE_ROOT_ID
]
root
:=
me
.
rootNode
return
fmt
.
Sprintf
(
"Mounts %20d
\n
Files %20d
\n
Inodes %20d
\n
"
,
return
fmt
.
Sprintf
(
"Mounts %20d
\n
Files %20d
\n
Inodes %20d
\n
"
,
root
.
totalMountCount
(),
root
.
totalMountCount
(),
len
(
me
.
openFiles
),
len
(
me
.
inodeMap
))
len
(
me
.
openFiles
),
len
(
me
.
inodeMap
))
...
@@ -233,12 +234,12 @@ func (me *FileSystemConnector) verify() {
...
@@ -233,12 +234,12 @@ func (me *FileSystemConnector) verify() {
if
v
.
NodeId
!=
k
{
if
v
.
NodeId
!=
k
{
panic
(
fmt
.
Sprintf
(
"nodeid mismatch %v %v"
,
v
,
k
))
panic
(
fmt
.
Sprintf
(
"nodeid mismatch %v %v"
,
v
,
k
))
}
}
if
v
.
Parent
==
nil
&&
v
.
NodeId
!=
FUSE_ROOT_ID
{
if
v
.
Parent
==
nil
&&
v
!=
me
.
rootNode
{
hiddenOpen
+=
v
.
OpenCount
hiddenOpen
+=
v
.
OpenCount
}
}
}
}
root
:=
me
.
inodeMap
[
FUSE_ROOT_ID
]
root
:=
me
.
rootNode
root
.
verify
()
root
.
verify
()
open
:=
root
.
totalOpenCount
()
open
:=
root
.
totalOpenCount
()
...
@@ -249,11 +250,14 @@ func (me *FileSystemConnector) verify() {
...
@@ -249,11 +250,14 @@ func (me *FileSystemConnector) verify() {
}
}
}
}
func
(
me
*
FileSystemConnector
)
newInode
()
*
inode
{
func
(
me
*
FileSystemConnector
)
newInode
(
root
bool
)
*
inode
{
data
:=
new
(
inode
)
data
:=
new
(
inode
)
data
.
NodeId
=
me
.
nextFreeInode
if
root
{
me
.
nextFreeInode
++
data
.
NodeId
=
FUSE_ROOT_ID
me
.
rootNode
=
data
}
else
{
data
.
NodeId
=
uint64
(
uintptr
(
unsafe
.
Pointer
(
data
)))
}
me
.
inodeMap
[
data
.
NodeId
]
=
data
me
.
inodeMap
[
data
.
NodeId
]
=
data
return
data
return
data
...
@@ -267,7 +271,7 @@ func (me *FileSystemConnector) lookupUpdate(parent *inode, name string, isDir bo
...
@@ -267,7 +271,7 @@ func (me *FileSystemConnector) lookupUpdate(parent *inode, name string, isDir bo
data
,
ok
:=
parent
.
Children
[
name
]
data
,
ok
:=
parent
.
Children
[
name
]
if
!
ok
{
if
!
ok
{
data
=
me
.
newInode
()
data
=
me
.
newInode
(
false
)
data
.
Name
=
name
data
.
Name
=
name
data
.
setParent
(
parent
)
data
.
setParent
(
parent
)
if
isDir
{
if
isDir
{
...
@@ -279,14 +283,11 @@ func (me *FileSystemConnector) lookupUpdate(parent *inode, name string, isDir bo
...
@@ -279,14 +283,11 @@ func (me *FileSystemConnector) lookupUpdate(parent *inode, name string, isDir bo
}
}
func
(
me
*
FileSystemConnector
)
getInodeData
(
nodeid
uint64
)
*
inode
{
func
(
me
*
FileSystemConnector
)
getInodeData
(
nodeid
uint64
)
*
inode
{
me
.
lock
.
RLock
()
if
nodeid
==
FUSE_ROOT_ID
{
defer
me
.
lock
.
RUnlock
()
return
me
.
rootNode
val
:=
me
.
inodeMap
[
nodeid
]
if
val
==
nil
{
panic
(
fmt
.
Sprintf
(
"inode %v unknown"
,
nodeid
))
}
}
return
val
return
(
*
inode
)(
unsafe
.
Pointer
(
uintptr
(
nodeid
)))
}
}
func
(
me
*
FileSystemConnector
)
forgetUpdate
(
nodeId
uint64
,
forgetCount
int
)
{
func
(
me
*
FileSystemConnector
)
forgetUpdate
(
nodeId
uint64
,
forgetCount
int
)
{
...
@@ -351,7 +352,7 @@ func (me *FileSystemConnector) findInode(fullPath string) *inode {
...
@@ -351,7 +352,7 @@ func (me *FileSystemConnector) findInode(fullPath string) *inode {
me
.
lock
.
RLock
()
me
.
lock
.
RLock
()
defer
me
.
lock
.
RUnlock
()
defer
me
.
lock
.
RUnlock
()
node
:=
me
.
inodeMap
[
FUSE_ROOT_ID
]
node
:=
me
.
rootNode
for
i
,
component
:=
range
comps
{
for
i
,
component
:=
range
comps
{
if
len
(
component
)
==
0
{
if
len
(
component
)
==
0
{
continue
continue
...
@@ -374,9 +375,7 @@ func EmptyFileSystemConnector() (out *FileSystemConnector) {
...
@@ -374,9 +375,7 @@ func EmptyFileSystemConnector() (out *FileSystemConnector) {
out
.
inodeMap
=
make
(
map
[
uint64
]
*
inode
)
out
.
inodeMap
=
make
(
map
[
uint64
]
*
inode
)
out
.
openFiles
=
make
(
map
[
uint64
]
interface
{})
out
.
openFiles
=
make
(
map
[
uint64
]
interface
{})
out
.
nextFreeInode
=
FUSE_ROOT_ID
rootData
:=
out
.
newInode
(
true
)
rootData
:=
out
.
newInode
()
rootData
.
NodeId
=
FUSE_ROOT_ID
rootData
.
Type
=
ModeToType
(
S_IFDIR
)
rootData
.
Type
=
ModeToType
(
S_IFDIR
)
rootData
.
Children
=
make
(
map
[
string
]
*
inode
,
initDirSize
)
rootData
.
Children
=
make
(
map
[
string
]
*
inode
,
initDirSize
)
...
...
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