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
e6fa94ed
Commit
e6fa94ed
authored
Sep 06, 2011
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Store interface{} to original object in HandleMap.
parent
f7e64903
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
21 deletions
+23
-21
fuse/fsconnector.go
fuse/fsconnector.go
+3
-3
fuse/fsmount.go
fuse/fsmount.go
+2
-2
fuse/handle.go
fuse/handle.go
+8
-7
fuse/handle_test.go
fuse/handle_test.go
+10
-9
No files found.
fuse/fsconnector.go
View file @
e6fa94ed
...
...
@@ -59,7 +59,7 @@ func (me *FileSystemConnector) verify() {
func
(
me
*
FileSystemConnector
)
newInode
(
isDir
bool
)
*
Inode
{
data
:=
new
(
Inode
)
data
.
nodeId
=
me
.
inodeMap
.
Register
(
&
data
.
handled
)
data
.
nodeId
=
me
.
inodeMap
.
Register
(
&
data
.
handled
,
data
)
data
.
connector
=
me
if
isDir
{
data
.
children
=
make
(
map
[
string
]
*
Inode
,
initDirSize
)
...
...
@@ -260,7 +260,7 @@ func (me *FileSystemConnector) Mount(parent *Inode, name string, nodeFs NodeFile
node
.
mountFs
(
nodeFs
,
opts
)
parent
.
addChild
(
name
,
node
)
if
parent
.
mounts
==
nil
{
parent
.
mounts
=
make
(
map
[
string
]
*
fileSystemMount
)
}
...
...
@@ -275,7 +275,7 @@ func (me *FileSystemConnector) Mount(parent *Inode, name string, nodeFs NodeFile
return
OK
}
// Unmount() tries to unmount the given inode.
// Unmount() tries to unmount the given inode.
//
// Returns the following error codes:
//
...
...
fuse/fsmount.go
View file @
e6fa94ed
...
...
@@ -13,7 +13,7 @@ var _ = log.Println
type
openedFile
struct
{
Handled
WithFlags
WithFlags
dir
rawDir
}
...
...
@@ -119,6 +119,6 @@ func (me *fileSystemMount) registerFileHandle(node *Inode, dir rawDir, f File, f
}
node
.
openFiles
=
append
(
node
.
openFiles
,
b
)
handle
:=
me
.
openFiles
.
Register
(
&
b
.
Handled
)
handle
:=
me
.
openFiles
.
Register
(
&
b
.
Handled
,
b
)
return
handle
,
b
}
fuse/handle.go
View file @
e6fa94ed
...
...
@@ -20,14 +20,14 @@ import (
//
// This structure is thread-safe.
type
HandleMap
interface
{
Register
(
obj
*
Handled
)
uint64
Register
(
obj
*
Handled
,
asInt
interface
{}
)
uint64
Count
()
int
Forget
(
uint64
)
*
Handled
}
// TODO - store interface{} pointer to wrapped object.
type
Handled
struct
{
check
uint32
check
uint32
object
interface
{}
}
// 32 bits version of HandleMap
...
...
@@ -36,7 +36,7 @@ type int32HandleMap struct {
handles
map
[
uint32
]
*
Handled
}
func
(
me
*
int32HandleMap
)
Register
(
obj
*
Handled
)
uint64
{
func
(
me
*
int32HandleMap
)
Register
(
obj
*
Handled
,
asInt
interface
{}
)
uint64
{
me
.
mutex
.
Lock
()
defer
me
.
mutex
.
Unlock
()
handle
:=
uint32
(
uintptr
(
unsafe
.
Pointer
(
obj
)))
...
...
@@ -112,7 +112,7 @@ func (me *int64HandleMap) Count() int {
return
len
(
me
.
handles
)
}
func
(
me
*
int64HandleMap
)
Register
(
obj
*
Handled
)
(
handle
uint64
)
{
func
(
me
*
int64HandleMap
)
Register
(
obj
*
Handled
,
asInterface
interface
{}
)
(
handle
uint64
)
{
defer
me
.
verify
()
me
.
mutex
.
Lock
()
...
...
@@ -142,6 +142,7 @@ func (me *int64HandleMap) Register(obj *Handled) (handle uint64) {
obj
.
check
=
check
}
obj
.
object
=
asInterface
me
.
handles
[
handle
]
=
obj
return
handle
}
...
...
@@ -169,8 +170,8 @@ func DecodeHandle(handle uint64) (val *Handled) {
val
=
(
*
Handled
)(
unsafe
.
Pointer
(
uintptr
(
handle
&
((
1
<<
32
)
-
1
))))
}
if
val
.
check
!=
check
{
msg
:=
fmt
.
Sprintf
(
"handle check mismatch; handle has 0x%x, object has 0x%x"
,
check
,
val
.
check
)
msg
:=
fmt
.
Sprintf
(
"handle check mismatch; handle has 0x%x, object has 0x%x
: %v
"
,
check
,
val
.
check
,
val
.
object
)
panic
(
msg
)
}
return
val
...
...
fuse/handle_test.go
View file @
e6fa94ed
...
...
@@ -26,10 +26,11 @@ func TestHandleMapDoubleRegister(t *testing.T) {
log
.
Println
(
"TestDoubleRegister"
)
defer
markSeen
(
"already has a handle"
)
hm
:=
NewHandleMap
(
true
)
hm
.
Register
(
&
Handled
{})
obj
:=
&
Handled
{}
hm
.
Register
(
obj
,
obj
)
v
:=
&
Handled
{}
hm
.
Register
(
v
)
hm
.
Register
(
v
)
hm
.
Register
(
v
,
v
)
hm
.
Register
(
v
,
v
)
t
.
Error
(
"Double register did not panic"
)
}
...
...
@@ -44,7 +45,7 @@ func TestHandleMapUnaligned(t *testing.T) {
v
:=
(
*
Handled
)(
unsafe
.
Pointer
(
&
b
[
1
]))
defer
markSeen
(
"unaligned"
)
hm
.
Register
(
v
)
hm
.
Register
(
v
,
v
)
t
.
Error
(
"Unaligned register did not panic"
)
}
...
...
@@ -59,7 +60,7 @@ func TestHandleMapPointerLayout(t *testing.T) {
p
:=
uintptr
(
bogus
)
v
:=
(
*
Handled
)(
unsafe
.
Pointer
(
p
))
defer
markSeen
(
"48"
)
hm
.
Register
(
v
)
hm
.
Register
(
v
,
v
)
t
.
Error
(
"bogus register did not panic"
)
}
...
...
@@ -70,7 +71,7 @@ func TestHandleMapBasic(t *testing.T) {
}
v
:=
new
(
Handled
)
hm
:=
NewHandleMap
(
true
)
h
:=
hm
.
Register
(
v
)
h
:=
hm
.
Register
(
v
,
v
)
log
.
Printf
(
"Got handle 0x%x"
,
h
)
if
DecodeHandle
(
h
)
!=
v
{
t
.
Fatal
(
"address mismatch"
)
...
...
@@ -92,7 +93,7 @@ func TestHandleMapMultiple(t *testing.T) {
hm
:=
NewHandleMap
(
true
)
for
i
:=
0
;
i
<
10
;
i
++
{
v
:=
&
Handled
{}
h
:=
hm
.
Register
(
v
)
h
:=
hm
.
Register
(
v
,
v
)
if
DecodeHandle
(
h
)
!=
v
{
t
.
Fatal
(
"address mismatch"
)
}
...
...
@@ -111,7 +112,7 @@ func TestHandleMapCheckFail(t *testing.T) {
v
:=
new
(
Handled
)
hm
:=
NewHandleMap
(
true
)
h
:=
hm
.
Register
(
v
)
h
:=
hm
.
Register
(
v
,
v
)
DecodeHandle
(
h
|
(
uint64
(
1
)
<<
63
))
t
.
Error
(
"Borked decode did not panic"
)
}
...
...
@@ -123,7 +124,7 @@ func TestHandleMapNoCheck(t *testing.T) {
}
v
:=
new
(
Handled
)
hm
:=
NewHandleMap
(
false
)
h
:=
hm
.
Register
(
v
)
h
:=
hm
.
Register
(
v
,
v
)
if
h
>
uint64
(
0xffffffff
)
{
t
.
Errorf
(
"handles should in 32 bit if verification switched off: %x"
,
h
)
}
...
...
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