forked from conclusiveeng/lib9p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fcall.h
624 lines (572 loc) · 15.4 KB
/
fcall.h
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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
/*
* Copyright 2016 Jakub Klama <[email protected]>
* All rights reserved
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted providing that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
/*
* Based on libixp code: ©2007-2010 Kris Maglione <maglione.k at Gmail>
*/
#ifndef LIB9P_FCALL_H
#define LIB9P_FCALL_H
#include <stdint.h>
#define L9P_MAX_WELEM 256
/*
* Function call/reply (Tfoo/Rfoo) numbers.
*
* These are protocol code numbers, so the exact values
* matter. However, __FIRST and __LAST_PLUS_ONE are for
* debug code, and just need to encompass the entire range.
*
* Note that we rely (in the debug code) on Rfoo == Tfoo+1.
*/
enum l9p_ftype {
L9P__FIRST = 6, /* NB: must be <= all legal values */
L9P_TLERROR = 6, /* illegal; exists for parity with Rlerror */
L9P_RLERROR,
L9P_TSTATFS = 8,
L9P_RSTATFS,
L9P_TLOPEN = 12,
L9P_RLOPEN,
L9P_TLCREATE = 14,
L9P_RLCREATE,
L9P_TSYMLINK = 16,
L9P_RSYMLINK,
L9P_TMKNOD = 18,
L9P_RMKNOD,
L9P_TRENAME = 20,
L9P_RRENAME,
L9P_TREADLINK = 22,
L9P_RREADLINK,
L9P_TGETATTR = 24,
L9P_RGETATTR,
L9P_TSETATTR = 26,
L9P_RSETATTR,
L9P_TXATTRWALK = 30,
L9P_RXATTRWALK,
L9P_TXATTRCREATE = 32,
L9P_RXATTRCREATE,
L9P_TREADDIR = 40,
L9P_RREADDIR,
L9P_TFSYNC = 50,
L9P_RFSYNC,
L9P_TLOCK = 52,
L9P_RLOCK,
L9P_TGETLOCK = 54,
L9P_RGETLOCK,
L9P_TLINK = 70,
L9P_RLINK,
L9P_TMKDIR = 72,
L9P_RMKDIR,
L9P_TRENAMEAT = 74,
L9P_RRENAMEAT,
L9P_TUNLINKAT = 76,
L9P_RUNLINKAT,
L9P_TVERSION = 100,
L9P_RVERSION,
L9P_TAUTH = 102,
L9P_RAUTH,
L9P_TATTACH = 104,
L9P_RATTACH,
L9P_TERROR = 106, /* illegal */
L9P_RERROR,
L9P_TFLUSH = 108,
L9P_RFLUSH,
L9P_TWALK = 110,
L9P_RWALK,
L9P_TOPEN = 112,
L9P_ROPEN,
L9P_TCREATE = 114,
L9P_RCREATE,
L9P_TREAD = 116,
L9P_RREAD,
L9P_TWRITE = 118,
L9P_RWRITE,
L9P_TCLUNK = 120,
L9P_RCLUNK,
L9P_TREMOVE = 122,
L9P_RREMOVE,
L9P_TSTAT = 124,
L9P_RSTAT,
L9P_TWSTAT = 126,
L9P_RWSTAT,
L9P__LAST_PLUS_1, /* NB: must be last */
};
/*
* When a Tfoo request comes over the wire, we decode it
* (pack.c) from wire format into a request laid out in
* a "union l9p_fcall" object. This object is not in wire
* format, but rather in something more convenient for us
* to operate on.
*
* We then dispatch the request (request.c, backend/fs.c) and
* use another "union l9p_fcall" object to build a reply.
* The reply is converted to wire format on the way back out
* (pack.c again).
*
* All sub-objects start with a header containing the request
* or reply type code and two-byte tag, and whether or not it
* is needed, a four-byte fid.
*
* What this means here is that the data structures within
* the union can be shared across various requests and replies.
* For instance, replies to OPEN, CREATE, LCREATE, LOPEN, MKDIR, and
* SYMLINK are all fairly similar (providing a qid and sometimes
* an iounit) and hence can all use the l9p_f_ropen structure.
* Which structures are used for which operations is somewhat
* arbitrary; for programming ease, if an operation shares a
* data structure, it still has its own name: there are union
* members named ropen, rcreate, rlcreate, rlopen, rmkdir, and
* rsymlink, even though all use struct l9p_f_ropen.
*
* The big exception to the above rule is struct l9p_f_io, which
* is used as both request and reply for all of READ, WRITE, and
* READDIR. Moreover, the READDIR reply must be pre-packed into
* wire format (it is handled like raw data a la READ).
*
* Some request messages (e.g., TREADLINK) fit in a header, having
* just type code, tag, and fid. These have no separate data
* structure, nor union member name. Similarly, some reply
* messages (e.g., RCLUNK, RREMOVE, RRENAME) have just the type
* code and tag.
*/
/*
* Type code bits in (the first byte of) a qid.
*/
enum l9p_qid_type {
L9P_QTDIR = 0x80, /* type bit for directories */
L9P_QTAPPEND = 0x40, /* type bit for append only files */
L9P_QTEXCL = 0x20, /* type bit for exclusive use files */
L9P_QTMOUNT = 0x10, /* type bit for mounted channel */
L9P_QTAUTH = 0x08, /* type bit for authentication file */
L9P_QTTMP = 0x04, /* type bit for non-backed-up file */
L9P_QTSYMLINK = 0x02, /* type bit for symbolic link */
L9P_QTFILE = 0x00 /* type bits for plain file */
};
/*
* Extra permission bits in create and file modes (stat).
*/
#define L9P_DMDIR 0x80000000
enum {
L9P_DMAPPEND = 0x40000000,
L9P_DMEXCL = 0x20000000,
L9P_DMMOUNT = 0x10000000,
L9P_DMAUTH = 0x08000000,
L9P_DMTMP = 0x04000000,
L9P_DMSYMLINK = 0x02000000,
/* 9P2000.u extensions */
L9P_DMDEVICE = 0x00800000,
L9P_DMNAMEDPIPE = 0x00200000,
L9P_DMSOCKET = 0x00100000,
L9P_DMSETUID = 0x00080000,
L9P_DMSETGID = 0x00040000,
};
/*
* Open/create mode bits in 9P2000 and 9P2000.u operations
* (not Linux lopen and lcreate flags, which are different).
* Note that the mode field is only one byte wide.
*/
enum l9p_omode {
L9P_OREAD = 0, /* open for read */
L9P_OWRITE = 1, /* write */
L9P_ORDWR = 2, /* read and write */
L9P_OEXEC = 3, /* execute, == read but check execute permission */
L9P_OACCMODE = 3, /* mask for the above access-mode bits */
L9P_OTRUNC = 16, /* or'ed in (except for exec), truncate file first */
L9P_OCEXEC = 32, /* or'ed in, close on exec */
L9P_ORCLOSE = 64, /* or'ed in, remove on close */
L9P_ODIRECT = 128, /* or'ed in, direct access */
};
/*
* Flag bits in 9P2000.L operations (Tlopen, Tlcreate). These are
* basically just the Linux L_* flags. The bottom 3 bits are the
* same as for l9p_omode, although open-for-exec is not used:
* instead, the client does a Tgetattr and checks the mode for
* execute bits, then just opens for reading.
*
* Each L_O_xxx is just value O_xxx has on Linux in <fcntl.h>;
* not all are necessarily used. From observation, we do get
* L_O_CREAT and L_O_EXCL when creating with exclusive, and always
* get L_O_LARGEFILE. We do get L_O_APPEND when opening for
* append. We also get both L_O_DIRECT and L_O_DIRECTORY set
* when opening directories.
*
* We probably never get L_O_NOCTTY which makes no sense, and
* some of the other options may need to be handled on the client.
*/
enum l9p_l_o_flags {
L9P_L_O_CREAT = 000000100U,
L9P_L_O_EXCL = 000000200U,
L9P_L_O_NOCTTY = 000000400U,
L9P_L_O_TRUNC = 000001000U,
L9P_L_O_APPEND = 000002000U,
L9P_L_O_NONBLOCK = 000004000U,
L9P_L_O_DSYNC = 000010000U,
L9P_L_O_FASYNC = 000020000U,
L9P_L_O_DIRECT = 000040000U,
L9P_L_O_LARGEFILE = 000100000U,
L9P_L_O_DIRECTORY = 000200000U,
L9P_L_O_NOFOLLOW = 000400000U,
L9P_L_O_NOATIME = 001000000U,
L9P_L_O_CLOEXEC = 002000000U,
L9P_L_O_SYNC = 004000000U,
L9P_L_O_PATH = 010000000U,
L9P_L_O_TMPFILE = 020000000U,
};
struct l9p_hdr {
uint8_t type;
uint16_t tag;
uint32_t fid;
};
struct l9p_qid {
enum l9p_qid_type type;
uint32_t version;
uint64_t path;
};
struct l9p_stat {
uint16_t type;
uint32_t dev;
struct l9p_qid qid;
uint32_t mode;
uint32_t atime;
uint32_t mtime;
uint64_t length;
char *name;
char *uid;
char *gid;
char *muid;
char *extension;
uint32_t n_uid;
uint32_t n_gid;
uint32_t n_muid;
};
#define L9P_FSTYPE 0x01021997
struct l9p_statfs {
uint32_t type; /* file system type */
uint32_t bsize; /* block size for I/O */
uint64_t blocks; /* file system size (bsize-byte blocks) */
uint64_t bfree; /* free blocks in fs */
uint64_t bavail; /* free blocks avail to non-superuser*/
uint64_t files; /* file nodes in file system (# inodes) */
uint64_t ffree; /* free file nodes in fs */
uint64_t fsid; /* file system identifier */
uint32_t namelen; /* maximum length of filenames */
};
struct l9p_f_version {
struct l9p_hdr hdr;
uint32_t msize;
char *version;
};
struct l9p_f_tflush {
struct l9p_hdr hdr;
uint16_t oldtag;
};
struct l9p_f_error {
struct l9p_hdr hdr;
char *ename;
uint32_t errnum;
};
struct l9p_f_ropen {
struct l9p_hdr hdr;
struct l9p_qid qid;
uint32_t iounit;
};
struct l9p_f_rauth {
struct l9p_hdr hdr;
struct l9p_qid aqid;
};
struct l9p_f_attach {
struct l9p_hdr hdr;
uint32_t afid;
char *uname;
char *aname;
uint32_t n_uname;
};
#define L9P_NOFID ((uint32_t)-1) /* in Tattach, no auth fid */
#define L9P_NONUNAME ((uint32_t)-1) /* in Tattach, no n_uname */
struct l9p_f_tcreate {
struct l9p_hdr hdr;
uint32_t perm;
char *name;
uint8_t mode; /* +Topen */
char *extension;
};
struct l9p_f_twalk {
struct l9p_hdr hdr;
uint32_t newfid;
uint16_t nwname;
char *wname[L9P_MAX_WELEM];
};
struct l9p_f_rwalk {
struct l9p_hdr hdr;
uint16_t nwqid;
struct l9p_qid wqid[L9P_MAX_WELEM];
};
struct l9p_f_io {
struct l9p_hdr hdr;
uint64_t offset; /* Tread, Twrite, Treaddir */
uint32_t count; /* Tread, Twrite, Rread, Treaddir, Rreaddir */
};
struct l9p_f_rstat {
struct l9p_hdr hdr;
struct l9p_stat stat;
};
struct l9p_f_twstat {
struct l9p_hdr hdr;
struct l9p_stat stat;
};
struct l9p_f_rstatfs {
struct l9p_hdr hdr;
struct l9p_statfs statfs;
};
/* Used for Tlcreate, Tlopen, Tmkdir, Tunlinkat. */
struct l9p_f_tlcreate {
struct l9p_hdr hdr;
char *name; /* Tlcreate, Tmkdir, Tunlinkat */
uint32_t flags; /* Tlcreate, Tlopen, Tmkdir, Tunlinkat */
uint32_t mode; /* Tlcreate, Tmkdir */
uint32_t gid; /* Tlcreate, Tmkdir */
};
struct l9p_f_tsymlink {
struct l9p_hdr hdr;
char *name;
char *symtgt;
uint32_t gid;
};
struct l9p_f_tmknod {
struct l9p_hdr hdr;
char *name;
uint32_t mode;
uint32_t major;
uint32_t minor;
uint32_t gid;
};
struct l9p_f_trename {
struct l9p_hdr hdr;
uint32_t dfid;
char *name;
};
struct l9p_f_rreadlink {
struct l9p_hdr hdr;
char *target;
};
struct l9p_f_tgetattr {
struct l9p_hdr hdr;
uint64_t request_mask;
};
struct l9p_f_rgetattr {
struct l9p_hdr hdr;
uint64_t valid;
struct l9p_qid qid;
uint32_t mode;
uint32_t uid;
uint32_t gid;
uint64_t nlink;
uint64_t rdev;
uint64_t size;
uint64_t blksize;
uint64_t blocks;
uint64_t atime_sec;
uint64_t atime_nsec;
uint64_t mtime_sec;
uint64_t mtime_nsec;
uint64_t ctime_sec;
uint64_t ctime_nsec;
uint64_t btime_sec;
uint64_t btime_nsec;
uint64_t gen;
uint64_t data_version;
};
/* Fields in req->request_mask and reply->valid for Tgetattr, Rgetattr. */
enum l9pl_getattr_flags {
L9PL_GETATTR_MODE = 0x00000001,
L9PL_GETATTR_NLINK = 0x00000002,
L9PL_GETATTR_UID = 0x00000004,
L9PL_GETATTR_GID = 0x00000008,
L9PL_GETATTR_RDEV = 0x00000010,
L9PL_GETATTR_ATIME = 0x00000020,
L9PL_GETATTR_MTIME = 0x00000040,
L9PL_GETATTR_CTIME = 0x00000080,
L9PL_GETATTR_INO = 0x00000100,
L9PL_GETATTR_SIZE = 0x00000200,
L9PL_GETATTR_BLOCKS = 0x00000400,
/* everything up to and including BLOCKS is BASIC */
L9PL_GETATTR_BASIC = L9PL_GETATTR_MODE |
L9PL_GETATTR_NLINK |
L9PL_GETATTR_UID |
L9PL_GETATTR_GID |
L9PL_GETATTR_RDEV |
L9PL_GETATTR_ATIME |
L9PL_GETATTR_MTIME |
L9PL_GETATTR_CTIME |
L9PL_GETATTR_INO |
L9PL_GETATTR_SIZE |
L9PL_GETATTR_BLOCKS,
L9PL_GETATTR_BTIME = 0x00000800,
L9PL_GETATTR_GEN = 0x00001000,
L9PL_GETATTR_DATA_VERSION = 0x00002000,
/* BASIC + birthtime + gen + data-version = ALL */
L9PL_GETATTR_ALL = L9PL_GETATTR_BASIC |
L9PL_GETATTR_BTIME |
L9PL_GETATTR_GEN |
L9PL_GETATTR_DATA_VERSION,
};
struct l9p_f_tsetattr {
struct l9p_hdr hdr;
uint32_t valid;
uint32_t mode;
uint32_t uid;
uint32_t gid;
uint64_t size;
uint64_t atime_sec; /* if valid & L9PL_SETATTR_ATIME_SET */
uint64_t atime_nsec; /* (else use on-server time) */
uint64_t mtime_sec; /* if valid & L9PL_SETATTR_MTIME_SET */
uint64_t mtime_nsec; /* (else use on-server time) */
};
/* Fields in req->valid for Tsetattr. */
enum l9pl_setattr_flags {
L9PL_SETATTR_MODE = 0x00000001,
L9PL_SETATTR_UID = 0x00000002,
L9PL_SETATTR_GID = 0x00000004,
L9PL_SETATTR_SIZE = 0x00000008,
L9PL_SETATTR_ATIME = 0x00000010,
L9PL_SETATTR_MTIME = 0x00000020,
L9PL_SETATTR_CTIME = 0x00000040,
L9PL_SETATTR_ATIME_SET = 0x00000080,
L9PL_SETATTR_MTIME_SET = 0x00000100,
};
struct l9p_f_txattrwalk {
struct l9p_hdr hdr;
uint32_t newfid;
char *name;
};
struct l9p_f_rxattrwalk {
struct l9p_hdr hdr;
uint64_t size;
};
struct l9p_f_txattrcreate {
struct l9p_hdr hdr;
char *name;
uint64_t attr_size;
uint32_t flags;
};
struct l9p_f_tlock {
struct l9p_hdr hdr;
uint8_t type; /* from l9pl_lock_type */
uint32_t flags; /* from l9pl_lock_flags */
uint64_t start;
uint64_t length;
uint32_t proc_id;
char *client_id;
};
enum l9pl_lock_type {
L9PL_LOCK_TYPE_RDLOCK = 0,
L9PL_LOCK_TYPE_WRLOCK = 1,
L9PL_LOCK_TYPE_UNLOCK = 2,
};
enum l9pl_lock_flags {
L9PL_LOCK_TYPE_BLOCK = 1,
L9PL_LOCK_TYPE_RECLAIM = 2,
};
struct l9p_f_rlock {
struct l9p_hdr hdr;
uint8_t status; /* from l9pl_lock_status */
};
enum l9pl_lock_status {
L9PL_LOCK_SUCCESS = 0,
L9PL_LOCK_BLOCKED = 1,
L9PL_LOCK_ERROR = 2,
L9PL_LOCK_GRACE = 3,
};
struct l9p_f_getlock {
struct l9p_hdr hdr;
uint8_t type; /* from l9pl_lock_type */
uint64_t start;
uint64_t length;
uint32_t proc_id;
char *client_id;
};
struct l9p_f_tlink {
struct l9p_hdr hdr;
uint32_t dfid;
char *name;
};
struct l9p_f_trenameat {
struct l9p_hdr hdr;
char *oldname;
uint32_t newdirfid;
char *newname;
};
/*
* Flags in Tunlinkat (which re-uses f_tlcreate data structure but
* with different meaning).
*/
enum l9p_l_unlinkat_flags {
/* not sure if any other AT_* flags are passed through */
L9PL_AT_REMOVEDIR = 0x0200,
};
union l9p_fcall {
struct l9p_hdr hdr;
struct l9p_f_version version;
struct l9p_f_tflush tflush;
struct l9p_f_ropen ropen;
struct l9p_f_ropen rcreate;
struct l9p_f_ropen rattach;
struct l9p_f_error error;
struct l9p_f_rauth rauth;
struct l9p_f_attach tattach;
struct l9p_f_attach tauth;
struct l9p_f_tcreate tcreate;
struct l9p_f_tcreate topen;
struct l9p_f_twalk twalk;
struct l9p_f_rwalk rwalk;
struct l9p_f_twstat twstat;
struct l9p_f_rstat rstat;
struct l9p_f_rstatfs rstatfs;
struct l9p_f_tlcreate tlopen;
struct l9p_f_ropen rlopen;
struct l9p_f_tlcreate tlcreate;
struct l9p_f_ropen rlcreate;
struct l9p_f_tsymlink tsymlink;
struct l9p_f_ropen rsymlink;
struct l9p_f_tmknod tmknod;
struct l9p_f_ropen rmknod;
struct l9p_f_trename trename;
struct l9p_f_rreadlink rreadlink;
struct l9p_f_tgetattr tgetattr;
struct l9p_f_rgetattr rgetattr;
struct l9p_f_tsetattr tsetattr;
struct l9p_f_txattrwalk txattrwalk;
struct l9p_f_rxattrwalk rxattrwalk;
struct l9p_f_txattrcreate txattrcreate;
struct l9p_f_tlock tlock;
struct l9p_f_rlock rlock;
struct l9p_f_getlock getlock;
struct l9p_f_tlink tlink;
struct l9p_f_tlcreate tmkdir;
struct l9p_f_ropen rmkdir;
struct l9p_f_trenameat trenameat;
struct l9p_f_tlcreate tunlinkat;
struct l9p_f_io io;
};
#endif /* LIB9P_FCALL_H */