2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 4. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * @(#)nfs_subs.c 8.8 (Berkeley) 5/22/95
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
39 * These functions support the macros and help fiddle mbuf chains for
40 * the nfs op functions. They do things like create the rpc header and
41 * copy data between mbuf chains and uio lists.
44 #include "opt_inet6.h"
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.h>
52 #include <sys/mount.h>
53 #include <sys/vnode.h>
54 #include <sys/namei.h>
56 #include <sys/refcount.h>
57 #include <sys/socket.h>
59 #include <sys/malloc.h>
60 #include <sys/module.h>
61 #include <sys/sysent.h>
62 #include <sys/syscall.h>
63 #include <sys/sysproto.h>
66 #include <vm/vm_object.h>
67 #include <vm/vm_extern.h>
72 #include <nfs/nfsproto.h>
73 #include <nfsserver/nfs.h>
74 #include <nfs/xdr_subs.h>
75 #include <nfsserver/nfsm_subs.h>
77 #include <netinet/in.h>
80 * Data items converted to xdr at startup, since they are constant
81 * This is kinda hokey, but may save a little time doing byte swaps
83 u_int32_t nfsrv_nfs_xdrneg1;
84 u_int32_t nfsrv_nfs_true, nfsrv_nfs_false;
86 /* And other global data */
87 static const nfstype nfsv2_type[9] = { NFNON, NFREG, NFDIR, NFBLK, NFCHR,
88 NFLNK, NFNON, NFCHR, NFNON };
89 #define vtonfsv2_type(a) txdr_unsigned(nfsv2_type[((int32_t)(a))])
90 #define vtonfsv3_mode(m) txdr_unsigned((m) & ALLPERMS)
97 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
99 const int nfsrv_nfsv3_procid[NFS_NPROCS] = {
126 * and the reverse mapping from generic to Version 2 procedure numbers
128 const int nfsrvv2_procid[NFS_NPROCS] = {
155 * Maps errno values to nfs error numbers.
156 * Use 0 (which gets converted to NFSERR_IO) as the catch all for ones not
157 * specifically defined in RFC 1094.
159 static const u_char nfsrv_v2errmap[ELAST] = {
160 NFSERR_PERM, NFSERR_NOENT, 0, 0, 0,
161 NFSERR_NXIO, 0, 0, 0, 0,
162 0, 0, NFSERR_ACCES, 0, 0,
163 0, NFSERR_EXIST, 0, NFSERR_NODEV, NFSERR_NOTDIR,
164 NFSERR_ISDIR, 0, 0, 0, 0,
165 0, NFSERR_FBIG, NFSERR_NOSPC, 0, NFSERR_ROFS,
172 0, 0, NFSERR_NAMETOL, 0, 0,
173 NFSERR_NOTEMPTY, 0, 0, NFSERR_DQUOT, NFSERR_STALE,
178 * Maps errno values to nfs error numbers.
179 * Although it is not obvious whether or not NFS clients really care if
180 * a returned error value is in the specified list for the procedure, the
181 * safest thing to do is filter them appropriately. For Version 2, the
182 * X/Open XNFS document is the only specification that defines error values
183 * for each RPC (The RFC simply lists all possible error values for all RPCs),
184 * so I have decided to not do this for Version 2.
185 * The first entry is the default error return and the rest are the valid
186 * errors for that RPC in increasing numeric order.
188 static const short nfsv3err_null[] = {
193 static const short nfsv3err_getattr[] = {
202 static const short nfsv3err_setattr[] = {
218 static const short nfsv3err_lookup[] = {
231 static const short nfsv3err_access[] = {
240 static const short nfsv3err_readlink[] = {
252 static const short nfsv3err_read[] = {
264 static const short nfsv3err_write[] = {
279 static const short nfsv3err_create[] = {
296 static const short nfsv3err_mkdir[] = {
313 static const short nfsv3err_symlink[] = {
330 static const short nfsv3err_mknod[] = {
348 static const short nfsv3err_remove[] = {
362 static const short nfsv3err_rmdir[] = {
380 static const short nfsv3err_rename[] = {
403 static const short nfsv3err_link[] = {
423 static const short nfsv3err_readdir[] = {
436 static const short nfsv3err_readdirplus[] = {
450 static const short nfsv3err_fsstat[] = {
459 static const short nfsv3err_fsinfo[] = {
467 static const short nfsv3err_pathconf[] = {
475 static const short nfsv3err_commit[] = {
484 static const short *nfsrv_v3errmap[] = {
502 nfsv3err_readdirplus,
509 extern int (*nfsd_call_nfsserver)(struct thread *, struct nfssvc_args *);
512 * Called once to initialize data structures...
515 nfsrv_modevent(module_t mod, int type, void *data)
521 mtx_init(&nfsd_mtx, "nfsd_mtx", NULL, MTX_DEF);
522 nfsrv_nfs_true = txdr_unsigned(TRUE);
523 nfsrv_nfs_false = txdr_unsigned(FALSE);
524 nfsrv_nfs_xdrneg1 = txdr_unsigned(-1);
525 nfsrv_ticks = (hz * NFS_TICKINTVL + 500) / 1000;
530 nfsrv_init(0); /* Init server data structures */
533 nfsd_call_nfsserver = nfssvc_nfsserver;
537 if (nfsrv_numnfsd != 0) {
542 nfsd_call_nfsserver = NULL;
543 callout_drain(&nfsrv_callout);
544 mtx_destroy(&nfsd_mtx);
552 static moduledata_t nfsserver_mod = {
557 DECLARE_MODULE(nfsserver, nfsserver_mod, SI_SUB_VFS, SI_ORDER_ANY);
559 /* So that loader and kldload(2) can find us, wherever we are.. */
560 MODULE_VERSION(nfsserver, 1);
561 MODULE_DEPEND(nfsserver, nfssvc, 1, 1, 1);
562 MODULE_DEPEND(nfsserver, krpc, 1, 1, 1);
563 MODULE_DEPEND(nfsserver, nfs_common, 1, 1, 1);
566 * Set up nameidata for a lookup() call and do it.
568 * If pubflag is set, this call is done for a lookup operation on the
569 * public filehandle. In that case we allow crossing mountpoints and
570 * absolute pathnames. However, the caller is expected to check that
571 * the lookup result is within the public fs, and deny access if
574 * nfs_namei() clears out garbage fields that namei() might leave garbage.
575 * This is mainly ni_vp and ni_dvp when an error occurs, and ni_dvp when no
576 * error occurs but the parent was not requested.
578 * dirp may be set whether an error is returned or not, and must be
579 * released by the caller.
582 nfs_namei(struct nameidata *ndp, struct nfsrv_descript *nfsd,
583 fhandle_t *fhp, int len, struct nfssvc_sock *slp,
584 struct sockaddr *nam, struct mbuf **mdp,
585 caddr_t *dposp, struct vnode **retdirp, int v3, struct vattr *retdirattrp,
586 int *retdirattr_retp, int pubflag)
590 char *fromcp, *tocp, *cp;
594 int error, rdonly, linklen;
595 struct componentname *cnp = &ndp->ni_cnd;
596 int lockleaf = (cnp->cn_flags & LOCKLEAF) != 0;
599 cnp->cn_flags |= NOMACCHECK;
600 cnp->cn_pnbuf = uma_zalloc(namei_zone, M_WAITOK);
603 * Copy the name from the mbuf list to ndp->ni_pnbuf
604 * and set the various ndp fields appropriately.
607 tocp = cnp->cn_pnbuf;
609 rem = mtod(md, caddr_t) + md->m_len - fromcp;
610 for (i = 0; i < len; i++) {
617 fromcp = mtod(md, caddr_t);
620 if (*fromcp == '\0' || (!pubflag && *fromcp == '/')) {
630 len = nfsm_rndup(len)-len;
634 else if ((error = nfs_adv(mdp, dposp, len, rem)) != 0)
638 if (!pubflag && nfs_ispublicfh(fhp))
642 * Extract and set starting directory.
644 error = nfsrv_fhtovp(fhp, 0, &dp, nfsd, slp, nam, &rdonly);
647 if (dp->v_type != VDIR) {
654 cnp->cn_flags |= RDONLY;
657 * Set return directory. Reference to dp is implicitly transfered
658 * to the returned pointer
662 *retdirattr_retp = VOP_GETATTR(dp, retdirattrp,
663 ndp->ni_cnd.cn_cred);
670 * Oh joy. For WebNFS, handle those pesky '%' escapes,
671 * and the 'native path' indicator.
673 cp = uma_zalloc(namei_zone, M_WAITOK);
674 fromcp = cnp->cn_pnbuf;
676 if ((unsigned char)*fromcp >= WEBNFS_SPECCHAR_START) {
677 switch ((unsigned char)*fromcp) {
678 case WEBNFS_NATIVE_CHAR:
680 * 'Native' path for us is the same
681 * as a path according to the NFS spec,
682 * just skip the escape char.
687 * More may be added in the future, range 0x80-0xff
691 uma_zfree(namei_zone, cp);
696 * Translate the '%' escapes, URL-style.
698 while (*fromcp != '\0') {
699 if (*fromcp == WEBNFS_ESC_CHAR) {
700 if (fromcp[1] != '\0' && fromcp[2] != '\0') {
702 *tocp++ = HEXSTRTOI(fromcp);
707 uma_zfree(namei_zone, cp);
714 uma_zfree(namei_zone, cnp->cn_pnbuf);
718 ndp->ni_pathlen = (tocp - cnp->cn_pnbuf) + 1;
719 ndp->ni_segflg = UIO_SYSSPACE;
722 ndp->ni_rootdir = rootvnode;
725 if (cnp->cn_pnbuf[0] == '/')
728 cnp->cn_flags |= NOCROSSMOUNT;
732 * Initialize for scan, set ni_startdir and bump ref on dp again
733 * because lookup() will dereference ni_startdir.
736 cnp->cn_thread = curthread;
738 ndp->ni_startdir = dp;
741 cnp->cn_flags |= LOCKLEAF;
743 cnp->cn_nameptr = cnp->cn_pnbuf;
745 * Call lookup() to do the real work. If an error occurs,
746 * ndp->ni_vp and ni_dvp are left uninitialized or NULL and
747 * we do not have to dereference anything before returning.
748 * In either case ni_startdir will be dereferenced and NULLed
756 * Check for encountering a symbolic link. Trivial
757 * termination occurs if no symlink encountered.
758 * Note: zfree is safe because error is 0, so we will
759 * not zfree it again when we break.
761 if ((cnp->cn_flags & ISSYMLINK) == 0) {
762 if (cnp->cn_flags & (SAVENAME | SAVESTART))
763 cnp->cn_flags |= HASBUF;
765 uma_zfree(namei_zone, cnp->cn_pnbuf);
766 if (ndp->ni_vp && !lockleaf)
767 VOP_UNLOCK(ndp->ni_vp, 0);
774 if ((cnp->cn_flags & LOCKPARENT) && ndp->ni_pathlen == 1)
775 VOP_UNLOCK(ndp->ni_dvp, 0);
781 if (ndp->ni_loopcnt++ >= MAXSYMLINKS) {
785 if (ndp->ni_pathlen > 1)
786 cp = uma_zalloc(namei_zone, M_WAITOK);
790 aiov.iov_len = MAXPATHLEN;
791 auio.uio_iov = &aiov;
794 auio.uio_rw = UIO_READ;
795 auio.uio_segflg = UIO_SYSSPACE;
797 auio.uio_resid = MAXPATHLEN;
798 error = VOP_READLINK(ndp->ni_vp, &auio, cnp->cn_cred);
801 if (ndp->ni_pathlen > 1)
802 uma_zfree(namei_zone, cp);
808 linklen = MAXPATHLEN - auio.uio_resid;
813 if (linklen + ndp->ni_pathlen >= MAXPATHLEN) {
814 error = ENAMETOOLONG;
819 * Adjust or replace path
821 if (ndp->ni_pathlen > 1) {
822 bcopy(ndp->ni_next, cp + linklen, ndp->ni_pathlen);
823 uma_zfree(namei_zone, cnp->cn_pnbuf);
826 cnp->cn_pnbuf[linklen] = '\0';
827 ndp->ni_pathlen += linklen;
830 * Cleanup refs for next loop and check if root directory
831 * should replace current directory. Normally ni_dvp
832 * becomes the new base directory and is cleaned up when
833 * we loop. Explicitly null pointers after invalidation
834 * to clarify operation.
839 if (cnp->cn_pnbuf[0] == '/') {
841 ndp->ni_dvp = ndp->ni_rootdir;
844 ndp->ni_startdir = ndp->ni_dvp;
848 cnp->cn_flags &= ~LOCKLEAF;
851 * nfs_namei() guarentees that fields will not contain garbage
852 * whether an error occurs or not. This allows the caller to track
853 * cleanup state trivially.
857 uma_zfree(namei_zone, cnp->cn_pnbuf);
860 ndp->ni_startdir = NULL;
861 cnp->cn_flags &= ~HASBUF;
862 } else if ((ndp->ni_cnd.cn_flags & (WANTPARENT|LOCKPARENT)) == 0) {
869 * A fiddled version of m_adj() that ensures null fill to a long
870 * boundary and only trims off the back end
873 nfsm_adj(struct mbuf *mp, int len, int nul)
880 * Trim from tail. Scan the mbuf chain,
881 * calculating its length and finding the last mbuf.
882 * If the adjustment only affects this mbuf, then just
883 * adjust and return. Otherwise, rescan and truncate
884 * after the remaining size.
890 if (m->m_next == NULL)
894 if (m->m_len > len) {
897 cp = mtod(m, caddr_t)+m->m_len-nul;
898 for (i = 0; i < nul; i++)
907 * Correct length for chain is "count".
908 * Find the mbuf with last data, adjust its length,
909 * and toss data from remaining mbufs on chain.
911 for (m = mp; m; m = m->m_next) {
912 if (m->m_len >= count) {
915 cp = mtod(m, caddr_t)+m->m_len-nul;
916 for (i = 0; i < nul; i++)
919 if (m->m_next != NULL) {
930 * Make these functions instead of macros, so that the kernel text size
931 * doesn't get too big...
934 nfsm_srvwcc(struct nfsrv_descript *nfsd, int before_ret,
935 struct vattr *before_vap, int after_ret, struct vattr *after_vap,
936 struct mbuf **mbp, char **bposp)
938 struct mbuf *mb = *mbp;
943 tl = nfsm_build(u_int32_t *, NFSX_UNSIGNED);
944 *tl = nfsrv_nfs_false;
946 tl = nfsm_build(u_int32_t *, 7 * NFSX_UNSIGNED);
947 *tl++ = nfsrv_nfs_true;
948 txdr_hyper(before_vap->va_size, tl);
950 txdr_nfsv3time(&(before_vap->va_mtime), tl);
952 txdr_nfsv3time(&(before_vap->va_ctime), tl);
956 nfsm_srvpostopattr(nfsd, after_ret, after_vap, mbp, bposp);
960 nfsm_srvpostopattr(struct nfsrv_descript *nfsd, int after_ret,
961 struct vattr *after_vap, struct mbuf **mbp, char **bposp)
963 struct mbuf *mb = *mbp;
966 struct nfs_fattr *fp;
969 tl = nfsm_build(u_int32_t *, NFSX_UNSIGNED);
970 *tl = nfsrv_nfs_false;
972 tl = nfsm_build(u_int32_t *, NFSX_UNSIGNED + NFSX_V3FATTR);
973 *tl++ = nfsrv_nfs_true;
974 fp = (struct nfs_fattr *)tl;
975 nfsm_srvfattr(nfsd, after_vap, fp);
982 nfsm_srvfattr(struct nfsrv_descript *nfsd, struct vattr *vap,
983 struct nfs_fattr *fp)
986 fp->fa_nlink = txdr_unsigned(vap->va_nlink);
987 fp->fa_uid = txdr_unsigned(vap->va_uid);
988 fp->fa_gid = txdr_unsigned(vap->va_gid);
989 if (nfsd->nd_flag & ND_NFSV3) {
990 fp->fa_type = vtonfsv3_type(vap->va_type);
991 fp->fa_mode = vtonfsv3_mode(vap->va_mode);
992 txdr_hyper(vap->va_size, &fp->fa3_size);
993 txdr_hyper(vap->va_bytes, &fp->fa3_used);
994 fp->fa3_rdev.specdata1 = txdr_unsigned(major(vap->va_rdev));
995 fp->fa3_rdev.specdata2 = txdr_unsigned(minor(vap->va_rdev));
996 fp->fa3_fsid.nfsuquad[0] = 0;
997 fp->fa3_fsid.nfsuquad[1] = txdr_unsigned(vap->va_fsid);
998 fp->fa3_fileid.nfsuquad[0] = 0;
999 fp->fa3_fileid.nfsuquad[1] = txdr_unsigned(vap->va_fileid);
1000 txdr_nfsv3time(&vap->va_atime, &fp->fa3_atime);
1001 txdr_nfsv3time(&vap->va_mtime, &fp->fa3_mtime);
1002 txdr_nfsv3time(&vap->va_ctime, &fp->fa3_ctime);
1004 fp->fa_type = vtonfsv2_type(vap->va_type);
1005 fp->fa_mode = vtonfsv2_mode(vap->va_type, vap->va_mode);
1006 fp->fa2_size = txdr_unsigned(vap->va_size);
1007 fp->fa2_blocksize = txdr_unsigned(vap->va_blocksize);
1008 if (vap->va_type == VFIFO)
1009 fp->fa2_rdev = 0xffffffff;
1011 fp->fa2_rdev = txdr_unsigned(vap->va_rdev);
1012 fp->fa2_blocks = txdr_unsigned(vap->va_bytes / NFS_FABLKSIZE);
1013 fp->fa2_fsid = txdr_unsigned(vap->va_fsid);
1014 fp->fa2_fileid = txdr_unsigned(vap->va_fileid);
1015 txdr_nfsv2time(&vap->va_atime, &fp->fa2_atime);
1016 txdr_nfsv2time(&vap->va_mtime, &fp->fa2_mtime);
1017 txdr_nfsv2time(&vap->va_ctime, &fp->fa2_ctime);
1022 * nfsrv_fhtovp() - convert a fh to a vnode ptr (optionally locked)
1023 * - look up fsid in mount list (if not found ret error)
1024 * - get vp and export rights by calling VFS_FHTOVP()
1025 * - if cred->cr_uid == 0 or MNT_EXPORTANON set it to credanon
1028 nfsrv_fhtovp(fhandle_t *fhp, int flags, struct vnode **vpp,
1029 struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
1030 struct sockaddr *nam, int *rdonlyp)
1034 struct ucred *cred, *credanon;
1036 #ifdef MNT_EXNORESPORT /* XXX needs mountd and /etc/exports help yet */
1037 struct sockaddr_int *saddr;
1040 int numsecflavors, *secflavors;
1042 int v3 = nfsd->nd_flag & ND_NFSV3;
1047 if (nfs_ispublicfh(fhp)) {
1048 if (!nfs_pub.np_valid)
1050 fhp = &nfs_pub.np_handle;
1053 mp = vfs_busyfs(&fhp->fh_fsid);
1056 error = VFS_CHECKEXP(mp, nam, &exflags, &credanon,
1057 &numsecflavors, &secflavors);
1062 if (numsecflavors == 0) {
1064 * This can happen if the system is running with an
1065 * old mountd that doesn't pass in a secflavor list.
1069 secflavors = &authsys;
1071 credflavor = nfsd->nd_credflavor;
1072 for (i = 0; i < numsecflavors; i++) {
1073 if (secflavors[i] == credflavor)
1076 if (i == numsecflavors) {
1078 * RFC 2623 section 2.3.2 - allow certain procedures
1079 * used at NFS client mount time even if they have
1080 * weak authentication.
1084 if (nfsd->nd_procnum == NFSPROC_FSINFO
1085 || nfsd->nd_procnum == NFSPROC_GETATTR)
1088 if (nfsd->nd_procnum == NFSPROC_FSSTAT
1089 || nfsd->nd_procnum == NFSPROC_GETATTR)
1093 error = NFSERR_AUTHERR | AUTH_TOOWEAK;
1098 error = VFS_FHTOVP(mp, &fhp->fh_fid, LK_EXCLUSIVE, vpp);
1100 /* Make sure the server replies ESTALE to the client. */
1105 #ifdef MNT_EXNORESPORT
1106 if (!(exflags & (MNT_EXNORESPORT|MNT_EXPUBLIC))) {
1107 saddr = (struct sockaddr_in *)nam;
1108 if ((saddr->sin_family == AF_INET ||
1109 saddr->sin_family == AF_INET6) &&
1110 /* same code for INET and INET6: sin*_port at same offet */
1111 ntohs(saddr->sin_port) >= IPPORT_RESERVED) {
1114 error = NFSERR_AUTHERR | AUTH_TOOWEAK;
1121 * Check/setup credentials.
1124 if (cred->cr_uid == 0 || (exflags & MNT_EXPORTANON)) {
1125 cred->cr_uid = credanon->cr_uid;
1126 crsetgroups(cred, credanon->cr_ngroups, credanon->cr_groups);
1128 if (exflags & MNT_EXRDONLY)
1133 if (!(flags & NFSRV_FLAG_BUSY))
1136 if (credanon != NULL)
1144 * WebNFS: check if a filehandle is a public filehandle. For v3, this
1145 * means a length of 0, for v2 it means all zeroes. nfsm_srvmtofh has
1146 * transformed this to all zeroes in both cases, so check for it.
1149 nfs_ispublicfh(fhandle_t *fhp)
1151 char *cp = (char *)fhp;
1154 NFSD_LOCK_DONTCARE();
1156 for (i = 0; i < NFSX_V3FH; i++)
1163 * Map errnos to NFS error numbers. For Version 3 also filter out error
1164 * numbers not specified for the associated procedure.
1167 nfsrv_errmap(struct nfsrv_descript *nd, int err)
1169 const short *defaulterrp, *errp;
1173 if (nd->nd_flag & ND_NFSV3) {
1174 if (nd->nd_procnum <= NFSPROC_COMMIT) {
1175 errp = defaulterrp = nfsrv_v3errmap[nd->nd_procnum];
1179 else if (*errp > err)
1182 return ((int)*defaulterrp);
1184 return (err & 0xffff);
1188 e = nfsrv_v2errmap[err - 1];
1195 * Sort the group list in increasing numerical order.
1196 * (Insertion sort by Chris Torek, who was grossed out by the bubble sort
1197 * that used to be here.)
1200 nfsrvw_sort(gid_t *list, int num)
1205 /* Insertion sort. */
1206 for (i = 1; i < num; i++) {
1208 /* find correct slot for value v, moving others up */
1209 for (j = i; --j >= 0 && v < list[j];)
1210 list[j + 1] = list[j];
1216 * Helper functions for macros.
1220 nfsm_srvfhtom_xx(fhandle_t *f, int v3, struct mbuf **mb, caddr_t *bpos)
1225 tl = nfsm_build_xx(NFSX_UNSIGNED + NFSX_V3FH, mb, bpos);
1226 *tl++ = txdr_unsigned(NFSX_V3FH);
1227 bcopy(f, tl, NFSX_V3FH);
1229 tl = nfsm_build_xx(NFSX_V2FH, mb, bpos);
1230 bcopy(f, tl, NFSX_V2FH);
1235 nfsm_srvpostop_fh_xx(fhandle_t *f, struct mbuf **mb, caddr_t *bpos)
1239 tl = nfsm_build_xx(2 * NFSX_UNSIGNED + NFSX_V3FH, mb, bpos);
1240 *tl++ = nfsrv_nfs_true;
1241 *tl++ = txdr_unsigned(NFSX_V3FH);
1242 bcopy(f, tl, NFSX_V3FH);
1246 nfsm_srvstrsiz_xx(int *s, int m, struct mbuf **md, caddr_t *dpos)
1250 tl = nfsm_dissect_xx_nonblock(NFSX_UNSIGNED, md, dpos);
1253 *s = fxdr_unsigned(int32_t, *tl);
1254 if (*s > m || *s <= 0)
1260 nfsm_srvnamesiz_xx(int *s, int m, struct mbuf **md, caddr_t *dpos)
1264 NFSD_LOCK_DONTCARE();
1266 tl = nfsm_dissect_xx_nonblock(NFSX_UNSIGNED, md, dpos);
1269 *s = fxdr_unsigned(int32_t, *tl);
1271 return NFSERR_NAMETOL;
1278 nfsm_srvnamesiz0_xx(int *s, int m, struct mbuf **md, caddr_t *dpos)
1282 tl = nfsm_dissect_xx_nonblock(NFSX_UNSIGNED, md, dpos);
1285 *s = fxdr_unsigned(int32_t, *tl);
1287 return NFSERR_NAMETOL;
1294 nfsm_clget_xx(u_int32_t **tl, struct mbuf *mb, struct mbuf **mp,
1295 char **bp, char **be, caddr_t bpos)
1299 NFSD_UNLOCK_ASSERT();
1303 (*mp)->m_len += *bp - bpos;
1304 MGET(nmp, M_WAITOK, MT_DATA);
1305 MCLGET(nmp, M_WAITOK);
1306 nmp->m_len = NFSMSIZ(nmp);
1307 (*mp)->m_next = nmp;
1309 *bp = mtod(*mp, caddr_t);
1310 *be = *bp + (*mp)->m_len;
1312 *tl = (u_int32_t *)*bp;
1316 nfsm_srvmtofh_xx(fhandle_t *f, int v3, struct mbuf **md, caddr_t *dpos)
1322 tl = nfsm_dissect_xx_nonblock(NFSX_UNSIGNED, md, dpos);
1325 fhlen = fxdr_unsigned(int, *tl);
1326 if (fhlen != 0 && fhlen != NFSX_V3FH)
1332 tl = nfsm_dissect_xx_nonblock(fhlen, md, dpos);
1335 bcopy((caddr_t)tl, (caddr_t)(f), fhlen);
1337 bzero((caddr_t)(f), NFSX_V3FH);
1343 nfsm_srvsattr_xx(struct vattr *a, struct mbuf **md, caddr_t *dpos)
1348 tl = nfsm_dissect_xx_nonblock(NFSX_UNSIGNED, md, dpos);
1351 if (*tl == nfsrv_nfs_true) {
1352 tl = nfsm_dissect_xx_nonblock(NFSX_UNSIGNED, md, dpos);
1355 (a)->va_mode = nfstov_mode(*tl);
1357 tl = nfsm_dissect_xx_nonblock(NFSX_UNSIGNED, md, dpos);
1360 if (*tl == nfsrv_nfs_true) {
1361 tl = nfsm_dissect_xx_nonblock(NFSX_UNSIGNED, md, dpos);
1364 (a)->va_uid = fxdr_unsigned(uid_t, *tl);
1366 tl = nfsm_dissect_xx_nonblock(NFSX_UNSIGNED, md, dpos);
1369 if (*tl == nfsrv_nfs_true) {
1370 tl = nfsm_dissect_xx_nonblock(NFSX_UNSIGNED, md, dpos);
1373 (a)->va_gid = fxdr_unsigned(gid_t, *tl);
1375 tl = nfsm_dissect_xx_nonblock(NFSX_UNSIGNED, md, dpos);
1378 if (*tl == nfsrv_nfs_true) {
1379 tl = nfsm_dissect_xx_nonblock(2 * NFSX_UNSIGNED, md, dpos);
1382 (a)->va_size = fxdr_hyper(tl);
1384 tl = nfsm_dissect_xx_nonblock(NFSX_UNSIGNED, md, dpos);
1387 switch (fxdr_unsigned(int, *tl)) {
1388 case NFSV3SATTRTIME_TOCLIENT:
1389 tl = nfsm_dissect_xx_nonblock(2 * NFSX_UNSIGNED, md, dpos);
1392 fxdr_nfsv3time(tl, &(a)->va_atime);
1395 case NFSV3SATTRTIME_TOSERVER:
1396 vfs_timestamp(&a->va_atime);
1397 a->va_vaflags |= VA_UTIMES_NULL;
1400 tl = nfsm_dissect_xx_nonblock(NFSX_UNSIGNED, md, dpos);
1403 switch (fxdr_unsigned(int, *tl)) {
1404 case NFSV3SATTRTIME_TOCLIENT:
1405 tl = nfsm_dissect_xx_nonblock(2 * NFSX_UNSIGNED, md, dpos);
1408 fxdr_nfsv3time(tl, &(a)->va_mtime);
1409 a->va_vaflags &= ~VA_UTIMES_NULL;
1411 case NFSV3SATTRTIME_TOSERVER:
1412 vfs_timestamp(&a->va_mtime);
1414 a->va_vaflags |= VA_UTIMES_NULL;