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 (
)
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 {
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
// }
}
}
......
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)
......
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_readahead uint32
Flags uint32
Max_background uint16
Congestion_threshold uint16
Major uint32
Minor uint32
MaxReadahead uint32
Flags uint32
MaxBackground uint16
CongestionThreshold 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_major uint32 /* chardev major */
Dev_minor uint32 /* chardev minor */
Spare [10]uint32
DevMajor uint32 /* chardev major */
DevMinor 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_size uint32
Out_size uint32
Fh uint64
Flags uint32
Cmd uint32
Arg uint64
InSize uint32
OutSize 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
......
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