Commit 54857599 authored by Ivan Krasin's avatar Ivan Krasin

File.Read -> File.ReadAt is now compatible with io.ReaderAt

parent 5e8fa0ba
...@@ -14,7 +14,7 @@ const ( ...@@ -14,7 +14,7 @@ const (
) )
type File interface { type File interface {
Read(offset uint64) (data []byte, status Status) ReadAt(p []byte, off int64) (n int, err os.Error)
Close() (status Status) Close() (status Status)
} }
...@@ -289,7 +289,7 @@ func read(fs FileSystem, h *InHeader, ing interface{}, c *managerClient) (interf ...@@ -289,7 +289,7 @@ func read(fs FileSystem, h *InHeader, ing interface{}, c *managerClient) (interf
} }
fileRespChan := make(chan *fileResponse, 1) fileRespChan := make(chan *fileResponse, 1)
fmt.Printf("Sending file request, in.Offset: %v\n", in.Offset) fmt.Printf("Sending file request, in.Offset: %v\n", in.Offset)
resp.fileReq <- &fileRequest{ h.NodeId, in.Offset, fileRespChan} resp.fileReq <- &fileRequest{ h.NodeId, in.Offset, in.Size, fileRespChan}
fmt.Printf("receiving file response\n") fmt.Printf("receiving file response\n")
fileResp := <-fileRespChan fileResp := <-fileRespChan
fmt.Printf("received %v\n", fileResp) fmt.Printf("received %v\n", fileResp)
...@@ -412,6 +412,7 @@ type dirHandle struct { ...@@ -412,6 +412,7 @@ type dirHandle struct {
type fileRequest struct { type fileRequest struct {
nodeId uint64 nodeId uint64
offset uint64 offset uint64
size uint32
resp chan *fileResponse resp chan *fileResponse
} }
...@@ -695,11 +696,12 @@ func readFileRoutine(fs FileSystem, c *managerClient, h *fileHandle) { ...@@ -695,11 +696,12 @@ func readFileRoutine(fs FileSystem, c *managerClient, h *fileHandle) {
defer close(h.req) defer close(h.req)
offset := uint64(0) offset := uint64(0)
for req := range h.req { for req := range h.req {
if req.offset != offset { data := make([]byte, req.size)
req.resp <- &fileResponse { nil, OK } n, err := h.file.ReadAt(data, int64(offset))
if err != nil {
req.resp <- &fileResponse { nil, EIO }
continue
} }
data, status := h.file.Read(offset) req.resp <- &fileResponse { data[0:n], OK }
req.resp <- &fileResponse { data, status }
offset += uint64(len(data))
} }
} }
...@@ -41,11 +41,16 @@ func (fs *testFuse) Open(path string) (file File, code Status) { ...@@ -41,11 +41,16 @@ func (fs *testFuse) Open(path string) (file File, code Status) {
type testFile struct {} type testFile struct {}
func (f *testFile) Read(offset uint64) (data []byte, code Status) { func (f *testFile) ReadAt(data []byte, offset int64) (n int, err os.Error) {
if offset < 13 { if offset < 13 {
return []byte("Hello world!\n"[offset:]), OK our := []byte("Hello world!\n")[offset:]
for i, b := range our {
data[i] = b
}
n = len(our)
return
} }
return nil, OK return 0, os.EOF
} }
func (f *testFile) Close() (status Status) { func (f *testFile) Close() (status Status) {
......
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