Commit ccdeeb8c authored by Ivan Krasin's avatar Ivan Krasin

fuse.go formatted

parent 340517c2
...@@ -53,7 +53,7 @@ func loop(f *os.File, fs FileSystem, errors chan os.Error) { ...@@ -53,7 +53,7 @@ func loop(f *os.File, fs FileSystem, errors chan os.Error) {
} }
} }
func dispatch(fs FileSystem, in_data []byte, toW chan[][]byte, errors chan os.Error) { func dispatch(fs FileSystem, in_data []byte, toW chan [][]byte, errors chan os.Error) {
fmt.Printf("in_data: %v\n", in_data) fmt.Printf("in_data: %v\n", in_data)
r := bytes.NewBuffer(in_data) r := bytes.NewBuffer(in_data)
h := new(InHeader) h := new(InHeader)
...@@ -68,14 +68,22 @@ func dispatch(fs FileSystem, in_data []byte, toW chan[][]byte, errors chan os.Er ...@@ -68,14 +68,22 @@ func dispatch(fs FileSystem, in_data []byte, toW chan[][]byte, errors chan os.Er
var out [][]byte var out [][]byte
fmt.Printf("Opcode: %v, NodeId: %v, h: %v\n", h.Opcode, h.NodeId, h) fmt.Printf("Opcode: %v, NodeId: %v, h: %v\n", h.Opcode, h.NodeId, h)
switch h.Opcode { switch h.Opcode {
case FUSE_INIT: out, err = initFuse(fs, h, r) case FUSE_INIT:
case FUSE_FORGET: return out, err = initFuse(fs, h, r)
case FUSE_GETATTR: out, err = getAttr(fs, h, r) case FUSE_FORGET:
case FUSE_GETXATTR: out, err = getXAttr(h, r) return
case FUSE_OPENDIR: out, err = openDir(h, r) case FUSE_GETATTR:
case FUSE_READDIR: out, err = readDir(h, r) out, err = getAttr(fs, h, r)
case FUSE_LOOKUP: out, err = lookup(h, r) case FUSE_GETXATTR:
case FUSE_RELEASEDIR: out, err = releaseDir(h, r) out, err = getXAttr(h, r)
case FUSE_OPENDIR:
out, err = openDir(h, r)
case FUSE_READDIR:
out, err = readDir(h, r)
case FUSE_LOOKUP:
out, err = lookup(h, r)
case FUSE_RELEASEDIR:
out, err = releaseDir(h, r)
default: default:
errors <- os.NewError(fmt.Sprintf("Unsupported OpCode: %d", h.Opcode)) errors <- os.NewError(fmt.Sprintf("Unsupported OpCode: %d", h.Opcode))
out, err = serialize(h, EIO, nil) out, err = serialize(h, EIO, nil)
...@@ -118,104 +126,104 @@ func serialize(h *InHeader, res Error, out interface{}) (data [][]byte, err os.E ...@@ -118,104 +126,104 @@ func serialize(h *InHeader, res Error, out interface{}) (data [][]byte, err os.E
return return
} }
_, _ = b.Write(out_data) _, _ = b.Write(out_data)
data = [][]byte { b.Bytes() } data = [][]byte{b.Bytes()}
return return
} }
func initFuse(fs FileSystem, h *InHeader, r io.Reader) (data [][]byte, err os.Error) { func initFuse(fs FileSystem, h *InHeader, r io.Reader) (data [][]byte, err os.Error) {
in := new(InitIn) in := new(InitIn)
err = binary.Read(r, binary.LittleEndian, in) err = binary.Read(r, binary.LittleEndian, in)
if err != nil { if err != nil {
return return
} }
fmt.Printf("in: %v\n", in) fmt.Printf("in: %v\n", in)
var out *InitOut var out *InitOut
out, res, err := fs.Init(in) out, res, err := fs.Init(in)
if err != nil { if err != nil {
return
}
data, err = serialize(h, res, out)
return return
}
data, err = serialize(h, res, out)
return
} }
func getAttr(fs FileSystem, h *InHeader, r io.Reader) (data [][]byte, err os.Error) { func getAttr(fs FileSystem, h *InHeader, r io.Reader) (data [][]byte, err os.Error) {
in := new(GetAttrIn) in := new(GetAttrIn)
err = binary.Read(r, binary.LittleEndian, in) err = binary.Read(r, binary.LittleEndian, in)
if err != nil { if err != nil {
return return
} }
fmt.Printf("FUSE_GETATTR: %v\n", in) fmt.Printf("FUSE_GETATTR: %v\n", in)
var out *AttrOut var out *AttrOut
out, res, err := fs.GetAttr(h, in) out, res, err := fs.GetAttr(h, in)
if err != nil { if err != nil {
return
}
data, err = serialize(h, res, out)
return return
}
data, err = serialize(h, res, out)
return
} }
func getXAttr(h *InHeader, r io.Reader) (data [][]byte, err os.Error) { func getXAttr(h *InHeader, r io.Reader) (data [][]byte, err os.Error) {
out := new(GetXAttrOut) out := new(GetXAttrOut)
data, err = serialize(h, OK, out) data, err = serialize(h, OK, out)
return return
} }
func openDir(h *InHeader, r io.Reader) (data [][]byte, err os.Error) { func openDir(h *InHeader, r io.Reader) (data [][]byte, err os.Error) {
in := new(OpenIn) in := new(OpenIn)
err = binary.Read(r, binary.LittleEndian, in) err = binary.Read(r, binary.LittleEndian, in)
if err != nil { if err != nil {
return
}
fmt.Printf("FUSE_OPENDIR: %v\n", in)
out := new(OpenOut)
out.Fh = 1
was = false
res := OK
data, err = serialize(h, res, out)
return return
}
fmt.Printf("FUSE_OPENDIR: %v\n", in)
out := new(OpenOut)
out.Fh = 1
was = false
res := OK
data, err = serialize(h, res, out)
return
} }
func readDir(h *InHeader, r io.Reader) (data [][]byte, err os.Error) { func readDir(h *InHeader, r io.Reader) (data [][]byte, err os.Error) {
if was { if was {
data, err = serialize(h, OK, nil) data, err = serialize(h, OK, nil)
return return
} }
in := new(ReadIn) in := new(ReadIn)
err = binary.Read(r, binary.LittleEndian, in) err = binary.Read(r, binary.LittleEndian, in)
if err != nil { if err != nil {
return
}
fmt.Printf("FUSE_READDIR: %v\n", in)
dirent := new(Dirent)
dirent.Off = 1
dirent.Ino = h.NodeId
dirent.NameLen = 7
dirent.Typ = (S_IFDIR & 0170000) >> 12;
buf := new(bytes.Buffer)
err = binary.Write(buf, binary.LittleEndian, dirent)
if err != nil {
fmt.Printf("AAA!!! binary.Write failed\n")
os.Exit(1)
}
buf.Write([]byte("hello12"))
buf.WriteByte(0)
out := buf.Bytes()
was = true
res := OK
data, err = serialize(h, res, out)
return return
}
fmt.Printf("FUSE_READDIR: %v\n", in)
dirent := new(Dirent)
dirent.Off = 1
dirent.Ino = h.NodeId
dirent.NameLen = 7
dirent.Typ = (S_IFDIR & 0170000) >> 12
buf := new(bytes.Buffer)
err = binary.Write(buf, binary.LittleEndian, dirent)
if err != nil {
fmt.Printf("AAA!!! binary.Write failed\n")
os.Exit(1)
}
buf.Write([]byte("hello12"))
buf.WriteByte(0)
out := buf.Bytes()
was = true
res := OK
data, err = serialize(h, res, out)
return
} }
func lookup(h *InHeader, r *bytes.Buffer) (data [][]byte, err os.Error) { func lookup(h *InHeader, r *bytes.Buffer) (data [][]byte, err os.Error) {
filename := string(r.Bytes()) filename := string(r.Bytes())
fmt.Printf("filename: %s\n", filename) fmt.Printf("filename: %s\n", filename)
out := new(EntryOut) out := new(EntryOut)
out.NodeId = h.NodeId + 1 out.NodeId = h.NodeId + 1
out.Mode = S_IFDIR out.Mode = S_IFDIR
res := OK res := OK
data, err = serialize(h, res, out) data, err = serialize(h, res, out)
return return
} }
func releaseDir(h *InHeader, r io.Reader) (data [][]byte, err os.Error) { func releaseDir(h *InHeader, r io.Reader) (data [][]byte, err os.Error) {
...@@ -234,4 +242,3 @@ func writer(f *os.File, in chan [][]byte, errors chan os.Error) { ...@@ -234,4 +242,3 @@ func writer(f *os.File, in chan [][]byte, errors chan os.Error) {
fmt.Printf("writer: OK\n") fmt.Printf("writer: OK\n")
} }
} }
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