forked from docker-archive/go-p9p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filesys.go
84 lines (72 loc) · 3.04 KB
/
filesys.go
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
package p9p
import "context"
// Note: Like information from all ent/file inputs, the server
// should copy details from the AuthFile if you want
// to retain them internally past the lifetime of this function call.
//
// The client, on the other hand, uniquely owns the function outputs.
//
// RequireAuth is not able to be determined reliably by the client,
// which will always return false without asking the server.
type FileSys interface {
RequireAuth(ctx context.Context) bool
Auth(ctx context.Context, uname, aname string) (AuthFile, error)
Attach(ctx context.Context, uname, aname string, af AuthFile) (Dirent, error)
}
type AuthFile interface {
File // For read/write in auth protocols.
Close(ctx context.Context) error
Success() bool // Was the authentication successful?
}
// Simplified interface to a file that has been Open-ed.
// Note: Since a Dirent can only be opened once,
// it is up to Clunk to close any underlying File state,
// Including remove on close (ORCLOSE flag)
// FileSys won't call it automatically.
type File interface {
Read(ctx context.Context, p []byte, offset int64) (int, error)
Write(ctx context.Context, p []byte, offset int64) (int, error)
// IOUnit must be >0 on the client side (unless the File is invalid)
// May be 0 on the server side.
// Must not be <0.
IOUnit() int
}
// Simplified interface for servers to implement files.
type Dirent interface {
Qid() Qid
// OpenDir, Walk, Create are only called if IsDir()
// Note: IsDir iff. Qid.Type & p9p.QTDIR != 0
OpenDir(ctx context.Context) (ReadNext, error)
// Walk is guaranteed not to see '.' or have paths containing '/'
// NOTE(frobnitzem): we could expand Walk to take a bool
// indicating whether to re-use the same Fid.
// For now, the client assumes it will make a new Fid,
// and the server honors the client's choice either way.
Walk(ctx context.Context, name ...string) ([]Qid, Dirent, error)
// Note: Open is not called after create.
// The server must create and open together.
//
// If the file represents a Dir, then the file returned
// is discarded and replaced with a nice directory entry reader.
Create(ctx context.Context, name string,
perm uint32, mode Flag) (Dirent, File, error)
// Methods on file
// Note: Open() is not called if IsDir()
// An internal implementation calls OpenDir() instead.
Open(ctx context.Context, mode Flag) (File, error)
// Note: If remove is called, the Dirent will no longer
// be referenced by the server, but Clunk will not be called.
// If remove is called on an open file, it is responsible
// for releasing server resources associated with the file.
Remove(ctx context.Context) error
// If Clunk is called on an open file, it is responsible
// for releasing server resources associated with the file.
// It is also responsible for implementing actions like ORCLOSE.
Clunk(ctx context.Context) error
Stat(ctx context.Context) (Dir, error)
WStat(ctx context.Context, stat Dir) error
}
// Helper function to check Dirent.Qid().Type for QTDIR bit.
func IsDir(d Dirent) bool {
return d.Qid().Type&QTDIR != 0
}