lib9p

Go 9P library.
Log | Files | Refs

commit 2f684278221f6368e13b20c2a3a3c992885ae991
parent 25e73f7fd31b727d844cabc4ce36613916590da5
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Mon, 25 Sep 2023 12:23:36 +0900

add diroffset

Diffstat:
Mfid.go | 19++++++++++---------
Mserver.go | 13+++++++++----
2 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/fid.go b/fid.go @@ -19,19 +19,20 @@ const ( ) type Fid struct { - Fid uint32 - OMode OpenMode /* -1 = not open */ - File File - Uid string -// Qid Qid - DirOffset int + Fid uint32 + OMode OpenMode /* -1 = not open */ + File File + Uid string + dirOffset uint64 + dirIndex int + session *session } const NOFID = ^uint32(0) func newFid(fid uint32) *Fid { return &Fid{ - Fid: fid, + Fid: fid, OMode: -1, } } @@ -45,13 +46,13 @@ func (f *Fid) String() string { } type FidPool struct { - m map[uint32]*Fid + m map[uint32]*Fid lock *sync.Mutex } func allocFidPool() *FidPool { return &FidPool{ - m: make(map[uint32]*Fid), + m: make(map[uint32]*Fid), lock: new(sync.Mutex), } } diff --git a/server.go b/server.go @@ -126,7 +126,6 @@ func sVersion(s *Server, r *Req) { version = "9P2000" } - // TODO: In plan9, s.mSize is changed in rversion(). msize := ifcall.MSize() if msize > s.mSize { msize = s.mSize @@ -454,10 +453,15 @@ func sRead(s *Server, r *Req) { } // TODO: check if TRead offset matches that of last TRead message. + if ifcall.Offset() != 0 && ifcall.Offset() != r.fid.dirOffset { + respond(r, fmt.Errorf("invalid dir offset")) + return + } if ifcall.Offset() == 0 { - r.fid.DirOffset = 0 + r.fid.dirIndex = 0 + r.fid.dirOffset = 0 } - k := r.fid.DirOffset + k := r.fid.dirIndex for ; k < len(children); k++ { if children[k] == nil { continue @@ -477,7 +481,8 @@ func sRead(s *Server, r *Req) { } n += len(buf) } - r.fid.DirOffset = k + r.fid.dirOffset += uint64(n) + r.fid.dirIndex = k } else { if reader, ok := r.fid.File.(io.ReaderAt); ok { n, err = reader.ReadAt(data, int64(ifcall.Offset()))