Blame


1 fb1a36c0 2022-01-09 op /*
2 fb1a36c0 2022-01-09 op * Copyright (c) 2021, 2022 Omar Polo <op@omarpolo.com>
3 fb1a36c0 2022-01-09 op *
4 fb1a36c0 2022-01-09 op * Permission to use, copy, modify, and distribute this software for any
5 fb1a36c0 2022-01-09 op * purpose with or without fee is hereby granted, provided that the above
6 fb1a36c0 2022-01-09 op * copyright notice and this permission notice appear in all copies.
7 fb1a36c0 2022-01-09 op *
8 fb1a36c0 2022-01-09 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 fb1a36c0 2022-01-09 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 fb1a36c0 2022-01-09 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 fb1a36c0 2022-01-09 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 fb1a36c0 2022-01-09 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 fb1a36c0 2022-01-09 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 fb1a36c0 2022-01-09 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 fb1a36c0 2022-01-09 op */
16 fb1a36c0 2022-01-09 op
17 fb1a36c0 2022-01-09 op #ifndef KAMI_H
18 fb1a36c0 2022-01-09 op #define KAMI_H
19 fb1a36c0 2022-01-09 op
20 fb1a36c0 2022-01-09 op /*
21 fb1a36c0 2022-01-09 op * 9p message header.
22 fb1a36c0 2022-01-09 op *
23 fb1a36c0 2022-01-09 op * The message itself is len bytes long (counting the whole header
24 fb1a36c0 2022-01-09 op * too.)
25 fb1a36c0 2022-01-09 op */
26 fb1a36c0 2022-01-09 op struct np_msg_header {
27 fb1a36c0 2022-01-09 op uint32_t len;
28 fb1a36c0 2022-01-09 op uint8_t type;
29 fb1a36c0 2022-01-09 op uint16_t tag;
30 fb1a36c0 2022-01-09 op };
31 fb1a36c0 2022-01-09 op
32 344d2bad 2022-01-22 op /*
33 344d2bad 2022-01-22 op * The qid represents the server unique identification for the file.
34 344d2bad 2022-01-22 op * NOTE: the struct fields don't reflect the layout on the wire!
35 344d2bad 2022-01-22 op */
36 fb1a36c0 2022-01-09 op struct qid {
37 fb1a36c0 2022-01-09 op uint64_t path;
38 fb1a36c0 2022-01-09 op uint32_t vers;
39 fb1a36c0 2022-01-09 op uint8_t type;
40 fb1a36c0 2022-01-09 op };
41 fb1a36c0 2022-01-09 op
42 4cce062e 2022-01-16 op struct np_stat {
43 9029ac6f 2022-01-19 op uint16_t size;
44 4cce062e 2022-01-16 op uint16_t type;
45 4cce062e 2022-01-16 op uint32_t dev;
46 4cce062e 2022-01-16 op struct qid qid;
47 4cce062e 2022-01-16 op uint32_t mode;
48 4cce062e 2022-01-16 op uint32_t atime;
49 4cce062e 2022-01-16 op uint32_t mtime;
50 4cce062e 2022-01-16 op uint64_t length;
51 4cce062e 2022-01-16 op char *name;
52 4cce062e 2022-01-16 op char *uid;
53 4cce062e 2022-01-16 op char *gid;
54 4cce062e 2022-01-16 op char *muid;
55 4cce062e 2022-01-16 op };
56 4cce062e 2022-01-16 op
57 fb1a36c0 2022-01-09 op /* useful constants */
58 fb1a36c0 2022-01-09 op #define HEADERSIZE (4 + 1 + 2)
59 fb1a36c0 2022-01-09 op #define VERSION9P "9P2000"
60 fb1a36c0 2022-01-09 op #define MSIZE9P ((uint32_t)4*1024*1024)
61 fb1a36c0 2022-01-09 op #define NOTAG ((uint16_t)~0U)
62 fb1a36c0 2022-01-09 op #define NOFID ((uint32_t)~0U)
63 fb1a36c0 2022-01-09 op #define NOUID (-1)
64 fb1a36c0 2022-01-09 op #define QIDSIZE 13
65 fb1a36c0 2022-01-09 op #define MAXWELEM 16
66 fb1a36c0 2022-01-09 op
67 7bafb2fd 2022-08-28 op /*
68 7bafb2fd 2022-08-28 op * from u9fs "ample room for Twrite/Rread header". It's a bit sloppy
69 7bafb2fd 2022-08-28 op * but otherwise it fails with "i/o count too large". Only for usage in
70 7bafb2fd 2022-08-28 op * clients.
71 7bafb2fd 2022-08-28 op */
72 7bafb2fd 2022-08-28 op #define IOHDRSZ 24
73 7bafb2fd 2022-08-28 op
74 fb1a36c0 2022-01-09 op #define NPSTATSIZ(namlen, uidnam, gidnam, unam) \
75 fb1a36c0 2022-01-09 op (6 + QIDSIZE + 20 + 2 + namlen + 2 + uidnam + 2 + gidnam + 2 + unam)
76 fb1a36c0 2022-01-09 op
77 fb1a36c0 2022-01-09 op /* bits in Qid.type */
78 fb1a36c0 2022-01-09 op #define QTDIR 0x80 /* type bit for directories */
79 fb1a36c0 2022-01-09 op #define QTAPPEND 0x40 /* type bit for append only files */
80 fb1a36c0 2022-01-09 op #define QTEXCL 0x20 /* type bit for exclusive use files */
81 fb1a36c0 2022-01-09 op #define QTMOUNT 0x10 /* type bit for mounted channel */
82 fb1a36c0 2022-01-09 op #define QTAUTH 0x08 /* type bit for authentication file */
83 fb1a36c0 2022-01-09 op #define QTTMP 0x04 /* type bit for non-backed-up file */
84 fb1a36c0 2022-01-09 op #define QTSYMLINK 0x02 /* type bit for symbolic link */
85 fb1a36c0 2022-01-09 op #define QTFILE 0x00 /* type bits for plain file */
86 fb1a36c0 2022-01-09 op
87 fb1a36c0 2022-01-09 op /* Topen mode/flags */
88 fb1a36c0 2022-01-09 op #define KOREAD 0x00
89 fb1a36c0 2022-01-09 op #define KOWRITE 0x01
90 fb1a36c0 2022-01-09 op #define KORDWR 0x02
91 fb1a36c0 2022-01-09 op #define KOEXEC 0x03
92 fb1a36c0 2022-01-09 op #define KOTRUNC 0x10
93 fb1a36c0 2022-01-09 op #define KORCLOSE 0x40
94 fb1a36c0 2022-01-09 op
95 fb1a36c0 2022-01-09 op /* 9p message types */
96 fb1a36c0 2022-01-09 op enum {
97 fb1a36c0 2022-01-09 op Treaddir = 40, /* .L */
98 fb1a36c0 2022-01-09 op Rreaddir,
99 fb1a36c0 2022-01-09 op
100 aa495dd9 2022-01-22 op Tversion = 100, /* 0x64 */
101 fb1a36c0 2022-01-09 op Rversion,
102 aa495dd9 2022-01-22 op Tauth = 102, /* 0x66 */
103 fb1a36c0 2022-01-09 op Rauth,
104 aa495dd9 2022-01-22 op Tattach = 104, /* 0x68 */
105 fb1a36c0 2022-01-09 op Rattach,
106 fb1a36c0 2022-01-09 op Terror = 106, /* illegal */
107 fb1a36c0 2022-01-09 op Rerror,
108 aa495dd9 2022-01-22 op Tflush = 108, /* 0x6c */
109 fb1a36c0 2022-01-09 op Rflush,
110 aa495dd9 2022-01-22 op Twalk = 110, /* 0x6e */
111 fb1a36c0 2022-01-09 op Rwalk,
112 aa495dd9 2022-01-22 op Topen = 112, /* 0x70 */
113 fb1a36c0 2022-01-09 op Ropen,
114 aa495dd9 2022-01-22 op Tcreate = 114, /* 0x72 */
115 fb1a36c0 2022-01-09 op Rcreate,
116 aa495dd9 2022-01-22 op Tread = 116, /* 0x74 */
117 fb1a36c0 2022-01-09 op Rread,
118 aa495dd9 2022-01-22 op Twrite = 118, /* 0x76 */
119 fb1a36c0 2022-01-09 op Rwrite,
120 aa495dd9 2022-01-22 op Tclunk = 120, /* 0x78 */
121 fb1a36c0 2022-01-09 op Rclunk,
122 aa495dd9 2022-01-22 op Tremove = 122, /* 0x7a */
123 fb1a36c0 2022-01-09 op Rremove,
124 aa495dd9 2022-01-22 op Tstat = 124, /* 0x7c */
125 fb1a36c0 2022-01-09 op Rstat,
126 aa495dd9 2022-01-22 op Twstat = 126, /* 0x7e */
127 fb1a36c0 2022-01-09 op Rwstat,
128 fb1a36c0 2022-01-09 op Tmax,
129 fb1a36c0 2022-01-09 op
130 fb1a36c0 2022-01-09 op /*
131 fb1a36c0 2022-01-09 op * plan9ports' include/fcall.h also has a
132 fb1a36c0 2022-01-09 op *
133 fb1a36c0 2022-01-09 op * Topenfd = 98,
134 fb1a36c0 2022-01-09 op * Ropenfd,
135 fb1a36c0 2022-01-09 op *
136 fb1a36c0 2022-01-09 op * which it's not mentioned in the 9p "rfc" over at
137 fb1a36c0 2022-01-09 op * 9p.cat-v.org. Ignoring that for now.
138 fb1a36c0 2022-01-09 op */
139 fb1a36c0 2022-01-09 op };
140 fb1a36c0 2022-01-09 op
141 fb1a36c0 2022-01-09 op #endif