blob: 2bb89b4005a1b8f7fbff962c9ed09a2f84b4611b [file] [log] [blame]
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -07001/*
2 * linux/fs/9p/9p.h
3 *
4 * 9P protocol definitions.
5 *
Latchesar Ionkov531b1092006-01-08 01:05:00 -08006 * Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net>
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -07007 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
8 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to:
22 * Free Software Foundation
23 * 51 Franklin Street, Fifth Floor
24 * Boston, MA 02111-1301 USA
25 *
26 */
27
28/* Message Types */
29enum {
30 TVERSION = 100,
31 RVERSION,
32 TAUTH = 102,
33 RAUTH,
34 TATTACH = 104,
35 RATTACH,
36 TERROR = 106,
37 RERROR,
38 TFLUSH = 108,
39 RFLUSH,
40 TWALK = 110,
41 RWALK,
42 TOPEN = 112,
43 ROPEN,
44 TCREATE = 114,
45 RCREATE,
46 TREAD = 116,
47 RREAD,
48 TWRITE = 118,
49 RWRITE,
50 TCLUNK = 120,
51 RCLUNK,
52 TREMOVE = 122,
53 RREMOVE,
54 TSTAT = 124,
55 RSTAT,
56 TWSTAT = 126,
57 RWSTAT,
58};
59
60/* modes */
61enum {
62 V9FS_OREAD = 0x00,
63 V9FS_OWRITE = 0x01,
64 V9FS_ORDWR = 0x02,
65 V9FS_OEXEC = 0x03,
66 V9FS_OEXCL = 0x04,
67 V9FS_OTRUNC = 0x10,
68 V9FS_OREXEC = 0x20,
69 V9FS_ORCLOSE = 0x40,
70 V9FS_OAPPEND = 0x80,
71};
72
73/* permissions */
74enum {
75 V9FS_DMDIR = 0x80000000,
76 V9FS_DMAPPEND = 0x40000000,
77 V9FS_DMEXCL = 0x20000000,
78 V9FS_DMMOUNT = 0x10000000,
79 V9FS_DMAUTH = 0x08000000,
80 V9FS_DMTMP = 0x04000000,
81 V9FS_DMSYMLINK = 0x02000000,
82 V9FS_DMLINK = 0x01000000,
83 /* 9P2000.u extensions */
84 V9FS_DMDEVICE = 0x00800000,
85 V9FS_DMNAMEDPIPE = 0x00200000,
86 V9FS_DMSOCKET = 0x00100000,
87 V9FS_DMSETUID = 0x00080000,
88 V9FS_DMSETGID = 0x00040000,
89};
90
91/* qid.types */
92enum {
93 V9FS_QTDIR = 0x80,
94 V9FS_QTAPPEND = 0x40,
95 V9FS_QTEXCL = 0x20,
96 V9FS_QTMOUNT = 0x10,
97 V9FS_QTAUTH = 0x08,
98 V9FS_QTTMP = 0x04,
99 V9FS_QTSYMLINK = 0x02,
100 V9FS_QTLINK = 0x01,
101 V9FS_QTFILE = 0x00,
102};
103
Latchesar Ionkov3cf64292006-01-08 01:04:58 -0800104#define V9FS_NOTAG (u16)(~0)
105#define V9FS_NOFID (u32)(~0)
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800106#define V9FS_MAXWELEM 16
Latchesar Ionkov3cf64292006-01-08 01:04:58 -0800107
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700108/* ample room for Twrite/Rread header (iounit) */
109#define V9FS_IOHDRSZ 24
110
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800111struct v9fs_str {
112 u16 len;
113 char *str;
114};
115
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700116/* qids are the unique ID for a file (like an inode */
117struct v9fs_qid {
118 u8 type;
119 u32 version;
120 u64 path;
121};
122
123/* Plan 9 file metadata (stat) structure */
124struct v9fs_stat {
125 u16 size;
126 u16 type;
127 u32 dev;
128 struct v9fs_qid qid;
129 u32 mode;
130 u32 atime;
131 u32 mtime;
132 u64 length;
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800133 struct v9fs_str name;
134 struct v9fs_str uid;
135 struct v9fs_str gid;
136 struct v9fs_str muid;
137 struct v9fs_str extension; /* 9p2000.u extensions */
138 u32 n_uid; /* 9p2000.u extensions */
139 u32 n_gid; /* 9p2000.u extensions */
140 u32 n_muid; /* 9p2000.u extensions */
141};
142
143/* file metadata (stat) structure used to create Twstat message
144 The is similar to v9fs_stat, but the strings don't point to
145 the same memory block and should be freed separately
146*/
147struct v9fs_wstat {
148 u16 size;
149 u16 type;
150 u32 dev;
151 struct v9fs_qid qid;
152 u32 mode;
153 u32 atime;
154 u32 mtime;
155 u64 length;
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700156 char *name;
157 char *uid;
158 char *gid;
159 char *muid;
160 char *extension; /* 9p2000.u extensions */
161 u32 n_uid; /* 9p2000.u extensions */
162 u32 n_gid; /* 9p2000.u extensions */
163 u32 n_muid; /* 9p2000.u extensions */
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700164};
165
166/* Structures for Protocol Operations */
167
168struct Tversion {
169 u32 msize;
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800170 struct v9fs_str version;
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700171};
172
173struct Rversion {
174 u32 msize;
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800175 struct v9fs_str version;
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700176};
177
178struct Tauth {
179 u32 afid;
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800180 struct v9fs_str uname;
181 struct v9fs_str aname;
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700182};
183
184struct Rauth {
185 struct v9fs_qid qid;
186};
187
188struct Rerror {
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800189 struct v9fs_str error;
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700190 u32 errno; /* 9p2000.u extension */
191};
192
193struct Tflush {
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800194 u16 oldtag;
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700195};
196
197struct Rflush {
198};
199
200struct Tattach {
201 u32 fid;
202 u32 afid;
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800203 struct v9fs_str uname;
204 struct v9fs_str aname;
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700205};
206
207struct Rattach {
208 struct v9fs_qid qid;
209};
210
211struct Twalk {
212 u32 fid;
213 u32 newfid;
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800214 u16 nwname;
215 struct v9fs_str wnames[16];
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700216};
217
218struct Rwalk {
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800219 u16 nwqid;
220 struct v9fs_qid wqids[16];
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700221};
222
223struct Topen {
224 u32 fid;
225 u8 mode;
226};
227
228struct Ropen {
229 struct v9fs_qid qid;
230 u32 iounit;
231};
232
233struct Tcreate {
234 u32 fid;
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800235 struct v9fs_str name;
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700236 u32 perm;
237 u8 mode;
Latchesar Ionkov16cce6d2006-03-25 03:07:26 -0800238 struct v9fs_str extension;
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700239};
240
241struct Rcreate {
242 struct v9fs_qid qid;
243 u32 iounit;
244};
245
246struct Tread {
247 u32 fid;
248 u64 offset;
249 u32 count;
250};
251
252struct Rread {
253 u32 count;
254 u8 *data;
255};
256
257struct Twrite {
258 u32 fid;
259 u64 offset;
260 u32 count;
261 u8 *data;
262};
263
264struct Rwrite {
265 u32 count;
266};
267
268struct Tclunk {
269 u32 fid;
270};
271
272struct Rclunk {
273};
274
275struct Tremove {
276 u32 fid;
277};
278
279struct Rremove {
280};
281
282struct Tstat {
283 u32 fid;
284};
285
286struct Rstat {
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800287 struct v9fs_stat stat;
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700288};
289
290struct Twstat {
291 u32 fid;
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800292 struct v9fs_stat stat;
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700293};
294
295struct Rwstat {
296};
297
298/*
299 * fcall is the primary packet structure
300 *
301 */
302
303struct v9fs_fcall {
304 u32 size;
305 u8 id;
306 u16 tag;
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800307 void *sdata;
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700308
309 union {
310 struct Tversion tversion;
311 struct Rversion rversion;
312 struct Tauth tauth;
313 struct Rauth rauth;
314 struct Rerror rerror;
315 struct Tflush tflush;
316 struct Rflush rflush;
317 struct Tattach tattach;
318 struct Rattach rattach;
319 struct Twalk twalk;
320 struct Rwalk rwalk;
321 struct Topen topen;
322 struct Ropen ropen;
323 struct Tcreate tcreate;
324 struct Rcreate rcreate;
325 struct Tread tread;
326 struct Rread rread;
327 struct Twrite twrite;
328 struct Rwrite rwrite;
329 struct Tclunk tclunk;
330 struct Rclunk rclunk;
331 struct Tremove tremove;
332 struct Rremove rremove;
333 struct Tstat tstat;
334 struct Rstat rstat;
335 struct Twstat twstat;
336 struct Rwstat rwstat;
337 } params;
338};
339
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800340#define PRINT_FCALL_ERROR(s, fcall) dprintk(DEBUG_ERROR, "%s: %.*s\n", s, \
341 fcall?fcall->params.rerror.error.len:0, \
342 fcall?fcall->params.rerror.error.str:"");
Latchesar Ionkov3cf64292006-01-08 01:04:58 -0800343
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700344int v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize,
345 char *version, struct v9fs_fcall **rcall);
346
347int v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname,
348 u32 fid, u32 afid, struct v9fs_fcall **rcall);
349
Latchesar Ionkov3cf64292006-01-08 01:04:58 -0800350int v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid);
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700351
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700352int v9fs_t_stat(struct v9fs_session_info *v9ses, u32 fid,
353 struct v9fs_fcall **rcall);
354
355int v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid,
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800356 struct v9fs_wstat *wstat, struct v9fs_fcall **rcall);
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700357
358int v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid,
359 char *name, struct v9fs_fcall **rcall);
360
361int v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode,
362 struct v9fs_fcall **rcall);
363
364int v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid,
365 struct v9fs_fcall **rcall);
366
367int v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name,
Latchesar Ionkov16cce6d2006-03-25 03:07:26 -0800368 u32 perm, u8 mode, char *extension, struct v9fs_fcall **rcall);
Eric Van Hensbergenb8cf9452005-09-09 13:04:21 -0700369
370int v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid,
371 u64 offset, u32 count, struct v9fs_fcall **rcall);
372
373int v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid, u64 offset,
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800374 u32 count, const char __user * data,
375 struct v9fs_fcall **rcall);
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800376int v9fs_printfcall(char *, int, struct v9fs_fcall *, int);