lib9p

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

commit b892d5497da09471cd1c2c53a238472ef63d77f2
parent 319ffd2f3612b0d89d4cc75add8c35b0b85063fc
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Fri,  5 Jan 2024 09:32:55 +0900

change TWStat to TWstat, RWStat to RWstat

Diffstat:
Mfcall.go | 40++++++++++++++++++++--------------------
Mparse.go | 4++--
Mserver.go | 6+++---
Mserver_test.go | 68++++++++++++++++++++++++++++++++++----------------------------------
4 files changed, 59 insertions(+), 59 deletions(-)

diff --git a/fcall.go b/fcall.go @@ -138,9 +138,9 @@ func (msg bufMsg) String() string { case Rstat: return newRStat(msg).String() case Twstat: - return newTWStat(msg).String() + return newTWstat(msg).String() case Rwstat: - return newRWStat(msg).String() + return newRWstat(msg).String() default: return fmt.Sprint([]byte(msg[:msg.Size()])) } @@ -1286,26 +1286,26 @@ func (msg *RStat) String() string { return fmt.Sprintf("Rstat Tag %d stat %s", msg.Tag, msg.Stat) } -type TWStat struct { +type TWstat struct { Tag uint16 Fid uint32 Stat *Stat } -func newTWStat(buf []byte) *TWStat { - msg := new(TWStat) +func newTWstat(buf []byte) *TWstat { + msg := new(TWstat) msg.Tag = gbit16(buf[5:7]) msg.Fid = gbit32(buf[7:11]) msg.Stat = NewStat(buf[13:]) return msg } -func (msg *TWStat) Size() uint32 { +func (msg *TWstat) Size() uint32 { return uint32(4 + 1 + 2 + 4 + 2 + 2 + msg.Stat.Size()) } -func (msg *TWStat) Type() MsgType { return Twstat } -func (msg *TWStat) GetTag() uint16 { return msg.Tag } -func (msg *TWStat) SetTag(t uint16) { msg.Tag = t } -func (msg *TWStat) marshal() []byte { +func (msg *TWstat) Type() MsgType { return Twstat } +func (msg *TWstat) GetTag() uint16 { return msg.Tag } +func (msg *TWstat) SetTag(t uint16) { msg.Tag = t } +func (msg *TWstat) marshal() []byte { buf := make([]byte, msg.Size()) pbit32(buf[0:4], msg.Size()) buf[4] = uint8(msg.Type()) @@ -1319,30 +1319,30 @@ func (msg *TWStat) marshal() []byte { return buf } -func (msg *TWStat) String() string { +func (msg *TWstat) String() string { return fmt.Sprintf("Twstat Tag %d fid %d stat %s", msg.Tag, msg.Fid, msg.Stat) } -type RWStat struct { +type RWstat struct { Tag uint16 } -func newRWStat(buf []byte) *RWStat { - msg := new(RWStat) +func newRWstat(buf []byte) *RWstat { + msg := new(RWstat) msg.Tag = gbit16(buf[5:7]) return msg } -func (msg *RWStat) Size() uint32 { return 4 + 1 + 2 } -func (msg *RWStat) Type() MsgType { return Rwstat } -func (msg *RWStat) GetTag() uint16 { return msg.Tag } -func (msg *RWStat) SetTag(t uint16) { msg.Tag = t } -func (msg *RWStat) marshal() []byte { +func (msg *RWstat) Size() uint32 { return 4 + 1 + 2 } +func (msg *RWstat) Type() MsgType { return Rwstat } +func (msg *RWstat) GetTag() uint16 { return msg.Tag } +func (msg *RWstat) SetTag(t uint16) { msg.Tag = t } +func (msg *RWstat) marshal() []byte { m := make([]byte, msg.Size()) pbit32(m[0:4], msg.Size()) m[4] = uint8(msg.Type()) pbit16(m[5:7], msg.Tag) return m } -func (msg *RWStat) String() string { +func (msg *RWstat) String() string { return fmt.Sprintf("Rwstat Tag %d", msg.Tag) } diff --git a/parse.go b/parse.go @@ -91,9 +91,9 @@ func unmarshal(buf []byte) (Msg, error) { case Rstat: return newRStat(buf), nil case Twstat: - return newTWStat(buf), nil + return newTWstat(buf), nil case Rwstat: - return newRWStat(buf), nil + return newRWstat(buf), nil default: return nil, fmt.Errorf("unknown message type %v", t) } diff --git a/server.go b/server.go @@ -1024,7 +1024,7 @@ func sWStat(ctx context.Context, c *conn, rc <-chan *request) { fi fs.FileInfo err error ) - ifcall := r.ifcall.(*TWStat) + ifcall := r.ifcall.(*TWstat) r.fid, ok = c.fPool.lookup(ifcall.Fid) if !ok { r.err = ErrUnknownFid @@ -1139,7 +1139,7 @@ func sWStat(ctx context.Context, c *conn, rc <-chan *request) { r.err = fmt.Errorf("wstat: %v", err) goto resp } - r.ofcall = &RWStat{} + r.ofcall = &RWstat{} // TODO: update r.fid.path resp: if r.err != nil { @@ -1258,7 +1258,7 @@ L: removeChan <- r case *TStat: statChan <- r - case *TWStat: + case *TWstat: wstatChan <- r } } diff --git a/server_test.go b/server_test.go @@ -789,131 +789,131 @@ func TestSWstat(t *testing.T) { path string uid string stat *Stat - ifcall *TWStat + ifcall *TWstat want Msg }{ // 0 ok: rename by owner of the directory. {0, "./d/unko", "glenda", &Stat{Name: "unko"}, - &TWStat{ + &TWstat{ Fid: 0, Stat: &Stat{Name: "oppai"}, - }, &RWStat{}}, + }, &RWstat{}}, // 1 ok: rename by group member of the directory. {0, "./d/unko", "ken", &Stat{Name: "unko"}, - &TWStat{ + &TWstat{ Fid: 0, Stat: &Stat{Name: "oppai"}, - }, &RWStat{}}, + }, &RWstat{}}, // 2 permission denied: rename by other. {0, "./d/unko", "kenji", &Stat{Name: "unko"}, - &TWStat{ + &TWstat{ Fid: 0, Stat: &Stat{Name: "oppai"}, }, &RError{Ename: ErrPerm}}, // 3 ok: length change by owner with write permission {0, "unko", "glenda", &Stat{Uid: "glenda", Mode: 0700, Length: 10}, - &TWStat{ + &TWstat{ Fid: 0, Stat: &Stat{Uid: "glenda", Mode: 0700, Length: 20}, - }, &RWStat{}}, + }, &RWstat{}}, // 4 permission denied: length change by owner without write permission {0, "unko", "glenda", &Stat{Uid: "glenda", Mode: 0000, Length: 10}, - &TWStat{ + &TWstat{ Fid: 0, Stat: &Stat{Uid: "glenda", Mode: 0700, Length: 20}, }, &RError{Ename: ErrPerm}}, // 5 operation not permitted: length change of a directory to other than 0 {0, "unko", "glenda", &Stat{Uid: "glenda", Mode: fs.ModeDir | 0700, Length: 10}, - &TWStat{ + &TWstat{ Fid: 0, Stat: &Stat{Uid: "glenda", Mode: fs.ModeDir | 0700, Length: 20}, }, &RError{}}, /* // TODO: change directory length to 0. {0, "unko", "glenda", &Stat{Uid: "glenda", Mode: fs.ModeDir | 0700, Length: 10}, - &TWStat{ + &TWstat{ Fid: 0, Stat: &Stat{Uid: "glenda", Mode: fs.ModeDir | 0700, Length:0}, - }, &RWStat{}}, + }, &RWstat{}}, */ // 6 ok: change mode by owner {0, "unko", "glenda", &Stat{Uid: "glenda", Mode: fs.ModeDir | 0700}, - &TWStat{ + &TWstat{ Fid: 0, Stat: &Stat{Uid: "glenda", Mode: fs.ModeDir | 0755}, - }, &RWStat{}}, + }, &RWstat{}}, // 7 ok: change mode by the leader {0, "unko", "glenda", &Stat{Gid: "bell", Mode: fs.ModeDir | 0700}, - &TWStat{ + &TWstat{ Fid: 0, Stat: &Stat{Gid: "glenda", Mode: fs.ModeDir | 0755}, - }, &RWStat{}}, + }, &RWstat{}}, // 8 permission denied: change mode by a non-leader member {0, "unko", "ken", &Stat{Gid: "bell", Mode: fs.ModeDir | 0700}, - &TWStat{ + &TWstat{ Fid: 0, Stat: &Stat{Gid: "glenda", Mode: fs.ModeDir | 0755}, }, &RError{}}, // 9 ok: change mtime by owner {0, "unko", "glenda", &Stat{Uid: "glenda", Mtime: 1}, - &TWStat{ + &TWstat{ Fid: 0, Stat: &Stat{Uid: "glenda", Mtime: 0}, - }, &RWStat{}}, + }, &RWstat{}}, // 10 ok: change mtime by the leader {0, "unko", "glenda", &Stat{Gid: "bell", Mtime: 1}, - &TWStat{ + &TWstat{ Fid: 0, Stat: &Stat{Gid: "bell", Mtime: 0}, - }, &RWStat{}}, + }, &RWstat{}}, // 11 permission denied: change mtime by a non-leader member {0, "unko", "ken", &Stat{Gid: "bell", Mtime: 0}, - &TWStat{ + &TWstat{ Fid: 0, Stat: &Stat{Gid: "bel", Mtime: 1}, }, &RError{}}, // 12 operation not permitted: change directory bit. {0, "unko", "glenda", &Stat{Uid: "glenda", Mode: fs.ModeDir}, - &TWStat{ + &TWstat{ Fid: 0, Stat: &Stat{Uid: "glenda"}, }, &RError{}}, // 13 ok: change gid by the owner, also a member of new group. {0, "unko", "glenda", &Stat{Uid: "glenda", Gid: "kessoku"}, - &TWStat{ + &TWstat{ Fid: 0, Stat: &Stat{Uid: "glenda", Gid: "bell"}, - }, &RWStat{}}, + }, &RWstat{}}, // 14 ok: change gid by the leader, also the leader of new group. {0, "unko", "glenda", &Stat{Uid: "ken", Gid: "glenda"}, - &TWStat{ + &TWstat{ Fid: 0, Stat: &Stat{Uid: "ken", Gid: "bell"}, - }, &RWStat{}}, + }, &RWstat{}}, // 15 permission denied: change gid by the leader, non-member of new group. {0, "unko", "ken", &Stat{Uid: "glenda", Gid: "ken"}, - &TWStat{ + &TWstat{ Fid: 0, Stat: &Stat{Uid: "glenda", Gid: "kessoku"}, }, &RError{}}, // 16 permission denied: change gid by the owner, non-member of new group. {0, "unko", "ken", &Stat{Uid: "glenda", Gid: "ken"}, - &TWStat{ + &TWstat{ Fid: 0, Stat: &Stat{Uid: "glenda", Gid: "kessoku"}, }, &RError{}}, // 17 operation not permitted: change uid {0, "unko", "ken", &Stat{Uid: "glenda"}, - &TWStat{ + &TWstat{ Fid: 0, Stat: &Stat{Uid: "ken"}, }, &RError{}}, // 18 ok: change mode and gid. {0, "unko", "glenda", &Stat{Gid: "bell", Mode: 0777}, - &TWStat{ + &TWstat{ Fid: 0, Stat: &Stat{Gid: "glenda", Mode: 0755}, - }, &RWStat{}}, + }, &RWstat{}}, } c, tc, rc := setupConn(testfs) ctx, cancel := context.WithCancel(context.Background()) @@ -935,8 +935,8 @@ func TestSWstat(t *testing.T) { tc <- &request{ifcall: test.ifcall} ofcall := (<-rc).ofcall switch ofcall := ofcall.(type) { - case *RWStat: - if _, ok := test.want.(*RWStat); !ok { + case *RWstat: + if _, ok := test.want.(*RWstat); !ok { t.Errorf("%d: unexpected message:\n\twant: %v\n\tgot: %v", i, test.want, ofcall) return