Commit a6dfd5ae authored by Ivan Krasin's avatar Ivan Krasin

something corrups the memory. test raises a panic and the place seems to be random.

parent ea88e396
...@@ -15,14 +15,17 @@ import ( ...@@ -15,14 +15,17 @@ import (
) )
const ( const (
bufSize = 65536 + 100 // See the link above for the details bufSize = 66000
) )
type FileSystem interface{} type FileSystem interface{
Init(in *InitIn) (out *InitOut, code Error)
}
type MountPoint struct { type MountPoint struct {
mountPoint string mountPoint string
f *os.File f *os.File
fs FileSystem
} }
// Mount create a fuse fs on the specified mount point. // 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) { ...@@ -63,7 +66,7 @@ func Mount(mountPoint string, fs FileSystem) (m *MountPoint, err os.Error) {
if err != nil { if err != nil {
return return
} }
m = &MountPoint{mountPoint, f} m = &MountPoint{mountPoint, f, fs}
go m.loop() go m.loop()
return return
} }
...@@ -88,36 +91,76 @@ func (m *MountPoint) loop() { ...@@ -88,36 +91,76 @@ func (m *MountPoint) loop() {
} }
} }
func (m *MountPoint) handle(in []byte, toW chan [][]byte, errors chan os.Error) { func (m *MountPoint) handle(in_data []byte, toW chan [][]byte, errors chan os.Error) {
r := bytes.NewBuffer(in) r := bytes.NewBuffer(in_data)
var h InHeader h := new(InHeader)
err := binary.Read(r, binary.LittleEndian, &h) err := binary.Read(r, binary.LittleEndian, h)
if err == os.EOF { 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 { if err != nil {
errors <- err errors <- err
return return
} }
var out interface{}
var result Error = OK
switch h.Opcode { 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: default:
errors <- os.NewError(fmt.Sprintf("Unsupported OpCode: %d", h.Opcode)) errors <- os.NewError(fmt.Sprintf("Unsupported OpCode: %d", h.Opcode))
fmt.Printf("Unsupported OpCode: %d\n", h.Opcode) result = EIO
// TODO: report an error to the kernel
os.Exit(1)
} }
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) { func (m *MountPoint) writer(f *os.File, in chan [][]byte, errors chan os.Error) {
fd := f.Fd() // fd := f.Fd()
for packet := range in { for _ = range in {
_, err := Writev(fd, packet) // _, err := Writev(fd, packet)
if err != nil { // if err != nil {
errors <- err // errors <- err
continue // continue
} // }
} }
} }
......
package fuse package fuse
import ( import (
"fmt"
"os" "os"
"testing" "testing"
) )
...@@ -11,6 +12,22 @@ const ( ...@@ -11,6 +12,22 @@ const (
type testFuse struct {} 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) { func TestMount(t *testing.T) {
fs := new(testFuse) fs := new(testFuse)
err := os.Mkdir(tempMountDir, 0777) err := os.Mkdir(tempMountDir, 0777)
......
package fuse package fuse
import (
"syscall"
)
const ( const (
/** Version number of this interface */ /** Version number of this interface */
...@@ -124,6 +128,14 @@ const ( ...@@ -124,6 +128,14 @@ const (
CUSE_INIT_INFO_MAX = 4096 CUSE_INIT_INFO_MAX = 4096
) )
type Error int32
const (
OK = Error(0)
EIO = Error(syscall.EIO)
ENOSYS = Error(syscall.ENOSYS)
)
type Opcode int type Opcode int
const ( const (
...@@ -273,22 +285,22 @@ type LinkIn struct { ...@@ -273,22 +285,22 @@ type LinkIn struct {
} }
type SetattrIn struct { type SetattrIn struct {
Valid uint32 Valid uint32
Padding uint32 Padding uint32
Fh uint64 Fh uint64
Size uint64 Size uint64
LockOwner uint64 LockOwner uint64
Atime uint64 Atime uint64
Mtime uint64 Mtime uint64
Unused2 uint64 Unused2 uint64
Atimensec uint32 Atimensec uint32
Mtimensec uint32 Mtimensec uint32
Unused3 uint32 Unused3 uint32
Mode uint32 Mode uint32
Unused4 uint32 Unused4 uint32
Uid uint32 Uid uint32
Gid uint32 Gid uint32
Unused5 uint32 Unused5 uint32
} }
type OpenIn struct { type OpenIn struct {
...@@ -313,13 +325,13 @@ type ReleaseIn struct { ...@@ -313,13 +325,13 @@ type ReleaseIn struct {
Fh uint64 Fh uint64
Flags uint32 Flags uint32
Release_flags uint32 Release_flags uint32
LockOwner uint64 LockOwner uint64
} }
type FlushIn struct { type FlushIn struct {
Fh uint64 Fh uint64
Unused uint32 Unused uint32
Padding uint32 Padding uint32
LockOwner uint64 LockOwner uint64
} }
...@@ -328,7 +340,7 @@ type ReadIn struct { ...@@ -328,7 +340,7 @@ type ReadIn struct {
Offset uint64 Offset uint64
Size uint32 Size uint32
Read_flags uint32 Read_flags uint32
LockOwner uint64 LockOwner uint64
Flags uint32 Flags uint32
Padding uint32 Padding uint32
} }
...@@ -339,7 +351,7 @@ type WriteIn struct { ...@@ -339,7 +351,7 @@ type WriteIn struct {
Offset uint64 Offset uint64
Size uint32 Size uint32
Write_flags uint32 Write_flags uint32
LockOwner uint64 LockOwner uint64
Flags uint32 Flags uint32
Padding uint32 Padding uint32
} }
...@@ -400,12 +412,12 @@ type InitIn struct { ...@@ -400,12 +412,12 @@ type InitIn struct {
} }
type InitOut struct { type InitOut struct {
Major uint32 Major uint32
Minor uint32 Minor uint32
Max_readahead uint32 MaxReadahead uint32
Flags uint32 Flags uint32
Max_background uint16 MaxBackground uint16
Congestion_threshold uint16 CongestionThreshold uint16
MaxWrite uint32 MaxWrite uint32
} }
...@@ -417,15 +429,15 @@ type CuseInitIn struct { ...@@ -417,15 +429,15 @@ type CuseInitIn struct {
} }
type CuseInitOut struct { type CuseInitOut struct {
Major uint32 Major uint32
Minor uint32 Minor uint32
Unused uint32 Unused uint32
Flags uint32 Flags uint32
Max_read uint32 Max_read uint32
MaxWrite uint32 MaxWrite uint32
Dev_major uint32 /* chardev major */ DevMajor uint32 /* chardev major */
Dev_minor uint32 /* chardev minor */ DevMinor uint32 /* chardev minor */
Spare [10]uint32 Spare [10]uint32
} }
type InterruptIn struct { type InterruptIn struct {
...@@ -443,17 +455,17 @@ type BmapOut struct { ...@@ -443,17 +455,17 @@ type BmapOut struct {
} }
type IoctlIn struct { type IoctlIn struct {
Fh uint64 Fh uint64
Flags uint32 Flags uint32
Cmd uint32 Cmd uint32
Arg uint64 Arg uint64
In_size uint32 InSize uint32
Out_size uint32 OutSize uint32
} }
type IoctlOut struct { type IoctlOut struct {
Result int32 Result int32
Flags uint32 Flags uint32
InIovs uint32 InIovs uint32
OutIovs uint32 OutIovs uint32
} }
...@@ -485,6 +497,8 @@ type InHeader struct { ...@@ -485,6 +497,8 @@ type InHeader struct {
Padding uint32 Padding uint32
} }
const SizeOfOutHeader = 16
type OutHeader struct { type OutHeader struct {
Length uint32 Length uint32
Error int32 Error int32
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment