-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
381 lines (318 loc) · 6.45 KB
/
types.go
File metadata and controls
381 lines (318 loc) · 6.45 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
package fuse
import (
"fmt"
"syscall"
"unsafe"
"bytelog.org/fuse/proto"
)
var (
ENOENT = syscall.ENOENT
ENOSYS = syscall.ENOSYS
EPROTO = syscall.EPROTO
)
type Context struct {
noCopy noCopy
buf []byte
off int
sess *session
// Request buffer begins here. NO ADDITIONAL FIELDS BELOW THIS LINE.
Header
}
func (ctx *Context) Interrupt() <-chan struct{} {
return nil
}
func (ctx *Context) String() string {
return "OP_" + ctx.Op.String()
}
// pointer to the request data
func (ctx *Context) in() unsafe.Pointer {
return unsafe.Pointer(&ctx.buf[headerInSize])
}
func (ctx *Context) bytes(off uintptr) []byte {
return ctx.buf[headerInSize+off : ctx.off]
}
func (ctx *Context) string() string {
buf := ctx.bytes(0)
return string(buf[:strlen(buf)])
}
func (ctx *Context) strings(n int) []string {
buf := ctx.bytes(0)
s := make([]string, n)
for i := range s {
n := strlen(buf)
s[i] = string(buf[:n])
if len(buf) == n {
return s
}
buf = buf[n+1:]
}
return s
}
// pointer to the response data
func (ctx *Context) out() unsafe.Pointer {
return unsafe.Pointer(&ctx.buf[ctx.off+int(headerOutSize)])
}
// pointer to the response buffer, with size bytes zero initialized
func (ctx *Context) outzero(size uintptr) unsafe.Pointer {
start := ctx.off + int(headerOutSize)
if size > 0 {
buf := ctx.buf[start : start+int(size)]
for i := range buf {
buf[i] = 0
}
}
return unsafe.Pointer(&ctx.buf[start])
}
func (ctx *Context) outBuf() []byte {
return ctx.buf[ctx.off:]
}
func (ctx *Context) outData() []byte {
return ctx.buf[ctx.off+int(headerOutSize):]
}
func (ctx *Context) outHeader() *proto.OutHeader {
return (*proto.OutHeader)(unsafe.Pointer(&ctx.buf[ctx.off]))
}
// bump the input buffer size and memclr the affected bytes
func (ctx *Context) shift(n int) {
buf := ctx.buf[ctx.off : ctx.off+n]
for i := range buf {
buf[i] = 0
}
ctx.off += n
}
func (ctx *Context) writeString(s string) (n int) {
// todo: bounds check
buf := ctx.outData()
n = copy(buf, s)
buf[n] = 0
return n + 1
}
type Header struct {
len uint32
Op proto.OpCode
ID uint64
NodeID uint64
UID uint32
GID uint32
PID uint32
_ uint32
}
func (h Header) Debug() string {
return fmt.Sprintf("{ID:%d NodeID:%d UID:%d GID:%d PID:%d}",
h.ID, h.NodeID, h.UID, h.GID, h.PID)
}
type InitIn struct {
Major uint32
Minor uint32
MaxReadahead uint32
Flags uint32
}
type InitOut struct {
major uint32
minor uint32
MaxReadahead uint32
Flags uint32
MaxBackground uint16
CongestionThreshold uint16
MaxWrite uint32
TimeGran uint32
MaxPages uint16
_ uint16
_ [8]uint32
}
type AccessIn struct {
Mask uint32
_ uint32
}
type GetattrIn struct {
// normally used to tell if Fh is set. We don't expose the flag bits since
// we don't consider 0 a valid file handle.
flags uint32
_ uint32
Fh uint64
}
type GetattrOut struct {
AttrValid uint64
AttrValidNsec uint32
_ uint32
Attr
}
type Attr struct {
Ino uint64
Size uint64
Blocks uint64
Atime uint64
Mtime uint64
Ctime uint64
Atimensec uint32
Mtimensec uint32
Ctimensec uint32
Mode uint32
Nlink uint32
Uid uint32
Gid uint32
Rdev uint32
Blksize uint32
_ uint32
}
type LookupIn struct {
Name string
}
type LookupOut struct {
EntryOut
}
type ForgetIn struct {
NLookup uint64
}
type SetattrValid uint32
func (v SetattrValid) Mode() bool { return v&proto.FATTR_MODE != 0 }
func (v SetattrValid) UID() bool { return v&proto.FATTR_UID != 0 }
func (v SetattrValid) GID() bool { return v&proto.FATTR_GID != 0 }
func (v SetattrValid) Size() bool { return v&proto.FATTR_SIZE != 0 }
func (v SetattrValid) Atime() bool { return v&proto.FATTR_ATIME != 0 }
func (v SetattrValid) Mtime() bool { return v&proto.FATTR_MTIME != 0 }
func (v SetattrValid) Fh() bool { return v&proto.FATTR_FH != 0 }
func (v SetattrValid) AtimeNow() bool { return v&proto.FATTR_ATIME_NOW != 0 }
func (v SetattrValid) MtimeNow() bool { return v&proto.FATTR_MTIME_NOW != 0 }
func (v SetattrValid) LockOwner() bool { return v&proto.FATTR_LOCKOWNER != 0 }
func (v SetattrValid) Ctime() bool { return v&proto.FATTR_CTIME != 0 }
type SetattrIn struct {
Valid SetattrValid
_ uint32
Fh uint64
Size uint64
LockOwner uint64
Atime uint64
Mtime uint64
Ctime uint64
Atimensec uint32
Mtimensec uint32
Ctimensec uint32
Mode uint32
_ uint32
Uid uint32
Gid uint32
_ uint32
}
type SetattrOut struct {
EntryOut
}
type EntryOut struct {
// Inode ID
Nodeid uint64
// Inode generation: Nodeid:gen must be unique for the fs's lifetime
Generation uint64
// Cache timeout for the name
EntryValid uint64
// Cache timeout for the attributes
AttrValid uint64
EntryValidNsec uint32
AttrValidNsec uint32
Attr Attr
}
type ReadlinkOut struct {
Name string
}
type SymlinkIn struct {
Name string
Linkname string
}
type SymlinkOut struct {
EntryOut
}
// nocast
type MknodIn struct {
Name string
Mode uint32
Rdev uint32
Umask uint32
_ uint32
}
type MknodOut struct {
EntryOut
}
type MkdirIn struct {
Name string
Mode uint32
Umask uint32
}
type MkdirOut struct {
EntryOut
}
type UnlinkIn struct {
Name string
}
type RmdirIn struct {
Name string
}
type RenameIn struct {
Name string
Newname string
Newdir uint64
Flags uint32
}
type LinkIn struct {
Oldnodeid uint64
}
type LinkOut struct {
EntryOut
}
type OpenIn struct {
Flags uint32
_ uint32
}
type OpenOut struct {
EntryOut
}
type ReadIn struct {
Fh uint64
Offset uint64
Size uint32
ReadFlags uint32
LockOwner uint64
Flags uint32
_ uint32
}
type ReadOut struct {
Data []byte
}
type LseekIn struct {
Fh uint64
Offset uint64
Whence uint32
_ uint32
}
type LseekOut struct {
Offset uint64
}
type CopyFileRangeIn struct {
FhIn uint64
OffIn uint64
NodeidOut uint64
FhOut uint64
OffOut uint64
Len uint64
Flags uint64
}
type ReleaseIn struct {
Fh uint64
Flags uint32
ReleaseFlags uint32
LockOwner uint64
}
// nocast
type GetxattrIn struct {
Name string
}
// nocast
type GetxattrOut struct {
Value []byte
}
func strlen(n []byte) int {
for i := 0; i < len(n); i++ {
if n[i] == 0 {
return i
}
}
return len(n)
}