]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/net/9p/9p.h
fs/9p: Pass the correct user credentials during attach
[mirror_ubuntu-bionic-kernel.git] / include / net / 9p / 9p.h
CommitLineData
bd238fb4
LI
1/*
2 * include/net/9p/9p.h
3 *
4 * 9P protocol definitions.
5 *
6 * Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net>
7 * 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 version 2
12 * as published by the Free Software Foundation.
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#ifndef NET_9P_H
28#define NET_9P_H
29
ee443996
EVH
30/**
31 * enum p9_debug_flags - bits for mount time debug parameter
32 * @P9_DEBUG_ERROR: more verbose error messages including original error string
33 * @P9_DEBUG_9P: 9P protocol tracing
34 * @P9_DEBUG_VFS: VFS API tracing
35 * @P9_DEBUG_CONV: protocol conversion tracing
36 * @P9_DEBUG_MUX: trace management of concurrent transactions
37 * @P9_DEBUG_TRANS: transport tracing
38 * @P9_DEBUG_SLABS: memory management tracing
39 * @P9_DEBUG_FCALL: verbose dump of protocol messages
51a87c55 40 * @P9_DEBUG_FID: fid allocation/deallocation tracking
60e78d2c
AK
41 * @P9_DEBUG_PKT: packet marshalling/unmarshalling
42 * @P9_DEBUG_FSC: FS-cache tracing
ee443996
EVH
43 *
44 * These flags are passed at mount time to turn on various levels of
45 * verbosity and tracing which will be output to the system logs.
46 */
47
48enum p9_debug_flags {
49 P9_DEBUG_ERROR = (1<<0),
50 P9_DEBUG_9P = (1<<2),
51 P9_DEBUG_VFS = (1<<3),
52 P9_DEBUG_CONV = (1<<4),
53 P9_DEBUG_MUX = (1<<5),
54 P9_DEBUG_TRANS = (1<<6),
55 P9_DEBUG_SLABS = (1<<7),
56 P9_DEBUG_FCALL = (1<<8),
51a87c55 57 P9_DEBUG_FID = (1<<9),
e7f4b8f1 58 P9_DEBUG_PKT = (1<<10),
60e78d2c 59 P9_DEBUG_FSC = (1<<11),
ee443996 60};
bd238fb4 61
0b15a3a5 62#ifdef CONFIG_NET_9P_DEBUG
bd238fb4
LI
63extern unsigned int p9_debug_level;
64
65#define P9_DPRINTK(level, format, arg...) \
66do { \
02da398b
EVH
67 if ((p9_debug_level & level) == level) {\
68 if (level == P9_DEBUG_9P) \
69 printk(KERN_NOTICE "(%8.8d) " \
70 format , task_pid_nr(current) , ## arg); \
71 else \
72 printk(KERN_NOTICE "-- %s (%d): " \
73 format , __func__, task_pid_nr(current) , ## arg); \
74 } \
bd238fb4
LI
75} while (0)
76
bd238fb4
LI
77#else
78#define P9_DPRINTK(level, format, arg...) do { } while (0)
bd238fb4
LI
79#endif
80
81#define P9_EPRINTK(level, format, arg...) \
82do { \
83 printk(level "9p: %s (%d): " \
d5c003b4 84 format , __func__, task_pid_nr(current), ## arg); \
bd238fb4
LI
85} while (0)
86
ee443996
EVH
87/**
88 * enum p9_msg_t - 9P message types
bda8e775
SK
89 * @P9_TSTATFS: file system status request
90 * @P9_RSTATFS: file system status response
4681dbda
SK
91 * @P9_TRENAME: rename request
92 * @P9_RRENAME: rename response
ee443996
EVH
93 * @P9_TVERSION: version handshake request
94 * @P9_RVERSION: version handshake response
95 * @P9_TAUTH: request to establish authentication channel
96 * @P9_RAUTH: response with authentication information
97 * @P9_TATTACH: establish user access to file service
98 * @P9_RATTACH: response with top level handle to file hierarchy
99 * @P9_TERROR: not used
100 * @P9_RERROR: response for any failed request
101 * @P9_TFLUSH: request to abort a previous request
102 * @P9_RFLUSH: response when previous request has been cancelled
103 * @P9_TWALK: descend a directory hierarchy
104 * @P9_RWALK: response with new handle for position within hierarchy
105 * @P9_TOPEN: prepare a handle for I/O on an existing file
106 * @P9_ROPEN: response with file access information
107 * @P9_TCREATE: prepare a handle for I/O on a new file
108 * @P9_RCREATE: response with file access information
109 * @P9_TREAD: request to transfer data from a file or directory
110 * @P9_RREAD: response with data requested
111 * @P9_TWRITE: reuqest to transfer data to a file
112 * @P9_RWRITE: response with out much data was transfered to file
113 * @P9_TCLUNK: forget about a handle to an entity within the file system
114 * @P9_RCLUNK: response when server has forgotten about the handle
115 * @P9_TREMOVE: request to remove an entity from the hierarchy
116 * @P9_RREMOVE: response when server has removed the entity
117 * @P9_TSTAT: request file entity attributes
118 * @P9_RSTAT: response with file entity attributes
119 * @P9_TWSTAT: request to update file entity attributes
120 * @P9_RWSTAT: response when file entity attributes are updated
121 *
122 * There are 14 basic operations in 9P2000, paired as
123 * requests and responses. The one special case is ERROR
124 * as there is no @P9_TERROR request for clients to transmit to
125 * the server, but the server may respond to any other request
126 * with an @P9_RERROR.
127 *
128 * See Also: http://plan9.bell-labs.com/sys/man/5/INDEX.html
129 */
bd238fb4 130
ee443996 131enum p9_msg_t {
bda8e775
SK
132 P9_TSTATFS = 8,
133 P9_RSTATFS,
4681dbda
SK
134 P9_TRENAME = 20,
135 P9_RRENAME,
7751bdb3
SK
136 P9_TREADDIR = 40,
137 P9_RREADDIR,
bd238fb4
LI
138 P9_TVERSION = 100,
139 P9_RVERSION,
140 P9_TAUTH = 102,
141 P9_RAUTH,
142 P9_TATTACH = 104,
143 P9_RATTACH,
144 P9_TERROR = 106,
145 P9_RERROR,
146 P9_TFLUSH = 108,
147 P9_RFLUSH,
148 P9_TWALK = 110,
149 P9_RWALK,
150 P9_TOPEN = 112,
151 P9_ROPEN,
152 P9_TCREATE = 114,
153 P9_RCREATE,
154 P9_TREAD = 116,
155 P9_RREAD,
156 P9_TWRITE = 118,
157 P9_RWRITE,
158 P9_TCLUNK = 120,
159 P9_RCLUNK,
160 P9_TREMOVE = 122,
161 P9_RREMOVE,
162 P9_TSTAT = 124,
163 P9_RSTAT,
164 P9_TWSTAT = 126,
165 P9_RWSTAT,
166};
167
ee443996
EVH
168/**
169 * enum p9_open_mode_t - 9P open modes
170 * @P9_OREAD: open file for reading only
171 * @P9_OWRITE: open file for writing only
172 * @P9_ORDWR: open file for reading or writing
173 * @P9_OEXEC: open file for execution
174 * @P9_OTRUNC: truncate file to zero-length before opening it
175 * @P9_OREXEC: close the file when an exec(2) system call is made
176 * @P9_ORCLOSE: remove the file when the file is closed
177 * @P9_OAPPEND: open the file and seek to the end
178 * @P9_OEXCL: only create a file, do not open it
179 *
180 * 9P open modes differ slightly from Posix standard modes.
181 * In particular, there are extra modes which specify different
182 * semantic behaviors than may be available on standard Posix
183 * systems. For example, @P9_OREXEC and @P9_ORCLOSE are modes that
184 * most likely will not be issued from the Linux VFS client, but may
185 * be supported by servers.
186 *
187 * See Also: http://plan9.bell-labs.com/magic/man2html/2/open
188 */
189
190enum p9_open_mode_t {
bd238fb4
LI
191 P9_OREAD = 0x00,
192 P9_OWRITE = 0x01,
193 P9_ORDWR = 0x02,
194 P9_OEXEC = 0x03,
bd238fb4
LI
195 P9_OTRUNC = 0x10,
196 P9_OREXEC = 0x20,
197 P9_ORCLOSE = 0x40,
198 P9_OAPPEND = 0x80,
ee443996
EVH
199 P9_OEXCL = 0x1000,
200};
201
202/**
203 * enum p9_perm_t - 9P permissions
204 * @P9_DMDIR: mode bite for directories
205 * @P9_DMAPPEND: mode bit for is append-only
206 * @P9_DMEXCL: mode bit for excluse use (only one open handle allowed)
207 * @P9_DMMOUNT: mode bite for mount points
208 * @P9_DMAUTH: mode bit for authentication file
209 * @P9_DMTMP: mode bit for non-backed-up files
210 * @P9_DMSYMLINK: mode bit for symbolic links (9P2000.u)
211 * @P9_DMLINK: mode bit for hard-link (9P2000.u)
212 * @P9_DMDEVICE: mode bit for device files (9P2000.u)
213 * @P9_DMNAMEDPIPE: mode bit for named pipe (9P2000.u)
214 * @P9_DMSOCKET: mode bit for socket (9P2000.u)
215 * @P9_DMSETUID: mode bit for setuid (9P2000.u)
216 * @P9_DMSETGID: mode bit for setgid (9P2000.u)
217 * @P9_DMSETVTX: mode bit for sticky bit (9P2000.u)
218 *
219 * 9P permissions differ slightly from Posix standard modes.
220 *
221 * See Also: http://plan9.bell-labs.com/magic/man2html/2/stat
222 */
223enum p9_perm_t {
bd238fb4
LI
224 P9_DMDIR = 0x80000000,
225 P9_DMAPPEND = 0x40000000,
226 P9_DMEXCL = 0x20000000,
227 P9_DMMOUNT = 0x10000000,
228 P9_DMAUTH = 0x08000000,
229 P9_DMTMP = 0x04000000,
ee443996 230/* 9P2000.u extensions */
bd238fb4
LI
231 P9_DMSYMLINK = 0x02000000,
232 P9_DMLINK = 0x01000000,
bd238fb4
LI
233 P9_DMDEVICE = 0x00800000,
234 P9_DMNAMEDPIPE = 0x00200000,
235 P9_DMSOCKET = 0x00100000,
236 P9_DMSETUID = 0x00080000,
237 P9_DMSETGID = 0x00040000,
d199d652 238 P9_DMSETVTX = 0x00010000,
bd238fb4
LI
239};
240
ee443996
EVH
241/**
242 * enum p9_qid_t - QID types
243 * @P9_QTDIR: directory
244 * @P9_QTAPPEND: append-only
245 * @P9_QTEXCL: excluse use (only one open handle allowed)
246 * @P9_QTMOUNT: mount points
247 * @P9_QTAUTH: authentication file
248 * @P9_QTTMP: non-backed-up files
249 * @P9_QTSYMLINK: symbolic links (9P2000.u)
250 * @P9_QTLINK: hard-link (9P2000.u)
251 * @P9_QTFILE: normal files
252 *
253 * QID types are a subset of permissions - they are primarily
254 * used to differentiate semantics for a file system entity via
255 * a jump-table. Their value is also the most signifigant 16 bits
256 * of the permission_t
257 *
258 * See Also: http://plan9.bell-labs.com/magic/man2html/2/stat
259 */
260enum p9_qid_t {
bd238fb4
LI
261 P9_QTDIR = 0x80,
262 P9_QTAPPEND = 0x40,
263 P9_QTEXCL = 0x20,
264 P9_QTMOUNT = 0x10,
265 P9_QTAUTH = 0x08,
266 P9_QTTMP = 0x04,
267 P9_QTSYMLINK = 0x02,
268 P9_QTLINK = 0x01,
269 P9_QTFILE = 0x00,
270};
271
ee443996 272/* 9P Magic Numbers */
bd238fb4
LI
273#define P9_NOTAG (u16)(~0)
274#define P9_NOFID (u32)(~0)
275#define P9_MAXWELEM 16
276
277/* ample room for Twrite/Rread header */
278#define P9_IOHDRSZ 24
279
7751bdb3
SK
280/* Room for readdir header */
281#define P9_READDIRHDRSZ 24
282
ee443996
EVH
283/**
284 * struct p9_str - length prefixed string type
285 * @len: length of the string
286 * @str: the string
287 *
288 * The protocol uses length prefixed strings for all
289 * string data, so we replicate that for our internal
290 * string members.
291 */
292
bd238fb4
LI
293struct p9_str {
294 u16 len;
295 char *str;
296};
297
ee443996
EVH
298/**
299 * struct p9_qid - file system entity information
300 * @type: 8-bit type &p9_qid_t
301 * @version: 16-bit monotonically incrementing version number
302 * @path: 64-bit per-server-unique ID for a file system element
303 *
304 * qids are identifiers used by 9P servers to track file system
305 * entities. The type is used to differentiate semantics for operations
306 * on the entity (ie. read means something different on a directory than
307 * on a file). The path provides a server unique index for an entity
308 * (roughly analogous to an inode number), while the version is updated
309 * every time a file is modified and can be used to maintain cache
310 * coherency between clients and serves.
311 * Servers will often differentiate purely synthetic entities by setting
312 * their version to 0, signaling that they should never be cached and
313 * should be accessed synchronously.
314 *
315 * See Also://plan9.bell-labs.com/magic/man2html/2/stat
316 */
317
bd238fb4
LI
318struct p9_qid {
319 u8 type;
320 u32 version;
321 u64 path;
322};
323
ee443996
EVH
324/**
325 * struct p9_stat - file system metadata information
326 * @size: length prefix for this stat structure instance
327 * @type: the type of the server (equivilent to a major number)
328 * @dev: the sub-type of the server (equivilent to a minor number)
329 * @qid: unique id from the server of type &p9_qid
330 * @mode: Plan 9 format permissions of type &p9_perm_t
331 * @atime: Last access/read time
332 * @mtime: Last modify/write time
333 * @length: file length
334 * @name: last element of path (aka filename) in type &p9_str
335 * @uid: owner name in type &p9_str
336 * @gid: group owner in type &p9_str
337 * @muid: last modifier in type &p9_str
338 * @extension: area used to encode extended UNIX support in type &p9_str
339 * @n_uid: numeric user id of owner (part of 9p2000.u extension)
340 * @n_gid: numeric group id (part of 9p2000.u extension)
341 * @n_muid: numeric user id of laster modifier (part of 9p2000.u extension)
342 *
343 * See Also: http://plan9.bell-labs.com/magic/man2html/2/stat
344 */
345
bd238fb4
LI
346struct p9_wstat {
347 u16 size;
348 u16 type;
349 u32 dev;
350 struct p9_qid qid;
351 u32 mode;
352 u32 atime;
353 u32 mtime;
354 u64 length;
355 char *name;
356 char *uid;
357 char *gid;
358 char *muid;
359 char *extension; /* 9p2000.u extensions */
360 u32 n_uid; /* 9p2000.u extensions */
361 u32 n_gid; /* 9p2000.u extensions */
362 u32 n_muid; /* 9p2000.u extensions */
363};
364
365/* Structures for Protocol Operations */
bda8e775
SK
366struct p9_tstatfs {
367 u32 fid;
368};
369
370struct p9_rstatfs {
371 u32 type;
372 u32 bsize;
373 u64 blocks;
374 u64 bfree;
375 u64 bavail;
376 u64 files;
377 u64 ffree;
378 u64 fsid;
379 u32 namelen;
380};
381
4681dbda
SK
382struct p9_trename {
383 u32 fid;
384 u32 newdirfid;
385 struct p9_str name;
386};
387
388struct p9_rrename {
389};
390
bd238fb4
LI
391struct p9_tversion {
392 u32 msize;
393 struct p9_str version;
394};
395
396struct p9_rversion {
397 u32 msize;
398 struct p9_str version;
399};
400
401struct p9_tauth {
402 u32 afid;
403 struct p9_str uname;
404 struct p9_str aname;
ba17674f 405 u32 n_uname; /* 9P2000.u extensions */
bd238fb4
LI
406};
407
408struct p9_rauth {
409 struct p9_qid qid;
410};
411
412struct p9_rerror {
413 struct p9_str error;
414 u32 errno; /* 9p2000.u extension */
415};
416
417struct p9_tflush {
418 u16 oldtag;
419};
420
421struct p9_rflush {
422};
423
424struct p9_tattach {
425 u32 fid;
426 u32 afid;
427 struct p9_str uname;
428 struct p9_str aname;
ba17674f 429 u32 n_uname; /* 9P2000.u extensions */
bd238fb4
LI
430};
431
432struct p9_rattach {
433 struct p9_qid qid;
434};
435
436struct p9_twalk {
437 u32 fid;
438 u32 newfid;
439 u16 nwname;
440 struct p9_str wnames[16];
441};
442
443struct p9_rwalk {
444 u16 nwqid;
445 struct p9_qid wqids[16];
446};
447
448struct p9_topen {
449 u32 fid;
450 u8 mode;
451};
452
453struct p9_ropen {
454 struct p9_qid qid;
455 u32 iounit;
456};
457
458struct p9_tcreate {
459 u32 fid;
460 struct p9_str name;
461 u32 perm;
462 u8 mode;
463 struct p9_str extension;
464};
465
466struct p9_rcreate {
467 struct p9_qid qid;
468 u32 iounit;
469};
470
471struct p9_tread {
472 u32 fid;
473 u64 offset;
474 u32 count;
475};
476
477struct p9_rread {
478 u32 count;
479 u8 *data;
480};
481
482struct p9_twrite {
483 u32 fid;
484 u64 offset;
485 u32 count;
486 u8 *data;
487};
488
489struct p9_rwrite {
490 u32 count;
491};
492
7751bdb3
SK
493struct p9_treaddir {
494 u32 fid;
495 u64 offset;
496 u32 count;
497};
498
499struct p9_rreaddir {
500 u32 count;
501 u8 *data;
502};
503
504
bd238fb4
LI
505struct p9_tclunk {
506 u32 fid;
507};
508
509struct p9_rclunk {
510};
511
512struct p9_tremove {
513 u32 fid;
514};
515
516struct p9_rremove {
517};
518
519struct p9_tstat {
520 u32 fid;
521};
522
523struct p9_rstat {
02da398b 524 struct p9_wstat stat;
bd238fb4
LI
525};
526
527struct p9_twstat {
528 u32 fid;
02da398b 529 struct p9_wstat stat;
bd238fb4
LI
530};
531
532struct p9_rwstat {
533};
534
ee443996
EVH
535/**
536 * struct p9_fcall - primary packet structure
537 * @size: prefixed length of the structure
538 * @id: protocol operating identifier of type &p9_msg_t
539 * @tag: transaction id of the request
ace51c4d
EVH
540 * @offset: used by marshalling routines to track currentposition in buffer
541 * @capacity: used by marshalling routines to track total capacity
ee443996 542 * @sdata: payload
ee443996
EVH
543 *
544 * &p9_fcall represents the structure for all 9P RPC
545 * transactions. Requests are packaged into fcalls, and reponses
546 * must be extracted from them.
547 *
548 * See Also: http://plan9.bell-labs.com/magic/man2html/2/fcall
549 */
bd238fb4
LI
550
551struct p9_fcall {
552 u32 size;
553 u8 id;
554 u16 tag;
ace51c4d
EVH
555
556 size_t offset;
557 size_t capacity;
558
559 uint8_t *sdata;
bd238fb4
LI
560};
561
562struct p9_idpool;
563
bd238fb4
LI
564int p9_errstr2errno(char *errstr, int len);
565
566struct p9_idpool *p9_idpool_create(void);
567void p9_idpool_destroy(struct p9_idpool *);
568int p9_idpool_get(struct p9_idpool *p);
569void p9_idpool_put(int id, struct p9_idpool *p);
570int p9_idpool_check(int id, struct p9_idpool *p);
571
572int p9_error_init(void);
573int p9_errstr2errno(char *, int);
887b3ece 574int p9_trans_fd_init(void);
72029fe8 575void p9_trans_fd_exit(void);
bd238fb4 576#endif /* NET_9P_H */