]> bbs.cooldavid.org Git - net-next-2.6.git/blob - fs/9p/9p.h
[PATCH] v9fs: new multiplexer implementation
[net-next-2.6.git] / fs / 9p / 9p.h
1 /*
2  * linux/fs/9p/9p.h
3  *
4  * 9P protocol definitions.
5  *
6  *  Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
7  *  Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to:
21  *  Free Software Foundation
22  *  51 Franklin Street, Fifth Floor
23  *  Boston, MA  02111-1301  USA
24  *
25  */
26
27 /* Message Types */
28 enum {
29         TVERSION = 100,
30         RVERSION,
31         TAUTH = 102,
32         RAUTH,
33         TATTACH = 104,
34         RATTACH,
35         TERROR = 106,
36         RERROR,
37         TFLUSH = 108,
38         RFLUSH,
39         TWALK = 110,
40         RWALK,
41         TOPEN = 112,
42         ROPEN,
43         TCREATE = 114,
44         RCREATE,
45         TREAD = 116,
46         RREAD,
47         TWRITE = 118,
48         RWRITE,
49         TCLUNK = 120,
50         RCLUNK,
51         TREMOVE = 122,
52         RREMOVE,
53         TSTAT = 124,
54         RSTAT,
55         TWSTAT = 126,
56         RWSTAT,
57 };
58
59 /* modes */
60 enum {
61         V9FS_OREAD = 0x00,
62         V9FS_OWRITE = 0x01,
63         V9FS_ORDWR = 0x02,
64         V9FS_OEXEC = 0x03,
65         V9FS_OEXCL = 0x04,
66         V9FS_OTRUNC = 0x10,
67         V9FS_OREXEC = 0x20,
68         V9FS_ORCLOSE = 0x40,
69         V9FS_OAPPEND = 0x80,
70 };
71
72 /* permissions */
73 enum {
74         V9FS_DMDIR = 0x80000000,
75         V9FS_DMAPPEND = 0x40000000,
76         V9FS_DMEXCL = 0x20000000,
77         V9FS_DMMOUNT = 0x10000000,
78         V9FS_DMAUTH = 0x08000000,
79         V9FS_DMTMP = 0x04000000,
80         V9FS_DMSYMLINK = 0x02000000,
81         V9FS_DMLINK = 0x01000000,
82         /* 9P2000.u extensions */
83         V9FS_DMDEVICE = 0x00800000,
84         V9FS_DMNAMEDPIPE = 0x00200000,
85         V9FS_DMSOCKET = 0x00100000,
86         V9FS_DMSETUID = 0x00080000,
87         V9FS_DMSETGID = 0x00040000,
88 };
89
90 /* qid.types */
91 enum {
92         V9FS_QTDIR = 0x80,
93         V9FS_QTAPPEND = 0x40,
94         V9FS_QTEXCL = 0x20,
95         V9FS_QTMOUNT = 0x10,
96         V9FS_QTAUTH = 0x08,
97         V9FS_QTTMP = 0x04,
98         V9FS_QTSYMLINK = 0x02,
99         V9FS_QTLINK = 0x01,
100         V9FS_QTFILE = 0x00,
101 };
102
103 #define V9FS_NOTAG      (u16)(~0)
104 #define V9FS_NOFID      (u32)(~0)
105
106 /* ample room for Twrite/Rread header (iounit) */
107 #define V9FS_IOHDRSZ    24
108
109 /* qids are the unique ID for a file (like an inode */
110 struct v9fs_qid {
111         u8 type;
112         u32 version;
113         u64 path;
114 };
115
116 /* Plan 9 file metadata (stat) structure */
117 struct v9fs_stat {
118         u16 size;
119         u16 type;
120         u32 dev;
121         struct v9fs_qid qid;
122         u32 mode;
123         u32 atime;
124         u32 mtime;
125         u64 length;
126         char *name;
127         char *uid;
128         char *gid;
129         char *muid;
130         char *extension;        /* 9p2000.u extensions */
131         u32 n_uid;              /* 9p2000.u extensions */
132         u32 n_gid;              /* 9p2000.u extensions */
133         u32 n_muid;             /* 9p2000.u extensions */
134         char data[0];
135 };
136
137 /* Structures for Protocol Operations */
138
139 struct Tversion {
140         u32 msize;
141         char *version;
142 };
143
144 struct Rversion {
145         u32 msize;
146         char *version;
147 };
148
149 struct Tauth {
150         u32 afid;
151         char *uname;
152         char *aname;
153 };
154
155 struct Rauth {
156         struct v9fs_qid qid;
157 };
158
159 struct Rerror {
160         char *error;
161         u32 errno;              /* 9p2000.u extension */
162 };
163
164 struct Tflush {
165         u32 oldtag;
166 };
167
168 struct Rflush {
169 };
170
171 struct Tattach {
172         u32 fid;
173         u32 afid;
174         char *uname;
175         char *aname;
176 };
177
178 struct Rattach {
179         struct v9fs_qid qid;
180 };
181
182 struct Twalk {
183         u32 fid;
184         u32 newfid;
185         u32 nwname;
186         char **wnames;
187 };
188
189 struct Rwalk {
190         u32 nwqid;
191         struct v9fs_qid *wqids;
192 };
193
194 struct Topen {
195         u32 fid;
196         u8 mode;
197 };
198
199 struct Ropen {
200         struct v9fs_qid qid;
201         u32 iounit;
202 };
203
204 struct Tcreate {
205         u32 fid;
206         char *name;
207         u32 perm;
208         u8 mode;
209 };
210
211 struct Rcreate {
212         struct v9fs_qid qid;
213         u32 iounit;
214 };
215
216 struct Tread {
217         u32 fid;
218         u64 offset;
219         u32 count;
220 };
221
222 struct Rread {
223         u32 count;
224         u8 *data;
225 };
226
227 struct Twrite {
228         u32 fid;
229         u64 offset;
230         u32 count;
231         u8 *data;
232 };
233
234 struct Rwrite {
235         u32 count;
236 };
237
238 struct Tclunk {
239         u32 fid;
240 };
241
242 struct Rclunk {
243 };
244
245 struct Tremove {
246         u32 fid;
247 };
248
249 struct Rremove {
250 };
251
252 struct Tstat {
253         u32 fid;
254 };
255
256 struct Rstat {
257         struct v9fs_stat *stat;
258 };
259
260 struct Twstat {
261         u32 fid;
262         struct v9fs_stat *stat;
263 };
264
265 struct Rwstat {
266 };
267
268 /*
269   * fcall is the primary packet structure
270   *
271   */
272
273 struct v9fs_fcall {
274         u32 size;
275         u8 id;
276         u16 tag;
277
278         union {
279                 struct Tversion tversion;
280                 struct Rversion rversion;
281                 struct Tauth tauth;
282                 struct Rauth rauth;
283                 struct Rerror rerror;
284                 struct Tflush tflush;
285                 struct Rflush rflush;
286                 struct Tattach tattach;
287                 struct Rattach rattach;
288                 struct Twalk twalk;
289                 struct Rwalk rwalk;
290                 struct Topen topen;
291                 struct Ropen ropen;
292                 struct Tcreate tcreate;
293                 struct Rcreate rcreate;
294                 struct Tread tread;
295                 struct Rread rread;
296                 struct Twrite twrite;
297                 struct Rwrite rwrite;
298                 struct Tclunk tclunk;
299                 struct Rclunk rclunk;
300                 struct Tremove tremove;
301                 struct Rremove rremove;
302                 struct Tstat tstat;
303                 struct Rstat rstat;
304                 struct Twstat twstat;
305                 struct Rwstat rwstat;
306         } params;
307 };
308
309 #define V9FS_FCALLHDRSZ (sizeof(struct v9fs_fcall) + \
310         sizeof(struct v9fs_stat) + 16*sizeof(struct v9fs_qid) + 16)
311
312 #define FCALL_ERROR(fcall) (fcall ? fcall->params.rerror.error : "")
313
314 int v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize,
315                    char *version, struct v9fs_fcall **rcall);
316
317 int v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname,
318                   u32 fid, u32 afid, struct v9fs_fcall **rcall);
319
320 int v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid);
321
322 int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 oldtag);
323
324 int v9fs_t_stat(struct v9fs_session_info *v9ses, u32 fid,
325                 struct v9fs_fcall **rcall);
326
327 int v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid,
328                  struct v9fs_stat *stat, struct v9fs_fcall **rcall);
329
330 int v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid,
331                 char *name, struct v9fs_fcall **rcall);
332
333 int v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode,
334                 struct v9fs_fcall **rcall);
335
336 int v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid,
337                   struct v9fs_fcall **rcall);
338
339 int v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name,
340                   u32 perm, u8 mode, struct v9fs_fcall **rcall);
341
342 int v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid,
343                 u64 offset, u32 count, struct v9fs_fcall **rcall);
344
345 int v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid, u64 offset,
346                  u32 count, void *data, struct v9fs_fcall **rcall);