2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
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.
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.
33 write_hdr(uint32_t len, uint8_t type, uint16_t tag)
37 log_debug("enqueuing a packet; len=%"PRIu32" type=%d[%s] tag=%d",
38 len, type, pp_msg_type(type), tag);
41 /* type is one byte, no endiannes issues */
44 evbuffer_add(evb, &len, sizeof(len));
45 evbuffer_add(evb, &type, sizeof(type));
46 evbuffer_add(evb, &tag, sizeof(tag));
50 write_hdr_auto(uint32_t len, uint8_t type)
52 if (++iota_tag == NOTAG)
54 write_hdr(len, type, iota_tag);
58 write_str(uint16_t len, const char *str)
63 evbuffer_add(evb, &len, sizeof(len));
64 evbuffer_add(evb, str, l);
68 write_str_auto(const char *str)
70 write_str(strlen(str), str);
77 evbuffer_add(evb, &x, sizeof(x));
81 write_32(uint32_t fid)
84 evbuffer_add(evb, &fid, sizeof(fid));
88 write_16(uint16_t tag)
91 evbuffer_add(evb, &tag, sizeof(tag));
97 evbuffer_add(evb, &x, sizeof(x));
103 tversion(const char *v, uint32_t msize)
110 /* msize[4] version[s] */
111 len = sizeof(msize) + sizeof(sl) + sl;
112 write_hdr(len, Tversion, NOTAG);
118 tattach(uint32_t fid, uint32_t afid, const char *uname, const char *aname)
126 /* fid[4] afid[4] uname[s] aname[s] */
127 len = sizeof(fid) + sizeof(afid) + sizeof(ul) + ul
129 write_hdr_auto(len, Tattach);
132 write_str(ul, uname);
133 write_str(al, aname);
143 write_hdr_auto(len, Tclunk);
148 tflush(uint16_t oldtag)
153 len = sizeof(oldtag);
154 write_hdr_auto(len, Tflush);
159 twalk(uint32_t fid, uint32_t newfid, const char **wnames, size_t nwname)
164 /* fid[4] newfid[4] nwname[2] nwname*(wname[s]) */
165 len = sizeof(fid) + sizeof(newfid) + 2;
166 for (i = 0; i < nwname; ++i)
167 len += 2 + strlen(wnames[i]);
169 write_hdr_auto(len, Twalk);
173 for (i = 0; i < nwname; ++i)
174 write_str_auto(wnames[i]);
178 topen(uint32_t fid, uint8_t mode)
183 len = sizeof(fid) + sizeof(mode);
184 write_hdr_auto(len, Topen);
190 tread(uint32_t fid, uint64_t off, uint32_t count)
194 /* fid[4] off[8] count[4] */
195 len = sizeof(fid) + sizeof(off) + sizeof(count);
196 write_hdr_auto(len, Tread);