2 /* $Id: nfs4_subs.c,v 1.52 2003/11/05 14:58:59 rees Exp $ */
6 * the regents of the university of michigan
9 * permission is granted to use, copy, create derivative works and redistribute
10 * this software and such derivative works for any purpose, so long as the name
11 * of the university of michigan is not used in any advertising or publicity
12 * pertaining to the use or distribution of this software without specific,
13 * written prior authorization. if the above copyright notice or any other
14 * identification of the university of michigan is included in any copy of any
15 * portion of this software, then the disclaimer below must also be included.
17 * this software is provided as is, without representation from the university
18 * of michigan as to its fitness for any purpose, and without warranty by the
19 * university of michigan of any kind, either express or implied, including
20 * without limitation the implied warranties of merchantability and fitness for
21 * a particular purpose. the regents of the university of michigan shall not be
22 * liable for any damages, including special, indirect, incidental, or
23 * consequential damages, with respect to any claim arising out of or in
24 * connection with the use of the software, even if it has been or is hereafter
25 * advised of the possibility of such damages.
28 #include <sys/cdefs.h>
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
36 #include <sys/mount.h>
37 #include <sys/vnode.h>
38 #include <sys/namei.h>
40 #include <sys/socket.h>
42 #include <sys/malloc.h>
43 #include <sys/sysent.h>
44 #include <sys/syscall.h>
45 #include <sys/sysproto.h>
46 #include <sys/fcntl.h>
48 #include <machine/stdarg.h>
51 #include <vm/vm_object.h>
52 #include <vm/vm_extern.h>
55 #include <rpc/rpcclnt.h>
57 #include <nfs/rpcv2.h>
58 #include <nfs/nfsproto.h>
59 #include <nfsclient/nfs.h>
60 #include <nfs4client/nfs4.h>
61 #include <nfsclient/nfsnode.h>
62 #include <nfsclient/nfsmount.h>
63 #include <nfs/xdr_subs.h>
64 #include <nfsclient/nfsm_subs.h>
66 #include <nfs4client/nfs4_dev.h>
67 #include <nfs4client/nfs4_idmap.h>
68 #include <nfs4client/nfs4m_subs.h>
70 #include <netinet/in.h>
72 #define NFSM_DISSECT(s) do { \
73 tl = nfsm_dissect_xx((s), md, dpos); \
75 printf("NFSM_DISSECT error; allocation (%s/%d) (%s:%d)\n", #s, s, __FILE__, __LINE__); \
80 #define NFSM_ADV(s) do { \
81 t1 = nfsm_adv_xx((s), md, dpos); \
83 printf("NFSM_ADV error; allocation (%s/%d) (%s:%d)\n", #s, s, __FILE__, __LINE__); \
88 #define NFSM_MTOTIME(t) do { \
89 NFSM_DISSECT(3 * NFSX_UNSIGNED); \
90 (t).tv_sec = fxdr_hyper(tl); \
92 (t).tv_nsec = fxdr_unsigned(long, *tl++); \
95 static uint32_t __fsinfo_bm[2], __fsattr_bm[2], __getattr_bm[2], __readdir_bm[2];
97 nfsv4bitmap nfsv4_fsinfobm = { 2, __fsinfo_bm };
98 nfsv4bitmap nfsv4_fsattrbm = { 2, __fsattr_bm };
99 nfsv4bitmap nfsv4_getattrbm = { 2, __getattr_bm };
100 nfsv4bitmap nfsv4_readdirbm = { 2, __readdir_bm };
102 /* Helper routines */
103 int nfsm_v4build_attrs_xx(struct vattr *, struct mbuf **, caddr_t *);
104 int nfsm_v4dissect_changeinfo_xx(nfsv4changeinfo *, struct mbuf **, caddr_t *);
110 /* Set up bitmasks */
111 FA4_SET(FA4_FSID, __fsinfo_bm);
112 FA4_SET(FA4_MAXREAD, __fsinfo_bm);
113 FA4_SET(FA4_MAXWRITE, __fsinfo_bm);
114 FA4_SET(FA4_LEASE_TIME, __fsinfo_bm);
116 FA4_SET(FA4_FSID, __fsattr_bm);
117 FA4_SET(FA4_FILES_FREE, __fsattr_bm);
118 FA4_SET(FA4_FILES_TOTAL, __fsattr_bm);
119 FA4_SET(FA4_SPACE_AVAIL, __fsattr_bm);
120 FA4_SET(FA4_SPACE_FREE, __fsattr_bm);
121 FA4_SET(FA4_SPACE_TOTAL, __fsattr_bm);
123 FA4_SET(FA4_TYPE, __getattr_bm);
124 FA4_SET(FA4_FSID, __getattr_bm);
125 FA4_SET(FA4_SIZE, __getattr_bm);
126 FA4_SET(FA4_MODE, __getattr_bm);
127 FA4_SET(FA4_RAWDEV, __getattr_bm);
128 FA4_SET(FA4_NUMLINKS, __getattr_bm);
129 FA4_SET(FA4_OWNER, __getattr_bm);
130 FA4_SET(FA4_OWNER_GROUP, __getattr_bm);
131 FA4_SET(FA4_FILEID, __getattr_bm);
132 FA4_SET(FA4_TIME_MODIFY, __getattr_bm);
133 FA4_SET(FA4_TIME_ACCESS, __getattr_bm);
135 FA4_SET(FA4_TYPE, __readdir_bm);
136 FA4_SET(FA4_FSID, __readdir_bm);
137 FA4_SET(FA4_FILEID, __readdir_bm);
138 FA4_SET(FA4_RDATTR_ERROR, __readdir_bm);
146 nfs_v4fileid4_to_fileid(uint64_t fid)
148 return ((uint32_t)((fid >> 32) | fid));
152 nfs_v4initcompound(struct nfs4_compound *cp)
154 bzero(cp, sizeof(*cp));
158 * Build/dissect XDR buffer with a format string.
162 * s - stringlength, string
163 * k - skip length (bytes)
164 * a - arraylength, componentlenght, array
165 * o - opaque fix length
166 * O - opaque var length in bytes
170 nfsm_buildf_xx(struct mbuf **mb, caddr_t *bpos, char *fmt, ...)
172 uint32_t *tl, t1, len, uval;
178 for (which = fmt; *which != '\0'; which++)
180 case 'u': /* Unsigned */
181 tl = nfsm_build_xx(NFSX_UNSIGNED, mb, bpos);
182 uval = va_arg(args, uint32_t);
183 *tl++ = txdr_unsigned(uval);
185 case 'h': /* Hyper */
186 tl = nfsm_build_xx(2 * NFSX_UNSIGNED, mb, bpos);
187 hval = va_arg(args, uint64_t);
188 txdr_hyper(hval, tl);
190 case 'o': /* Fixed-length opaque */
191 len = va_arg(args, uint32_t);
192 p = va_arg(args, char *);
193 tl = nfsm_build_xx(nfsm_rndup(len), mb, bpos);
196 case 'O': /* Variable-length opaque */
197 case 's': /* String */
198 len = va_arg(args, uint32_t);
199 p = va_arg(args, char *);
200 t1 = nfsm_strtom_xx(p, len, len, mb, bpos);
203 len = va_arg(args, uint32_t);
204 nfsm_build_xx(nfsm_rndup(len), mb, bpos);
207 panic("Invalid buildf string %s[%c]", fmt, *which);
214 nfsm_dissectf_xx(struct mbuf **md, caddr_t *dpos, char *fmt, ...)
216 uint32_t *tl, t1, len, *uval;
222 for (which = fmt; *which != '\0'; which++)
224 case 'u': /* Unsigned */
225 tl = nfsm_dissect_xx(NFSX_UNSIGNED, md, dpos);
228 uval = va_arg(args, uint32_t *);
229 *uval = fxdr_unsigned(uint32_t, *tl++);
231 case 'h': /* Hyper */
232 tl = nfsm_dissect_xx(2 * NFSX_UNSIGNED, md, dpos);
235 hval = va_arg(args, uint64_t *);
236 *hval = fxdr_hyper(tl);
238 case 'o': /* Fixed-length opaque */
239 len = va_arg(args, uint32_t);
240 p = va_arg(args, void *);
241 tl = nfsm_dissect_xx(nfsm_rndup(len), md, dpos);
246 case 'O': /* Variable-length opaque */
247 case 's': /* String */
248 len = va_arg(args, uint32_t);
249 p = va_arg(args, char *);
250 tl = nfsm_dissect_xx(nfsm_rndup(len), md, dpos);
255 case 'k': /* Skip bytes */
256 len = va_arg(args, uint32_t);
257 t1 = nfsm_adv_xx(nfsm_rndup(len), md, dpos);
260 panic("Invalid dissectf string %s[%c]", fmt, *which);
269 * XXX - There are a few problems with the way the postops are places
270 * in the code. Ideally, they should be taken care of immediately, as
271 * to avoid uneceesary waits for mutexes, but then we would be
272 * introducing even more complexity by having to handle two separate
273 * cases. Also, since they are placed at the end of the vnops', there
274 * may be operations which sleep in between, further extending this
275 * wait. It is conceivable that there is a deadlock condition there,
278 * Also, for vnops that do multiple operations, it's inconvenient
279 * since on error, individual decoding will got nfsmout.
283 nfs_v4postop(struct nfs4_compound *cp, int status)
285 struct nfs4_fctx *fcp = cp->fcp;
288 * XXX does the previous result need to be stores with the
289 * lockowner? ack, spec is unclear ..
293 if (cp->seqidused < cp->rep_nops ||
294 (cp->seqidused + 1 == cp->rep_nops &&
295 NFS4_SEQIDMUTATINGERROR(status)))
296 fcp->lop->lo_seqid++;
302 nfs_v4handlestatus(int status, struct nfs4_compound *cp)
308 * Initial setup of compound.
312 nfsm_v4build_compound_xx(struct nfs4_compound *cp, char *tag,
313 struct mbuf **mb, caddr_t *bpos)
315 uint32_t t1, *tl, siz;
319 t1 = nfsm_rndup(siz) + NFSX_UNSIGNED;
320 if (t1 <= M_TRAILINGSPACE(*mb)) {
321 tl = nfsm_build_xx(t1, mb, bpos);
322 *tl++ = txdr_unsigned(siz);
323 *(tl + ((t1 >> 2) - 2)) = 0;
326 t1 = nfsm_strtmbuf(mb, bpos, (const char *)tag, siz);
331 /* Minor version and argarray*/
332 tl = nfsm_build_xx(2 * NFSX_UNSIGNED, mb, bpos);
333 *tl++ = txdr_unsigned(NFS4_MINOR_VERSION);
334 /* Save for backfill */
336 *tl = txdr_unsigned(0);
346 * - backfill for stateid, and such
349 nfsm_v4build_finalize_xx(struct nfs4_compound *cp, struct mbuf **mb, caddr_t *bpos)
351 *cp->req_nopsp = txdr_unsigned(cp->req_nops);
357 nfsm_v4build_putfh_xx(struct nfs4_compound *cp, struct vnode *vp,
358 struct mbuf **mb, caddr_t *bpos)
363 nfsm_buildf_xx(mb, bpos, "u", NFSV4OP_PUTFH);
366 t1 = nfsm_fhtom_xx(vp, 1, mb, bpos);
377 nfsm_v4build_putfh_nv_xx(struct nfs4_compound *cp, struct nfs4_oparg_getfh *gfh,
378 struct mbuf **mb, caddr_t *bpos)
380 nfsm_buildf_xx(mb, bpos, "uuo",
392 nfsm_v4build_simple_xx(struct nfs4_compound *cp, uint32_t op,
393 struct mbuf **mb, caddr_t *bpos)
395 nfsm_buildf_xx(mb, bpos, "u", op);
403 nfsm_v4build_getattr_xx(struct nfs4_compound *cp, struct nfs4_oparg_getattr *ga,
404 struct mbuf **mb, caddr_t *bpos)
408 /* Op + bitmap length + bitmap */
409 nfsm_buildf_xx(mb, bpos, "uu", NFSV4OP_GETATTR, ga->bm->bmlen);
410 for (i = 0; i < ga->bm->bmlen; i++)
411 nfsm_buildf_xx(mb, bpos, "u", ga->bm->bmval[i]);
420 nfsm_v4build_setattr_xx(struct nfs4_compound *cp, struct vattr *vap,
421 struct nfs4_fctx *fcp, struct mbuf **mb, caddr_t *bpos)
424 static char zero_stateid[NFSX_V4STATEID];
426 nfsm_buildf_xx(mb, bpos, "uo",
428 NFSX_V4STATEID, fcp ? fcp->stateid : zero_stateid);
429 error = nfsm_v4build_attrs_xx(vap, mb, bpos);
437 nfsm_v4build_getfh_xx(struct nfs4_compound *cp, struct nfs4_oparg_getfh *gfh,
438 struct mbuf **mb, caddr_t *bpos)
440 nfsm_buildf_xx(mb, bpos, "u", NFSV4OP_GETFH);
449 nfsm_v4build_lookup_xx(struct nfs4_compound *cp, struct nfs4_oparg_lookup *l,
450 struct mbuf **mb, caddr_t *bpos)
452 nfsm_buildf_xx(mb, bpos, "us", NFSV4OP_LOOKUP, l->namelen, l->name);
461 nfsm_v4build_setclientid_xx(struct nfs4_compound *cp,
462 struct nfs4_oparg_setclientid *sci, struct mbuf **mb, caddr_t *bpos)
468 nfsm_buildf_xx(mb, bpos, "uuusussu",
470 tv.tv_sec, tv.tv_usec,
471 sci->namelen, sci->name,
473 sci->cb_netidlen, sci->cb_netid,
474 sci->cb_univaddrlen, sci->cb_univaddr,
483 nfsm_v4build_setclientid_confirm_xx(struct nfs4_compound *cp,
484 struct nfs4_oparg_setclientid *sci, struct mbuf **mb, caddr_t *bpos)
486 nfsm_buildf_xx(mb, bpos, "uho",
487 NFSV4OP_SETCLIENTID_CONFIRM,
489 sizeof(sci->verf), sci->verf);
497 nfsm_v4build_open_xx(struct nfs4_compound *cp, struct nfs4_oparg_open *op,
498 struct mbuf **mb, caddr_t *bpos)
501 struct nfs4_lowner *lop = op->fcp->lop;
503 nfsm_buildf_xx(mb, bpos, "uuuuhuu",
506 op->flags & O_ACCMODE,
507 NFSV4OPENSHARE_DENY_NONE,
508 cp->nmp->nm_clientid,
511 if (op->flags & O_CREAT) {
512 nfsm_buildf_xx(mb, bpos, "u", OTCREATE);
513 /* openflag4: mode */
514 nfsm_buildf_xx(mb, bpos, "u", CMUNCHECKED);
515 /* openflag4: createattrs... */
516 if (op->vap != NULL) {
517 if (op->flags & O_TRUNC)
518 op->vap->va_size = 0;
519 error = nfsm_v4build_attrs_xx(op->vap, mb, bpos);
523 nfsm_buildf_xx(mb, bpos, "uu", 0, 0);
525 nfsm_buildf_xx(mb, bpos, "u", OTNOCREATE);
527 nfsm_buildf_xx(mb, bpos, "us", op->ctype,
528 op->cnp->cn_namelen, op->cnp->cn_nameptr);
530 cp->seqidused = cp->req_nops++;
541 nfsm_v4build_open_confirm_xx(struct nfs4_compound *cp, struct nfs4_oparg_open *op,
542 struct mbuf **mb, caddr_t *bpos)
544 nfsm_buildf_xx(mb, bpos, "uou",
545 NFSV4OP_OPEN_CONFIRM,
546 NFSX_V4STATEID, op->fcp->stateid,
547 op->fcp->lop->lo_seqid);
549 cp->seqidused = cp->req_nops++;
560 nfsm_v4build_close_xx(struct nfs4_compound *cp, struct nfs4_fctx *fcp,
561 struct mbuf **mb, caddr_t *bpos)
563 struct nfs4_lowner *lop = fcp->lop;
565 nfsm_buildf_xx(mb, bpos, "uuo",
568 NFSX_V4STATEID, fcp->stateid);
570 cp->seqidused = cp->req_nops++;
577 nfsm_v4build_access_xx(struct nfs4_compound *cp, struct nfs4_oparg_access *acc,
578 struct mbuf **mb, caddr_t *bpos)
580 nfsm_buildf_xx(mb, bpos, "uu", NFSV4OP_ACCESS, acc->mode);
587 nfsm_v4build_read_xx(struct nfs4_compound *cp, struct nfs4_oparg_read *r,
588 struct mbuf **mb, caddr_t *bpos)
590 nfsm_buildf_xx(mb, bpos, "uohu",
592 NFSX_V4STATEID, r->fcp->stateid,
601 nfsm_v4build_write_xx(struct nfs4_compound *cp, struct nfs4_oparg_write *w,
602 struct mbuf **mb, caddr_t *bpos)
604 nfsm_buildf_xx(mb, bpos, "uohuu",
606 NFSX_V4STATEID, w->fcp->stateid,
611 return (nfsm_uiotombuf(w->uiop, mb, w->cnt, bpos));
615 nfsm_v4build_commit_xx(struct nfs4_compound *cp, struct nfs4_oparg_commit *c,
616 struct mbuf **mb, caddr_t *bpos)
618 nfsm_buildf_xx(mb, bpos, "uhu", NFSV4OP_COMMIT, c->start, c->len);
625 nfsm_v4build_readdir_xx(struct nfs4_compound *cp, struct nfs4_oparg_readdir *r,
626 struct mbuf **mb, caddr_t *bpos)
630 nfsm_buildf_xx(mb, bpos, "uhouuu",
633 sizeof(r->verf), r->verf,
634 r->cnt >> 4, /* meaningless "dircount" field */
638 for (i = 0; i < r->bm->bmlen; i++)
639 nfsm_buildf_xx(mb, bpos, "u", r->bm->bmval[i]);
647 nfsm_v4build_renew_xx(struct nfs4_compound *cp, uint64_t cid,
648 struct mbuf **mb, caddr_t *bpos)
650 nfsm_buildf_xx(mb, bpos, "uh", NFSV4OP_RENEW, cid);
657 nfsm_v4build_create_xx(struct nfs4_compound *cp, struct nfs4_oparg_create *c,
658 struct mbuf **mb, caddr_t *bpos)
662 nfsm_buildf_xx(mb, bpos, "uu", NFSV4OP_CREATE, c->type);
664 if (c->type == NFLNK)
666 nfsm_buildf_xx(mb, bpos, "s", strlen(c->linktext), c->linktext);
667 else if (c->type == NFCHR || c->type == NFBLK)
668 nfsm_buildf_xx(mb, bpos, "uu",
669 umajor(c->vap->va_rdev), uminor(c->vap->va_rdev));
672 nfsm_buildf_xx(mb, bpos, "s", c->namelen, c->name);
675 t1 = nfsm_v4build_attrs_xx(c->vap, mb, bpos);
685 nfsm_v4build_rename_xx(struct nfs4_compound *cp, struct nfs4_oparg_rename *r,
686 struct mbuf **mb, caddr_t *bpos)
688 nfsm_buildf_xx(mb, bpos, "uss", NFSV4OP_RENAME, r->fnamelen, r->fname,
689 r->tnamelen, r->tname);
697 nfsm_v4build_link_xx(struct nfs4_compound *cp, struct nfs4_oparg_link *l,
698 struct mbuf **mb, caddr_t *bpos)
700 nfsm_buildf_xx(mb, bpos, "us", NFSV4OP_LINK, l->namelen, l->name);
708 nfsm_v4build_remove_xx(struct nfs4_compound *cp, const char *name, u_int namelen,
709 struct mbuf **mb, caddr_t *bpos)
711 nfsm_buildf_xx(mb, bpos, "us", NFSV4OP_REMOVE, namelen, name);
719 nfsm_v4build_attrs_xx(struct vattr *vap, struct mbuf **mb, caddr_t *bpos)
721 uint32_t *tl, *attrlenp, *bmvalp, len;
724 tl = nfsm_build_xx(4 * NFSX_UNSIGNED, mb, bpos);
726 *tl++ = txdr_unsigned(2); /* bitmap length */
733 if (vap->va_size != VNOVAL) {
734 tl = nfsm_build_xx(2 * NFSX_UNSIGNED, mb, bpos);
735 FA4_SET(FA4_SIZE, bmvalp);
736 txdr_hyper(vap->va_size, tl); tl += 2;
737 len += 2 * NFSX_UNSIGNED;
739 if (vap->va_mode != (u_short)VNOVAL) {
740 tl = nfsm_build_xx(NFSX_UNSIGNED, mb, bpos);
741 FA4_SET(FA4_MODE, bmvalp);
742 *tl++ = txdr_unsigned(vap->va_mode);
743 len += NFSX_UNSIGNED;
745 if (vap->va_uid != VNOVAL) {
748 error = idmap_uid_to_name(vap->va_uid, &name, &siz);
749 if (error || name == NULL || siz == 0) {
751 siz = sizeof("nobody") - 1;
752 tl = nfsm_build_xx(NFSX_UNSIGNED + nfsm_rndup(siz), mb,
754 *tl++ = txdr_unsigned(siz);
755 bcopy("nobody", tl, siz);
756 len += NFSX_UNSIGNED + nfsm_rndup(siz);
758 tl = nfsm_build_xx(NFSX_UNSIGNED + nfsm_rndup(siz), mb,
760 *tl++ = txdr_unsigned(siz);
761 bcopy(name, tl, siz);
762 len += NFSX_UNSIGNED + nfsm_rndup(siz);
764 FA4_SET(FA4_OWNER, bmvalp);
766 if (vap->va_gid != VNOVAL) {
769 error = idmap_gid_to_name(vap->va_gid, &name, &siz);
770 if (error || name == NULL || siz == 0) {
772 siz = sizeof("nogroup") - 1;
773 tl = nfsm_build_xx(NFSX_UNSIGNED + nfsm_rndup(siz), mb,
775 *tl++ = txdr_unsigned(siz);
776 bcopy("nogroup", tl, siz);
777 len += NFSX_UNSIGNED + nfsm_rndup(siz);
779 tl = nfsm_build_xx(NFSX_UNSIGNED + nfsm_rndup(siz), mb,
781 *tl++ = txdr_unsigned(siz);
782 bcopy(name, tl, siz);
783 len += NFSX_UNSIGNED + nfsm_rndup(siz);
785 FA4_SET(FA4_OWNER_GROUP, bmvalp);
787 if (vap->va_atime.tv_sec != VNOVAL) {
788 uint64_t val = vap->va_atime.tv_sec;
789 tl = nfsm_build_xx(4 * NFSX_UNSIGNED, mb, bpos);
790 FA4_SET(FA4_TIME_ACCESS_SET, bmvalp);
791 *tl++ = txdr_unsigned(THCLIENTTIME);
792 txdr_hyper(val, tl); tl += 2;
793 *tl++ = txdr_unsigned(vap->va_atime.tv_nsec);
794 len += 4 * NFSX_UNSIGNED;
796 if (vap->va_mtime.tv_sec != VNOVAL) {
797 uint64_t val = vap->va_mtime.tv_sec;
798 tl = nfsm_build_xx(4 * NFSX_UNSIGNED, mb, bpos);
799 FA4_SET(FA4_TIME_MODIFY_SET, bmvalp);
800 *tl++ = txdr_unsigned(THCLIENTTIME);
801 txdr_hyper(val, tl); tl += 2;
802 *tl++ = txdr_unsigned(vap->va_mtime.tv_nsec);
803 len += 4 * NFSX_UNSIGNED;
806 bmvalp[0] = txdr_unsigned(bmvalp[0]);
807 bmvalp[1] = txdr_unsigned(bmvalp[1]);
809 *attrlenp = txdr_unsigned(len);
815 nfsm_v4dissect_compound_xx(struct nfs4_compound *cp, struct mbuf **md, caddr_t *dpos)
817 uint32_t taglen, t1, *tl;
819 tl = nfsm_dissect_xx(NFSX_UNSIGNED, md, dpos);
823 /* Reply status is handled by the RPC code */
825 taglen = fxdr_unsigned(uint32_t, *tl++);
826 t1 = nfsm_adv_xx(nfsm_rndup(taglen), md, dpos);
830 tl = nfsm_dissect_xx(NFSX_UNSIGNED, md, dpos);
834 cp->rep_nops = fxdr_unsigned(uint32_t, *tl++);
840 nfsm_v4dissect_simple_xx(struct nfs4_compound *cp, uint32_t op,
841 uint32_t skipbytes, struct mbuf **md, caddr_t *dpos)
843 uint32_t t1, dop, status;
845 t1 = nfsm_dissectf_xx(md, dpos, "uu", &dop, &status);
849 if (dop != op || status != 0)
853 NFSM_ADV(nfsm_rndup(skipbytes));
859 nfsm_v4dissect_getattr_xx(struct nfs4_compound *cp, struct nfs4_oparg_getattr *ga,
860 struct mbuf **md, caddr_t *dpos)
864 tl = nfsm_dissect_xx(2 * NFSX_UNSIGNED, md, dpos);
865 if (tl == NULL || fxdr_unsigned(uint32_t, *tl++) != NFSV4OP_GETATTR ||
869 return (nfsm_v4dissect_attrs_xx(&ga->fa, md, dpos));
873 nfsm_v4dissect_setattr_xx(struct nfs4_compound *cp, struct mbuf **md, caddr_t *dpos)
875 uint32_t t1, op, bmlen, status;
877 t1 = nfsm_dissectf_xx(md, dpos, "uu", &op, &status);
881 if (op != NFSV4OP_SETATTR || status != 0)
884 t1 = nfsm_dissectf_xx(md, dpos, "u", &bmlen);
888 return (nfsm_dissectf_xx(md, dpos, "k", bmlen << 2));
892 nfsm_v4dissect_getfh_xx(struct nfs4_compound *cp, struct nfs4_oparg_getfh *gfh,
893 struct mbuf **md, caddr_t *dpos)
895 uint32_t *tl, len, xdrlen;
897 tl = nfsm_dissect_xx(2 * NFSX_UNSIGNED, md, dpos);
898 if (tl == NULL || fxdr_unsigned(uint32_t, *tl++) != NFSV4OP_GETFH)
904 NFSM_DISSECT(NFSX_UNSIGNED);
905 len = fxdr_unsigned(uint32_t, *tl++);
909 /* XXX integrate this into nfs_mtofh()? */
912 xdrlen = nfsm_rndup(len);
914 NFSM_DISSECT(xdrlen);
915 bcopy(tl, &gfh->fh_val, xdrlen);
921 nfsm_v4dissect_setclientid_xx(struct nfs4_compound *cp,
922 struct nfs4_oparg_setclientid *sci, struct mbuf **md, caddr_t *dpos)
926 tl = nfsm_dissect_xx(2 * NFSX_UNSIGNED, md, dpos);
927 if (tl == NULL || fxdr_unsigned(uint32_t, *tl++) != NFSV4OP_SETCLIENTID)
930 /* Handle NFS4ERR_CLID_INUSE specially */
934 NFSM_DISSECT(2 * NFSX_UNSIGNED);
935 sci->clientid = fxdr_hyper(tl);
937 NFSM_DISSECT(nfsm_rndup(NFSX_V4VERF));
938 bcopy(tl, sci->verf, NFSX_V4VERF);
944 nfsm_v4dissect_close_xx(struct nfs4_compound *cp, struct nfs4_fctx *fcp,
945 struct mbuf **md, caddr_t *dpos)
949 tl = nfsm_dissect_xx(2 * NFSX_UNSIGNED, md, dpos);
950 if (tl == NULL || fxdr_unsigned(uint32_t, *tl++) != NFSV4OP_CLOSE ||
955 t1 = nfsm_dissectf_xx(md, dpos, "o", NFSX_V4STATEID, fcp->stateid);
963 nfsm_v4dissect_access_xx(struct nfs4_compound *cp, struct nfs4_oparg_access *acc,
964 struct mbuf **md, caddr_t *dpos)
968 tl = nfsm_dissect_xx(4 * NFSX_UNSIGNED, md, dpos);
969 if (tl == NULL || fxdr_unsigned(uint32_t, *tl++) != NFSV4OP_ACCESS ||
973 acc->supported = fxdr_unsigned(uint32_t, *tl++);
974 acc->rmode = fxdr_unsigned(uint32_t, *tl++);
980 nfsm_v4dissect_open_xx(struct nfs4_compound *cp, struct nfs4_oparg_open *op,
981 struct mbuf **md, caddr_t *dpos)
983 uint32_t *tl, t1, bmlen, delegtype = ODNONE;
985 nfsv4changeinfo cinfo;
986 struct nfs4_fctx *fcp = op->fcp;
988 tl = nfsm_dissect_xx(2 * NFSX_UNSIGNED, md, dpos);
989 if (tl == NULL || fxdr_unsigned(uint32_t, *tl++) != NFSV4OP_OPEN ||
993 t1 = nfsm_dissectf_xx(md, dpos, "o", NFSX_V4STATEID, fcp->stateid);
997 error = nfsm_v4dissect_changeinfo_xx(&cinfo, md, dpos);
1001 NFSM_DISSECT(2 * NFSX_UNSIGNED);
1003 op->rflags = fxdr_unsigned(uint32_t, *tl++);
1004 bmlen = fxdr_unsigned(uint32_t, *tl++);
1011 NFSM_ADV(nfsm_rndup(bmlen << 2));
1013 NFSM_DISSECT(NFSX_UNSIGNED);
1014 delegtype = fxdr_unsigned(uint32_t, *tl++);
1015 switch (delegtype) {
1018 printf("nfs4: client delegation not yet supported\n");
1032 nfsm_v4dissect_open_confirm_xx(struct nfs4_compound *cp, struct nfs4_oparg_open *op,
1033 struct mbuf **md, caddr_t *dpos)
1037 tl = nfsm_dissect_xx(2 * NFSX_UNSIGNED, md, dpos);
1038 if (tl == NULL || fxdr_unsigned(uint32_t, *tl++) != NFSV4OP_OPEN_CONFIRM ||
1042 return nfsm_dissectf_xx(md, dpos, "o", NFSX_V4STATEID, op->fcp->stateid);
1046 nfsm_v4dissect_read_xx(struct nfs4_compound *cp, struct nfs4_oparg_read *r,
1047 struct mbuf **md, caddr_t *dpos)
1049 uint32_t op, status, t1;
1051 t1 = nfsm_dissectf_xx(md, dpos, "uu", &op, &status);
1055 if (op != NFSV4OP_READ || status != 0)
1058 t1 = nfsm_dissectf_xx(md, dpos, "uu", &r->eof, &r->retlen);
1062 return (nfsm_mbuftouio(md, r->uiop, r->retlen, dpos));
1066 nfsm_v4dissect_write_xx(struct nfs4_compound *cp, struct nfs4_oparg_write *w,
1067 struct mbuf **md, caddr_t *dpos)
1069 uint32_t op, status, t1;
1071 t1 = nfsm_dissectf_xx(md, dpos, "uu", &op, &status);
1075 if (op != NFSV4OP_WRITE || status != 0)
1078 return (nfsm_dissectf_xx(md, dpos, "uuo", &w->retlen, &w->committed,
1079 NFSX_V4VERF, w->wverf));
1083 nfsm_v4dissect_commit_xx(struct nfs4_compound *cp, struct nfs4_oparg_commit *c,
1084 struct mbuf **md, caddr_t *dpos)
1086 uint32_t t1, op, status;
1088 t1 = nfsm_dissectf_xx(md, dpos, "uu", &op, &status);
1092 if (op != NFSV4OP_COMMIT || status != 0)
1095 return (nfsm_dissectf_xx(md, dpos, "o", NFSX_V4VERF, c->verf));
1099 nfsm_v4dissect_create_xx(struct nfs4_compound *cp, struct nfs4_oparg_create *c,
1100 struct mbuf **md, caddr_t *dpos)
1102 uint32_t t1, *tl, op, status, bmlen;
1105 t1 = nfsm_dissectf_xx(md, dpos, "uu", &op, &status);
1109 if (op != NFSV4OP_CREATE || status != 0)
1112 /* Just throw this away for now */
1113 t1 = nfsm_v4dissect_changeinfo_xx(&ci, md, dpos);
1117 /* Throw this away too */
1118 NFSM_DISSECT(NFSX_UNSIGNED);
1119 bmlen = fxdr_unsigned(uint32_t, *tl++);
1120 NFSM_DISSECT(bmlen * NFSX_UNSIGNED);
1127 nfsm_v4dissect_readlink_xx(struct nfs4_compound *cp, struct uio *uiop,
1128 struct mbuf **md, caddr_t *dpos)
1130 uint32_t t1, *tl, op, status, linklen;
1132 t1 = nfsm_dissectf_xx(md, dpos, "uu", &op, &status);
1136 if (op != NFSV4OP_READLINK || status != 0)
1139 /* Do this one manually for careful checking of sizes. */
1140 NFSM_DISSECT(NFSX_UNSIGNED);
1141 linklen = fxdr_unsigned(uint32_t, *tl++);
1145 return (nfsm_mbuftouio(md, uiop, MIN(linklen, uiop->uio_resid), dpos));
1149 nfsm_v4dissect_changeinfo_xx(nfsv4changeinfo *ci,
1150 struct mbuf **md, caddr_t *dpos)
1154 NFSM_DISSECT(5 * NFSX_UNSIGNED);
1156 ci->ciatomic = fxdr_unsigned(uint32_t, *tl++);
1157 ci->cibefore = fxdr_hyper(tl); tl += 2;
1158 ci->ciafter = fxdr_hyper(tl); tl += 2;
1164 nfsm_v4dissect_attrs_xx(struct nfsv4_fattr *fa, struct mbuf **md, caddr_t *dpos)
1166 uint32_t t1, *tl, bmlen, bmval[2], attrlen, len = 0;
1168 /* Bitmap length + value */
1169 NFSM_DISSECT(NFSX_UNSIGNED);
1171 bmlen = fxdr_unsigned(uint32_t, *tl++);
1178 NFSM_DISSECT(nfsm_rndup(bmlen << 2) + NFSX_UNSIGNED);
1180 bmval[0] = bmlen > 0 ? fxdr_unsigned(uint32_t, *tl++) : 0;
1181 bmval[1] = bmlen > 1 ? fxdr_unsigned(uint32_t, *tl++) : 0;
1183 /* Attribute length */
1184 attrlen = fxdr_unsigned(uint32_t, *tl++);
1187 * XXX check for correct (<=) attributes mask return from
1188 * server. need to pass this in.
1191 if (FA4_ISSET(FA4_TYPE, bmval)) {
1192 /* overflow check */
1193 NFSM_DISSECT(NFSX_UNSIGNED);
1194 fa->fa4_type = fxdr_unsigned(uint32_t, *tl++);
1195 fa->fa4_valid |= FA4V_TYPE;
1196 len += NFSX_UNSIGNED;
1198 if (FA4_ISSET(FA4_CHANGE, bmval)) {
1199 NFSM_DISSECT(2 * NFSX_UNSIGNED);
1200 fa->fa4_changeid = fxdr_hyper(tl);
1201 fa->fa4_valid |= FA4V_CHANGEID;
1202 len += 2 * NFSX_UNSIGNED;
1204 if (FA4_ISSET(FA4_SIZE, bmval)) {
1205 NFSM_DISSECT(2 * NFSX_UNSIGNED);
1206 fa->fa4_size = fxdr_hyper(tl);
1207 fa->fa4_valid |= FA4V_SIZE;
1208 len += 2 * NFSX_UNSIGNED;
1210 if (FA4_ISSET(FA4_FSID, bmval)) {
1211 NFSM_DISSECT(4 * NFSX_UNSIGNED);
1212 fa->fa4_fsid_major = fxdr_hyper(tl); tl += 2;
1213 fa->fa4_fsid_minor = fxdr_hyper(tl);
1214 fa->fa4_valid |= FA4V_SIZE;
1215 len += 4 * NFSX_UNSIGNED;
1217 if (FA4_ISSET(FA4_LEASE_TIME, bmval)) {
1218 NFSM_DISSECT(NFSX_UNSIGNED);
1219 fa->fa4_lease_time = fxdr_unsigned(uint32_t, *tl++);
1220 fa->fa4_valid |= FA4V_LEASE_TIME;
1221 len += NFSX_UNSIGNED;
1223 if (FA4_ISSET(FA4_RDATTR_ERROR, bmval)) {
1224 /* ignore for now; we only ask for it so the compound won't fail */
1225 NFSM_DISSECT(NFSX_UNSIGNED);
1227 len += NFSX_UNSIGNED;
1229 if (FA4_ISSET(FA4_FILEID, bmval)) {
1230 NFSM_DISSECT(2 * NFSX_UNSIGNED);
1231 fa->fa4_fileid = fxdr_hyper(tl);
1232 fa->fa4_valid |= FA4V_FILEID;
1233 len += 2 * NFSX_UNSIGNED;
1235 if (FA4_ISSET(FA4_FILES_FREE, bmval)) {
1236 NFSM_DISSECT(2 * NFSX_UNSIGNED);
1237 fa->fa4_ffree = fxdr_hyper(tl);
1238 fa->fa4_valid |= FA4V_FFREE;
1239 len += 2 * NFSX_UNSIGNED;
1241 if (FA4_ISSET(FA4_FILES_TOTAL, bmval)) {
1242 NFSM_DISSECT(2 * NFSX_UNSIGNED);
1243 fa->fa4_ftotal = fxdr_hyper(tl);
1244 fa->fa4_valid |= FA4V_FTOTAL;
1245 len += 2 * NFSX_UNSIGNED;
1247 if (FA4_ISSET(FA4_MAXFILESIZE, bmval)) {
1248 NFSM_DISSECT(2 * NFSX_UNSIGNED);
1249 fa->fa4_maxfilesize = fxdr_hyper(tl);
1250 fa->fa4_valid |= FA4V_MAXFILESIZE;
1251 len += 2 * NFSX_UNSIGNED;
1253 if (FA4_ISSET(FA4_MAXNAME, bmval)) {
1254 NFSM_DISSECT(NFSX_UNSIGNED);
1255 fa->fa4_maxname = fxdr_unsigned(uint32_t, *tl++);
1256 fa->fa4_valid |= FA4V_MAXNAME;
1257 len += NFSX_UNSIGNED;
1259 if (FA4_ISSET(FA4_MAXREAD, bmval)) {
1260 NFSM_DISSECT(2 * NFSX_UNSIGNED);
1261 fa->fa4_maxread = fxdr_hyper(tl);
1262 fa->fa4_valid |= FA4V_MAXREAD;
1263 len += 2 * NFSX_UNSIGNED;
1265 if (FA4_ISSET(FA4_MAXWRITE, bmval)) {
1266 NFSM_DISSECT(2 * NFSX_UNSIGNED);
1267 fa->fa4_maxwrite = fxdr_hyper(tl);
1268 fa->fa4_valid |= FA4V_MAXWRITE;
1269 len += 2 * NFSX_UNSIGNED;
1272 if (FA4_ISSET(FA4_MODE, bmval)) {
1273 NFSM_DISSECT(NFSX_UNSIGNED);
1274 fa->fa4_mode = fxdr_unsigned(mode_t, *tl++);
1275 fa->fa4_valid |= FA4V_MODE;
1276 len += NFSX_UNSIGNED;
1278 if (FA4_ISSET(FA4_NUMLINKS, bmval)) {
1279 NFSM_DISSECT(NFSX_UNSIGNED);
1280 fa->fa4_nlink = fxdr_unsigned(nlink_t, *tl++);
1281 fa->fa4_valid |= FA4V_NLINK;
1282 len += NFSX_UNSIGNED;
1284 if (FA4_ISSET(FA4_OWNER, bmval)) {
1288 NFSM_DISSECT(NFSX_UNSIGNED);
1290 ownerlen = fxdr_unsigned(uint32_t, *tl++);
1291 NFSM_DISSECT(nfsm_rndup(ownerlen));
1292 error = idmap_name_to_uid((char *)tl, ownerlen, &fa->fa4_uid);
1295 fa->fa4_valid |= FA4V_UID;
1296 len += NFSX_UNSIGNED + nfsm_rndup(ownerlen);
1298 if (FA4_ISSET(FA4_OWNER_GROUP, bmval)) {
1299 uint32_t ownergrouplen;
1302 NFSM_DISSECT(NFSX_UNSIGNED);
1303 ownergrouplen = fxdr_unsigned(uint32_t, *tl++);
1304 NFSM_DISSECT(nfsm_rndup(ownergrouplen));
1305 error = idmap_name_to_gid((char *)tl, ownergrouplen, &fa->fa4_gid);
1308 fa->fa4_valid |= FA4V_GID;
1309 len += NFSX_UNSIGNED + nfsm_rndup(ownergrouplen);
1311 if (FA4_ISSET(FA4_RAWDEV, bmval)) {
1312 NFSM_DISSECT(2 * NFSX_UNSIGNED);
1313 fa->fa4_rdev_major = fxdr_unsigned(uint32_t, *tl++);
1314 fa->fa4_rdev_minor = fxdr_unsigned(uint32_t, *tl++);
1315 fa->fa4_valid |= FA4V_RDEV;
1316 len += 2 * NFSX_UNSIGNED;
1318 if (FA4_ISSET(FA4_SPACE_AVAIL, bmval)) {
1319 NFSM_DISSECT(2 * NFSX_UNSIGNED);
1320 fa->fa4_savail = fxdr_hyper(tl);
1321 fa->fa4_valid |= FA4V_SAVAIL;
1322 len += 2 * NFSX_UNSIGNED;
1324 if (FA4_ISSET(FA4_SPACE_FREE, bmval)) {
1325 NFSM_DISSECT(2 * NFSX_UNSIGNED);
1326 fa->fa4_sfree = fxdr_hyper(tl);
1327 fa->fa4_valid |= FA4V_SFREE;
1328 len += 2 * NFSX_UNSIGNED;
1330 if (FA4_ISSET(FA4_SPACE_TOTAL, bmval)) {
1331 NFSM_DISSECT(2 * NFSX_UNSIGNED);
1332 fa->fa4_stotal = fxdr_hyper(tl);
1333 fa->fa4_valid |= FA4V_STOTAL;
1334 len += 2 * NFSX_UNSIGNED;
1336 if (FA4_ISSET(FA4_SPACE_USED, bmval)) {
1337 NFSM_ADV(2 * NFSX_UNSIGNED);
1338 len += 2 * NFSX_UNSIGNED;
1340 if (FA4_ISSET(FA4_TIME_ACCESS, bmval)) {
1341 NFSM_MTOTIME(fa->fa4_atime);
1342 fa->fa4_valid |= FA4V_ATIME;
1343 len += 3 * NFSX_UNSIGNED;
1345 if (FA4_ISSET(FA4_TIME_CREATE, bmval)) {
1346 NFSM_MTOTIME(fa->fa4_ctime);
1347 fa->fa4_valid |= FA4V_CTIME;
1348 len += 3 * NFSX_UNSIGNED;
1350 if (FA4_ISSET(FA4_TIME_MODIFY, bmval)) {
1351 NFSM_MTOTIME(fa->fa4_mtime);
1352 fa->fa4_valid |= FA4V_MTIME;
1353 len += 3 * NFSX_UNSIGNED;