lib9p

Go 9P library.
Log | Files | Refs | LICENSE

commit 38c3bc8fa492579416f39451b013bb5d5e2613e0
parent 4a1fa9877ce303098dedd5c4127e5aa043cdb70a
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Fri, 27 Oct 2023 08:30:38 +0900

update client

Diffstat:
Mclient/client.go | 86++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mclient/file.go | 6+++---
Mclient/fs.go | 12++++++------
Mclient/req.go | 8++++----
4 files changed, 56 insertions(+), 56 deletions(-)

diff --git a/client/client.go b/client/client.go @@ -91,7 +91,7 @@ func (c *Client) runListener(ctx context.Context, r io.Reader) <-chan lib9p.Msg ) go func() { defer close(done) - msg, err = lib9p.recv(r) + msg, err = lib9p.RecvMsg(r) }() select { case <-done: @@ -135,7 +135,7 @@ func (c *Client) runSpeaker(ctx context.Context, w io.Writer) chan<- lib9p.Msg { // but this code breaks semantics? return } - if err := lib9p.send(msg, w); err != nil { + if err := lib9p.SendMsg(msg, w); err != nil { c.errc <- fmt.Errorf("send: %v", err) } } @@ -189,12 +189,12 @@ func (c *Client) runMultiplexer(ctx context.Context, tmsgc chan<- lib9p.Msg, rms // ctx is canceled. continue } - req, ok := rPool[msg.Tag()] + req, ok := rPool[msg.GetTag()] if !ok { c.errc <- fmt.Errorf("mux: unknown tag for msg: %v", msg) continue } - delete(rPool, msg.Tag()) + delete(rPool, msg.GetTag()) req.rmsg = msg go func() { defer close(req.rxc) @@ -255,56 +255,56 @@ func (c *Client) transact(ctx context.Context, tmsg lib9p.Msg) (lib9p.Msg, error } } -func (c *Client) Version(ctx context.Context, tag uint16, mSize uint32, version string) (uint32, string, error) { - tmsg := &lib9p.TVersion{tag: tag, mSize: mSize, version: version} +func (c *Client) Version(ctx context.Context, tag uint16, msize uint32, version string) (uint32, string, error) { + tmsg := &lib9p.TVersion{Tag: tag, Msize: msize, Version: version} rmsg, err := c.transact(ctx, tmsg) if err != nil { return 0, "", fmt.Errorf("transact: %v", err) } switch rmsg := rmsg.(type) { case *lib9p.RVersion: - return rmsg.mSize, rmsg.version, nil + return rmsg.Msize, rmsg.Version, nil case *lib9p.RError: - return 0, "", rmsg.ename + return 0, "", rmsg.Ename default: return 0, "", fmt.Errorf("invalid reply: %v", rmsg) } } func (c *Client) Auth(ctx context.Context, tag uint16, afid uint32, uname, aname string) (lib9p.Qid, error) { - tmsg := &lib9p.TAuth{tag: tag, afid: afid, uname: uname} + tmsg := &lib9p.TAuth{Tag: tag, Afid: afid, Uname: uname} rmsg, err := c.transact(ctx, tmsg) if err != nil { return lib9p.Qid{}, fmt.Errorf("transact: %v", err) } switch rmsg := rmsg.(type) { case *lib9p.RAuth: - return rmsg.aqid, nil + return rmsg.Aqid, nil case *lib9p.RError: - return lib9p.Qid{}, rmsg.ename + return lib9p.Qid{}, rmsg.Ename default: return lib9p.Qid{}, fmt.Errorf("invalid reply: %v", rmsg) } } func (c *Client) Attach(ctx context.Context, tag uint16, fid, afid uint32, uname, aname string) (lib9p.Qid, error) { - tmsg := &lib9p.TAttach{tag: tag, fid: fid, afid: afid, uname: uname, aname: aname} + tmsg := &lib9p.TAttach{Tag: tag, Fid: fid, Afid: afid, Uname: uname, Aname: aname} rmsg, err := c.transact(ctx, tmsg) if err != nil { return lib9p.Qid{}, fmt.Errorf("transact: %v", err) } switch rmsg := rmsg.(type) { case *lib9p.RAttach: - return rmsg.qid, nil + return rmsg.Qid, nil case *lib9p.RError: - return lib9p.Qid{}, rmsg.ename + return lib9p.Qid{}, rmsg.Ename default: return lib9p.Qid{}, fmt.Errorf("invalid reply: %v", rmsg) } } func (c *Client) Flush(ctx context.Context, tag, oldtag uint16) error { - tmsg := &lib9p.TFlush{tag: tag, oldtag: oldtag} + tmsg := &lib9p.TFlush{Tag: tag, Oldtag: oldtag} rmsg, err := c.transact(ctx, tmsg) if err != nil { return fmt.Errorf("transact: %v", err) @@ -313,88 +313,88 @@ func (c *Client) Flush(ctx context.Context, tag, oldtag uint16) error { case *lib9p.RFlush: return nil case *lib9p.RError: - return rmsg.ename + return rmsg.Ename default: return fmt.Errorf("invalid reply: %v", rmsg) } } -func (c *Client) Walk(ctx context.Context, tag uint16, fid, newFid uint32, wname []string) (wqid []lib9p.Qid, err error) { - tmsg := &lib9p.TWalk{tag: tag, fid: fid, newFid: newFid, wname: wname} +func (c *Client) Walk(ctx context.Context, tag uint16, fid, newfid uint32, wnames []string) (wqid []lib9p.Qid, err error) { + tmsg := &lib9p.TWalk{Tag: tag, Fid: fid, Newfid: newfid, Wnames: wnames} rmsg, err := c.transact(ctx, tmsg) if err != nil { return nil, fmt.Errorf("transact: %v", err) } switch rmsg := rmsg.(type) { case *lib9p.RWalk: - return rmsg.qid, nil + return rmsg.Qids, nil case *lib9p.RError: - return nil, rmsg.ename + return nil, rmsg.Ename default: return nil, fmt.Errorf("invalid reply: %v", rmsg) } } func (c *Client) Open(ctx context.Context, tag uint16, fid uint32, mode lib9p.OpenMode) (qid lib9p.Qid, iounit uint32, err error) { - tmsg := &lib9p.TOpen{tag: tag, fid: fid, mode: mode} + tmsg := &lib9p.TOpen{Tag: tag, Fid: fid, Mode: mode} rmsg, err := c.transact(ctx, tmsg) if err != nil { return lib9p.Qid{}, 0, fmt.Errorf("transact: %v", err) } switch rmsg := rmsg.(type) { case *lib9p.ROpen: - return rmsg.qid, rmsg.iounit, nil + return rmsg.Qid, rmsg.Iounit, nil case *lib9p.RError: - return lib9p.Qid{}, 0, rmsg.ename + return lib9p.Qid{}, 0, rmsg.Ename default: return lib9p.Qid{}, 0, fmt.Errorf("invalid reply: %v", rmsg) } } func (c *Client) Create(ctx context.Context, tag uint16, fid uint32, name string, perm lib9p.FileMode, mode lib9p.OpenMode) (lib9p.Qid, uint32, error) { - tmsg := &lib9p.TCreate{tag: tag, fid: fid, name: name, perm: perm, mode: mode} + tmsg := &lib9p.TCreate{Tag: tag, Fid: fid, Name: name, Perm: perm, Mode: mode} rmsg, err := c.transact(ctx, tmsg) if err != nil { return lib9p.Qid{}, 0, fmt.Errorf("transact: %v", err) } switch rmsg := rmsg.(type) { case *lib9p.RCreate: - return rmsg.qid, rmsg.iounit, nil + return rmsg.Qid, rmsg.Iounit, nil case *lib9p.RError: - return lib9p.Qid{}, 0, rmsg.ename + return lib9p.Qid{}, 0, rmsg.Ename default: return lib9p.Qid{}, 0, fmt.Errorf("invalid reply: %v", rmsg) } } func (c *Client) Read(ctx context.Context, tag uint16, fid uint32, offset uint64, count uint32) (data []byte, err error) { - tmsg := &lib9p.TRead{tag: tag, fid: fid, offset: offset, count: count} + tmsg := &lib9p.TRead{Tag: tag, Fid: fid, Offset: offset, Count: count} rmsg, err := c.transact(ctx, tmsg) if err != nil { return nil, fmt.Errorf("transact: %v", err) } switch rmsg := rmsg.(type) { case *lib9p.RRead: - return rmsg.data, nil + return rmsg.Data, nil case *lib9p.RError: - return nil, rmsg.ename + return nil, rmsg.Ename default: return nil, fmt.Errorf("invalid reply: %v", rmsg) } } func (c *Client) Write(ctx context.Context, tag uint16, fid uint32, offset uint64, count uint32, data []byte) (uint32, error) { - tmsg := &lib9p.TWrite{tag: tag, fid: fid, offset: offset, count: count, data: data} + tmsg := &lib9p.TWrite{Tag: tag, Fid: fid, Offset: offset, Count: count, Data: data} rmsg, err := c.transact(ctx, tmsg) if err != nil { return 0, fmt.Errorf("transact: %v", err) } switch rmsg := rmsg.(type) { case *lib9p.RWrite: - return rmsg.count, nil + return rmsg.Count, nil case *lib9p.RError: - return 0, rmsg.ename + return 0, rmsg.Ename default: return 0, fmt.Errorf("invalid reply: %v", rmsg) } } func (c *Client) Clunk(ctx context.Context, tag uint16, fid uint32) error { - tmsg := &lib9p.TClunk{tag: tag, fid: fid} + tmsg := &lib9p.TClunk{Tag: tag, Fid: fid} rmsg, err := c.transact(ctx, tmsg) if err != nil { return fmt.Errorf("transact: %v", err) @@ -403,13 +403,13 @@ func (c *Client) Clunk(ctx context.Context, tag uint16, fid uint32) error { case *lib9p.RClunk: return nil case *lib9p.RError: - return rmsg.ename + return rmsg.Ename default: return fmt.Errorf("invalid reply: %v", rmsg) } } func (c *Client) Remove(ctx context.Context, tag uint16, fid uint32) error { - tmsg := &lib9p.TRemove{tag: tag, fid: fid} + tmsg := &lib9p.TRemove{Tag: tag, Fid: fid} rmsg, err := c.transact(ctx, tmsg) if err != nil { return fmt.Errorf("transact: %v", err) @@ -418,37 +418,37 @@ func (c *Client) Remove(ctx context.Context, tag uint16, fid uint32) error { case *lib9p.RRemove: return nil case *lib9p.RError: - return rmsg.ename + return rmsg.Ename default: return fmt.Errorf("invalid reply: %v", rmsg) } } func (c *Client) Stat(ctx context.Context, tag uint16, fid uint32) (*lib9p.Stat, error) { - tmsg := &lib9p.Tlib9p.Stat{tag: tag, fid: fid} + tmsg := &lib9p.TStat{Tag: tag, Fid: fid} rmsg, err := c.transact(ctx, tmsg) if err != nil { return nil, fmt.Errorf("transact: %v", err) } switch rmsg := rmsg.(type) { - case *lib9p.Rlib9p.Stat: - return rmsg.stat, nil + case *lib9p.RStat: + return rmsg.Stat, nil case *lib9p.RError: - return nil, rmsg.ename + return nil, rmsg.Ename default: return nil, fmt.Errorf("invalid reply: %v", rmsg) } } func (c *Client) Wstat(ctx context.Context, tag uint16, fid uint32, stat *lib9p.Stat) error { - tmsg := &lib9p.TWlib9p.Stat{tag: tag, fid: fid, stat: stat} + tmsg := &lib9p.TWStat{Tag: tag, Fid: fid, Stat: stat} rmsg, err := c.transact(ctx, tmsg) if err != nil { return fmt.Errorf("transact: %v", err) } switch rmsg := rmsg.(type) { - case *lib9p.RWlib9p.Stat: + case *lib9p.RWStat: return nil case *lib9p.RError: - return rmsg.ename + return rmsg.Ename default: return fmt.Errorf("invalid reply: %v", rmsg) } diff --git a/client/file.go b/client/file.go @@ -28,7 +28,7 @@ func (cf *ClientFile) Stat() (*lib9p.FileInfo, error) { if err != nil { return nil, err } - return &FileInfo{*st}, nil + return &lib9p.FileInfo{*st}, nil } // Don't use closed file. @@ -51,8 +51,8 @@ func (cf *ClientFile) Read(b []byte) (int, error) { if cf.fid.omode == -1 { return 0, fmt.Errorf("not open") } - if cf.fid.omode&3 != OREAD && cf.fid.omode&3 != ORDWR { - return 0, ErrPerm + if cf.fid.omode&3 != lib9p.OREAD && cf.fid.omode&3 != lib9p.ORDWR { + return 0, lib9p.ErrPerm } count := uint32(len(b)) cur := 0 diff --git a/client/fs.go b/client/fs.go @@ -19,14 +19,14 @@ type ClientFS struct { // Open opens the file named name in fsys. func (fsys *ClientFS) Open(name string) (lib9p.File, error) { - return fsys.OpenFile(name, OREAD, 0) + return fsys.OpenFile(name, lib9p.OREAD, 0) } // OpenFile opens the file named name in fsys with omode. // If the file does not exist, it create it with perm. func (fsys *ClientFS) OpenFile(name string, omode lib9p.OpenMode, perm fs.FileMode) (lib9p.File, error) { var ( - qid Qid + qid lib9p.Qid iounit uint32 ) f, err := fsys.walkFile(name) @@ -86,9 +86,9 @@ func (fsys *ClientFS) walkFile(name string) (*ClientFile, error) { if err != nil { return nil, fmt.Errorf("walk: %v", err) } - var qid Qid + var qid lib9p.Qid if name == "." { - qid = Qid{} + qid = lib9p.Qid{} } else if len(wqid) > 0 { qid = wqid[len(wqid)-1] } else { @@ -122,7 +122,7 @@ func Mount(r io.Reader, w io.Writer, uname, aname string) (fs *ClientFS, err err cfs.c.Stop() } }() - rmSize, rver, err := cfs.c.Version(ctx, NOTAG, mSize, version) + rmSize, rver, err := cfs.c.Version(ctx, lib9p.NOTAG, mSize, version) if err != nil { return nil, fmt.Errorf("version: %v", err) } @@ -141,7 +141,7 @@ func Mount(r io.Reader, w io.Writer, uname, aname string) (fs *ClientFS, err err if err != nil { return nil, err } - _, err = cfs.c.Attach(ctx, tag, fid.fid, NOFID, uname, aname) + _, err = cfs.c.Attach(ctx, tag, fid.fid, lib9p.NOFID, uname, aname) cfs.tPool.delete(tag) if err != nil { return nil, fmt.Errorf("attach: %v", err) diff --git a/client/req.go b/client/req.go @@ -24,7 +24,7 @@ type clientReq struct { // it only needs the done channel. func newClientReq(ctx context.Context, msg lib9p.Msg) *clientReq { return &clientReq{ - tag: msg.Tag(), + tag: msg.GetTag(), tmsg: msg, rxc: make(chan *clientReq), ctxDone: ctx.Done(), @@ -47,15 +47,15 @@ func newTagPool() *tagPool { func (tp *tagPool) add() (uint16, error) { tp.lock.Lock() defer tp.lock.Unlock() - tag := NOTAG + tag := lib9p.NOTAG for i := uint16(0); i < i+1; i++ { if _, ok := tp.m[i]; !ok { tag = i break } } - if tag == NOTAG { - return NOTAG, fmt.Errorf("run out of tag") + if tag == lib9p.NOTAG { + return lib9p.NOTAG, fmt.Errorf("run out of tag") } tp.m[tag] = true return tag, nil