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 /*
33 * The qid represents the server unique identification for the file.
34 * NOTE: the struct fields don't reflect the layout on the wire!
35 */
36 struct qid {
37 uint64_t path;
38 uint32_t vers;
39 uint8_t type;
40 };
42 struct np_stat {
43 uint16_t size;
44 uint16_t type;
45 uint32_t dev;
46 struct qid qid;
47 uint32_t mode;
48 uint32_t atime;
49 uint32_t mtime;
50 uint64_t length;
51 char *name;
52 char *uid;
53 char *gid;
54 char *muid;
55 };
57 /* useful constants */
58 #define HEADERSIZE (4 + 1 + 2)
59 #define VERSION9P "9P2000"
60 #define MSIZE9P ((uint32_t)4*1024*1024)
61 #define NOTAG ((uint16_t)~0U)
62 #define NOFID ((uint32_t)~0U)
63 #define NOUID (-1)
64 #define QIDSIZE 13
65 #define MAXWELEM 16
67 /*
68 * from u9fs "ample room for Twrite/Rread header". It's a bit sloppy
69 * but otherwise it fails with "i/o count too large". Only for usage in
70 * clients.
71 */
72 #define IOHDRSZ 24
74 #define NPSTATSIZ(namlen, uidnam, gidnam, unam) \
75 (6 + QIDSIZE + 20 + 2 + namlen + 2 + uidnam + 2 + gidnam + 2 + unam)
77 /* bits in Qid.type */
78 #define QTDIR 0x80 /* type bit for directories */
79 #define QTAPPEND 0x40 /* type bit for append only files */
80 #define QTEXCL 0x20 /* type bit for exclusive use files */
81 #define QTMOUNT 0x10 /* type bit for mounted channel */
82 #define QTAUTH 0x08 /* type bit for authentication file */
83 #define QTTMP 0x04 /* type bit for non-backed-up file */
84 #define QTSYMLINK 0x02 /* type bit for symbolic link */
85 #define QTFILE 0x00 /* type bits for plain file */
87 /* Topen mode/flags */
88 #define KOREAD 0x00
89 #define KOWRITE 0x01
90 #define KORDWR 0x02
91 #define KOEXEC 0x03
92 #define KOTRUNC 0x10
93 #define KORCLOSE 0x40
95 /* 9p message types */
96 enum {
97 Treaddir = 40, /* .L */
98 Rreaddir,
100 Tversion = 100, /* 0x64 */
101 Rversion,
102 Tauth = 102, /* 0x66 */
103 Rauth,
104 Tattach = 104, /* 0x68 */
105 Rattach,
106 Terror = 106, /* illegal */
107 Rerror,
108 Tflush = 108, /* 0x6c */
109 Rflush,
110 Twalk = 110, /* 0x6e */
111 Rwalk,
112 Topen = 112, /* 0x70 */
113 Ropen,
114 Tcreate = 114, /* 0x72 */
115 Rcreate,
116 Tread = 116, /* 0x74 */
117 Rread,
118 Twrite = 118, /* 0x76 */
119 Rwrite,
120 Tclunk = 120, /* 0x78 */
121 Rclunk,
122 Tremove = 122, /* 0x7a */
123 Rremove,
124 Tstat = 124, /* 0x7c */
125 Rstat,
126 Twstat = 126, /* 0x7e */
127 Rwstat,
128 Tmax,
130 /*
131 * plan9ports' include/fcall.h also has a
133 * Topenfd = 98,
134 * Ropenfd,
136 * which it's not mentioned in the 9p "rfc" over at
137 * 9p.cat-v.org. Ignoring that for now.
138 */
139 };
141 #endif