Subversion Repositories planix.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
68 7u83 1
typedef struct C9r C9r;
2
typedef struct C9t C9t;
3
typedef struct C9stat C9stat;
4
typedef struct C9ctx C9ctx;
5
typedef struct C9qid C9qid;
6
typedef enum C9error C9error;
7
typedef enum C9mode C9mode;
8
typedef enum C9rtype C9rtype;
9
typedef enum C9ttype C9ttype;
10
typedef enum C9qt C9qt;
11
typedef uint32_t C9fid;
12
typedef uint16_t C9tag;
13
 
14
/* Stat field is not changed if it's set to this value when calling c9wstat. */
15
#define C9nochange (~0)
16
 
17
/* Special fid used with auth/attach to basically avoid authentication. */
18
#define C9nofid ((C9fid)~0)
19
 
20
/* C9modes for opening a file. */
21
enum C9mode
22
{
23
	C9read = 0,
24
	C9write = 1,
25
	C9rdwr = 2,
26
	C9exec = 3,
27
	C9trunc = 0x10,
28
	C9rclose = 0x40,
29
};
30
 
31
enum C9perm
32
{
33
	/* User/owner. */
34
	C9permur = 1<<8, /* Readable. */
35
	C9permuw = 1<<7, /* Writable. */
36
	C9permux = 1<<6, /* Executable. */
37
 
38
	/* Group. */
39
	C9permgr = 1<<5,
40
	C9permgw = 1<<4,
41
	C9permgx = 1<<3,
42
 
43
	/* Other. */
44
	C9permor = 1<<2,
45
	C9permow = 1<<1,
46
	C9permox = 1<<0,
47
};
48
 
49
/* Directory. */
50
#define C9permdir 0x80000000
51
 
52
/* Bitmask of stat.mode. */
53
#define C9stdir 0x80000000
54
#define C9stappend 0x40000000
55
#define C9stexcl 0x20000000
56
#define C9sttmp 0x04000000
57
 
58
/* Limits. */
59
enum
60
{
61
	C9maxtags = 64,    /* Maximal number of outstanding requests. [1-65535] */
62
	C9maxflush = 8,    /* Maximal number of outstanding flushes. [1-65535] */
63
	C9maxstr = 0xffff, /* Maximal string length. [1-65535] */
64
	C9minmsize = 4096, /* Minimal sane msize. [4096-...] */
65
	C9maxpathel = 16,  /* Maximal number of elements in a path. Do not change. */
66
};
67
 
68
/* Errors. */
69
enum C9error
70
{
71
	C9Einit = -1,  /* Initialization failed. */
72
	C9Ever = -2,   /* Protocol version doesn't match. */
73
	C9Epkt = -3,   /* Incoming packet error. */
74
	C9Etag = -4,   /* No free tags or bad tag. */
75
	C9Ebuf = -5,   /* No buffer space enough for a message. */
76
	C9Epath = -6,  /* Path is too long or just invalid. */
77
	C9Eflush = -7, /* Limit of outstanding flushes reached. */
78
	C9Esize = -8,  /* Can't fit data in one message. */
79
	C9Estr = -9    /* Bad string. */
80
};
81
 
82
/* Request types. */
83
enum C9ttype
84
{
85
	Tversion = 100,
86
	Tauth = 102,
87
	Tattach = 104,
88
	Tflush = 108,
89
	Twalk = 110,
90
	Topen = 112,
91
	Tcreate = 114,
92
	Tread = 116,
93
	Twrite = 118,
94
	Tclunk = 120,
95
	Tremove = 122,
96
	Tstat = 124,
97
	Twstat = 126
98
};
99
 
100
/* Response types. */
101
enum C9rtype
102
{
103
	Rversion = 101,
104
	Rauth = 103,
105
	Rattach = 105,
106
	Rerror = 107,
107
	Rflush = 109,
108
	Rwalk = 111,
109
	Ropen = 113,
110
	Rcreate = 115,
111
	Rread = 117,
112
	Rwrite = 119,
113
	Rclunk = 121,
114
	Rremove = 123,
115
	Rstat = 125,
116
	Rwstat = 127
117
};
118
 
119
/* Unique file id type. */
120
enum C9qt
121
{
122
	C9qtdir = 1<<7,
123
	C9qtappend = 1<<6,
124
	C9qtexcl = 1<<5,
125
	C9qtauth = 1<<3,
126
	C9qttmp = 1<<2,
127
	C9qtfile = 0
128
};
129
 
130
/* Unique file id. */
131
struct C9qid
132
{
133
	uint64_t path;
134
	uint32_t version;
135
	C9qt type;
136
};
137
 
138
/*
139
 * File stats. Version and muid are ignored on wstat. Dmdir bit
140
 * change in mode won't work on wstat. Set any integer field to
141
 * C9nochange to keep it unchanged on wstat. Set any string to NULL to
142
 * keep it unchanged. Strings can be empty (""), but never NULL after
143
 * stat call.
144
 */
145
struct C9stat
146
{
147
	uint64_t size; /* Size of the file (in bytes). */
148
	char *name;  /* Name of the file. */
149
	char *uid;   /* Owner of the file. */
150
	char *gid;   /* Group of the file. */
151
	char *muid;  /* The user who modified the file last. */
152
	C9qid qid;   /* Same as qid[0]. */
153
	uint32_t mode;   /* Permissions. See C9st* and C9perm. */
154
	uint32_t atime;  /* Last access time. */
155
	uint32_t mtime;  /* Last modification time. */
156
};
157
 
158
/* Response data. */
159
struct C9r
160
{
161
	union
162
	{
163
		char *error;
164
 
165
		struct
166
		{
167
			uint8_t *data;
168
			uint32_t size;
169
		}read;
170
 
171
		struct
172
		{
173
			uint32_t size;
174
		}write;
175
 
176
		/* File stats (only valid if type is Rstat). */
177
		C9stat stat;
178
 
179
		/*
180
		 * Qid(s). qid[0] is valid for auth/attach/create/stat/open.
181
		 * More ids may be a result of a walk, see numqid.
182
		 */
183
		C9qid qid[C9maxpathel];
184
	};
185
	C9rtype type; /* Response type. */
186
 
187
	/*
188
	 * If not zero, is the maximum number of bytes that are guaranteed
189
	 * to be read or written atomically, without breaking into multiple
190
	 * messages.
191
	 */
192
	uint32_t iounit;
193
 
194
	int numqid; /* Number of valid unique ids in qid array. */
195
	C9tag tag;  /* Tag number. */
196
};
197
 
198
/* Request data. */
199
struct C9t
200
{
201
	C9ttype type;
202
	C9tag tag;
203
	union
204
	{
205
		struct
206
		{
207
			char *uname;
208
			char *aname;
209
			C9fid afid;
210
		}attach;
211
 
212
		struct
213
		{
214
			char *uname;
215
			char *aname;
216
			C9fid afid;
217
		}auth;
218
 
219
		struct
220
		{
221
			char *name;
222
			uint32_t perm;
223
			C9mode mode;
224
		}create;
225
 
226
		struct
227
		{
228
			C9tag oldtag;
229
		}flush;
230
 
231
		struct
232
		{
233
			C9mode mode;
234
		}open;
235
 
236
		struct
237
		{
238
			uint64_t offset;
239
			uint32_t size;
240
		}read;
241
 
242
		struct
243
		{
244
			char *wname[C9maxpathel+1]; /* wname[16] is always NULL */
245
			C9fid newfid;
246
		}walk;
247
 
248
		struct
249
		{
250
			uint64_t offset;
251
			uint8_t *data;
252
			uint32_t size;
253
		}write;
254
 
255
		C9stat wstat;
256
	};
257
	C9fid fid;
258
};
259
 
260
enum
261
{
262
	C9tagsbits = sizeof(uint32_t) * 8,
263
};
264
 
265
struct C9ctx
266
{
267
	/*
268
	 * Should return a pointer to the data (exactly 'size' bytes) read.
269
	 * Set 'err' to non-zero and return NULL in case of error.
270
	 * 'err' set to zero (no error) should be used to return from c9process
271
	 * early (timeout on read to do non-blocking operations, for example).
272
	 */
273
	uint8_t *(*read)(C9ctx *ctx, uint32_t size, int *err) __attribute__((nonnull(1, 3)));
274
 
275
	/* Should return a buffer to store 'size' bytes. Nil means no memory. */
276
	uint8_t *(*begin)(C9ctx *ctx, uint32_t size) __attribute__((nonnull(1)));
277
 
278
	/*
279
	 * Marks the end of a message. Callback may decide if any accumulated
280
	 * messages should be sent to the server/client.
281
	 */
282
	int (*end)(C9ctx *ctx) __attribute__((nonnull(1)));
283
 
284
	/* Callback called every time a new R-message is received. */
285
	void (*r)(C9ctx *ctx, C9r *r) __attribute__((nonnull(1, 2)));
286
 
287
	/* Callback called every time a new T-message is received. */
288
	void (*t)(C9ctx *ctx, C9t *t) __attribute__((nonnull(1, 2)));
289
 
290
	/* Callback for error messages. */
291
	void (*error)(const char *fmt, ...) __attribute__((nonnull(1)));
292
 
293
	/* Auxiliary data, can be used by any of above callbacks. */
294
	void *aux;
295
 
296
	/* private stuff */
297
	uint32_t msize;
298
	uint32_t flush[C9maxflush];
299
	uint32_t tags[C9maxtags/C9tagsbits];
300
	union
301
	{
302
		C9tag lowfreetag;
303
		uint16_t svflags;
304
	};
305
};
306
 
307
/* Parse one directory entry. */
308
extern C9error c9parsedir(C9ctx *c, C9stat *stat, uint8_t **data, uint32_t *size) __attribute__((nonnull(1, 2, 3)));
309
 
310
extern C9error c9version(C9ctx *c, C9tag *tag, uint32_t msize) __attribute__((nonnull(1, 2)));
311
extern C9error c9auth(C9ctx *c, C9tag *tag, C9fid afid, const char *uname, const char *aname) __attribute__((nonnull(1, 2)));
312
extern C9error c9flush(C9ctx *c, C9tag *tag, C9tag oldtag) __attribute__((nonnull(1, 2)));
313
extern C9error c9attach(C9ctx *c, C9tag *tag, C9fid fid, C9fid afid, const char *uname, const char *aname) __attribute__((nonnull(1, 2)));
314
extern C9error c9walk(C9ctx *c, C9tag *tag, C9fid fid, C9fid newfid, const char *path[]) __attribute__((nonnull(1, 2, 5)));
315
extern C9error c9open(C9ctx *c, C9tag *tag, C9fid fid, C9mode mode) __attribute__((nonnull(1, 2)));
316
extern C9error c9create(C9ctx *c, C9tag *tag, C9fid fid, const char *name, uint32_t perm, C9mode mode) __attribute__((nonnull(1, 2, 4)));
317
extern C9error c9read(C9ctx *c, C9tag *tag, C9fid fid, uint64_t offset, uint32_t count) __attribute__((nonnull(1, 2)));
318
extern C9error c9write(C9ctx *c, C9tag *tag, C9fid fid, uint64_t offset, const void *in, uint32_t count) __attribute__((nonnull(1, 2, 5)));
319
extern C9error c9wrstr(C9ctx *c, C9tag *tag, C9fid fid, const char *s) __attribute__((nonnull(1, 2, 4)));
320
extern C9error c9clunk(C9ctx *c, C9tag *tag, C9fid fid) __attribute__((nonnull(1, 2)));
321
extern C9error c9remove(C9ctx *c, C9tag *tag, C9fid fid) __attribute__((nonnull(1, 2)));
322
extern C9error c9stat(C9ctx *c, C9tag *tag, C9fid fid) __attribute__((nonnull(1, 2)));
323
extern C9error c9wstat(C9ctx *c, C9tag *tag, C9fid fid, const C9stat *s) __attribute__((nonnull(1, 2, 4)));
324
 
325
/*
326
 * Wait until a response comes and process it. If the function returns
327
 * any error, context must be treated as 'broken' and no subsequent calls
328
 * should be made without reinitialization (c9version).
329
 */
330
extern C9error c9proc(C9ctx *c) __attribute__((nonnull(1)));
331
 
332
extern C9error s9version(C9ctx *c) __attribute__((nonnull(1)));
333
extern C9error s9auth(C9ctx *c, C9tag tag, const C9qid *aqid) __attribute__((nonnull(1, 3)));
334
extern C9error s9error(C9ctx *c, C9tag tag, const char *err) __attribute__((nonnull(1)));
335
extern C9error s9attach(C9ctx *c, C9tag tag, const C9qid *qid) __attribute__((nonnull(1, 3)));
336
extern C9error s9flush(C9ctx *c, C9tag tag) __attribute__((nonnull(1)));
337
extern C9error s9walk(C9ctx *c, C9tag tag, const C9qid *qids[]) __attribute__((nonnull(1, 3)));
338
extern C9error s9open(C9ctx *c, C9tag tag, const C9qid *qid, uint32_t iounit) __attribute__((nonnull(1, 3)));
339
extern C9error s9create(C9ctx *c, C9tag tag, const C9qid *qid, uint32_t iounit) __attribute__((nonnull(1, 3)));
340
extern C9error s9read(C9ctx *c, C9tag tag, const void *data, uint32_t size) __attribute__((nonnull(1, 3)));
341
extern C9error s9readdir(C9ctx *c, C9tag tag, const C9stat *st[], int *num, uint64_t *offset, uint32_t size) __attribute__((nonnull(1, 3, 4)));
342
extern C9error s9write(C9ctx *c, C9tag tag, uint32_t size) __attribute__((nonnull(1)));
343
extern C9error s9clunk(C9ctx *c, C9tag tag) __attribute__((nonnull(1)));
344
extern C9error s9remove(C9ctx *c, C9tag tag) __attribute__((nonnull(1)));
345
extern C9error s9stat(C9ctx *c, C9tag tag, const C9stat *s) __attribute__((nonnull(1, 3)));
346
extern C9error s9wstat(C9ctx *c, C9tag tag) __attribute__((nonnull(1)));
347
 
348
extern C9error s9proc(C9ctx *c) __attribute__((nonnull(1)));