2 * Copyright 2016 Jakub Klama <jceel@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted providing that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
22 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
23 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
29 * Based on libixp code: ©2007-2010 Kris Maglione <maglione.k at Gmail>
35 #include <sys/types.h>
36 #include <sys/param.h>
38 # include "apple_endian.h"
40 # include <sys/endian.h>
44 #include "lib9p_impl.h"
47 #define N(ary) (sizeof(ary) / sizeof(*ary))
48 #define STRING_SIZE(s) (L9P_WORD + (s != NULL ? (uint16_t)strlen(s) : 0))
49 #define QID_SIZE (L9P_BYTE + L9P_DWORD + L9P_QWORD)
51 static ssize_t l9p_iov_io(struct l9p_message *, void *, size_t);
52 static inline ssize_t l9p_pu8(struct l9p_message *, uint8_t *);
53 static inline ssize_t l9p_pu16(struct l9p_message *, uint16_t *);
54 static inline ssize_t l9p_pu32(struct l9p_message *, uint32_t *);
55 static inline ssize_t l9p_pu64(struct l9p_message *, uint64_t *);
56 static ssize_t l9p_pustring(struct l9p_message *, char **s);
57 static ssize_t l9p_pustrings(struct l9p_message *, uint16_t *, char **, size_t);
58 static ssize_t l9p_puqid(struct l9p_message *, struct l9p_qid *);
59 static ssize_t l9p_puqids(struct l9p_message *, uint16_t *, struct l9p_qid *q);
62 * Transfer data from incoming request, or to outgoing response,
63 * using msg to track position and direction within request/response.
65 * Returns the number of bytes actually transferred (which is always
66 * just len itself, converted to signed), or -1 if we ran out of space.
68 * Note that if we return -1, subsequent l9p_iov_io() calls with
69 * the same (and not-reset) msg and len > 0 will also return -1.
70 * This means most users can just check the *last* call for failure.
73 l9p_iov_io(struct l9p_message *msg, void *buffer, size_t len)
83 if (msg->lm_cursor_iov >= msg->lm_niov)
86 assert(buffer != NULL);
89 size_t idx = msg->lm_cursor_iov;
90 size_t space = msg->lm_iov[idx].iov_len - msg->lm_cursor_offset;
91 size_t towrite = MIN(space, left);
93 if (msg->lm_mode == L9P_PACK) {
94 memcpy((char *)msg->lm_iov[idx].iov_base +
95 msg->lm_cursor_offset, (char *)buffer + done,
99 if (msg->lm_mode == L9P_UNPACK) {
100 memcpy((char *)buffer + done,
101 (char *)msg->lm_iov[idx].iov_base +
102 msg->lm_cursor_offset, towrite);
105 msg->lm_cursor_offset += towrite;
110 if (space - towrite == 0) {
111 /* Advance to next iov */
112 msg->lm_cursor_iov++;
113 msg->lm_cursor_offset = 0;
115 if (msg->lm_cursor_iov >= msg->lm_niov && left > 0)
120 msg->lm_size += done;
121 return ((ssize_t)done);
125 * Pack or unpack a byte (8 bits).
127 * Returns 1 (success, 1 byte) or -1 (error).
129 static inline ssize_t
130 l9p_pu8(struct l9p_message *msg, uint8_t *val)
133 return (l9p_iov_io(msg, val, sizeof (uint8_t)));
137 * Pack or unpack 16-bit value.
141 static inline ssize_t
142 l9p_pu16(struct l9p_message *msg, uint16_t *val)
144 #if _BYTE_ORDER != _LITTLE_ENDIAN
146 * The ifdefs are annoying, but there is no need
147 * for all of this foolery on little-endian hosts,
148 * and I don't expect the compiler to optimize it
154 if (msg->lm_mode == L9P_PACK) {
155 copy = htole16(*val);
156 return (l9p_iov_io(msg, ©, sizeof (uint16_t)));
158 ret = l9p_iov_io(msg, val, sizeof (uint16_t));
159 *val = le16toh(*val);
162 return (l9p_iov_io(msg, val, sizeof (uint16_t)));
167 * Pack or unpack 32-bit value.
171 static inline ssize_t
172 l9p_pu32(struct l9p_message *msg, uint32_t *val)
174 #if _BYTE_ORDER != _LITTLE_ENDIAN
178 if (msg->lm_mode == L9P_PACK) {
179 copy = htole32(*val);
180 return (l9p_iov_io(msg, ©, sizeof (uint32_t)));
182 ret = l9p_iov_io(msg, val, sizeof (uint32_t));
183 *val = le32toh(*val);
186 return (l9p_iov_io(msg, val, sizeof (uint32_t)));
191 * Pack or unpack 64-bit value.
195 static inline ssize_t
196 l9p_pu64(struct l9p_message *msg, uint64_t *val)
198 #if _BYTE_ORDER != _LITTLE_ENDIAN
202 if (msg->lm_mode == L9P_PACK) {
203 copy = htole64(*val);
204 return (l9p_iov_io(msg, ©, sizeof (uint64_t)));
206 ret = l9p_iov_io(msg, val, sizeof (uint32_t));
207 *val = le64toh(*val);
210 return (l9p_iov_io(msg, val, sizeof (uint64_t)));
215 * Pack or unpack a string, encoded as 2-byte length followed by
216 * string bytes. The returned length is 2 greater than the
217 * length of the string itself.
219 * When unpacking, this allocates a new string (NUL-terminated).
221 * Return -1 on error (not space, or failed to allocate string,
222 * or illegal string).
224 * Note that pustring (and hence pustrings) can return an error
225 * even when l9p_iov_io succeeds.
228 l9p_pustring(struct l9p_message *msg, char **s)
232 if (msg->lm_mode == L9P_PACK)
233 len = *s != NULL ? (uint16_t)strlen(*s) : 0;
235 if (l9p_pu16(msg, &len) < 0)
238 if (msg->lm_mode == L9P_UNPACK) {
239 *s = l9p_calloc(1, len + 1);
244 if (l9p_iov_io(msg, *s, len) < 0)
247 if (msg->lm_mode == L9P_UNPACK) {
249 * An embedded NUL byte in a string is illegal.
250 * We don't necessarily have to check (we'll just
251 * treat it as a shorter string), but checking
252 * seems like a good idea.
254 if (memchr(*s, '\0', len) != NULL)
258 return ((ssize_t)len + 2);
262 * Pack or unpack a number (*num) of strings (but at most max of
265 * Returns the number of bytes transferred, including the packed
266 * number of strings. If packing and the packed number of strings
267 * was reduced, the original *num value is unchanged; only the
268 * wire-format number is reduced. If unpacking and the input
269 * number of strings exceeds the max, the incoming *num is reduced
270 * to lim, if needed. (NOTE ASYMMETRY HERE!)
272 * Returns -1 on error.
275 l9p_pustrings(struct l9p_message *msg, uint16_t *num, char **strings,
282 if (msg->lm_mode == L9P_PACK) {
286 adjusted = (uint16_t)lim;
287 r = l9p_pu16(msg, &adjusted);
289 r = l9p_pu16(msg, num);
292 *num = (uint16_t)(lim = max);
297 for (i = 0; i < lim; i++) {
298 ret = l9p_pustring(msg, &strings[i]);
309 * Pack or unpack a qid.
311 * Returns 13 (success) or -1 (error).
314 l9p_puqid(struct l9p_message *msg, struct l9p_qid *qid)
319 if (msg->lm_mode == L9P_PACK) {
321 r = l9p_pu8(msg, &type);
323 r = l9p_pu8(msg, &type);
327 r = l9p_pu32(msg, &qid->version);
329 r = l9p_pu64(msg, &qid->path);
331 return (r > 0 ? QID_SIZE : r);
335 * Pack or unpack *num qids.
337 * Returns 2 + 13 * *num (after possibly setting *num), or -1 on error.
340 l9p_puqids(struct l9p_message *msg, uint16_t *num, struct l9p_qid *qids)
345 r = l9p_pu16(msg, num);
349 if (*num > L9P_MAX_WELEM)
352 for (i = 0, lim = *num; i < lim; i++) {
353 ret = l9p_puqid(msg, &qids[i]);
362 * Pack or unpack a l9p_stat.
364 * These have variable size, and the size further depends on
365 * the protocol version.
367 * Returns the number of bytes packed/unpacked, or -1 on error.
370 l9p_pustat(struct l9p_message *msg, struct l9p_stat *stat,
371 enum l9p_version version)
376 /* The on-wire size field excludes the size of the size field. */
377 if (msg->lm_mode == L9P_PACK)
378 size = l9p_sizeof_stat(stat, version) - 2;
380 r += l9p_pu16(msg, &size);
381 r += l9p_pu16(msg, &stat->type);
382 r += l9p_pu32(msg, &stat->dev);
383 r += l9p_puqid(msg, &stat->qid);
384 r += l9p_pu32(msg, &stat->mode);
385 r += l9p_pu32(msg, &stat->atime);
386 r += l9p_pu32(msg, &stat->mtime);
387 r += l9p_pu64(msg, &stat->length);
388 r += l9p_pustring(msg, &stat->name);
389 r += l9p_pustring(msg, &stat->uid);
390 r += l9p_pustring(msg, &stat->gid);
391 r += l9p_pustring(msg, &stat->muid);
393 if (version >= L9P_2000U) {
394 r += l9p_pustring(msg, &stat->extension);
395 r += l9p_pu32(msg, &stat->n_uid);
396 r += l9p_pu32(msg, &stat->n_gid);
397 r += l9p_pu32(msg, &stat->n_muid);
407 * Pack or unpack a variable-length dirent.
409 * If unpacking, the name field is malloc()ed and the caller must
412 * Returns the wire-format length, or -1 if we ran out of room.
415 l9p_pudirent(struct l9p_message *msg, struct l9p_dirent *de)
419 r = l9p_puqid(msg, &de->qid);
420 r += l9p_pu64(msg, &de->offset);
421 r += l9p_pu8(msg, &de->type);
422 s = l9p_pustring(msg, &de->name);
423 if (r < QID_SIZE + 8 + 1 || s < 0)
429 * Pack or unpack a request or response (fcall).
431 * Returns 0 on success, -1 on error. (It's up to the caller
432 * to call l9p_freefcall on our failure.)
435 l9p_pufcall(struct l9p_message *msg, union l9p_fcall *fcall,
436 enum l9p_version version)
442 * Get overall length, type, and tag, which should appear
443 * in all messages. If not even that works, abort immediately.
445 l9p_pu32(msg, &length);
446 l9p_pu8(msg, &fcall->hdr.type);
447 r = l9p_pu16(msg, &fcall->hdr.tag);
452 * Decode remainder of message. When unpacking, this may
453 * allocate memory, even if we fail during the decode.
454 * Note that the initial fcall is zeroed out, though, so
455 * we can just freefcall() to release whatever might have
456 * gotten allocated, if the unpack fails due to a short
459 switch (fcall->hdr.type) {
462 l9p_pu32(msg, &fcall->version.msize);
463 r = l9p_pustring(msg, &fcall->version.version);
467 l9p_pu32(msg, &fcall->tauth.afid);
468 r = l9p_pustring(msg, &fcall->tauth.uname);
471 r = l9p_pustring(msg, &fcall->tauth.aname);
474 if (version >= L9P_2000U)
475 r = l9p_pu32(msg, &fcall->tauth.n_uname);
479 r = l9p_puqid(msg, &fcall->rauth.aqid);
483 l9p_pu32(msg, &fcall->hdr.fid);
484 l9p_pu32(msg, &fcall->tattach.afid);
485 r = l9p_pustring(msg, &fcall->tattach.uname);
488 r = l9p_pustring(msg, &fcall->tattach.aname);
491 if (version >= L9P_2000U)
492 r = l9p_pu32(msg, &fcall->tattach.n_uname);
496 r = l9p_puqid(msg, &fcall->rattach.qid);
500 r = l9p_pustring(msg, &fcall->error.ename);
503 if (version >= L9P_2000U)
504 r = l9p_pu32(msg, &fcall->error.errnum);
508 r = l9p_pu32(msg, &fcall->error.errnum);
512 r = l9p_pu16(msg, &fcall->tflush.oldtag);
519 l9p_pu32(msg, &fcall->hdr.fid);
520 l9p_pu32(msg, &fcall->twalk.newfid);
521 r = l9p_pustrings(msg, &fcall->twalk.nwname,
522 fcall->twalk.wname, N(fcall->twalk.wname));
526 r = l9p_puqids(msg, &fcall->rwalk.nwqid, fcall->rwalk.wqid);
530 l9p_pu32(msg, &fcall->hdr.fid);
531 r = l9p_pu8(msg, &fcall->topen.mode);
535 l9p_puqid(msg, &fcall->ropen.qid);
536 r = l9p_pu32(msg, &fcall->ropen.iounit);
540 l9p_pu32(msg, &fcall->hdr.fid);
541 r = l9p_pustring(msg, &fcall->tcreate.name);
544 l9p_pu32(msg, &fcall->tcreate.perm);
545 r = l9p_pu8(msg, &fcall->tcreate.mode);
546 if (version >= L9P_2000U)
547 r = l9p_pustring(msg, &fcall->tcreate.extension);
551 l9p_puqid(msg, &fcall->rcreate.qid);
552 r = l9p_pu32(msg, &fcall->rcreate.iounit);
557 l9p_pu32(msg, &fcall->hdr.fid);
558 l9p_pu64(msg, &fcall->io.offset);
559 r = l9p_pu32(msg, &fcall->io.count);
564 r = l9p_pu32(msg, &fcall->io.count);
568 l9p_pu32(msg, &fcall->hdr.fid);
569 l9p_pu64(msg, &fcall->io.offset);
570 r = l9p_pu32(msg, &fcall->io.count);
574 r = l9p_pu32(msg, &fcall->io.count);
581 r = l9p_pu32(msg, &fcall->hdr.fid);
590 uint16_t size = l9p_sizeof_stat(&fcall->rstat.stat,
592 l9p_pu16(msg, &size);
593 r = l9p_pustat(msg, &fcall->rstat.stat, version);
600 l9p_pu32(msg, &fcall->hdr.fid);
601 l9p_pu16(msg, &size);
602 r = l9p_pustat(msg, &fcall->twstat.stat, version);
610 l9p_pu32(msg, &fcall->rstatfs.statfs.type);
611 l9p_pu32(msg, &fcall->rstatfs.statfs.bsize);
612 l9p_pu64(msg, &fcall->rstatfs.statfs.blocks);
613 l9p_pu64(msg, &fcall->rstatfs.statfs.bfree);
614 l9p_pu64(msg, &fcall->rstatfs.statfs.bavail);
615 l9p_pu64(msg, &fcall->rstatfs.statfs.files);
616 l9p_pu64(msg, &fcall->rstatfs.statfs.ffree);
617 l9p_pu64(msg, &fcall->rstatfs.statfs.fsid);
618 r = l9p_pu32(msg, &fcall->rstatfs.statfs.namelen);
622 l9p_pu32(msg, &fcall->hdr.fid);
623 r = l9p_pu32(msg, &fcall->tlopen.flags);
627 l9p_puqid(msg, &fcall->rlopen.qid);
628 r = l9p_pu32(msg, &fcall->rlopen.iounit);
632 l9p_pu32(msg, &fcall->hdr.fid);
633 r = l9p_pustring(msg, &fcall->tlcreate.name);
636 l9p_pu32(msg, &fcall->tlcreate.flags);
637 l9p_pu32(msg, &fcall->tlcreate.mode);
638 r = l9p_pu32(msg, &fcall->tlcreate.gid);
642 l9p_puqid(msg, &fcall->rlcreate.qid);
643 r = l9p_pu32(msg, &fcall->rlcreate.iounit);
647 l9p_pu32(msg, &fcall->hdr.fid);
648 r = l9p_pustring(msg, &fcall->tsymlink.name);
651 r = l9p_pustring(msg, &fcall->tsymlink.symtgt);
654 r = l9p_pu32(msg, &fcall->tlcreate.gid);
658 r = l9p_puqid(msg, &fcall->rsymlink.qid);
662 l9p_pu32(msg, &fcall->hdr.fid);
663 r = l9p_pustring(msg, &fcall->tmknod.name);
666 l9p_pu32(msg, &fcall->tmknod.mode);
667 l9p_pu32(msg, &fcall->tmknod.major);
668 l9p_pu32(msg, &fcall->tmknod.minor);
669 r = l9p_pu32(msg, &fcall->tmknod.gid);
673 r = l9p_puqid(msg, &fcall->rmknod.qid);
677 l9p_pu32(msg, &fcall->hdr.fid);
678 l9p_pu32(msg, &fcall->trename.dfid);
679 r = l9p_pustring(msg, &fcall->trename.name);
686 r = l9p_pu32(msg, &fcall->hdr.fid);
690 r = l9p_pustring(msg, &fcall->rreadlink.target);
694 l9p_pu32(msg, &fcall->hdr.fid);
695 r = l9p_pu64(msg, &fcall->tgetattr.request_mask);
699 l9p_pu64(msg, &fcall->rgetattr.valid);
700 l9p_puqid(msg, &fcall->rgetattr.qid);
701 l9p_pu32(msg, &fcall->rgetattr.mode);
702 l9p_pu32(msg, &fcall->rgetattr.uid);
703 l9p_pu32(msg, &fcall->rgetattr.gid);
704 l9p_pu64(msg, &fcall->rgetattr.nlink);
705 l9p_pu64(msg, &fcall->rgetattr.rdev);
706 l9p_pu64(msg, &fcall->rgetattr.size);
707 l9p_pu64(msg, &fcall->rgetattr.blksize);
708 l9p_pu64(msg, &fcall->rgetattr.blocks);
709 l9p_pu64(msg, &fcall->rgetattr.atime_sec);
710 l9p_pu64(msg, &fcall->rgetattr.atime_nsec);
711 l9p_pu64(msg, &fcall->rgetattr.mtime_sec);
712 l9p_pu64(msg, &fcall->rgetattr.mtime_nsec);
713 l9p_pu64(msg, &fcall->rgetattr.ctime_sec);
714 l9p_pu64(msg, &fcall->rgetattr.ctime_nsec);
715 l9p_pu64(msg, &fcall->rgetattr.btime_sec);
716 l9p_pu64(msg, &fcall->rgetattr.btime_nsec);
717 l9p_pu64(msg, &fcall->rgetattr.gen);
718 r = l9p_pu64(msg, &fcall->rgetattr.data_version);
722 l9p_pu32(msg, &fcall->hdr.fid);
723 l9p_pu32(msg, &fcall->tsetattr.valid);
724 l9p_pu32(msg, &fcall->tsetattr.mode);
725 l9p_pu32(msg, &fcall->tsetattr.uid);
726 l9p_pu32(msg, &fcall->tsetattr.gid);
727 l9p_pu64(msg, &fcall->tsetattr.size);
728 l9p_pu64(msg, &fcall->tsetattr.atime_sec);
729 l9p_pu64(msg, &fcall->tsetattr.atime_nsec);
730 l9p_pu64(msg, &fcall->tsetattr.mtime_sec);
731 r = l9p_pu64(msg, &fcall->tsetattr.mtime_nsec);
738 l9p_pu32(msg, &fcall->hdr.fid);
739 l9p_pu32(msg, &fcall->txattrwalk.newfid);
740 r = l9p_pustring(msg, &fcall->txattrwalk.name);
744 r = l9p_pu64(msg, &fcall->rxattrwalk.size);
747 case L9P_TXATTRCREATE:
748 l9p_pu32(msg, &fcall->hdr.fid);
749 r = l9p_pustring(msg, &fcall->txattrcreate.name);
752 l9p_pu64(msg, &fcall->txattrcreate.attr_size);
753 r = l9p_pu32(msg, &fcall->txattrcreate.flags);
756 case L9P_RXATTRCREATE:
760 r = l9p_pu32(msg, &fcall->hdr.fid);
767 l9p_pu32(msg, &fcall->hdr.fid);
768 l9p_pu8(msg, &fcall->tlock.type);
769 l9p_pu32(msg, &fcall->tlock.flags);
770 l9p_pu64(msg, &fcall->tlock.start);
771 l9p_pu64(msg, &fcall->tlock.length);
772 l9p_pu32(msg, &fcall->tlock.proc_id);
773 r = l9p_pustring(msg, &fcall->tlock.client_id);
777 r = l9p_pu8(msg, &fcall->rlock.status);
781 l9p_pu32(msg, &fcall->hdr.fid);
785 l9p_pu8(msg, &fcall->getlock.type);
786 l9p_pu64(msg, &fcall->getlock.start);
787 l9p_pu64(msg, &fcall->getlock.length);
788 l9p_pu32(msg, &fcall->getlock.proc_id);
789 r = l9p_pustring(msg, &fcall->getlock.client_id);
793 l9p_pu32(msg, &fcall->tlink.dfid);
794 l9p_pu32(msg, &fcall->hdr.fid);
795 r = l9p_pustring(msg, &fcall->tlink.name);
802 l9p_pu32(msg, &fcall->hdr.fid);
803 r = l9p_pustring(msg, &fcall->tmkdir.name);
806 l9p_pu32(msg, &fcall->tmkdir.mode);
807 r = l9p_pu32(msg, &fcall->tmkdir.gid);
811 r = l9p_puqid(msg, &fcall->rmkdir.qid);
815 l9p_pu32(msg, &fcall->hdr.fid);
816 r = l9p_pustring(msg, &fcall->trenameat.oldname);
819 l9p_pu32(msg, &fcall->trenameat.newdirfid);
820 r = l9p_pustring(msg, &fcall->trenameat.newname);
827 l9p_pu32(msg, &fcall->hdr.fid);
828 r = l9p_pustring(msg, &fcall->tunlinkat.name);
831 r = l9p_pu32(msg, &fcall->tunlinkat.flags);
838 L9P_LOG(L9P_ERROR, "%s(): missing case for type %d",
839 __func__, fcall->hdr.type);
843 /* Check for over- or under-run, or pustring error. */
847 if (msg->lm_mode == L9P_PACK) {
848 /* Rewind to the beginning and install size at front. */
849 uint32_t len = (uint32_t)msg->lm_size;
850 msg->lm_cursor_offset = 0;
851 msg->lm_cursor_iov = 0;
854 * Subtract 4 bytes from current size, becase we're
855 * overwriting size (rewinding message to the beginning)
856 * and writing again, which will increase it 4 more.
858 msg->lm_size -= sizeof(uint32_t);
860 if (fcall->hdr.type == L9P_RREAD ||
861 fcall->hdr.type == L9P_RREADDIR)
862 len += fcall->io.count;
871 * Free any strings or other data malloc'ed in the process of
872 * packing or unpacking an fcall.
875 l9p_freefcall(union l9p_fcall *fcall)
879 switch (fcall->hdr.type) {
883 free(fcall->version.version);
887 free(fcall->tattach.aname);
888 free(fcall->tattach.uname);
892 for (i = 0; i < fcall->twalk.nwname; i++)
893 free(fcall->twalk.wname[i]);
898 free(fcall->tcreate.name);
899 free(fcall->tcreate.extension);
903 l9p_freestat(&fcall->rstat.stat);
907 l9p_freestat(&fcall->twstat.stat);
911 free(fcall->tlcreate.name);
915 free(fcall->tsymlink.name);
916 free(fcall->tsymlink.symtgt);
920 free(fcall->tmknod.name);
924 free(fcall->trename.name);
928 free(fcall->rreadlink.target);
932 free(fcall->txattrwalk.name);
935 case L9P_TXATTRCREATE:
936 free(fcall->txattrcreate.name);
940 free(fcall->tlock.client_id);
945 free(fcall->getlock.client_id);
949 free(fcall->tlink.name);
953 free(fcall->tmkdir.name);
957 free(fcall->trenameat.oldname);
958 free(fcall->trenameat.newname);
962 free(fcall->tunlinkat.name);
968 l9p_freestat(struct l9p_stat *stat)
971 free(stat->extension);
978 l9p_sizeof_stat(struct l9p_stat *stat, enum l9p_version version)
980 uint16_t size = L9P_WORD /* size */
981 + L9P_WORD /* type */
982 + L9P_DWORD /* dev */
984 + 3 * L9P_DWORD /* mode, atime, mtime */
985 + L9P_QWORD /* length */
986 + STRING_SIZE(stat->name)
987 + STRING_SIZE(stat->uid)
988 + STRING_SIZE(stat->gid)
989 + STRING_SIZE(stat->muid);
991 if (version >= L9P_2000U) {
992 size += STRING_SIZE(stat->extension)