lib9p

Go 9P library.
Log | Files | Refs

commit ac33e55bc3e82e91f35af8f219489b895cac5222
parent f18218b8afb78e449d2a06526d2ce4badec11dc6
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Sat, 14 Oct 2023 08:32:04 +0900

implement clientfile.Child(), .Read()

Diffstat:
Mclient_test.go | 1-
Mfile.go | 33++++++++++++++++++++++++++++++---
2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/client_test.go b/client_test.go @@ -133,7 +133,6 @@ func TestClient2(t *testing.T) { } t.Log(fs) - fs.walk(".") f := fs.Root() t.Log(f) diff --git a/file.go b/file.go @@ -93,7 +93,7 @@ func (cf *ClientFile) Child() ([]File, error) { return nil, fmt.Errorf("not a directory") } var data []byte - buf := make([]byte, 0, cf.iounit) + buf := make([]byte, cf.iounit) for { n, err := cf.Read(buf) if err == io.EOF { @@ -116,7 +116,7 @@ func (cf *ClientFile) Child() ([]File, error) { parent: cf, client: cf.client, }) - data = data[stat.size():] + data = data[stat.size()+2:] } return files, nil } @@ -154,5 +154,32 @@ func (cf *ClientFile) Close() error { } func (cf *ClientFile) Read(b []byte) (int, error) { - return 0, io.EOF + count := uint32(len(b)) + cur := 0 + for count > 0 { + var c uint32 + if count > cf.iounit { + c = cf.iounit + } else { + c = count + } + buf, err := cf.client.Read(context.TODO(), cf.fid.fid, cf.fid.offset, c) + var i int + for i = 0; i < len(buf); i++ { + b[cur + i] = buf[i] + } + cf.fid.offset += uint64(i) + cur += i + if err != nil { + return cur, err + } + + count -= c + } + + if cur == 0 { + return 0, io.EOF + } else { + return int(cur), nil + } }