1fe8e6c1cSAndre Przywara /*
2fe8e6c1cSAndre Przywara * include/net/9p/9p.h
3fe8e6c1cSAndre Przywara *
4fe8e6c1cSAndre Przywara * 9P protocol definitions.
5fe8e6c1cSAndre Przywara *
6fe8e6c1cSAndre Przywara * Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net>
7fe8e6c1cSAndre Przywara * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
8fe8e6c1cSAndre Przywara * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
9fe8e6c1cSAndre Przywara *
10fe8e6c1cSAndre Przywara * This program is free software; you can redistribute it and/or modify
11fe8e6c1cSAndre Przywara * it under the terms of the GNU General Public License version 2
12fe8e6c1cSAndre Przywara * as published by the Free Software Foundation.
13fe8e6c1cSAndre Przywara *
14fe8e6c1cSAndre Przywara * This program is distributed in the hope that it will be useful,
15fe8e6c1cSAndre Przywara * but WITHOUT ANY WARRANTY; without even the implied warranty of
16fe8e6c1cSAndre Przywara * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17fe8e6c1cSAndre Przywara * GNU General Public License for more details.
18fe8e6c1cSAndre Przywara *
19fe8e6c1cSAndre Przywara * You should have received a copy of the GNU General Public License
20fe8e6c1cSAndre Przywara * along with this program; if not, write to:
21fe8e6c1cSAndre Przywara * Free Software Foundation
22fe8e6c1cSAndre Przywara * 51 Franklin Street, Fifth Floor
23fe8e6c1cSAndre Przywara * Boston, MA 02111-1301 USA
24fe8e6c1cSAndre Przywara *
25fe8e6c1cSAndre Przywara */
26fe8e6c1cSAndre Przywara
27fe8e6c1cSAndre Przywara #ifndef NET_9P_H
28fe8e6c1cSAndre Przywara #define NET_9P_H
29fe8e6c1cSAndre Przywara
30*c6cb7c75SAndre Przywara /* These definitions are from Linux include/linux/uidgid.h */
31*c6cb7c75SAndre Przywara typedef struct {
32*c6cb7c75SAndre Przywara uid_t val;
33*c6cb7c75SAndre Przywara } kuid_t;
34*c6cb7c75SAndre Przywara
35*c6cb7c75SAndre Przywara typedef struct {
36*c6cb7c75SAndre Przywara gid_t val;
37*c6cb7c75SAndre Przywara } kgid_t;
38*c6cb7c75SAndre Przywara
39*c6cb7c75SAndre Przywara #define KUIDT_INIT(value) (kuid_t){ value }
40*c6cb7c75SAndre Przywara #define KGIDT_INIT(value) (kgid_t){ value }
41*c6cb7c75SAndre Przywara
__kuid_val(kuid_t uid)42*c6cb7c75SAndre Przywara static inline uid_t __kuid_val(kuid_t uid)
43*c6cb7c75SAndre Przywara {
44*c6cb7c75SAndre Przywara return uid.val;
45*c6cb7c75SAndre Przywara }
46*c6cb7c75SAndre Przywara
__kgid_val(kgid_t gid)47*c6cb7c75SAndre Przywara static inline gid_t __kgid_val(kgid_t gid)
48*c6cb7c75SAndre Przywara {
49*c6cb7c75SAndre Przywara return gid.val;
50*c6cb7c75SAndre Przywara }
51*c6cb7c75SAndre Przywara
52*c6cb7c75SAndre Przywara
53fe8e6c1cSAndre Przywara /**
54fe8e6c1cSAndre Przywara * enum p9_debug_flags - bits for mount time debug parameter
55fe8e6c1cSAndre Przywara * @P9_DEBUG_ERROR: more verbose error messages including original error string
56fe8e6c1cSAndre Przywara * @P9_DEBUG_9P: 9P protocol tracing
57fe8e6c1cSAndre Przywara * @P9_DEBUG_VFS: VFS API tracing
58fe8e6c1cSAndre Przywara * @P9_DEBUG_CONV: protocol conversion tracing
59fe8e6c1cSAndre Przywara * @P9_DEBUG_MUX: trace management of concurrent transactions
60fe8e6c1cSAndre Przywara * @P9_DEBUG_TRANS: transport tracing
61fe8e6c1cSAndre Przywara * @P9_DEBUG_SLABS: memory management tracing
62fe8e6c1cSAndre Przywara * @P9_DEBUG_FCALL: verbose dump of protocol messages
63fe8e6c1cSAndre Przywara * @P9_DEBUG_FID: fid allocation/deallocation tracking
64fe8e6c1cSAndre Przywara * @P9_DEBUG_PKT: packet marshalling/unmarshalling
65fe8e6c1cSAndre Przywara * @P9_DEBUG_FSC: FS-cache tracing
66fe8e6c1cSAndre Przywara * @P9_DEBUG_VPKT: Verbose packet debugging (full packet dump)
67fe8e6c1cSAndre Przywara *
68fe8e6c1cSAndre Przywara * These flags are passed at mount time to turn on various levels of
69fe8e6c1cSAndre Przywara * verbosity and tracing which will be output to the system logs.
70fe8e6c1cSAndre Przywara */
71fe8e6c1cSAndre Przywara
72fe8e6c1cSAndre Przywara enum p9_debug_flags {
73fe8e6c1cSAndre Przywara P9_DEBUG_ERROR = (1<<0),
74fe8e6c1cSAndre Przywara P9_DEBUG_9P = (1<<2),
75fe8e6c1cSAndre Przywara P9_DEBUG_VFS = (1<<3),
76fe8e6c1cSAndre Przywara P9_DEBUG_CONV = (1<<4),
77fe8e6c1cSAndre Przywara P9_DEBUG_MUX = (1<<5),
78fe8e6c1cSAndre Przywara P9_DEBUG_TRANS = (1<<6),
79fe8e6c1cSAndre Przywara P9_DEBUG_SLABS = (1<<7),
80fe8e6c1cSAndre Przywara P9_DEBUG_FCALL = (1<<8),
81fe8e6c1cSAndre Przywara P9_DEBUG_FID = (1<<9),
82fe8e6c1cSAndre Przywara P9_DEBUG_PKT = (1<<10),
83fe8e6c1cSAndre Przywara P9_DEBUG_FSC = (1<<11),
84fe8e6c1cSAndre Przywara P9_DEBUG_VPKT = (1<<12),
85fe8e6c1cSAndre Przywara };
86fe8e6c1cSAndre Przywara
87fe8e6c1cSAndre Przywara #ifdef CONFIG_NET_9P_DEBUG
88fe8e6c1cSAndre Przywara extern unsigned int p9_debug_level;
89fe8e6c1cSAndre Przywara __printf(3, 4)
90fe8e6c1cSAndre Przywara void _p9_debug(enum p9_debug_flags level, const char *func,
91fe8e6c1cSAndre Przywara const char *fmt, ...);
92fe8e6c1cSAndre Przywara #define p9_debug(level, fmt, ...) \
93fe8e6c1cSAndre Przywara _p9_debug(level, __func__, fmt, ##__VA_ARGS__)
94fe8e6c1cSAndre Przywara #else
95fe8e6c1cSAndre Przywara #define p9_debug(level, fmt, ...) \
96fe8e6c1cSAndre Przywara no_printk(fmt, ##__VA_ARGS__)
97fe8e6c1cSAndre Przywara #endif
98fe8e6c1cSAndre Przywara
99fe8e6c1cSAndre Przywara /**
100fe8e6c1cSAndre Przywara * enum p9_msg_t - 9P message types
101fe8e6c1cSAndre Przywara * @P9_TLERROR: not used
102fe8e6c1cSAndre Przywara * @P9_RLERROR: response for any failed request for 9P2000.L
103fe8e6c1cSAndre Przywara * @P9_TSTATFS: file system status request
104fe8e6c1cSAndre Przywara * @P9_RSTATFS: file system status response
105fe8e6c1cSAndre Przywara * @P9_TSYMLINK: make symlink request
106fe8e6c1cSAndre Przywara * @P9_RSYMLINK: make symlink response
107fe8e6c1cSAndre Przywara * @P9_TMKNOD: create a special file object request
108fe8e6c1cSAndre Przywara * @P9_RMKNOD: create a special file object response
109fe8e6c1cSAndre Przywara * @P9_TLCREATE: prepare a handle for I/O on an new file for 9P2000.L
110fe8e6c1cSAndre Przywara * @P9_RLCREATE: response with file access information for 9P2000.L
111fe8e6c1cSAndre Przywara * @P9_TRENAME: rename request
112fe8e6c1cSAndre Przywara * @P9_RRENAME: rename response
113fe8e6c1cSAndre Przywara * @P9_TMKDIR: create a directory request
114fe8e6c1cSAndre Przywara * @P9_RMKDIR: create a directory response
115fe8e6c1cSAndre Przywara * @P9_TVERSION: version handshake request
116fe8e6c1cSAndre Przywara * @P9_RVERSION: version handshake response
117fe8e6c1cSAndre Przywara * @P9_TAUTH: request to establish authentication channel
118fe8e6c1cSAndre Przywara * @P9_RAUTH: response with authentication information
119fe8e6c1cSAndre Przywara * @P9_TATTACH: establish user access to file service
120fe8e6c1cSAndre Przywara * @P9_RATTACH: response with top level handle to file hierarchy
121fe8e6c1cSAndre Przywara * @P9_TERROR: not used
122fe8e6c1cSAndre Przywara * @P9_RERROR: response for any failed request
123fe8e6c1cSAndre Przywara * @P9_TFLUSH: request to abort a previous request
124fe8e6c1cSAndre Przywara * @P9_RFLUSH: response when previous request has been cancelled
125fe8e6c1cSAndre Przywara * @P9_TWALK: descend a directory hierarchy
126fe8e6c1cSAndre Przywara * @P9_RWALK: response with new handle for position within hierarchy
127fe8e6c1cSAndre Przywara * @P9_TOPEN: prepare a handle for I/O on an existing file
128fe8e6c1cSAndre Przywara * @P9_ROPEN: response with file access information
129fe8e6c1cSAndre Przywara * @P9_TCREATE: prepare a handle for I/O on a new file
130fe8e6c1cSAndre Przywara * @P9_RCREATE: response with file access information
131fe8e6c1cSAndre Przywara * @P9_TREAD: request to transfer data from a file or directory
132fe8e6c1cSAndre Przywara * @P9_RREAD: response with data requested
133fe8e6c1cSAndre Przywara * @P9_TWRITE: reuqest to transfer data to a file
134fe8e6c1cSAndre Przywara * @P9_RWRITE: response with out much data was transferred to file
135fe8e6c1cSAndre Przywara * @P9_TCLUNK: forget about a handle to an entity within the file system
136fe8e6c1cSAndre Przywara * @P9_RCLUNK: response when server has forgotten about the handle
137fe8e6c1cSAndre Przywara * @P9_TREMOVE: request to remove an entity from the hierarchy
138fe8e6c1cSAndre Przywara * @P9_RREMOVE: response when server has removed the entity
139fe8e6c1cSAndre Przywara * @P9_TSTAT: request file entity attributes
140fe8e6c1cSAndre Przywara * @P9_RSTAT: response with file entity attributes
141fe8e6c1cSAndre Przywara * @P9_TWSTAT: request to update file entity attributes
142fe8e6c1cSAndre Przywara * @P9_RWSTAT: response when file entity attributes are updated
143fe8e6c1cSAndre Przywara *
144fe8e6c1cSAndre Przywara * There are 14 basic operations in 9P2000, paired as
145fe8e6c1cSAndre Przywara * requests and responses. The one special case is ERROR
146fe8e6c1cSAndre Przywara * as there is no @P9_TERROR request for clients to transmit to
147fe8e6c1cSAndre Przywara * the server, but the server may respond to any other request
148fe8e6c1cSAndre Przywara * with an @P9_RERROR.
149fe8e6c1cSAndre Przywara *
150fe8e6c1cSAndre Przywara * See Also: http://plan9.bell-labs.com/sys/man/5/INDEX.html
151fe8e6c1cSAndre Przywara */
152fe8e6c1cSAndre Przywara
153fe8e6c1cSAndre Przywara enum p9_msg_t {
154fe8e6c1cSAndre Przywara P9_TLERROR = 6,
155fe8e6c1cSAndre Przywara P9_RLERROR,
156fe8e6c1cSAndre Przywara P9_TSTATFS = 8,
157fe8e6c1cSAndre Przywara P9_RSTATFS,
158fe8e6c1cSAndre Przywara P9_TLOPEN = 12,
159fe8e6c1cSAndre Przywara P9_RLOPEN,
160fe8e6c1cSAndre Przywara P9_TLCREATE = 14,
161fe8e6c1cSAndre Przywara P9_RLCREATE,
162fe8e6c1cSAndre Przywara P9_TSYMLINK = 16,
163fe8e6c1cSAndre Przywara P9_RSYMLINK,
164fe8e6c1cSAndre Przywara P9_TMKNOD = 18,
165fe8e6c1cSAndre Przywara P9_RMKNOD,
166fe8e6c1cSAndre Przywara P9_TRENAME = 20,
167fe8e6c1cSAndre Przywara P9_RRENAME,
168fe8e6c1cSAndre Przywara P9_TREADLINK = 22,
169fe8e6c1cSAndre Przywara P9_RREADLINK,
170fe8e6c1cSAndre Przywara P9_TGETATTR = 24,
171fe8e6c1cSAndre Przywara P9_RGETATTR,
172fe8e6c1cSAndre Przywara P9_TSETATTR = 26,
173fe8e6c1cSAndre Przywara P9_RSETATTR,
174fe8e6c1cSAndre Przywara P9_TXATTRWALK = 30,
175fe8e6c1cSAndre Przywara P9_RXATTRWALK,
176fe8e6c1cSAndre Przywara P9_TXATTRCREATE = 32,
177fe8e6c1cSAndre Przywara P9_RXATTRCREATE,
178fe8e6c1cSAndre Przywara P9_TREADDIR = 40,
179fe8e6c1cSAndre Przywara P9_RREADDIR,
180fe8e6c1cSAndre Przywara P9_TFSYNC = 50,
181fe8e6c1cSAndre Przywara P9_RFSYNC,
182fe8e6c1cSAndre Przywara P9_TLOCK = 52,
183fe8e6c1cSAndre Przywara P9_RLOCK,
184fe8e6c1cSAndre Przywara P9_TGETLOCK = 54,
185fe8e6c1cSAndre Przywara P9_RGETLOCK,
186fe8e6c1cSAndre Przywara P9_TLINK = 70,
187fe8e6c1cSAndre Przywara P9_RLINK,
188fe8e6c1cSAndre Przywara P9_TMKDIR = 72,
189fe8e6c1cSAndre Przywara P9_RMKDIR,
190fe8e6c1cSAndre Przywara P9_TRENAMEAT = 74,
191fe8e6c1cSAndre Przywara P9_RRENAMEAT,
192fe8e6c1cSAndre Przywara P9_TUNLINKAT = 76,
193fe8e6c1cSAndre Przywara P9_RUNLINKAT,
194fe8e6c1cSAndre Przywara P9_TVERSION = 100,
195fe8e6c1cSAndre Przywara P9_RVERSION,
196fe8e6c1cSAndre Przywara P9_TAUTH = 102,
197fe8e6c1cSAndre Przywara P9_RAUTH,
198fe8e6c1cSAndre Przywara P9_TATTACH = 104,
199fe8e6c1cSAndre Przywara P9_RATTACH,
200fe8e6c1cSAndre Przywara P9_TERROR = 106,
201fe8e6c1cSAndre Przywara P9_RERROR,
202fe8e6c1cSAndre Przywara P9_TFLUSH = 108,
203fe8e6c1cSAndre Przywara P9_RFLUSH,
204fe8e6c1cSAndre Przywara P9_TWALK = 110,
205fe8e6c1cSAndre Przywara P9_RWALK,
206fe8e6c1cSAndre Przywara P9_TOPEN = 112,
207fe8e6c1cSAndre Przywara P9_ROPEN,
208fe8e6c1cSAndre Przywara P9_TCREATE = 114,
209fe8e6c1cSAndre Przywara P9_RCREATE,
210fe8e6c1cSAndre Przywara P9_TREAD = 116,
211fe8e6c1cSAndre Przywara P9_RREAD,
212fe8e6c1cSAndre Przywara P9_TWRITE = 118,
213fe8e6c1cSAndre Przywara P9_RWRITE,
214fe8e6c1cSAndre Przywara P9_TCLUNK = 120,
215fe8e6c1cSAndre Przywara P9_RCLUNK,
216fe8e6c1cSAndre Przywara P9_TREMOVE = 122,
217fe8e6c1cSAndre Przywara P9_RREMOVE,
218fe8e6c1cSAndre Przywara P9_TSTAT = 124,
219fe8e6c1cSAndre Przywara P9_RSTAT,
220fe8e6c1cSAndre Przywara P9_TWSTAT = 126,
221fe8e6c1cSAndre Przywara P9_RWSTAT,
222fe8e6c1cSAndre Przywara };
223fe8e6c1cSAndre Przywara
224fe8e6c1cSAndre Przywara /**
225fe8e6c1cSAndre Przywara * enum p9_open_mode_t - 9P open modes
226fe8e6c1cSAndre Przywara * @P9_OREAD: open file for reading only
227fe8e6c1cSAndre Przywara * @P9_OWRITE: open file for writing only
228fe8e6c1cSAndre Przywara * @P9_ORDWR: open file for reading or writing
229fe8e6c1cSAndre Przywara * @P9_OEXEC: open file for execution
230fe8e6c1cSAndre Przywara * @P9_OTRUNC: truncate file to zero-length before opening it
231fe8e6c1cSAndre Przywara * @P9_OREXEC: close the file when an exec(2) system call is made
232fe8e6c1cSAndre Przywara * @P9_ORCLOSE: remove the file when the file is closed
233fe8e6c1cSAndre Przywara * @P9_OAPPEND: open the file and seek to the end
234fe8e6c1cSAndre Przywara * @P9_OEXCL: only create a file, do not open it
235fe8e6c1cSAndre Przywara *
236fe8e6c1cSAndre Przywara * 9P open modes differ slightly from Posix standard modes.
237fe8e6c1cSAndre Przywara * In particular, there are extra modes which specify different
238fe8e6c1cSAndre Przywara * semantic behaviors than may be available on standard Posix
239fe8e6c1cSAndre Przywara * systems. For example, @P9_OREXEC and @P9_ORCLOSE are modes that
240fe8e6c1cSAndre Przywara * most likely will not be issued from the Linux VFS client, but may
241fe8e6c1cSAndre Przywara * be supported by servers.
242fe8e6c1cSAndre Przywara *
243fe8e6c1cSAndre Przywara * See Also: http://plan9.bell-labs.com/magic/man2html/2/open
244fe8e6c1cSAndre Przywara */
245fe8e6c1cSAndre Przywara
246fe8e6c1cSAndre Przywara enum p9_open_mode_t {
247fe8e6c1cSAndre Przywara P9_OREAD = 0x00,
248fe8e6c1cSAndre Przywara P9_OWRITE = 0x01,
249fe8e6c1cSAndre Przywara P9_ORDWR = 0x02,
250fe8e6c1cSAndre Przywara P9_OEXEC = 0x03,
251fe8e6c1cSAndre Przywara P9_OTRUNC = 0x10,
252fe8e6c1cSAndre Przywara P9_OREXEC = 0x20,
253fe8e6c1cSAndre Przywara P9_ORCLOSE = 0x40,
254fe8e6c1cSAndre Przywara P9_OAPPEND = 0x80,
255fe8e6c1cSAndre Przywara P9_OEXCL = 0x1000,
256fe8e6c1cSAndre Przywara };
257fe8e6c1cSAndre Przywara
258fe8e6c1cSAndre Przywara /**
259fe8e6c1cSAndre Przywara * enum p9_perm_t - 9P permissions
260fe8e6c1cSAndre Przywara * @P9_DMDIR: mode bit for directories
261fe8e6c1cSAndre Przywara * @P9_DMAPPEND: mode bit for is append-only
262fe8e6c1cSAndre Przywara * @P9_DMEXCL: mode bit for excluse use (only one open handle allowed)
263fe8e6c1cSAndre Przywara * @P9_DMMOUNT: mode bit for mount points
264fe8e6c1cSAndre Przywara * @P9_DMAUTH: mode bit for authentication file
265fe8e6c1cSAndre Przywara * @P9_DMTMP: mode bit for non-backed-up files
266fe8e6c1cSAndre Przywara * @P9_DMSYMLINK: mode bit for symbolic links (9P2000.u)
267fe8e6c1cSAndre Przywara * @P9_DMLINK: mode bit for hard-link (9P2000.u)
268fe8e6c1cSAndre Przywara * @P9_DMDEVICE: mode bit for device files (9P2000.u)
269fe8e6c1cSAndre Przywara * @P9_DMNAMEDPIPE: mode bit for named pipe (9P2000.u)
270fe8e6c1cSAndre Przywara * @P9_DMSOCKET: mode bit for socket (9P2000.u)
271fe8e6c1cSAndre Przywara * @P9_DMSETUID: mode bit for setuid (9P2000.u)
272fe8e6c1cSAndre Przywara * @P9_DMSETGID: mode bit for setgid (9P2000.u)
273fe8e6c1cSAndre Przywara * @P9_DMSETVTX: mode bit for sticky bit (9P2000.u)
274fe8e6c1cSAndre Przywara *
275fe8e6c1cSAndre Przywara * 9P permissions differ slightly from Posix standard modes.
276fe8e6c1cSAndre Przywara *
277fe8e6c1cSAndre Przywara * See Also: http://plan9.bell-labs.com/magic/man2html/2/stat
278fe8e6c1cSAndre Przywara */
279fe8e6c1cSAndre Przywara enum p9_perm_t {
280fe8e6c1cSAndre Przywara P9_DMDIR = 0x80000000,
281fe8e6c1cSAndre Przywara P9_DMAPPEND = 0x40000000,
282fe8e6c1cSAndre Przywara P9_DMEXCL = 0x20000000,
283fe8e6c1cSAndre Przywara P9_DMMOUNT = 0x10000000,
284fe8e6c1cSAndre Przywara P9_DMAUTH = 0x08000000,
285fe8e6c1cSAndre Przywara P9_DMTMP = 0x04000000,
286fe8e6c1cSAndre Przywara /* 9P2000.u extensions */
287fe8e6c1cSAndre Przywara P9_DMSYMLINK = 0x02000000,
288fe8e6c1cSAndre Przywara P9_DMLINK = 0x01000000,
289fe8e6c1cSAndre Przywara P9_DMDEVICE = 0x00800000,
290fe8e6c1cSAndre Przywara P9_DMNAMEDPIPE = 0x00200000,
291fe8e6c1cSAndre Przywara P9_DMSOCKET = 0x00100000,
292fe8e6c1cSAndre Przywara P9_DMSETUID = 0x00080000,
293fe8e6c1cSAndre Przywara P9_DMSETGID = 0x00040000,
294fe8e6c1cSAndre Przywara P9_DMSETVTX = 0x00010000,
295fe8e6c1cSAndre Przywara };
296fe8e6c1cSAndre Przywara
297fe8e6c1cSAndre Przywara /* 9p2000.L open flags */
298fe8e6c1cSAndre Przywara #define P9_DOTL_RDONLY 00000000
299fe8e6c1cSAndre Przywara #define P9_DOTL_WRONLY 00000001
300fe8e6c1cSAndre Przywara #define P9_DOTL_RDWR 00000002
301fe8e6c1cSAndre Przywara #define P9_DOTL_NOACCESS 00000003
302fe8e6c1cSAndre Przywara #define P9_DOTL_CREATE 00000100
303fe8e6c1cSAndre Przywara #define P9_DOTL_EXCL 00000200
304fe8e6c1cSAndre Przywara #define P9_DOTL_NOCTTY 00000400
305fe8e6c1cSAndre Przywara #define P9_DOTL_TRUNC 00001000
306fe8e6c1cSAndre Przywara #define P9_DOTL_APPEND 00002000
307fe8e6c1cSAndre Przywara #define P9_DOTL_NONBLOCK 00004000
308fe8e6c1cSAndre Przywara #define P9_DOTL_DSYNC 00010000
309fe8e6c1cSAndre Przywara #define P9_DOTL_FASYNC 00020000
310fe8e6c1cSAndre Przywara #define P9_DOTL_DIRECT 00040000
311fe8e6c1cSAndre Przywara #define P9_DOTL_LARGEFILE 00100000
312fe8e6c1cSAndre Przywara #define P9_DOTL_DIRECTORY 00200000
313fe8e6c1cSAndre Przywara #define P9_DOTL_NOFOLLOW 00400000
314fe8e6c1cSAndre Przywara #define P9_DOTL_NOATIME 01000000
315fe8e6c1cSAndre Przywara #define P9_DOTL_CLOEXEC 02000000
316fe8e6c1cSAndre Przywara #define P9_DOTL_SYNC 04000000
317fe8e6c1cSAndre Przywara
318fe8e6c1cSAndre Przywara /* 9p2000.L at flags */
319fe8e6c1cSAndre Przywara #define P9_DOTL_AT_REMOVEDIR 0x200
320fe8e6c1cSAndre Przywara
321fe8e6c1cSAndre Przywara /* 9p2000.L lock type */
322fe8e6c1cSAndre Przywara #define P9_LOCK_TYPE_RDLCK 0
323fe8e6c1cSAndre Przywara #define P9_LOCK_TYPE_WRLCK 1
324fe8e6c1cSAndre Przywara #define P9_LOCK_TYPE_UNLCK 2
325fe8e6c1cSAndre Przywara
326fe8e6c1cSAndre Przywara /**
327fe8e6c1cSAndre Przywara * enum p9_qid_t - QID types
328fe8e6c1cSAndre Przywara * @P9_QTDIR: directory
329fe8e6c1cSAndre Przywara * @P9_QTAPPEND: append-only
330fe8e6c1cSAndre Przywara * @P9_QTEXCL: excluse use (only one open handle allowed)
331fe8e6c1cSAndre Przywara * @P9_QTMOUNT: mount points
332fe8e6c1cSAndre Przywara * @P9_QTAUTH: authentication file
333fe8e6c1cSAndre Przywara * @P9_QTTMP: non-backed-up files
334fe8e6c1cSAndre Przywara * @P9_QTSYMLINK: symbolic links (9P2000.u)
335fe8e6c1cSAndre Przywara * @P9_QTLINK: hard-link (9P2000.u)
336fe8e6c1cSAndre Przywara * @P9_QTFILE: normal files
337fe8e6c1cSAndre Przywara *
338fe8e6c1cSAndre Przywara * QID types are a subset of permissions - they are primarily
339fe8e6c1cSAndre Przywara * used to differentiate semantics for a file system entity via
340fe8e6c1cSAndre Przywara * a jump-table. Their value is also the most significant 16 bits
341fe8e6c1cSAndre Przywara * of the permission_t
342fe8e6c1cSAndre Przywara *
343fe8e6c1cSAndre Przywara * See Also: http://plan9.bell-labs.com/magic/man2html/2/stat
344fe8e6c1cSAndre Przywara */
345fe8e6c1cSAndre Przywara enum p9_qid_t {
346fe8e6c1cSAndre Przywara P9_QTDIR = 0x80,
347fe8e6c1cSAndre Przywara P9_QTAPPEND = 0x40,
348fe8e6c1cSAndre Przywara P9_QTEXCL = 0x20,
349fe8e6c1cSAndre Przywara P9_QTMOUNT = 0x10,
350fe8e6c1cSAndre Przywara P9_QTAUTH = 0x08,
351fe8e6c1cSAndre Przywara P9_QTTMP = 0x04,
352fe8e6c1cSAndre Przywara P9_QTSYMLINK = 0x02,
353fe8e6c1cSAndre Przywara P9_QTLINK = 0x01,
354fe8e6c1cSAndre Przywara P9_QTFILE = 0x00,
355fe8e6c1cSAndre Przywara };
356fe8e6c1cSAndre Przywara
357fe8e6c1cSAndre Przywara /* 9P Magic Numbers */
358fe8e6c1cSAndre Przywara #define P9_NOTAG (u16)(~0)
359fe8e6c1cSAndre Przywara #define P9_NOFID (u32)(~0)
360fe8e6c1cSAndre Przywara #define P9_MAXWELEM 16
361fe8e6c1cSAndre Przywara
362fe8e6c1cSAndre Przywara /* ample room for Twrite/Rread header */
363fe8e6c1cSAndre Przywara #define P9_IOHDRSZ 24
364fe8e6c1cSAndre Przywara
365fe8e6c1cSAndre Przywara /* Room for readdir header */
366fe8e6c1cSAndre Przywara #define P9_READDIRHDRSZ 24
367fe8e6c1cSAndre Przywara
368fe8e6c1cSAndre Przywara /* size of header for zero copy read/write */
369fe8e6c1cSAndre Przywara #define P9_ZC_HDR_SZ 4096
370fe8e6c1cSAndre Przywara
371fe8e6c1cSAndre Przywara /**
372fe8e6c1cSAndre Przywara * struct p9_qid - file system entity information
373fe8e6c1cSAndre Przywara * @type: 8-bit type &p9_qid_t
374fe8e6c1cSAndre Przywara * @version: 16-bit monotonically incrementing version number
375fe8e6c1cSAndre Przywara * @path: 64-bit per-server-unique ID for a file system element
376fe8e6c1cSAndre Przywara *
377fe8e6c1cSAndre Przywara * qids are identifiers used by 9P servers to track file system
378fe8e6c1cSAndre Przywara * entities. The type is used to differentiate semantics for operations
379fe8e6c1cSAndre Przywara * on the entity (ie. read means something different on a directory than
380fe8e6c1cSAndre Przywara * on a file). The path provides a server unique index for an entity
381fe8e6c1cSAndre Przywara * (roughly analogous to an inode number), while the version is updated
382fe8e6c1cSAndre Przywara * every time a file is modified and can be used to maintain cache
383fe8e6c1cSAndre Przywara * coherency between clients and serves.
384fe8e6c1cSAndre Przywara * Servers will often differentiate purely synthetic entities by setting
385fe8e6c1cSAndre Przywara * their version to 0, signaling that they should never be cached and
386fe8e6c1cSAndre Przywara * should be accessed synchronously.
387fe8e6c1cSAndre Przywara *
388fe8e6c1cSAndre Przywara * See Also://plan9.bell-labs.com/magic/man2html/2/stat
389fe8e6c1cSAndre Przywara */
390fe8e6c1cSAndre Przywara
391fe8e6c1cSAndre Przywara struct p9_qid {
392fe8e6c1cSAndre Przywara u8 type;
393fe8e6c1cSAndre Przywara u32 version;
394fe8e6c1cSAndre Przywara u64 path;
395fe8e6c1cSAndre Przywara };
396fe8e6c1cSAndre Przywara
397fe8e6c1cSAndre Przywara /**
398fe8e6c1cSAndre Przywara * struct p9_wstat - file system metadata information
399fe8e6c1cSAndre Przywara * @size: length prefix for this stat structure instance
400fe8e6c1cSAndre Przywara * @type: the type of the server (equivalent to a major number)
401fe8e6c1cSAndre Przywara * @dev: the sub-type of the server (equivalent to a minor number)
402fe8e6c1cSAndre Przywara * @qid: unique id from the server of type &p9_qid
403fe8e6c1cSAndre Przywara * @mode: Plan 9 format permissions of type &p9_perm_t
404fe8e6c1cSAndre Przywara * @atime: Last access/read time
405fe8e6c1cSAndre Przywara * @mtime: Last modify/write time
406fe8e6c1cSAndre Przywara * @length: file length
407fe8e6c1cSAndre Przywara * @name: last element of path (aka filename)
408fe8e6c1cSAndre Przywara * @uid: owner name
409fe8e6c1cSAndre Przywara * @gid: group owner
410fe8e6c1cSAndre Przywara * @muid: last modifier
411fe8e6c1cSAndre Przywara * @extension: area used to encode extended UNIX support
412fe8e6c1cSAndre Przywara * @n_uid: numeric user id of owner (part of 9p2000.u extension)
413fe8e6c1cSAndre Przywara * @n_gid: numeric group id (part of 9p2000.u extension)
414fe8e6c1cSAndre Przywara * @n_muid: numeric user id of laster modifier (part of 9p2000.u extension)
415fe8e6c1cSAndre Przywara *
416fe8e6c1cSAndre Przywara * See Also: http://plan9.bell-labs.com/magic/man2html/2/stat
417fe8e6c1cSAndre Przywara */
418fe8e6c1cSAndre Przywara
419fe8e6c1cSAndre Przywara struct p9_wstat {
420fe8e6c1cSAndre Przywara u16 size;
421fe8e6c1cSAndre Przywara u16 type;
422fe8e6c1cSAndre Przywara u32 dev;
423fe8e6c1cSAndre Przywara struct p9_qid qid;
424fe8e6c1cSAndre Przywara u32 mode;
425fe8e6c1cSAndre Przywara u32 atime;
426fe8e6c1cSAndre Przywara u32 mtime;
427fe8e6c1cSAndre Przywara u64 length;
428fe8e6c1cSAndre Przywara char *name;
429fe8e6c1cSAndre Przywara char *uid;
430fe8e6c1cSAndre Przywara char *gid;
431fe8e6c1cSAndre Przywara char *muid;
432fe8e6c1cSAndre Przywara char *extension; /* 9p2000.u extensions */
433fe8e6c1cSAndre Przywara kuid_t n_uid; /* 9p2000.u extensions */
434fe8e6c1cSAndre Przywara kgid_t n_gid; /* 9p2000.u extensions */
435fe8e6c1cSAndre Przywara kuid_t n_muid; /* 9p2000.u extensions */
436fe8e6c1cSAndre Przywara };
437fe8e6c1cSAndre Przywara
438fe8e6c1cSAndre Przywara struct p9_stat_dotl {
439fe8e6c1cSAndre Przywara u64 st_result_mask;
440fe8e6c1cSAndre Przywara struct p9_qid qid;
441fe8e6c1cSAndre Przywara u32 st_mode;
442fe8e6c1cSAndre Przywara kuid_t st_uid;
443fe8e6c1cSAndre Przywara kgid_t st_gid;
444fe8e6c1cSAndre Przywara u64 st_nlink;
445fe8e6c1cSAndre Przywara u64 st_rdev;
446fe8e6c1cSAndre Przywara u64 st_size;
447fe8e6c1cSAndre Przywara u64 st_blksize;
448fe8e6c1cSAndre Przywara u64 st_blocks;
449fe8e6c1cSAndre Przywara u64 st_atime_sec;
450fe8e6c1cSAndre Przywara u64 st_atime_nsec;
451fe8e6c1cSAndre Przywara u64 st_mtime_sec;
452fe8e6c1cSAndre Przywara u64 st_mtime_nsec;
453fe8e6c1cSAndre Przywara u64 st_ctime_sec;
454fe8e6c1cSAndre Przywara u64 st_ctime_nsec;
455fe8e6c1cSAndre Przywara u64 st_btime_sec;
456fe8e6c1cSAndre Przywara u64 st_btime_nsec;
457fe8e6c1cSAndre Przywara u64 st_gen;
458fe8e6c1cSAndre Przywara u64 st_data_version;
459fe8e6c1cSAndre Przywara };
460fe8e6c1cSAndre Przywara
461fe8e6c1cSAndre Przywara #define P9_STATS_MODE 0x00000001ULL
462fe8e6c1cSAndre Przywara #define P9_STATS_NLINK 0x00000002ULL
463fe8e6c1cSAndre Przywara #define P9_STATS_UID 0x00000004ULL
464fe8e6c1cSAndre Przywara #define P9_STATS_GID 0x00000008ULL
465fe8e6c1cSAndre Przywara #define P9_STATS_RDEV 0x00000010ULL
466fe8e6c1cSAndre Przywara #define P9_STATS_ATIME 0x00000020ULL
467fe8e6c1cSAndre Przywara #define P9_STATS_MTIME 0x00000040ULL
468fe8e6c1cSAndre Przywara #define P9_STATS_CTIME 0x00000080ULL
469fe8e6c1cSAndre Przywara #define P9_STATS_INO 0x00000100ULL
470fe8e6c1cSAndre Przywara #define P9_STATS_SIZE 0x00000200ULL
471fe8e6c1cSAndre Przywara #define P9_STATS_BLOCKS 0x00000400ULL
472fe8e6c1cSAndre Przywara
473fe8e6c1cSAndre Przywara #define P9_STATS_BTIME 0x00000800ULL
474fe8e6c1cSAndre Przywara #define P9_STATS_GEN 0x00001000ULL
475fe8e6c1cSAndre Przywara #define P9_STATS_DATA_VERSION 0x00002000ULL
476fe8e6c1cSAndre Przywara
477fe8e6c1cSAndre Przywara #define P9_STATS_BASIC 0x000007ffULL /* Mask for fields up to BLOCKS */
478fe8e6c1cSAndre Przywara #define P9_STATS_ALL 0x00003fffULL /* Mask for All fields above */
479fe8e6c1cSAndre Przywara
480fe8e6c1cSAndre Przywara /**
481fe8e6c1cSAndre Przywara * struct p9_iattr_dotl - P9 inode attribute for setattr
482fe8e6c1cSAndre Przywara * @valid: bitfield specifying which fields are valid
483fe8e6c1cSAndre Przywara * same as in struct iattr
484fe8e6c1cSAndre Przywara * @mode: File permission bits
485fe8e6c1cSAndre Przywara * @uid: user id of owner
486fe8e6c1cSAndre Przywara * @gid: group id
487fe8e6c1cSAndre Przywara * @size: File size
488fe8e6c1cSAndre Przywara * @atime_sec: Last access time, seconds
489fe8e6c1cSAndre Przywara * @atime_nsec: Last access time, nanoseconds
490fe8e6c1cSAndre Przywara * @mtime_sec: Last modification time, seconds
491fe8e6c1cSAndre Przywara * @mtime_nsec: Last modification time, nanoseconds
492fe8e6c1cSAndre Przywara */
493fe8e6c1cSAndre Przywara
494fe8e6c1cSAndre Przywara struct p9_iattr_dotl {
495fe8e6c1cSAndre Przywara u32 valid;
496fe8e6c1cSAndre Przywara u32 mode;
497fe8e6c1cSAndre Przywara kuid_t uid;
498fe8e6c1cSAndre Przywara kgid_t gid;
499fe8e6c1cSAndre Przywara u64 size;
500fe8e6c1cSAndre Przywara u64 atime_sec;
501fe8e6c1cSAndre Przywara u64 atime_nsec;
502fe8e6c1cSAndre Przywara u64 mtime_sec;
503fe8e6c1cSAndre Przywara u64 mtime_nsec;
504fe8e6c1cSAndre Przywara };
505fe8e6c1cSAndre Przywara
506fe8e6c1cSAndre Przywara #define P9_LOCK_SUCCESS 0
507fe8e6c1cSAndre Przywara #define P9_LOCK_BLOCKED 1
508fe8e6c1cSAndre Przywara #define P9_LOCK_ERROR 2
509fe8e6c1cSAndre Przywara #define P9_LOCK_GRACE 3
510fe8e6c1cSAndre Przywara
511fe8e6c1cSAndre Przywara #define P9_LOCK_FLAGS_BLOCK 1
512fe8e6c1cSAndre Przywara #define P9_LOCK_FLAGS_RECLAIM 2
513fe8e6c1cSAndre Przywara
514fe8e6c1cSAndre Przywara /* struct p9_flock: POSIX lock structure
515fe8e6c1cSAndre Przywara * @type - type of lock
516fe8e6c1cSAndre Przywara * @flags - lock flags
517fe8e6c1cSAndre Przywara * @start - starting offset of the lock
518fe8e6c1cSAndre Przywara * @length - number of bytes
519fe8e6c1cSAndre Przywara * @proc_id - process id which wants to take lock
520fe8e6c1cSAndre Przywara * @client_id - client id
521fe8e6c1cSAndre Przywara */
522fe8e6c1cSAndre Przywara
523fe8e6c1cSAndre Przywara struct p9_flock {
524fe8e6c1cSAndre Przywara u8 type;
525fe8e6c1cSAndre Przywara u32 flags;
526fe8e6c1cSAndre Przywara u64 start;
527fe8e6c1cSAndre Przywara u64 length;
528fe8e6c1cSAndre Przywara u32 proc_id;
529fe8e6c1cSAndre Przywara char *client_id;
530fe8e6c1cSAndre Przywara };
531fe8e6c1cSAndre Przywara
532fe8e6c1cSAndre Przywara /* struct p9_getlock: getlock structure
533fe8e6c1cSAndre Przywara * @type - type of lock
534fe8e6c1cSAndre Przywara * @start - starting offset of the lock
535fe8e6c1cSAndre Przywara * @length - number of bytes
536fe8e6c1cSAndre Przywara * @proc_id - process id which wants to take lock
537fe8e6c1cSAndre Przywara * @client_id - client id
538fe8e6c1cSAndre Przywara */
539fe8e6c1cSAndre Przywara
540fe8e6c1cSAndre Przywara struct p9_getlock {
541fe8e6c1cSAndre Przywara u8 type;
542fe8e6c1cSAndre Przywara u64 start;
543fe8e6c1cSAndre Przywara u64 length;
544fe8e6c1cSAndre Przywara u32 proc_id;
545fe8e6c1cSAndre Przywara char *client_id;
546fe8e6c1cSAndre Przywara };
547fe8e6c1cSAndre Przywara
548fe8e6c1cSAndre Przywara struct p9_rstatfs {
549fe8e6c1cSAndre Przywara u32 type;
550fe8e6c1cSAndre Przywara u32 bsize;
551fe8e6c1cSAndre Przywara u64 blocks;
552fe8e6c1cSAndre Przywara u64 bfree;
553fe8e6c1cSAndre Przywara u64 bavail;
554fe8e6c1cSAndre Przywara u64 files;
555fe8e6c1cSAndre Przywara u64 ffree;
556fe8e6c1cSAndre Przywara u64 fsid;
557fe8e6c1cSAndre Przywara u32 namelen;
558fe8e6c1cSAndre Przywara };
559fe8e6c1cSAndre Przywara
560fe8e6c1cSAndre Przywara /**
561fe8e6c1cSAndre Przywara * struct p9_fcall - primary packet structure
562fe8e6c1cSAndre Przywara * @size: prefixed length of the structure
563fe8e6c1cSAndre Przywara * @id: protocol operating identifier of type &p9_msg_t
564fe8e6c1cSAndre Przywara * @tag: transaction id of the request
565fe8e6c1cSAndre Przywara * @offset: used by marshalling routines to track current position in buffer
566fe8e6c1cSAndre Przywara * @capacity: used by marshalling routines to track total malloc'd capacity
567fe8e6c1cSAndre Przywara * @sdata: payload
568fe8e6c1cSAndre Przywara *
569fe8e6c1cSAndre Przywara * &p9_fcall represents the structure for all 9P RPC
570fe8e6c1cSAndre Przywara * transactions. Requests are packaged into fcalls, and reponses
571fe8e6c1cSAndre Przywara * must be extracted from them.
572fe8e6c1cSAndre Przywara *
573fe8e6c1cSAndre Przywara * See Also: http://plan9.bell-labs.com/magic/man2html/2/fcall
574fe8e6c1cSAndre Przywara */
575fe8e6c1cSAndre Przywara
576fe8e6c1cSAndre Przywara struct p9_fcall {
577fe8e6c1cSAndre Przywara u32 size;
578fe8e6c1cSAndre Przywara u8 id;
579fe8e6c1cSAndre Przywara u16 tag;
580fe8e6c1cSAndre Przywara
581fe8e6c1cSAndre Przywara size_t offset;
582fe8e6c1cSAndre Przywara size_t capacity;
583fe8e6c1cSAndre Przywara
584fe8e6c1cSAndre Przywara u8 *sdata;
585fe8e6c1cSAndre Przywara };
586fe8e6c1cSAndre Przywara
587fe8e6c1cSAndre Przywara struct p9_idpool;
588fe8e6c1cSAndre Przywara
589fe8e6c1cSAndre Przywara int p9_errstr2errno(char *errstr, int len);
590fe8e6c1cSAndre Przywara
591fe8e6c1cSAndre Przywara struct p9_idpool *p9_idpool_create(void);
592fe8e6c1cSAndre Przywara void p9_idpool_destroy(struct p9_idpool *);
593fe8e6c1cSAndre Przywara int p9_idpool_get(struct p9_idpool *p);
594fe8e6c1cSAndre Przywara void p9_idpool_put(int id, struct p9_idpool *p);
595fe8e6c1cSAndre Przywara int p9_idpool_check(int id, struct p9_idpool *p);
596fe8e6c1cSAndre Przywara
597fe8e6c1cSAndre Przywara int p9_error_init(void);
598fe8e6c1cSAndre Przywara int p9_trans_fd_init(void);
599fe8e6c1cSAndre Przywara void p9_trans_fd_exit(void);
600fe8e6c1cSAndre Przywara #endif /* NET_9P_H */
601