commit e634e721d9c36d833791880f538111ab95f8f6ab
parent 8434a9645adcf7db17aecfc4299818c13ffaef55
Author: Matsuda Kenji <info@mtkn.jp>
Date: Fri, 29 Dec 2023 09:05:28 +0900
unexport Req.Fid, Req.Afid, Req.Oldreq
Diffstat:
5 files changed, 80 insertions(+), 79 deletions(-)
diff --git a/auth_test.go b/auth_test.go
@@ -21,7 +21,7 @@ func TestAuth(t *testing.T) {
conn.S.Auth = func(ctx context.Context, r *lib9p.Req) {
ifcall := r.Ifcall().(*lib9p.TAuth)
aqid := lib9p.Qid{Type: lib9p.QTAUTH, Vers: 0, Path: ^uint64(0)}
- r.Afid.File = &lib9p.AuthFile{
+ r.Afid().File = &lib9p.AuthFile{
Qid: aqid,
Uname: ifcall.Uname,
Aname: ifcall.Aname,
@@ -33,7 +33,7 @@ func TestAuth(t *testing.T) {
asr.Close()
asw.Close()
}()
- runAuth(ctx, t, r.Afid.File.(*lib9p.AuthFile), asr, asw)
+ runAuth(ctx, t, r.Afid().File.(*lib9p.AuthFile), asr, asw)
r.SetOfcall(&lib9p.RAuth{Tag: ifcall.Tag, Aqid: aqid})
}
ctx := context.Background()
diff --git a/export_test.go b/export_test.go
@@ -61,6 +61,7 @@ func (r *Req) Ifcall() Msg { return r.ifcall }
func (r *Req) SetIfcall(m Msg) { r.ifcall = m }
func (r *Req) Ofcall() Msg { return r.ofcall }
func (r *Req) SetOfcall(m Msg) { r.ofcall = m }
+func (r *Req) Afid() *Fid { return r.afid }
func (rp *ReqPool) Add(tag uint16) (*Req, error) { return rp.add(tag) }
diff --git a/req.go b/req.go
@@ -11,10 +11,10 @@ type Req struct {
ifcall Msg
// Ofcall is response message to Ifcall.
ofcall Msg
- Fid *Fid
- Afid *Fid
+ fid *Fid
+ afid *Fid
// Oldreq is set with Tflush message.
- Oldreq *Req
+ oldreq *Req
// Pool is the pool this request belongs to.
pool *ReqPool
// Done is used by time consuming goroutines to check whether the request
diff --git a/server.go b/server.go
@@ -183,7 +183,7 @@ func getReq(r io.Reader, rp *ReqPool, chatty bool) *Req {
req.ifcall = ifcall
req.done = make(chan struct{})
if ifcall, ok := req.ifcall.(*TFlush); ok {
- req.Oldreq, _ = rp.lookup(ifcall.Oldtag)
+ req.oldreq, _ = rp.lookup(ifcall.Oldtag)
}
if chatty {
fmt.Fprintf(os.Stderr, "<-- %v\n", req.ifcall)
@@ -263,7 +263,7 @@ func sAuth(ctx context.Context, s *Server, c <-chan *Req) {
}
continue
}
- r.Afid, err = s.fPool.add(ifcall.Afid)
+ r.afid, err = s.fPool.add(ifcall.Afid)
if err != nil {
setError(r, ErrDupFid)
select {
@@ -293,7 +293,7 @@ func sAttach(ctx context.Context, s *Server, c <-chan *Req) {
return
}
ifcall := r.ifcall.(*TAttach)
- r.Fid, err = s.fPool.add(ifcall.Fid)
+ r.fid, err = s.fPool.add(ifcall.Fid)
if err != nil {
r.err = ErrDupFid
goto resp
@@ -322,9 +322,9 @@ func sAttach(ctx context.Context, s *Server, c <-chan *Req) {
goto resp
}
}
- r.Fid.OMode = -1
- r.Fid.path = "."
- r.Fid.Uid = ifcall.Uname
+ r.fid.OMode = -1
+ r.fid.path = "."
+ r.fid.Uid = ifcall.Uname
st, err = fs.Stat(ExportFS{s.fs}, ".")
if err != nil {
r.err = fmt.Errorf("stat root: %v", err)
@@ -335,8 +335,8 @@ func sAttach(ctx context.Context, s *Server, c <-chan *Req) {
}
resp:
if r.err != nil {
- if r.Fid != nil {
- s.fPool.delete(r.Fid.Fid)
+ if r.fid != nil {
+ s.fPool.delete(r.fid.Fid)
}
setError(r, r.err)
}
@@ -358,8 +358,8 @@ func sFlush(ctx context.Context, s *Server, c <-chan *Req) {
if !ok {
return
}
- if r.Oldreq != nil {
- r.Oldreq.flush()
+ if r.oldreq != nil {
+ r.oldreq.flush()
}
r.ofcall = &RFlush{}
select {
@@ -480,19 +480,19 @@ func sOpen(ctx context.Context, s *Server, c <-chan *Req) {
st fs.FileInfo
)
ifcall := r.ifcall.(*TOpen)
- r.Fid, ok = s.fPool.lookup(ifcall.Fid)
+ r.fid, ok = s.fPool.lookup(ifcall.Fid)
if !ok {
r.err = ErrUnknownFid
goto resp
}
- if r.Fid.OMode != -1 {
+ if r.fid.OMode != -1 {
r.err = ErrBotch
goto resp
}
- if afile, ok := r.Fid.File.(*AuthFile); ok {
- // s.Auth should set r.Fid.File to a valid *AuthFile,
- // so r.Fid.File should not be nil.
- st, err = r.Fid.File.Stat()
+ if afile, ok := r.fid.File.(*AuthFile); ok {
+ // s.Auth should set r.fid.File to a valid *AuthFile,
+ // so r.fid.File should not be nil.
+ st, err = r.fid.File.Stat()
if err != nil {
r.err = fmt.Errorf("stat: %v", err)
goto resp
@@ -503,7 +503,7 @@ func sOpen(ctx context.Context, s *Server, c <-chan *Req) {
// See open(5).
// In plan9 implementation, ifcall.Mode() is ANDed with ^ORCLOSE,
// but ORCLOSE is also prohibitted by the protocol...
- st, err = fs.Stat(ExportFS{s.fs}, r.Fid.path)
+ st, err = fs.Stat(ExportFS{s.fs}, r.fid.path)
if err != nil {
r.err = fmt.Errorf("stat: %v", err)
goto resp
@@ -533,18 +533,18 @@ func sOpen(ctx context.Context, s *Server, c <-chan *Req) {
r.err = ErrPerm
goto resp
}
- if !hasPerm(s.fs, st, r.Fid.Uid, p) {
+ if !hasPerm(s.fs, st, r.fid.Uid, p) {
r.err = ErrPerm
goto resp
}
if ifcall.Mode&ORCLOSE != 0 {
- parentPath := path.Dir(r.Fid.path)
+ parentPath := path.Dir(r.fid.path)
st, err := fs.Stat(ExportFS{s.fs}, parentPath)
if err != nil {
r.err = fmt.Errorf("stat parent: %v", err)
goto resp
}
- if !hasPerm(s.fs, st, r.Fid.Uid, AWRITE) {
+ if !hasPerm(s.fs, st, r.fid.Uid, AWRITE) {
r.err = ErrPerm
goto resp
}
@@ -563,8 +563,8 @@ func sOpen(ctx context.Context, s *Server, c <-chan *Req) {
}
continue
}
- r.Fid.OMode = r.ifcall.(*TOpen).Mode
- if _, ok := r.Fid.File.(*AuthFile); ok {
+ r.fid.OMode = r.ifcall.(*TOpen).Mode
+ if _, ok := r.fid.File.(*AuthFile); ok {
select {
case s.respChan <- r:
case <-ctx.Done():
@@ -572,7 +572,7 @@ func sOpen(ctx context.Context, s *Server, c <-chan *Req) {
}
continue
}
- f, err := s.fs.OpenFile(r.Fid.path, r.Fid.OMode)
+ f, err := s.fs.OpenFile(r.fid.path, r.fid.OMode)
if err != nil {
setError(r, err)
select {
@@ -582,7 +582,7 @@ func sOpen(ctx context.Context, s *Server, c <-chan *Req) {
}
continue
}
- r.Fid.File = f
+ r.fid.File = f
select {
case s.respChan <- r:
case <-ctx.Done():
@@ -612,12 +612,12 @@ func sCreate(ctx context.Context, s *Server, c <-chan *Req) {
dirperm FileMode
)
ifcall := r.ifcall.(*TCreate)
- r.Fid, ok = s.fPool.lookup(ifcall.Fid)
+ r.fid, ok = s.fPool.lookup(ifcall.Fid)
if !ok {
r.err = ErrUnknownFid
goto resp
}
- dirstat, err = fs.Stat(ExportFS{s.fs}, r.Fid.path)
+ dirstat, err = fs.Stat(ExportFS{s.fs}, r.fid.path)
if err != nil {
r.err = fmt.Errorf("stat: %v", err)
goto resp
@@ -626,7 +626,7 @@ func sCreate(ctx context.Context, s *Server, c <-chan *Req) {
r.err = fmt.Errorf("create in non-dir")
goto resp
}
- if !hasPerm(s.fs, dirstat, r.Fid.Uid, AWRITE) {
+ if !hasPerm(s.fs, dirstat, r.fid.Uid, AWRITE) {
r.err = ErrPerm
goto resp
}
@@ -642,16 +642,16 @@ func sCreate(ctx context.Context, s *Server, c <-chan *Req) {
} else {
perm &= ^FileMode(0777) | (dirperm & FileMode(0777))
}
- cpath = path.Join(r.Fid.path, ifcall.Name)
- file, err = cfs.Create(cpath, r.Fid.Uid, ifcall.Mode, perm)
+ cpath = path.Join(r.fid.path, ifcall.Name)
+ file, err = cfs.Create(cpath, r.fid.Uid, ifcall.Mode, perm)
if err != nil {
r.err = fmt.Errorf("create: %v", err)
goto resp
}
- r.Fid.File = file
- r.Fid.path = cpath
- r.Fid.OMode = ifcall.Mode
- st, err = r.Fid.File.Stat()
+ r.fid.File = file
+ r.fid.path = cpath
+ r.fid.OMode = ifcall.Mode
+ st, err = r.fid.File.Stat()
if err != nil {
r.err = fmt.Errorf("stat: %v", err)
goto resp
@@ -692,20 +692,20 @@ func sRead(ctx context.Context, s *Server, c <-chan *Req) {
return
}
ifcall := r.ifcall.(*TRead)
- r.Fid, ok = s.fPool.lookup(ifcall.Fid)
+ r.fid, ok = s.fPool.lookup(ifcall.Fid)
if !ok {
r.err = ErrUnknownFid
goto resp
}
- if r.Fid.OMode == -1 {
+ if r.fid.OMode == -1 {
r.err = fmt.Errorf("not open")
goto resp
}
- if r.Fid.OMode != OREAD && r.Fid.OMode != ORDWR && r.Fid.OMode != OEXEC {
+ if r.fid.OMode != OREAD && r.fid.OMode != ORDWR && r.fid.OMode != OEXEC {
r.err = ErrPerm
goto resp
}
- fi, err = r.Fid.File.Stat()
+ fi, err = r.fid.File.Stat()
if err != nil {
r.err = fmt.Errorf("stat: %v", err)
goto resp
@@ -715,20 +715,20 @@ func sRead(ctx context.Context, s *Server, c <-chan *Req) {
go func() {
defer close(errc)
if fi.IsDir() {
- if ifcall.Offset != 0 && ifcall.Offset != r.Fid.dirOffset {
+ if ifcall.Offset != 0 && ifcall.Offset != r.fid.dirOffset {
errc <- fmt.Errorf("invalid dir offset")
return
}
- children, err := fs.Glob(ExportFS{s.fs}, path.Join(r.Fid.path, "*"))
+ children, err := fs.Glob(ExportFS{s.fs}, path.Join(r.fid.path, "*"))
if err != nil {
errc <- fmt.Errorf("glob children: %v", err)
return
}
if ifcall.Offset == 0 {
- r.Fid.dirIndex = 0
- r.Fid.dirOffset = 0
+ r.fid.dirIndex = 0
+ r.fid.dirOffset = 0
}
- k := r.Fid.dirIndex
+ k := r.fid.dirIndex
for ; k < len(children); k++ {
fi, err := fs.Stat(ExportFS{s.fs}, children[k])
if err != nil {
@@ -745,14 +745,14 @@ func sRead(ctx context.Context, s *Server, c <-chan *Req) {
}
n += len(buf)
}
- r.Fid.dirOffset += uint64(n)
- r.Fid.dirIndex = k
+ r.fid.dirOffset += uint64(n)
+ r.fid.dirIndex = k
} else {
var err error
- if reader, ok := r.Fid.File.(io.ReaderAt); ok {
+ if reader, ok := r.fid.File.(io.ReaderAt); ok {
n, err = reader.ReadAt(data, int64(ifcall.Offset))
} else {
- n, err = r.Fid.File.Read(data)
+ n, err = r.fid.File.Read(data)
}
if err != io.EOF && err != nil {
errc <- err
@@ -804,7 +804,7 @@ func sWrite(ctx context.Context, s *Server, c <-chan *Req) {
omode OpenMode
)
ifcall := r.ifcall.(*TWrite)
- r.Fid, ok = s.fPool.lookup(ifcall.Fid)
+ r.fid, ok = s.fPool.lookup(ifcall.Fid)
if !ok {
r.err = ErrUnknownFid
goto resp
@@ -812,16 +812,16 @@ func sWrite(ctx context.Context, s *Server, c <-chan *Req) {
if ifcall.Count > s.mSize()-IOHDRSZ {
ifcall.Count = s.mSize() - IOHDRSZ
}
- omode = r.Fid.OMode & 3
+ omode = r.fid.OMode & 3
if omode != OWRITE && omode != ORDWR {
- r.err = fmt.Errorf("write on fid with open mode 0x%x", r.Fid.OMode)
+ r.err = fmt.Errorf("write on fid with open mode 0x%x", r.fid.OMode)
goto resp
}
ofcall = new(RWrite)
errc = make(chan error)
go func() {
defer close(errc)
- switch file := r.Fid.File.(type) {
+ switch file := r.fid.File.(type) {
case io.WriterAt:
n, err := file.WriteAt(ifcall.Data, int64(ifcall.Offset))
if err != nil {
@@ -919,22 +919,22 @@ func sRemove(ctx context.Context, s *Server, c <-chan *Req) {
rfs RemoverFS
)
ifcall := r.ifcall.(*TRemove)
- r.Fid, ok = s.fPool.lookup(ifcall.Fid)
+ r.fid, ok = s.fPool.lookup(ifcall.Fid)
if !ok {
r.err = ErrUnknownFid
goto resp
}
s.fPool.delete(ifcall.Fid)
- if r.Fid.OMode != -1 {
- r.Fid.File.Close()
+ if r.fid.OMode != -1 {
+ r.fid.File.Close()
}
- parentPath = path.Dir(r.Fid.path)
+ parentPath = path.Dir(r.fid.path)
pstat, err = fs.Stat(ExportFS{s.fs}, parentPath)
if err != nil {
r.err = fmt.Errorf("stat parent: %v", err)
goto resp
}
- if !hasPerm(s.fs, pstat, r.Fid.Uid, AWRITE) {
+ if !hasPerm(s.fs, pstat, r.fid.Uid, AWRITE) {
r.err = ErrPerm
goto resp
}
@@ -943,7 +943,7 @@ func sRemove(ctx context.Context, s *Server, c <-chan *Req) {
r.err = ErrOperation
goto resp
}
- if err = rfs.Remove(r.Fid.path); err != nil {
+ if err = rfs.Remove(r.fid.path); err != nil {
r.err = fmt.Errorf("remove: %v", err)
goto resp
}
@@ -975,12 +975,12 @@ func sStat(ctx context.Context, s *Server, c <-chan *Req) {
err error
)
ifcall := r.ifcall.(*TStat)
- r.Fid, ok = s.fPool.lookup(ifcall.Fid)
+ r.fid, ok = s.fPool.lookup(ifcall.Fid)
if !ok {
r.err = ErrUnknownFid
goto resp
}
- fi, err = fs.Stat(ExportFS{s.fs}, r.Fid.path)
+ fi, err = fs.Stat(ExportFS{s.fs}, r.fid.path)
if err != nil {
r.err = fmt.Errorf("stat: %v", err)
goto resp
@@ -1018,27 +1018,27 @@ func sWStat(ctx context.Context, s *Server, c <-chan *Req) {
err error
)
ifcall := r.ifcall.(*TWStat)
- r.Fid, ok = s.fPool.lookup(ifcall.Fid)
+ r.fid, ok = s.fPool.lookup(ifcall.Fid)
if !ok {
r.err = ErrUnknownFid
goto resp
}
- if r.Fid.OMode == -1 {
+ if r.fid.OMode == -1 {
var err error
- r.Fid.File, err = s.fs.OpenFile(r.Fid.path, OREAD)
+ r.fid.File, err = s.fs.OpenFile(r.fid.path, OREAD)
if err != nil {
r.err = fmt.Errorf("open: %v", err)
goto resp
}
- defer r.Fid.File.Close()
+ defer r.fid.File.Close()
}
- wsfile, ok = r.Fid.File.(WriterStatFile)
+ wsfile, ok = r.fid.File.(WriterStatFile)
if !ok {
r.err = ErrOperation
goto resp
}
wstat = ifcall.Stat
- fi, err = r.Fid.File.Stat()
+ fi, err = r.fid.File.Stat()
if err != nil {
r.err = fmt.Errorf("stat: %v", err)
goto resp
@@ -1056,13 +1056,13 @@ func sWStat(ctx context.Context, s *Server, c <-chan *Req) {
goto resp
}
if wstat.Name != "" && newStat.Name != wstat.Name {
- parentPath := path.Dir(r.Fid.path)
+ parentPath := path.Dir(r.fid.path)
pstat, err := fs.Stat(ExportFS{s.fs}, parentPath)
if err != nil {
r.err = fmt.Errorf("stat parent: %v", err)
goto resp
}
- if !hasPerm(s.fs, pstat, r.Fid.Uid, AWRITE) {
+ if !hasPerm(s.fs, pstat, r.fid.Uid, AWRITE) {
r.err = ErrPerm
goto resp
}
@@ -1087,7 +1087,7 @@ func sWStat(ctx context.Context, s *Server, c <-chan *Req) {
newStat.Name = wstat.Name
}
if wstat.Length != ^int64(0) && wstat.Length != newStat.Length {
- if fi.IsDir() || !hasPerm(s.fs, fi, r.Fid.Uid, AWRITE) {
+ if fi.IsDir() || !hasPerm(s.fs, fi, r.fid.Uid, AWRITE) {
r.err = ErrPerm
goto resp
}
@@ -1095,7 +1095,7 @@ func sWStat(ctx context.Context, s *Server, c <-chan *Req) {
}
if wstat.Mode != FileMode(^uint32(0)) && wstat.Mode != newStat.Mode {
// the owner of the file or the group leader of the file's group.
- if r.Fid.Uid != newStat.Uid && r.Fid.Uid != newStat.Gid {
+ if r.fid.Uid != newStat.Uid && r.fid.Uid != newStat.Gid {
r.err = ErrPerm
goto resp
}
@@ -1107,7 +1107,7 @@ func sWStat(ctx context.Context, s *Server, c <-chan *Req) {
}
if wstat.Mtime != ^uint32(0) && wstat.Mtime != newStat.Mtime {
// the owner of the file or the group leader of the file's group.
- if r.Fid.Uid != newStat.Uid && r.Fid.Uid != newStat.Gid {
+ if r.fid.Uid != newStat.Uid && r.fid.Uid != newStat.Gid {
r.err = ErrPerm
goto resp
}
@@ -1117,9 +1117,9 @@ func sWStat(ctx context.Context, s *Server, c <-chan *Req) {
// by the owner if also a member of the new group;
// or by the group leader of the file's current group if
// also the leader of the new group.
- if r.Fid.Uid == newStat.Uid && s.fs.IsGroupMember(wstat.Gid, r.Fid.Uid) ||
- s.fs.IsGroupLeader(newStat.Gid, r.Fid.Uid) &&
- s.fs.IsGroupLeader(wstat.Gid, r.Fid.Uid) {
+ if r.fid.Uid == newStat.Uid && s.fs.IsGroupMember(wstat.Gid, r.fid.Uid) ||
+ s.fs.IsGroupLeader(newStat.Gid, r.fid.Uid) &&
+ s.fs.IsGroupLeader(wstat.Gid, r.fid.Uid) {
newStat.Gid = wstat.Gid
} else {
r.err = ErrPerm
diff --git a/server2_test.go b/server2_test.go
@@ -233,7 +233,7 @@ func TestSFlush(t *testing.T) {
input *Req
}{
{&Req{ifcall: &TFlush{},
- Oldreq: &Req{pool: rp, done: make(chan struct{})}}},
+ oldreq: &Req{pool: rp, done: make(chan struct{})}}},
}
tc := make(chan *Req)
rc := make(chan *Req)
@@ -246,7 +246,7 @@ func TestSFlush(t *testing.T) {
if gotmsg, ok := (<-rc).ofcall.(*RFlush); !ok {
t.Errorf("unexpected message: %v", gotmsg)
}
- if _, ok := <-test.input.Oldreq.done; ok {
+ if _, ok := <-test.input.oldreq.done; ok {
t.Errorf("done channel not closed")
}
}