Blob


1 /*
2 * Copyright (c) 2021, 2022 Omar Polo <op@omarpolo.com>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 #ifndef KAMI_H
18 #define KAMI_H
20 /*
21 * 9p message header.
22 *
23 * The message itself is len bytes long (counting the whole header
24 * too.)
25 */
26 struct np_msg_header {
27 uint32_t len;
28 uint8_t type;
29 uint16_t tag;
30 };
32 struct qid {
33 uint64_t path;
34 uint32_t vers;
35 uint8_t type;
36 };
38 /* useful constants */
39 #define HEADERSIZE (4 + 1 + 2)
40 #define VERSION9P "9P2000"
41 #define MSIZE9P ((uint32_t)4*1024*1024)
42 #define NOTAG ((uint16_t)~0U)
43 #define NOFID ((uint32_t)~0U)
44 #define NOUID (-1)
45 #define QIDSIZE 13
46 #define MAXWELEM 16
48 #define NPSTATSIZ(namlen, uidnam, gidnam, unam) \
49 (6 + QIDSIZE + 20 + 2 + namlen + 2 + uidnam + 2 + gidnam + 2 + unam)
51 /* bits in Qid.type */
52 #define QTDIR 0x80 /* type bit for directories */
53 #define QTAPPEND 0x40 /* type bit for append only files */
54 #define QTEXCL 0x20 /* type bit for exclusive use files */
55 #define QTMOUNT 0x10 /* type bit for mounted channel */
56 #define QTAUTH 0x08 /* type bit for authentication file */
57 #define QTTMP 0x04 /* type bit for non-backed-up file */
58 #define QTSYMLINK 0x02 /* type bit for symbolic link */
59 #define QTFILE 0x00 /* type bits for plain file */
61 /* Topen mode/flags */
62 #define KOREAD 0x00
63 #define KOWRITE 0x01
64 #define KORDWR 0x02
65 #define KOEXEC 0x03
66 #define KOTRUNC 0x10
67 #define KORCLOSE 0x40
69 /* 9p message types */
70 enum {
71 Treaddir = 40, /* .L */
72 Rreaddir,
74 Tversion = 100,
75 Rversion,
76 Tauth = 102,
77 Rauth,
78 Tattach = 104,
79 Rattach,
80 Terror = 106, /* illegal */
81 Rerror,
82 Tflush = 108,
83 Rflush,
84 Twalk = 110,
85 Rwalk,
86 Topen = 112,
87 Ropen,
88 Tcreate = 114,
89 Rcreate,
90 Tread = 116,
91 Rread,
92 Twrite = 118,
93 Rwrite,
94 Tclunk = 120,
95 Rclunk,
96 Tremove = 122,
97 Rremove,
98 Tstat = 124,
99 Rstat,
100 Twstat = 126,
101 Rwstat,
102 Tmax,
104 /*
105 * plan9ports' include/fcall.h also has a
107 * Topenfd = 98,
108 * Ropenfd,
110 * which it's not mentioned in the 9p "rfc" over at
111 * 9p.cat-v.org. Ignoring that for now.
112 */
113 };
115 #endif