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
a6dfd5ae
Commit
a6dfd5ae
authored
Aug 12, 2010
by
Ivan Krasin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
something corrups the memory. test raises a panic and the place seems to be random.
parent
ea88e396
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
137 additions
and
63 deletions
+137
-63
fuse/fuse.go
fuse/fuse.go
+63
-20
fuse/fuse_test.go
fuse/fuse_test.go
+17
-0
fuse/types.go
fuse/types.go
+57
-43
No files found.
fuse/fuse.go
View file @
a6dfd5ae
...
...
@@ -15,14 +15,17 @@ import (
)
const
(
bufSize
=
6
5536
+
100
// See the link above for the details
bufSize
=
6
6000
)
type
FileSystem
interface
{}
type
FileSystem
interface
{
Init
(
in
*
InitIn
)
(
out
*
InitOut
,
code
Error
)
}
type
MountPoint
struct
{
mountPoint
string
f
*
os
.
File
fs
FileSystem
}
// Mount create a fuse fs on the specified mount point.
...
...
@@ -63,7 +66,7 @@ func Mount(mountPoint string, fs FileSystem) (m *MountPoint, err os.Error) {
if
err
!=
nil
{
return
}
m
=
&
MountPoint
{
mountPoint
,
f
}
m
=
&
MountPoint
{
mountPoint
,
f
,
fs
}
go
m
.
loop
()
return
}
...
...
@@ -88,36 +91,76 @@ func (m *MountPoint) loop() {
}
}
func
(
m
*
MountPoint
)
handle
(
in
[]
byte
,
toW
chan
[][]
byte
,
errors
chan
os
.
Error
)
{
r
:=
bytes
.
NewBuffer
(
in
)
var
h
InHeader
err
:=
binary
.
Read
(
r
,
binary
.
LittleEndian
,
&
h
)
func
(
m
*
MountPoint
)
handle
(
in
_data
[]
byte
,
toW
chan
[][]
byte
,
errors
chan
os
.
Error
)
{
r
:=
bytes
.
NewBuffer
(
in
_data
)
h
:=
new
(
InHeader
)
err
:=
binary
.
Read
(
r
,
binary
.
LittleEndian
,
h
)
if
err
==
os
.
EOF
{
err
=
os
.
NewError
(
fmt
.
Sprintf
(
"MountPoint, handle: can't read a header, in
: %v"
,
in
))
err
=
os
.
NewError
(
fmt
.
Sprintf
(
"MountPoint, handle: can't read a header, in
_data: %v"
,
in_data
))
}
if
err
!=
nil
{
errors
<-
err
return
}
var
out
interface
{}
var
result
Error
=
OK
switch
h
.
Opcode
{
// case FUSE_INIT: // I too want to sleep. Will continue later.
case
FUSE_INIT
:
in
:=
new
(
InitIn
)
err
=
binary
.
Read
(
r
,
binary
.
LittleEndian
,
in
)
if
err
!=
nil
{
break
}
fmt
.
Printf
(
"in: %v
\n
"
,
in
)
var
init_out
*
InitOut
init_out
,
result
=
m
.
fs
.
Init
(
in
)
if
init_out
!=
nil
{
out
=
init_out
}
default
:
errors
<-
os
.
NewError
(
fmt
.
Sprintf
(
"Unsupported OpCode: %d"
,
h
.
Opcode
))
fmt
.
Printf
(
"Unsupported OpCode: %d
\n
"
,
h
.
Opcode
)
// TODO: report an error to the kernel
os
.
Exit
(
1
)
result
=
EIO
}
if
err
!=
nil
{
errors
<-
err
out
=
nil
result
=
EIO
// Add sending result msg with error
}
b
:=
new
(
bytes
.
Buffer
)
out_data
:=
make
([]
byte
,
0
)
if
out
!=
nil
&&
result
==
OK
{
fmt
.
Printf
(
"out = %v, out == nil: %v
\n
"
,
out
,
out
==
nil
)
return
err
=
binary
.
Write
(
b
,
binary
.
LittleEndian
,
out
)
if
err
==
nil
{
out_data
=
b
.
Bytes
()
}
else
{
errors
<-
os
.
NewError
(
fmt
.
Sprintf
(
"Can serialize out: %v"
,
err
))
}
}
var
hout
OutHeader
hout
.
Unique
=
h
.
Unique
hout
.
Error
=
int32
(
result
)
hout
.
Length
=
uint32
(
len
(
out_data
)
+
SizeOfOutHeader
)
b
=
new
(
bytes
.
Buffer
)
err
=
binary
.
Write
(
b
,
binary
.
LittleEndian
,
&
hout
)
if
err
!=
nil
{
errors
<-
err
return
}
_
,
_
=
b
.
Write
(
out_data
)
toW
<-
[][]
byte
{
b
.
Bytes
()
}
}
func
(
m
*
MountPoint
)
writer
(
f
*
os
.
File
,
in
chan
[][]
byte
,
errors
chan
os
.
Error
)
{
fd
:=
f
.
Fd
()
for
packet
:
=
range
in
{
_
,
err
:=
Writev
(
fd
,
packet
)
if
err
!=
nil
{
errors
<-
err
continue
}
//
fd := f.Fd()
for
_
=
range
in
{
//
_, err := Writev(fd, packet)
//
if err != nil {
//
errors <- err
//
continue
//
}
}
}
...
...
fuse/fuse_test.go
View file @
a6dfd5ae
package
fuse
import
(
"fmt"
"os"
"testing"
)
...
...
@@ -11,6 +12,22 @@ const (
type
testFuse
struct
{}
func
(
fs
*
testFuse
)
Init
(
in
*
InitIn
)
(
out
*
InitOut
,
code
Error
)
{
if
(
in
.
Major
!=
FUSE_KERNEL_VERSION
)
{
fmt
.
Printf
(
"Major versions does not match. Given %d, want %d
\n
"
,
in
.
Major
,
FUSE_KERNEL_VERSION
)
return
nil
,
EIO
}
if
(
in
.
Minor
<
FUSE_KERNEL_MINOR_VERSION
)
{
fmt
.
Printf
(
"Minor version is less than we support. Given %d, want at least %d
\n
"
,
in
.
Minor
,
FUSE_KERNEL_MINOR_VERSION
)
return
nil
,
EIO
}
out
.
Major
=
FUSE_KERNEL_VERSION
out
.
Minor
=
FUSE_KERNEL_MINOR_VERSION
out
.
MaxReadahead
=
65536
out
.
MaxWrite
=
65536
return
}
func
TestMount
(
t
*
testing
.
T
)
{
fs
:=
new
(
testFuse
)
err
:=
os
.
Mkdir
(
tempMountDir
,
0777
)
...
...
fuse/types.go
View file @
a6dfd5ae
package
fuse
import
(
"syscall"
)
const
(
/** Version number of this interface */
...
...
@@ -124,6 +128,14 @@ const (
CUSE_INIT_INFO_MAX
=
4096
)
type
Error
int32
const
(
OK
=
Error
(
0
)
EIO
=
Error
(
syscall
.
EIO
)
ENOSYS
=
Error
(
syscall
.
ENOSYS
)
)
type
Opcode
int
const
(
...
...
@@ -273,22 +285,22 @@ type LinkIn struct {
}
type
SetattrIn
struct
{
Valid
uint32
Padding
uint32
Fh
uint64
Size
uint64
Valid
uint32
Padding
uint32
Fh
uint64
Size
uint64
LockOwner
uint64
Atime
uint64
Mtime
uint64
Unused2
uint64
Atimensec
uint32
Mtimensec
uint32
Unused3
uint32
Mode
uint32
Unused4
uint32
Uid
uint32
Gid
uint32
Unused5
uint32
Atime
uint64
Mtime
uint64
Unused2
uint64
Atimensec
uint32
Mtimensec
uint32
Unused3
uint32
Mode
uint32
Unused4
uint32
Uid
uint32
Gid
uint32
Unused5
uint32
}
type
OpenIn
struct
{
...
...
@@ -313,13 +325,13 @@ type ReleaseIn struct {
Fh
uint64
Flags
uint32
Release_flags
uint32
LockOwner
uint64
LockOwner
uint64
}
type
FlushIn
struct
{
Fh
uint64
Unused
uint32
Padding
uint32
Fh
uint64
Unused
uint32
Padding
uint32
LockOwner
uint64
}
...
...
@@ -328,7 +340,7 @@ type ReadIn struct {
Offset
uint64
Size
uint32
Read_flags
uint32
LockOwner
uint64
LockOwner
uint64
Flags
uint32
Padding
uint32
}
...
...
@@ -339,7 +351,7 @@ type WriteIn struct {
Offset
uint64
Size
uint32
Write_flags
uint32
LockOwner
uint64
LockOwner
uint64
Flags
uint32
Padding
uint32
}
...
...
@@ -400,12 +412,12 @@ type InitIn struct {
}
type
InitOut
struct
{
Major
uint32
Minor
uint32
Max
_r
eadahead
uint32
Flags
uint32
Max
_b
ackground
uint16
Congestion
_t
hreshold
uint16
Major
uint32
Minor
uint32
Max
R
eadahead
uint32
Flags
uint32
Max
B
ackground
uint16
Congestion
T
hreshold
uint16
MaxWrite
uint32
}
...
...
@@ -417,15 +429,15 @@ type CuseInitIn struct {
}
type
CuseInitOut
struct
{
Major
uint32
Minor
uint32
Unused
uint32
Flags
uint32
Max_read
uint32
Major
uint32
Minor
uint32
Unused
uint32
Flags
uint32
Max_read
uint32
MaxWrite
uint32
Dev
_m
ajor
uint32
/* chardev major */
Dev
_m
inor
uint32
/* chardev minor */
Spare
[
10
]
uint32
Dev
M
ajor
uint32
/* chardev major */
Dev
M
inor
uint32
/* chardev minor */
Spare
[
10
]
uint32
}
type
InterruptIn
struct
{
...
...
@@ -443,17 +455,17 @@ type BmapOut struct {
}
type
IoctlIn
struct
{
Fh
uint64
Flags
uint32
Cmd
uint32
Arg
uint64
In
_s
ize
uint32
Out
_s
ize
uint32
Fh
uint64
Flags
uint32
Cmd
uint32
Arg
uint64
In
S
ize
uint32
Out
S
ize
uint32
}
type
IoctlOut
struct
{
Result
int32
Flags
uint32
Result
int32
Flags
uint32
InIovs
uint32
OutIovs
uint32
}
...
...
@@ -485,6 +497,8 @@ type InHeader struct {
Padding
uint32
}
const
SizeOfOutHeader
=
16
type
OutHeader
struct
{
Length
uint32
Error
int32
...
...
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