~moody/ninep

ref: d394458419b1bc3ea43eb8426ccecfc427352ab9 ninep/fs.go -rw-r--r-- 2.5 KiB
d3944584 — Jacob Moody Rework api 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package ninep

import "errors"

//FS is the interface that 9p servers must satisfy to be used
//with Srv. Each function that accepts a T* message
//is expected to call T*'s Respond method.
//Respond takes the corespdonding R* message and
//err string. If the err string is non empty then a Rerror is
//sent to the client with the string included as the error message
//instead.
type FS interface {
	//Attach is the first message sent on a session, for which
	//the root Qid should be returned.
	Attach(t *Tattach)

	//Walk is called multiple times for a single Twalk request,
	//once for each walk elemenent within the message. For each
	//call cur is set to the directory from which the walk is
	//starting, with next being the path element that the client
	//wishes to walk to within the directory. The return value
	//should represent the Qid for the file identified by next
	//or nil if the file does not exist.
	Walk(cur *Qid, next string) *Qid

	//The Qid passed to create is the directory for which
	//the new file is to be created in.
	Create(t *Tcreate, q *Qid)

	//For Open, Read, Write, Stat, Wstat, and Remove. The Qid passed
	//represents the specific file the client wishes to operate on.
	//Read is also the message called for listing files within
	//a directory, a helper function ReadDir is included for
	//this case.
	Open(t *Topen, q *Qid)
	Read(t *Tread, q *Qid)
	Write(t *Twrite, q *Qid)
	Stat(t *Tstat, q *Qid)
	Wstat(t *Twstat, q *Qid)
	Remove(t *Tremove, q *Qid)

	//Clunk is sent when the client no longer has any refrences
	//open to a specific file to allow the server to perform
	//clenup.
	Clunk(t *Tclunk, q *Qid)
}

//See the Srv documentation
type FSMaker func() FS

//NopFS is a filesystem that simply errors
//on each request message. NopFS can be
//embedded to respond to request types the
//server does not plan to support.
type NopFS struct{}

var errNotImpl = errors.New("not implemented")

func (n *NopFS) Attach(t *Tattach) {
	t.Err(errNotImpl)
}

func (n *NopFS) Walk(cur *Qid, next string) *Qid {
	return nil
}

func (n *NopFS) Create(t *Tcreate, q *Qid) {
	t.Err(errNotImpl)
}

func (n *NopFS) Open(t *Topen, q *Qid) {
	t.Err(errNotImpl)
}

func (n *NopFS) Read(t *Tread, q *Qid) {
	t.Err(errNotImpl)
}

func (n *NopFS) Write(t *Twrite, q *Qid) {
	t.Err(errNotImpl)
}

func (n *NopFS) Stat(t *Tstat, q *Qid) {
	t.Err(errNotImpl)
}

func (n *NopFS) Wstat(t *Twstat, q *Qid) {
	t.Err(errNotImpl)
}

func (n *NopFS) Remove(t *Tremove, q *Qid) {
	t.Err(errNotImpl)
}

func (n *NopFS) Clunk(t *Tclunk, q *Qid) {
	t.Err(errNotImpl)
}