Skip to content
This repository was archived by the owner on Mar 11, 2020. It is now read-only.

Commit e363538

Browse files
committed
lint/vet: address several issues identified by lint/vet
Signed-off-by: Stephen J Day <[email protected]>
1 parent b4b80bd commit e363538

File tree

8 files changed

+40
-6
lines changed

8 files changed

+40
-6
lines changed

Diff for: channel.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ type Channel interface {
3737
SetMSize(msize int)
3838
}
3939

40+
// NewChannel returns a new channel to read and write Fcalls with the provided
41+
// connection and message size.
4042
func NewChannel(conn net.Conn, msize int) Channel {
4143
return newChannel(conn, codec9p{}, msize)
4244
}
@@ -140,7 +142,7 @@ func (ch *channel) ReadFcall(ctx context.Context, fcall *Fcall) error {
140142
if n > len(ch.rdbuf) {
141143
// TODO(stevvooe): Make this error detectable and respond with error
142144
// message.
143-
return fmt.Errorf("message large than buffer:", n)
145+
return fmt.Errorf("message too large for buffer: %v > %v ", n, len(ch.rdbuf))
144146
}
145147

146148
// clear out the fcall

Diff for: dispatcher.go

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Handler interface {
1717
// HandlerFunc is a convenience type for defining inline handlers.
1818
type HandlerFunc func(ctx context.Context, msg Message) (Message, error)
1919

20+
// Handle implements the requirements for the Handler interface.
2021
func (fn HandlerFunc) Handle(ctx context.Context, msg Message) (Message, error) {
2122
return fn(ctx, msg)
2223
}

Diff for: encoding.go

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Codec interface {
2424
Size(v interface{}) int
2525
}
2626

27+
// NewCodec returns a new, standard 9P2000 codec, ready for use.
2728
func NewCodec() Codec {
2829
return codec9p{}
2930
}

Diff for: errors.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ type MessageRerror struct {
1010
Ename string
1111
}
1212

13+
// 9p wire errors returned by Session interface methods
1314
var (
14-
// 9p wire errors returned by Session interface methods
1515
ErrBadattach = new9pError("unknown specifier in attach")
1616
ErrBadoffset = new9pError("bad offset")
1717
ErrBadcount = new9pError("bad count")
@@ -33,6 +33,7 @@ var (
3333
ErrWalknodir = new9pError("walk in non-directory")
3434

3535
// extra errors not part of the normal protocol
36+
3637
ErrTimeout = new9pError("fcall timeout") // returned when timing out on the fcall
3738
ErrUnknownTag = new9pError("unknown tag")
3839
ErrUnknownMsg = new9pError("unknown message") // returned when encountering unknown message type
@@ -46,6 +47,8 @@ func new9pError(s string) error {
4647
return MessageRerror{Ename: s}
4748
}
4849

50+
// Type ensures that 9p errors can be transparently used as a 9p message in an
51+
// Fcall.
4952
func (MessageRerror) Type() FcallType {
5053
return Rerror
5154
}

Diff for: fcall.go

+4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package p9p
22

33
import "fmt"
44

5+
// FcallType encodes the message type for the target Fcall.
56
type FcallType uint8
67

8+
// Definitions for Fcall's used in 9P2000.
79
const (
810
Tversion FcallType = iota + 100
911
Rversion
@@ -100,6 +102,8 @@ func (fct FcallType) String() string {
100102
}
101103
}
102104

105+
// Fcall defines the fields for sending a 9p formatted message. The type will
106+
// be introspected from the Message implementation.
103107
type Fcall struct {
104108
Type FcallType
105109
Tag Tag

Diff for: readdir.go

+5
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ type Readdir struct {
2020
offset int64
2121
}
2222

23+
// NewReaddir returns a new Readdir to assist implementing server-side Readdir.
24+
// The codec will be used to decode messages with Dir entries. The provided
25+
// function next will be called until io.EOF is returned.
2326
func NewReaddir(codec Codec, next func() (Dir, error)) *Readdir {
2427
return &Readdir{
2528
nextfn: next,
2629
codec: codec,
2730
}
2831
}
2932

33+
// NewFixedReaddir returns a Readdir that will returned a fixed set of
34+
// directory entries.
3035
func NewFixedReaddir(codec Codec, dir []Dir) *Readdir {
3136
dirs := make([]Dir, len(dir))
3237
copy(dirs, dir) // make our own copy!

Diff for: server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (c *conn) write(responses chan *Fcall) {
211211
// TODO(stevvooe): A full idle timeout on the
212212
// connection should be enforced here. We log here,
213213
// since this is less common.
214-
log.Println("9p server: temporary error writing fcall: %v", err)
214+
log.Printf("9p server: temporary error writing fcall: %v", err)
215215
continue
216216
}
217217
}

Diff for: types.go

+21-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ import (
66
)
77

88
const (
9-
DefaultMSize = 64 << 10
9+
// DefaultMSize messages size used to establish a session.
10+
DefaultMSize = 64 << 10
11+
12+
// DefaultVersion for this package. Currently, the only supported version.
1013
DefaultVersion = "9P2000"
1114
)
1215

16+
// Mode constants for use Dir.Mode.
1317
const (
1418
DMDIR = 0x80000000 // mode bit for directories
1519
DMAPPEND = 0x40000000 // mode bit for append only files
@@ -19,6 +23,7 @@ const (
1923
DMTMP = 0x04000000 // mode bit for non-backed-up files
2024

2125
// 9p2000.u extensions
26+
2227
DMSYMLINK = 0x02000000
2328
DMDEVICE = 0x00800000
2429
DMNAMEDPIPE = 0x00200000
@@ -34,6 +39,7 @@ const (
3439
// Flag defines the flag type for use with open and create
3540
type Flag uint8
3641

42+
// Constants to use when opening files.
3743
const (
3844
OREAD Flag = 0x00 // open for read
3945
OWRITE = 0x01 // write
@@ -43,9 +49,9 @@ const (
4349
// PROPOSAL(stevvooe): Possible protocal extension to allow the create of
4450
// symlinks. Initially, the link is created with no value. Read and write
4551
// to read and set the link value.
52+
4653
OSYMLINK = 0x04
4754

48-
// or'd in
4955
OTRUNC = 0x10 // or'ed in (except for exec), truncate file first
5056
OCEXEC = 0x20 // or'ed in, close on exec
5157
ORCLOSE = 0x40 // or'ed in, remove on close
@@ -54,6 +60,7 @@ const (
5460
// QType indicates the type of a resource within the Qid.
5561
type QType uint8
5662

63+
// Constants for use in Qid to indicate resource type.
5764
const (
5865
QTDIR QType = 0x80 // type bit for directories
5966
QTAPPEND = 0x40 // type bit for append only files
@@ -88,14 +95,23 @@ func (qt QType) String() string {
8895
// Tag uniquely identifies an outstanding fcall in a 9p session.
8996
type Tag uint16
9097

98+
// NOTAG is a reserved values for messages sent before establishing a session,
99+
// such as Tversion.
91100
const NOTAG Tag = ^Tag(0)
92101

102+
// Fid defines a type to hold Fid values.
93103
type Fid uint32
94104

105+
// NOFID indicates the lack of an Fid.
95106
const NOFID Fid = ^Fid(0)
96107

108+
// Qid indicates the type, path and version of the resource returned by a
109+
// server. It is only valid for a session.
110+
//
111+
// Typically, a client maintains a mapping of Fid-Qid as Qids are returned by
112+
// the server.
97113
type Qid struct {
98-
Type QType `9p:type,1`
114+
Type QType `9p:"type,1"`
99115
Version uint32
100116
Path uint64
101117
}
@@ -105,6 +121,8 @@ func (qid Qid) String() string {
105121
qid.Type, qid.Version, qid.Path)
106122
}
107123

124+
// Dir defines the structure used for expressing resources in stat/wstat and
125+
// when reading directories.
108126
type Dir struct {
109127
Type uint16
110128
Dev uint32

0 commit comments

Comments
 (0)