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 #define NPSTATSIZ(namlen, uidnam, gidnam, unam) \
68 (6 + QIDSIZE + 20 + 2 + namlen + 2 + uidnam + 2 + gidnam + 2 + unam)
70 /* bits in Qid.type */
71 #define QTDIR 0x80 /* type bit for directories */
72 #define QTAPPEND 0x40 /* type bit for append only files */
73 #define QTEXCL 0x20 /* type bit for exclusive use files */
74 #define QTMOUNT 0x10 /* type bit for mounted channel */
75 #define QTAUTH 0x08 /* type bit for authentication file */
76 #define QTTMP 0x04 /* type bit for non-backed-up file */
77 #define QTSYMLINK 0x02 /* type bit for symbolic link */
78 #define QTFILE 0x00 /* type bits for plain file */
80 /* Topen mode/flags */
81 #define KOREAD 0x00
82 #define KOWRITE 0x01
83 #define KORDWR 0x02
84 #define KOEXEC 0x03
85 #define KOTRUNC 0x10
86 #define KORCLOSE 0x40
88 /* 9p message types */
89 enum {
90 Treaddir = 40, /* .L */
91 Rreaddir,
93 Tversion = 100, /* 0x64 */
94 Rversion,
95 Tauth = 102, /* 0x66 */
96 Rauth,
97 Tattach = 104, /* 0x68 */
98 Rattach,
99 Terror = 106, /* illegal */
100 Rerror,
101 Tflush = 108, /* 0x6c */
102 Rflush,
103 Twalk = 110, /* 0x6e */
104 Rwalk,
105 Topen = 112, /* 0x70 */
106 Ropen,
107 Tcreate = 114, /* 0x72 */
108 Rcreate,
109 Tread = 116, /* 0x74 */
110 Rread,
111 Twrite = 118, /* 0x76 */
112 Rwrite,
113 Tclunk = 120, /* 0x78 */
114 Rclunk,
115 Tremove = 122, /* 0x7a */
116 Rremove,
117 Tstat = 124, /* 0x7c */
118 Rstat,
119 Twstat = 126, /* 0x7e */
120 Rwstat,
121 Tmax,
123 /*
124 * plan9ports' include/fcall.h also has a
126 * Topenfd = 98,
127 * Ropenfd,
129 * which it's not mentioned in the 9p "rfc" over at
130 * 9p.cat-v.org. Ignoring that for now.
131 */
132 };
134 #endif