2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
24 * Copyright (c) 1989, 1993
25 * The Regents of the University of California. All rights reserved.
27 * This code is derived from software contributed to Berkeley by
28 * Rick Macklem at The University of Guelph.
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. All advertising materials mentioning features or use of this software
39 * must display the following acknowledgement:
40 * This product includes software developed by the University of
41 * California, Berkeley and its contributors.
42 * 4. Neither the name of the University nor the names of its contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
46 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * @(#)nfs_subs.c 8.8 (Berkeley) 5/22/95
59 * FreeBSD-Id: nfs_subs.c,v 1.47 1997/11/07 08:53:24 phk Exp $
63 * These functions support the macros and help fiddle mbuf chains for
64 * the nfs op functions. They do things like create the rpc header and
65 * copy data between mbuf chains and uio lists.
67 #include <sys/param.h>
69 #include <sys/systm.h>
70 #include <sys/kernel.h>
71 #include <sys/mount.h>
72 #include <sys/vnode.h>
73 #include <sys/namei.h>
75 #include <sys/socket.h>
77 #include <sys/malloc.h>
78 #include <sys/syscall.h>
82 #include <sys/vmparam.h>
83 #include <machine/spl.h>
88 #include <kern/clock.h>
90 #include <nfs/rpcv2.h>
91 #include <nfs/nfsproto.h>
93 #include <nfs/nfsnode.h>
94 #include <nfs/xdr_subs.h>
95 #include <nfs/nfsm_subs.h>
96 #include <nfs/nfsmount.h>
97 #include <nfs/nqnfs.h>
98 #include <nfs/nfsrtt.h>
100 #include <miscfs/specfs/specdev.h>
102 #include <netinet/in.h>
104 #include <netiso/iso.h>
108 * Data items converted to xdr at startup, since they are constant
109 * This is kinda hokey, but may save a little time doing byte swaps
112 u_long rpc_call
, rpc_vers
, rpc_reply
, rpc_msgdenied
, rpc_autherr
,
113 rpc_mismatch
, rpc_auth_unix
, rpc_msgaccepted
,
115 u_long nfs_prog
, nqnfs_prog
, nfs_true
, nfs_false
;
117 /* And other global data */
118 static u_long nfs_xid
= 0;
119 static enum vtype nv2tov_type
[8]= {
120 VNON
, VREG
, VDIR
, VBLK
, VCHR
, VLNK
, VNON
, VNON
122 enum vtype nv3tov_type
[8]= {
123 VNON
, VREG
, VDIR
, VBLK
, VCHR
, VLNK
, VSOCK
, VFIFO
129 struct nfs_reqq nfs_reqq
;
130 struct nfssvc_sockhead nfssvc_sockhead
;
131 int nfssvc_sockhead_flag
;
132 struct nfsd_head nfsd_head
;
134 struct nfs_bufq nfs_bufq
;
135 struct nqtimerhead nqtimerhead
;
136 struct nqfhhashhead
*nqfhhashtbl
;
141 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
143 int nfsv3_procid
[NFS_NPROCS
] = {
172 #endif /* NFS_NOSERVER */
174 * and the reverse mapping from generic to Version 2 procedure numbers
176 int nfsv2_procid
[NFS_NPROCS
] = {
207 * Maps errno values to nfs error numbers.
208 * Use NFSERR_IO as the catch all for ones not specifically defined in
211 static u_char nfsrv_v2errmap
[ELAST
] = {
212 NFSERR_PERM
, NFSERR_NOENT
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
213 NFSERR_NXIO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
214 NFSERR_IO
, NFSERR_IO
, NFSERR_ACCES
, NFSERR_IO
, NFSERR_IO
,
215 NFSERR_IO
, NFSERR_EXIST
, NFSERR_IO
, NFSERR_NODEV
, NFSERR_NOTDIR
,
216 NFSERR_ISDIR
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
217 NFSERR_IO
, NFSERR_FBIG
, NFSERR_NOSPC
, NFSERR_IO
, NFSERR_ROFS
,
218 NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
219 NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
220 NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
221 NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
222 NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
223 NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
224 NFSERR_IO
, NFSERR_IO
, NFSERR_NAMETOL
, NFSERR_IO
, NFSERR_IO
,
225 NFSERR_NOTEMPTY
, NFSERR_IO
, NFSERR_IO
, NFSERR_DQUOT
, NFSERR_STALE
,
226 NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
227 NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
228 NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
232 * Maps errno values to nfs error numbers.
233 * Although it is not obvious whether or not NFS clients really care if
234 * a returned error value is in the specified list for the procedure, the
235 * safest thing to do is filter them appropriately. For Version 2, the
236 * X/Open XNFS document is the only specification that defines error values
237 * for each RPC (The RFC simply lists all possible error values for all RPCs),
238 * so I have decided to not do this for Version 2.
239 * The first entry is the default error return and the rest are the valid
240 * errors for that RPC in increasing numeric order.
242 static short nfsv3err_null
[] = {
247 static short nfsv3err_getattr
[] = {
256 static short nfsv3err_setattr
[] = {
272 static short nfsv3err_lookup
[] = {
285 static short nfsv3err_access
[] = {
294 static short nfsv3err_readlink
[] = {
306 static short nfsv3err_read
[] = {
318 static short nfsv3err_write
[] = {
333 static short nfsv3err_create
[] = {
350 static short nfsv3err_mkdir
[] = {
367 static short nfsv3err_symlink
[] = {
384 static short nfsv3err_mknod
[] = {
402 static short nfsv3err_remove
[] = {
416 static short nfsv3err_rmdir
[] = {
434 static short nfsv3err_rename
[] = {
457 static short nfsv3err_link
[] = {
477 static short nfsv3err_readdir
[] = {
490 static short nfsv3err_readdirplus
[] = {
504 static short nfsv3err_fsstat
[] = {
513 static short nfsv3err_fsinfo
[] = {
521 static short nfsv3err_pathconf
[] = {
529 static short nfsv3err_commit
[] = {
538 static short *nfsrv_v3errmap
[] = {
556 nfsv3err_readdirplus
,
563 #endif /* NFS_NOSERVER */
565 extern struct nfsrtt nfsrtt
;
566 extern time_t nqnfsstarttime
;
567 extern int nqsrv_clockskew
;
568 extern int nqsrv_writeslack
;
569 extern int nqsrv_maxlease
;
570 extern struct nfsstats nfsstats
;
571 extern int nqnfs_piggy
[NFS_NPROCS
];
572 extern nfstype nfsv2_type
[9];
573 extern nfstype nfsv3_type
[9];
574 extern struct nfsnodehashhead
*nfsnodehashtbl
;
575 extern u_long nfsnodehash
;
578 extern int getfh(struct proc
*, struct getfh_args
*, int *);
580 extern int nfssvc(struct proc
*, struct nfssvc_args
*, int *);
582 LIST_HEAD(nfsnodehashhead
, nfsnode
);
584 int nfs_webnamei
__P((struct nameidata
*, struct vnode
*, struct proc
*));
587 * Create the header for an rpc request packet
588 * The hsiz is the size of the rest of the nfs request header.
589 * (just used to decide if a cluster is a good idea)
592 nfsm_reqh(vp
, procid
, hsiz
, bposp
)
598 register struct mbuf
*mb
;
600 register caddr_t bpos
;
602 struct nfsmount
*nmp
;
605 MGET(mb
, M_WAIT
, MT_DATA
);
606 if (hsiz
>= MINCLSIZE
)
609 bpos
= mtod(mb
, caddr_t
);
612 * For NQNFS, add lease request.
615 nmp
= VFSTONFS(vp
->v_mount
);
616 if (nmp
->nm_flag
& NFSMNT_NQNFS
) {
617 nqflag
= NQNFS_NEEDLEASE(vp
, procid
);
619 nfsm_build(tl
, u_long
*, 2*NFSX_UNSIGNED
);
620 *tl
++ = txdr_unsigned(nqflag
);
621 *tl
= txdr_unsigned(nmp
->nm_leaseterm
);
623 nfsm_build(tl
, u_long
*, NFSX_UNSIGNED
);
628 /* Finally, return values */
634 * Build the RPC header and fill in the authorization info.
635 * The authorization string argument is only used when the credentials
636 * come from outside of the kernel.
637 * Returns the head of the mbuf list.
640 nfsm_rpchead(cr
, nmflag
, procid
, auth_type
, auth_len
, auth_str
, verf_len
,
641 verf_str
, mrest
, mrest_len
, mbp
, xidp
)
642 register struct ucred
*cr
;
655 register struct mbuf
*mb
;
657 register caddr_t bpos
;
659 struct mbuf
*mreq
, *mb2
;
660 int siz
, grpsiz
, authsiz
;
664 authsiz
= nfsm_rndup(auth_len
);
665 MGETHDR(mb
, M_WAIT
, MT_DATA
);
666 if ((authsiz
+ 10 * NFSX_UNSIGNED
) >= MINCLSIZE
) {
668 } else if ((authsiz
+ 10 * NFSX_UNSIGNED
) < MHLEN
) {
669 MH_ALIGN(mb
, authsiz
+ 10 * NFSX_UNSIGNED
);
671 MH_ALIGN(mb
, 8 * NFSX_UNSIGNED
);
675 bpos
= mtod(mb
, caddr_t
);
678 * First the RPC header.
680 nfsm_build(tl
, u_long
*, 8 * NFSX_UNSIGNED
);
683 * derive initial xid from system time
684 * XXX time is invalid if root not yet mounted
686 if (!base
&& (rootvp
)) {
688 base
= tv
.tv_sec
<< 12;
692 * Skip zero xid if it should ever happen.
697 *tl
++ = *xidp
= txdr_unsigned(nfs_xid
);
700 if (nmflag
& NFSMNT_NQNFS
) {
701 *tl
++ = txdr_unsigned(NQNFS_PROG
);
702 *tl
++ = txdr_unsigned(NQNFS_VER3
);
704 *tl
++ = txdr_unsigned(NFS_PROG
);
705 if (nmflag
& NFSMNT_NFSV3
)
706 *tl
++ = txdr_unsigned(NFS_VER3
);
708 *tl
++ = txdr_unsigned(NFS_VER2
);
710 if (nmflag
& NFSMNT_NFSV3
)
711 *tl
++ = txdr_unsigned(procid
);
713 *tl
++ = txdr_unsigned(nfsv2_procid
[procid
]);
716 * And then the authorization cred.
718 *tl
++ = txdr_unsigned(auth_type
);
719 *tl
= txdr_unsigned(authsiz
);
722 nfsm_build(tl
, u_long
*, auth_len
);
723 *tl
++ = 0; /* stamp ?? */
724 *tl
++ = 0; /* NULL hostname */
725 *tl
++ = txdr_unsigned(cr
->cr_uid
);
726 *tl
++ = txdr_unsigned(cr
->cr_groups
[0]);
727 grpsiz
= (auth_len
>> 2) - 5;
728 *tl
++ = txdr_unsigned(grpsiz
);
729 for (i
= 1; i
<= grpsiz
; i
++)
730 *tl
++ = txdr_unsigned(cr
->cr_groups
[i
]);
735 if (M_TRAILINGSPACE(mb
) == 0) {
736 MGET(mb2
, M_WAIT
, MT_DATA
);
737 if (siz
>= MINCLSIZE
)
742 bpos
= mtod(mb
, caddr_t
);
744 i
= min(siz
, M_TRAILINGSPACE(mb
));
745 bcopy(auth_str
, bpos
, i
);
751 if ((siz
= (nfsm_rndup(auth_len
) - auth_len
)) > 0) {
752 for (i
= 0; i
< siz
; i
++)
760 * And the verifier...
762 nfsm_build(tl
, u_long
*, 2 * NFSX_UNSIGNED
);
764 *tl
++ = txdr_unsigned(RPCAUTH_KERB4
);
765 *tl
= txdr_unsigned(verf_len
);
768 if (M_TRAILINGSPACE(mb
) == 0) {
769 MGET(mb2
, M_WAIT
, MT_DATA
);
770 if (siz
>= MINCLSIZE
)
775 bpos
= mtod(mb
, caddr_t
);
777 i
= min(siz
, M_TRAILINGSPACE(mb
));
778 bcopy(verf_str
, bpos
, i
);
784 if ((siz
= (nfsm_rndup(verf_len
) - verf_len
)) > 0) {
785 for (i
= 0; i
< siz
; i
++)
790 *tl
++ = txdr_unsigned(RPCAUTH_NULL
);
794 mreq
->m_pkthdr
.len
= authsiz
+ 10 * NFSX_UNSIGNED
+ mrest_len
;
795 mreq
->m_pkthdr
.rcvif
= (struct ifnet
*)0;
801 * copies mbuf chain to the uio scatter/gather list
804 nfsm_mbuftouio(mrep
, uiop
, siz
, dpos
)
806 register struct uio
*uiop
;
810 register char *mbufcp
, *uiocp
;
811 register int xfer
, left
, len
;
812 register struct mbuf
*mp
;
818 len
= mtod(mp
, caddr_t
)+mp
->m_len
-mbufcp
;
819 rem
= nfsm_rndup(siz
)-siz
;
821 if (uiop
->uio_iovcnt
<= 0 || uiop
->uio_iov
== NULL
)
823 left
= uiop
->uio_iov
->iov_len
;
824 uiocp
= uiop
->uio_iov
->iov_base
;
833 mbufcp
= mtod(mp
, caddr_t
);
836 xfer
= (left
> len
) ? len
: left
;
839 if (uiop
->uio_iov
->iov_op
!= NULL
)
840 (*(uiop
->uio_iov
->iov_op
))
841 (mbufcp
, uiocp
, xfer
);
844 if (uiop
->uio_segflg
== UIO_SYSSPACE
)
845 bcopy(mbufcp
, uiocp
, xfer
);
847 copyout(mbufcp
, uiocp
, xfer
);
852 uiop
->uio_offset
+= xfer
;
853 uiop
->uio_resid
-= xfer
;
855 if (uiop
->uio_iov
->iov_len
<= siz
) {
859 uiop
->uio_iov
->iov_base
+= uiosiz
;
860 uiop
->uio_iov
->iov_len
-= uiosiz
;
868 error
= nfs_adv(mrep
, dpos
, rem
, len
);
876 * copies a uio scatter/gather list to an mbuf chain.
877 * NOTE: can ony handle iovcnt == 1
880 nfsm_uiotombuf(uiop
, mq
, siz
, bpos
)
881 register struct uio
*uiop
;
886 register char *uiocp
;
887 register struct mbuf
*mp
, *mp2
;
888 register int xfer
, left
, mlen
;
889 int uiosiz
, clflg
, rem
;
892 if (uiop
->uio_iovcnt
!= 1)
893 panic("nfsm_uiotombuf: iovcnt != 1");
895 if (siz
> MLEN
) /* or should it >= MCLBYTES ?? */
899 rem
= nfsm_rndup(siz
)-siz
;
902 left
= uiop
->uio_iov
->iov_len
;
903 uiocp
= uiop
->uio_iov
->iov_base
;
908 mlen
= M_TRAILINGSPACE(mp
);
910 MGET(mp
, M_WAIT
, MT_DATA
);
916 mlen
= M_TRAILINGSPACE(mp
);
918 xfer
= (left
> mlen
) ? mlen
: left
;
921 if (uiop
->uio_iov
->iov_op
!= NULL
)
922 (*(uiop
->uio_iov
->iov_op
))
923 (uiocp
, mtod(mp
, caddr_t
)+mp
->m_len
, xfer
);
926 if (uiop
->uio_segflg
== UIO_SYSSPACE
)
927 bcopy(uiocp
, mtod(mp
, caddr_t
)+mp
->m_len
, xfer
);
929 copyin(uiocp
, mtod(mp
, caddr_t
)+mp
->m_len
, xfer
);
933 uiop
->uio_offset
+= xfer
;
934 uiop
->uio_resid
-= xfer
;
936 uiop
->uio_iov
->iov_base
+= uiosiz
;
937 uiop
->uio_iov
->iov_len
-= uiosiz
;
941 if (rem
> M_TRAILINGSPACE(mp
)) {
942 MGET(mp
, M_WAIT
, MT_DATA
);
946 cp
= mtod(mp
, caddr_t
)+mp
->m_len
;
947 for (left
= 0; left
< rem
; left
++)
952 *bpos
= mtod(mp
, caddr_t
)+mp
->m_len
;
958 * Help break down an mbuf chain by setting the first siz bytes contiguous
959 * pointed to by returned val.
960 * This is used by the macros nfsm_dissect and nfsm_dissecton for tough
961 * cases. (The macros use the vars. dpos and dpos2)
964 nfsm_disct(mdp
, dposp
, siz
, left
, cp2
)
971 register struct mbuf
*mp
, *mp2
;
972 register int siz2
, xfer
;
977 *mdp
= mp
= mp
->m_next
;
981 *dposp
= mtod(mp
, caddr_t
);
986 } else if (mp
->m_next
== NULL
) {
988 } else if (siz
> MHLEN
) {
989 panic("nfs S too big");
991 MGET(mp2
, M_WAIT
, MT_DATA
);
992 mp2
->m_next
= mp
->m_next
;
996 *cp2
= p
= mtod(mp
, caddr_t
);
997 bcopy(*dposp
, p
, left
); /* Copy what was left */
1001 /* Loop around copying up the siz2 bytes */
1005 xfer
= (siz2
> mp2
->m_len
) ? mp2
->m_len
: siz2
;
1007 bcopy(mtod(mp2
, caddr_t
), p
, xfer
);
1018 *dposp
= mtod(mp2
, caddr_t
);
1024 * Advance the position in the mbuf chain.
1027 nfs_adv(mdp
, dposp
, offs
, left
)
1033 register struct mbuf
*m
;
1046 *dposp
= mtod(m
, caddr_t
)+offs
;
1051 * Copy a string into mbufs for the hard cases...
1054 nfsm_strtmbuf(mb
, bpos
, cp
, siz
)
1060 register struct mbuf
*m1
= 0, *m2
;
1061 long left
, xfer
, len
, tlen
;
1067 left
= M_TRAILINGSPACE(m2
);
1069 tl
= ((u_long
*)(*bpos
));
1070 *tl
++ = txdr_unsigned(siz
);
1072 left
-= NFSX_UNSIGNED
;
1073 m2
->m_len
+= NFSX_UNSIGNED
;
1075 bcopy(cp
, (caddr_t
) tl
, left
);
1082 /* Loop around adding mbufs */
1084 MGET(m1
, M_WAIT
, MT_DATA
);
1087 m1
->m_len
= NFSMSIZ(m1
);
1090 tl
= mtod(m1
, u_long
*);
1093 *tl
++ = txdr_unsigned(siz
);
1094 m1
->m_len
-= NFSX_UNSIGNED
;
1095 tlen
= NFSX_UNSIGNED
;
1098 if (siz
< m1
->m_len
) {
1099 len
= nfsm_rndup(siz
);
1102 *(tl
+(xfer
>>2)) = 0;
1104 xfer
= len
= m1
->m_len
;
1106 bcopy(cp
, (caddr_t
) tl
, xfer
);
1107 m1
->m_len
= len
+tlen
;
1112 *bpos
= mtod(m1
, caddr_t
)+m1
->m_len
;
1117 * Called once to initialize data structures...
1121 struct vfsconf
*vfsp
;
1126 * Check to see if major data structures haven't bloated.
1128 if (sizeof (struct nfsnode
) > NFS_NODEALLOC
) {
1129 printf("struct nfsnode bloated (> %dbytes)\n", NFS_NODEALLOC
);
1130 printf("Try reducing NFS_SMALLFH\n");
1132 if (sizeof (struct nfsmount
) > NFS_MNTALLOC
) {
1133 printf("struct nfsmount bloated (> %dbytes)\n", NFS_MNTALLOC
);
1134 printf("Try reducing NFS_MUIDHASHSIZ\n");
1136 if (sizeof (struct nfssvc_sock
) > NFS_SVCALLOC
) {
1137 printf("struct nfssvc_sock bloated (> %dbytes)\n",NFS_SVCALLOC
);
1138 printf("Try reducing NFS_UIDHASHSIZ\n");
1140 if (sizeof (struct nfsuid
) > NFS_UIDALLOC
) {
1141 printf("struct nfsuid bloated (> %dbytes)\n",NFS_UIDALLOC
);
1142 printf("Try unionizing the nu_nickname and nu_flag fields\n");
1144 nfs_mount_type
= vfsp
->vfc_typenum
;
1146 rpc_vers
= txdr_unsigned(RPC_VER2
);
1147 rpc_call
= txdr_unsigned(RPC_CALL
);
1148 rpc_reply
= txdr_unsigned(RPC_REPLY
);
1149 rpc_msgdenied
= txdr_unsigned(RPC_MSGDENIED
);
1150 rpc_msgaccepted
= txdr_unsigned(RPC_MSGACCEPTED
);
1151 rpc_mismatch
= txdr_unsigned(RPC_MISMATCH
);
1152 rpc_autherr
= txdr_unsigned(RPC_AUTHERR
);
1153 rpc_auth_unix
= txdr_unsigned(RPCAUTH_UNIX
);
1154 rpc_auth_kerb
= txdr_unsigned(RPCAUTH_KERB4
);
1155 nfs_prog
= txdr_unsigned(NFS_PROG
);
1156 nqnfs_prog
= txdr_unsigned(NQNFS_PROG
);
1157 nfs_true
= txdr_unsigned(TRUE
);
1158 nfs_false
= txdr_unsigned(FALSE
);
1159 nfs_xdrneg1
= txdr_unsigned(-1);
1160 nfs_ticks
= (hz
* NFS_TICKINTVL
+ 500) / 1000;
1163 /* Ensure async daemons disabled */
1164 for (i
= 0; i
< NFS_MAXASYNCDAEMON
; i
++) {
1165 nfs_iodwant
[i
] = (struct proc
*)0;
1166 nfs_iodmount
[i
] = (struct nfsmount
*)0;
1168 nfs_nhinit(); /* Init the nfsnode table */
1169 #ifndef NFS_NOSERVER
1170 nfsrv_init(0); /* Init server data structures */
1171 nfsrv_initcache(); /* Init the server request cache */
1175 * Initialize the nqnfs server stuff.
1177 if (nqnfsstarttime
== 0) {
1178 nqnfsstarttime
= boottime
.tv_sec
+ nqsrv_maxlease
1179 + nqsrv_clockskew
+ nqsrv_writeslack
;
1180 NQLOADNOVRAM(nqnfsstarttime
);
1181 CIRCLEQ_INIT(&nqtimerhead
);
1182 nqfhhashtbl
= hashinit(NQLCHSZ
, M_NQLEASE
, &nqfhhash
);
1186 * Initialize reply list and start timer
1188 TAILQ_INIT(&nfs_reqq
);
1193 /* XXX CSM 12/4/97 Where are these declared in FreeBSD? */
1196 * Set up lease_check and lease_updatetime so that other parts
1197 * of the system can call us, if we are loadable.
1199 #ifndef NFS_NOSERVER
1200 default_vnodeop_p
[VOFFSET(vop_lease
)] = (vop_t
*)nqnfs_vop_lease_check
;
1202 lease_updatetime
= nfs_lease_updatetime
;
1204 vfsp
->vfc_refcount
++; /* make us non-unloadable */
1205 sysent
[SYS_nfssvc
].sy_narg
= 2;
1206 sysent
[SYS_nfssvc
].sy_call
= nfssvc
;
1207 #ifndef NFS_NOSERVER
1208 sysent
[SYS_getfh
].sy_narg
= 2;
1209 sysent
[SYS_getfh
].sy_call
= getfh
;
1216 * Attribute cache routines.
1217 * nfs_loadattrcache() - loads or updates the cache contents from attributes
1218 * that are on the mbuf list
1219 * nfs_getattrcache() - returns valid attributes if found in cache, returns
1224 * Load the attribute cache (that lives in the nfsnode entry) with
1225 * the values on the mbuf list and
1227 * copy the attributes to *vaper
1230 nfs_loadattrcache(vpp
, mdp
, dposp
, vaper
)
1234 struct vattr
*vaper
;
1236 register struct vnode
*vp
= *vpp
;
1237 register struct vattr
*vap
;
1238 register struct nfs_fattr
*fp
;
1239 register struct nfsnode
*np
;
1242 int error
= 0, rdev
;
1246 struct timespec mtime
;
1250 /* this routine is a good place to check for VBAD again. We caught most of them
1251 * in nfsm_request, but postprocessing may indirectly get here, so check again.
1253 if (vp
->v_type
==VBAD
)
1257 NFSTRACE(NFSTRC_LAC
, vp
);
1259 t1
= (mtod(md
, caddr_t
) + md
->m_len
) - *dposp
;
1260 if ((error
= nfsm_disct(mdp
, dposp
, NFSX_FATTR(v3
), t1
, &cp2
)))
1262 fp
= (struct nfs_fattr
*)cp2
;
1264 vtyp
= nfsv3tov_type(fp
->fa_type
);
1265 vmode
= fxdr_unsigned(u_short
, fp
->fa_mode
);
1266 rdev
= makedev(fxdr_unsigned(int, fp
->fa3_rdev
.specdata1
),
1267 fxdr_unsigned(int, fp
->fa3_rdev
.specdata2
));
1268 fxdr_nfsv3time(&fp
->fa3_mtime
, &mtime
);
1270 vtyp
= nfsv2tov_type(fp
->fa_type
);
1271 vmode
= fxdr_unsigned(u_short
, fp
->fa_mode
);
1275 * The duplicate information returned in fa_type and fa_mode
1276 * is an ambiguity in the NFS version 2 protocol.
1278 * VREG should be taken literally as a regular file. If a
1279 * server intents to return some type information differently
1280 * in the upper bits of the mode field (e.g. for sockets, or
1281 * FIFOs), NFSv2 mandates fa_type to be VNON. Anyway, we
1282 * leave the examination of the mode bits even in the VREG
1283 * case to avoid breakage for bogus servers, but we make sure
1284 * that there are actually type bits set in the upper part of
1285 * fa_mode (and failing that, trust the va_type field).
1287 * NFSv3 cleared the issue, and requires fa_mode to not
1288 * contain any type information (while also introduing sockets
1289 * and FIFOs for fa_type).
1291 if (vtyp
== VNON
|| (vtyp
== VREG
&& (vmode
& S_IFMT
) != 0))
1292 vtyp
= IFTOVT(vmode
);
1293 rdev
= fxdr_unsigned(long, fp
->fa2_rdev
);
1294 fxdr_nfsv2time(&fp
->fa2_mtime
, &mtime
);
1297 * Really ugly NFSv2 kludge.
1299 if (vtyp
== VCHR
&& rdev
== 0xffffffff)
1304 * If v_type == VNON it is a new node, so fill in the v_type,
1305 * n_mtime fields. Check to see if it represents a special
1306 * device, and if so, check for a possible alias. Once the
1307 * correct vnode has been obtained, fill in the rest of the
1311 if (vp
->v_type
!= vtyp
) {
1314 if (UBCINFOMISSING(vp
) || UBCINFORECLAIMED(vp
))
1315 if (error
= ubc_info_init(vp
)) /* VREG */
1318 if (vp
->v_type
== VFIFO
) {
1319 vp
->v_op
= fifo_nfsv2nodeop_p
;
1321 if (vp
->v_type
== VCHR
|| vp
->v_type
== VBLK
) {
1322 vp
->v_op
= spec_nfsv2nodeop_p
;
1323 nvp
= checkalias(vp
, (dev_t
)rdev
, vp
->v_mount
);
1326 * Discard unneeded vnode, but save its nfsnode.
1327 * Since the nfsnode does not have a lock, its
1328 * vnode lock has to be carried over.
1330 nvp
->v_vnlock
= vp
->v_vnlock
;
1331 vp
->v_vnlock
= NULL
;
1332 nvp
->v_data
= vp
->v_data
;
1334 vp
->v_op
= spec_vnodeop_p
;
1338 * Reinitialize aliased node.
1344 np
->n_mtime
= mtime
.tv_sec
;
1345 NFSTRACE(NFSTRC_LAC_INIT
, vp
);
1348 vap
->va_type
= vtyp
;
1349 vap
->va_mode
= (vmode
& 07777);
1350 vap
->va_rdev
= (dev_t
)rdev
;
1351 vap
->va_mtime
= mtime
;
1352 vap
->va_fsid
= vp
->v_mount
->mnt_stat
.f_fsid
.val
[0];
1354 vap
->va_nlink
= fxdr_unsigned(u_short
, fp
->fa_nlink
);
1355 vap
->va_uid
= fxdr_unsigned(uid_t
, fp
->fa_uid
);
1356 vap
->va_gid
= fxdr_unsigned(gid_t
, fp
->fa_gid
);
1357 fxdr_hyper(&fp
->fa3_size
, &vap
->va_size
);
1358 vap
->va_blocksize
= NFS_FABLKSIZE
;
1359 fxdr_hyper(&fp
->fa3_used
, &vap
->va_bytes
);
1360 vap
->va_fileid
= fxdr_unsigned(int, fp
->fa3_fileid
.nfsuquad
[1]);
1361 fxdr_nfsv3time(&fp
->fa3_atime
, &vap
->va_atime
);
1362 fxdr_nfsv3time(&fp
->fa3_ctime
, &vap
->va_ctime
);
1364 vap
->va_filerev
= 0;
1366 vap
->va_nlink
= fxdr_unsigned(u_short
, fp
->fa_nlink
);
1367 vap
->va_uid
= fxdr_unsigned(uid_t
, fp
->fa_uid
);
1368 vap
->va_gid
= fxdr_unsigned(gid_t
, fp
->fa_gid
);
1369 vap
->va_size
= fxdr_unsigned(u_long
, fp
->fa2_size
);
1370 vap
->va_blocksize
= fxdr_unsigned(long, fp
->fa2_blocksize
);
1371 vap
->va_bytes
= fxdr_unsigned(long, fp
->fa2_blocks
) * NFS_FABLKSIZE
;
1372 vap
->va_fileid
= fxdr_unsigned(long, fp
->fa2_fileid
);
1373 fxdr_nfsv2time(&fp
->fa2_atime
, &vap
->va_atime
);
1375 vap
->va_ctime
.tv_sec
= fxdr_unsigned(long, fp
->fa2_ctime
.nfsv2_sec
);
1376 vap
->va_ctime
.tv_nsec
= 0;
1377 vap
->va_gen
= fxdr_unsigned(u_long
, fp
->fa2_ctime
.nfsv2_usec
);
1378 vap
->va_filerev
= 0;
1381 if (vap
->va_size
!= np
->n_size
) {
1382 NFSTRACE4(NFSTRC_LAC_NP
, vp
, vap
->va_size
, np
->n_size
,
1383 (vap
->va_type
== VREG
) |
1384 (np
->n_flag
& NMODIFIED
? 2 : 0));
1385 if (vap
->va_type
== VREG
) {
1388 orig_size
= np
->n_size
;
1390 if (np
->n_flag
& NMODIFIED
) {
1391 if (vap
->va_size
< np
->n_size
)
1392 vap
->va_size
= np
->n_size
;
1394 np
->n_size
= vap
->va_size
;
1396 np
->n_size
= vap
->va_size
;
1397 if (UBCISVALID(vp
) && np
->n_size
> orig_size
)
1398 ubc_setsize(vp
, (off_t
)np
->n_size
); /* XXX check error */
1400 np
->n_size
= vap
->va_size
;
1403 np
->n_attrstamp
= time
.tv_sec
;
1404 if (vaper
!= NULL
) {
1405 bcopy((caddr_t
)vap
, (caddr_t
)vaper
, sizeof(*vap
));
1406 if (np
->n_flag
& NCHG
) {
1407 if (np
->n_flag
& NACC
)
1408 vaper
->va_atime
= np
->n_atim
;
1409 if (np
->n_flag
& NUPD
)
1410 vaper
->va_mtime
= np
->n_mtim
;
1417 * Check the time stamp
1418 * If the cache is valid, copy contents to *vap and return 0
1419 * otherwise return an error
1422 nfs_getattrcache(vp
, vaper
)
1423 register struct vnode
*vp
;
1424 struct vattr
*vaper
;
1426 register struct nfsnode
*np
= VTONFS(vp
);
1427 register struct vattr
*vap
;
1429 if ((time
.tv_sec
- np
->n_attrstamp
) >= NFS_ATTRTIMEO(np
)) {
1430 NFSTRACE(NFSTRC_GAC_MISS
, vp
);
1431 nfsstats
.attrcache_misses
++;
1434 NFSTRACE(NFSTRC_GAC_HIT
, vp
);
1435 nfsstats
.attrcache_hits
++;
1438 if (vap
->va_size
!= np
->n_size
) {
1439 NFSTRACE4(NFSTRC_GAC_NP
, vp
, vap
->va_size
, np
->n_size
,
1440 (vap
->va_type
== VREG
) |
1441 (np
->n_flag
& NMODIFIED
? 2 : 0));
1442 if (vap
->va_type
== VREG
) {
1445 orig_size
= np
->n_size
;
1447 if (np
->n_flag
& NMODIFIED
) {
1448 if (vap
->va_size
< np
->n_size
)
1449 vap
->va_size
= np
->n_size
;
1451 np
->n_size
= vap
->va_size
;
1453 np
->n_size
= vap
->va_size
;
1454 if (UBCISVALID(vp
) && np
->n_size
> orig_size
)
1455 ubc_setsize(vp
, (off_t
)np
->n_size
); /* XXX check error */
1457 np
->n_size
= vap
->va_size
;
1460 bcopy((caddr_t
)vap
, (caddr_t
)vaper
, sizeof(struct vattr
));
1461 if (np
->n_flag
& NCHG
) {
1462 if (np
->n_flag
& NACC
)
1463 vaper
->va_atime
= np
->n_atim
;
1464 if (np
->n_flag
& NUPD
)
1465 vaper
->va_mtime
= np
->n_mtim
;
1470 #ifndef NFS_NOSERVER
1472 * Set up nameidata for a lookup() call and do it.
1474 * If pubflag is set, this call is done for a lookup operation on the
1475 * public filehandle. In that case we allow crossing mountpoints and
1476 * absolute pathnames. However, the caller is expected to check that
1477 * the lookup result is within the public fs, and deny access if
1481 nfs_namei(ndp
, fhp
, len
, slp
, nam
, mdp
, dposp
, retdirp
, p
, kerbflag
, pubflag
)
1482 register struct nameidata
*ndp
;
1485 struct nfssvc_sock
*slp
;
1489 struct vnode
**retdirp
;
1491 int kerbflag
, pubflag
;
1493 register int i
, rem
;
1494 register struct mbuf
*md
;
1495 register char *fromcp
, *tocp
, *cp
;
1499 int error
, rdonly
, linklen
;
1500 struct componentname
*cnp
= &ndp
->ni_cnd
;
1503 *retdirp
= (struct vnode
*)0;
1504 MALLOC_ZONE(cnp
->cn_pnbuf
, char *, len
+ 1, M_NAMEI
, M_WAITOK
);
1505 cnp
->cn_pnlen
= len
+ 1;
1508 * Copy the name from the mbuf list to ndp->ni_pnbuf
1509 * and set the various ndp fields appropriately.
1512 tocp
= cnp
->cn_pnbuf
;
1514 rem
= mtod(md
, caddr_t
) + md
->m_len
- fromcp
;
1516 for (i
= 1; i
<= len
; i
++) {
1523 fromcp
= mtod(md
, caddr_t
);
1526 /* XXX CSM 12/4/97 Revisit when enabling WebNFS */
1528 if (*fromcp
== '\0' || (!pubflag
&& *fromcp
== '/')) {
1530 if (*fromcp
== '\0' || *fromcp
== '/') {
1535 cnp
->cn_hash
+= (unsigned char)*fromcp
* i
;
1536 *tocp
++ = *fromcp
++;
1542 len
= nfsm_rndup(len
)-len
;
1546 else if ((error
= nfs_adv(mdp
, dposp
, len
, rem
)) != 0)
1551 * Extract and set starting directory.
1553 error
= nfsrv_fhtovp(fhp
, FALSE
, &dp
, ndp
->ni_cnd
.cn_cred
, slp
,
1554 nam
, &rdonly
, kerbflag
, pubflag
);
1557 if (dp
->v_type
!= VDIR
) {
1564 cnp
->cn_flags
|= RDONLY
;
1568 /* XXX CSM 12/4/97 Revisit when enabling WebNFS */
1569 /* XXX debo 12/15/97 Need to fix M_NAMEI allocations to use zone protocol */
1573 * Oh joy. For WebNFS, handle those pesky '%' escapes,
1574 * and the 'native path' indicator.
1576 MALLOC(cp
, char *, olen
+ 1, M_NAMEI
, M_WAITOK
);
1577 fromcp
= cnp
->cn_pnbuf
;
1579 if ((unsigned char)*fromcp
>= WEBNFS_SPECCHAR_START
) {
1580 switch ((unsigned char)*fromcp
) {
1581 case WEBNFS_NATIVE_CHAR
:
1583 * 'Native' path for us is the same
1584 * as a path according to the NFS spec,
1585 * just skip the escape char.
1590 * More may be added in the future, range 0x80-0xff
1599 * Translate the '%' escapes, URL-style.
1601 while (*fromcp
!= '\0') {
1602 if (*fromcp
== WEBNFS_ESC_CHAR
) {
1603 if (fromcp
[1] != '\0' && fromcp
[2] != '\0') {
1605 *tocp
++ = HEXSTRTOI(fromcp
);
1614 *tocp
++ = *fromcp
++;
1617 FREE(cnp
->cn_pnbuf
, M_NAMEI
);
1622 ndp
->ni_pathlen
= (tocp
- cnp
->cn_pnbuf
) + 1;
1623 ndp
->ni_segflg
= UIO_SYSSPACE
;
1625 /* XXX CSM 12/4/97 Revisit when enabling WebNFS */
1628 ndp
->ni_rootdir
= rootvnode
;
1629 ndp
->ni_loopcnt
= 0;
1630 if (cnp
->cn_pnbuf
[0] == '/')
1633 cnp
->cn_flags
|= NOCROSSMOUNT
;
1636 cnp
->cn_flags
|= NOCROSSMOUNT
;
1643 cnp
->cn_nameptr
= cnp
->cn_pnbuf
;
1644 ndp
->ni_startdir
= dp
;
1646 * And call lookup() to do the real work
1648 error
= lookup(ndp
);
1652 * Check for encountering a symbolic link
1654 if ((cnp
->cn_flags
& ISSYMLINK
) == 0) {
1655 nfsrv_object_create(ndp
->ni_vp
);
1656 if (cnp
->cn_flags
& (SAVENAME
| SAVESTART
)) {
1657 cnp
->cn_flags
|= HASBUF
;
1662 if ((cnp
->cn_flags
& LOCKPARENT
) && ndp
->ni_pathlen
== 1)
1663 VOP_UNLOCK(ndp
->ni_dvp
, 0, p
);
1664 /* XXX CSM 12/4/97 Revisit when enabling WebNFS */
1673 /* XXX CSM 12/4/97 Revisit when enabling WebNFS */
1674 /* XXX debo 12/15/97 Need to fix M_NAMEI allocations to use zone protocol */
1678 if (ndp
->ni_loopcnt
++ >= MAXSYMLINKS
) {
1682 if (ndp
->ni_pathlen
> 1)
1683 MALLOC(cp
, char *, olen
+ 1, M_NAMEI
, M_WAITOK
);
1687 aiov
.iov_len
= MAXPATHLEN
;
1688 auio
.uio_iov
= &aiov
;
1689 auio
.uio_iovcnt
= 1;
1690 auio
.uio_offset
= 0;
1691 auio
.uio_rw
= UIO_READ
;
1692 auio
.uio_segflg
= UIO_SYSSPACE
;
1693 auio
.uio_procp
= (struct proc
*)0;
1694 auio
.uio_resid
= MAXPATHLEN
;
1695 error
= VOP_READLINK(ndp
->ni_vp
, &auio
, cnp
->cn_cred
);
1698 if (ndp
->ni_pathlen
> 1)
1702 linklen
= MAXPATHLEN
- auio
.uio_resid
;
1707 if (linklen
+ ndp
->ni_pathlen
>= MAXPATHLEN
) {
1708 error
= ENAMETOOLONG
;
1711 if (ndp
->ni_pathlen
> 1) {
1712 bcopy(ndp
->ni_next
, cp
+ linklen
, ndp
->ni_pathlen
);
1713 FREE(cnp
->cn_pnbuf
, M_NAMEI
);
1716 cnp
->cn_pnbuf
[linklen
] = '\0';
1717 ndp
->ni_pathlen
+= linklen
;
1721 * Check if root directory should replace current directory.
1723 if (cnp
->cn_pnbuf
[0] == '/') {
1725 dp
= ndp
->ni_rootdir
;
1732 FREE_ZONE(cnp
->cn_pnbuf
, cnp
->cn_pnlen
, M_NAMEI
);
1737 * A fiddled version of m_adj() that ensures null fill to a long
1738 * boundary and only trims off the back end
1741 nfsm_adj(mp
, len
, nul
)
1746 register struct mbuf
*m
;
1747 register int count
, i
;
1751 * Trim from tail. Scan the mbuf chain,
1752 * calculating its length and finding the last mbuf.
1753 * If the adjustment only affects this mbuf, then just
1754 * adjust and return. Otherwise, rescan and truncate
1755 * after the remaining size.
1761 if (m
->m_next
== (struct mbuf
*)0)
1765 if (m
->m_len
> len
) {
1768 cp
= mtod(m
, caddr_t
)+m
->m_len
-nul
;
1769 for (i
= 0; i
< nul
; i
++)
1778 * Correct length for chain is "count".
1779 * Find the mbuf with last data, adjust its length,
1780 * and toss data from remaining mbufs on chain.
1782 for (m
= mp
; m
; m
= m
->m_next
) {
1783 if (m
->m_len
>= count
) {
1786 cp
= mtod(m
, caddr_t
)+m
->m_len
-nul
;
1787 for (i
= 0; i
< nul
; i
++)
1794 for (m
= m
->m_next
;m
;m
= m
->m_next
)
1799 * Make these functions instead of macros, so that the kernel text size
1800 * doesn't get too big...
1803 nfsm_srvwcc(nfsd
, before_ret
, before_vap
, after_ret
, after_vap
, mbp
, bposp
)
1804 struct nfsrv_descript
*nfsd
;
1806 register struct vattr
*before_vap
;
1808 struct vattr
*after_vap
;
1812 register struct mbuf
*mb
= *mbp
, *mb2
;
1813 register char *bpos
= *bposp
;
1814 register u_long
*tl
;
1817 nfsm_build(tl
, u_long
*, NFSX_UNSIGNED
);
1820 nfsm_build(tl
, u_long
*, 7 * NFSX_UNSIGNED
);
1822 txdr_hyper(&(before_vap
->va_size
), tl
);
1824 txdr_nfsv3time(&(before_vap
->va_mtime
), tl
);
1826 txdr_nfsv3time(&(before_vap
->va_ctime
), tl
);
1830 nfsm_srvpostopattr(nfsd
, after_ret
, after_vap
, mbp
, bposp
);
1834 nfsm_srvpostopattr(nfsd
, after_ret
, after_vap
, mbp
, bposp
)
1835 struct nfsrv_descript
*nfsd
;
1837 struct vattr
*after_vap
;
1841 register struct mbuf
*mb
= *mbp
, *mb2
;
1842 register char *bpos
= *bposp
;
1843 register u_long
*tl
;
1844 register struct nfs_fattr
*fp
;
1847 nfsm_build(tl
, u_long
*, NFSX_UNSIGNED
);
1850 nfsm_build(tl
, u_long
*, NFSX_UNSIGNED
+ NFSX_V3FATTR
);
1852 fp
= (struct nfs_fattr
*)tl
;
1853 nfsm_srvfattr(nfsd
, after_vap
, fp
);
1860 nfsm_srvfattr(nfsd
, vap
, fp
)
1861 register struct nfsrv_descript
*nfsd
;
1862 register struct vattr
*vap
;
1863 register struct nfs_fattr
*fp
;
1866 fp
->fa_nlink
= txdr_unsigned(vap
->va_nlink
);
1867 fp
->fa_uid
= txdr_unsigned(vap
->va_uid
);
1868 fp
->fa_gid
= txdr_unsigned(vap
->va_gid
);
1869 if (nfsd
->nd_flag
& ND_NFSV3
) {
1870 fp
->fa_type
= vtonfsv3_type(vap
->va_type
);
1871 fp
->fa_mode
= vtonfsv3_mode(vap
->va_mode
);
1872 txdr_hyper(&vap
->va_size
, &fp
->fa3_size
);
1873 txdr_hyper(&vap
->va_bytes
, &fp
->fa3_used
);
1874 fp
->fa3_rdev
.specdata1
= txdr_unsigned(major(vap
->va_rdev
));
1875 fp
->fa3_rdev
.specdata2
= txdr_unsigned(minor(vap
->va_rdev
));
1876 fp
->fa3_fsid
.nfsuquad
[0] = 0;
1877 fp
->fa3_fsid
.nfsuquad
[1] = txdr_unsigned(vap
->va_fsid
);
1878 fp
->fa3_fileid
.nfsuquad
[0] = 0;
1879 fp
->fa3_fileid
.nfsuquad
[1] = txdr_unsigned(vap
->va_fileid
);
1880 txdr_nfsv3time(&vap
->va_atime
, &fp
->fa3_atime
);
1881 txdr_nfsv3time(&vap
->va_mtime
, &fp
->fa3_mtime
);
1882 txdr_nfsv3time(&vap
->va_ctime
, &fp
->fa3_ctime
);
1884 fp
->fa_type
= vtonfsv2_type(vap
->va_type
);
1885 fp
->fa_mode
= vtonfsv2_mode(vap
->va_type
, vap
->va_mode
);
1886 fp
->fa2_size
= txdr_unsigned(vap
->va_size
);
1887 fp
->fa2_blocksize
= txdr_unsigned(vap
->va_blocksize
);
1888 if (vap
->va_type
== VFIFO
)
1889 fp
->fa2_rdev
= 0xffffffff;
1891 fp
->fa2_rdev
= txdr_unsigned(vap
->va_rdev
);
1892 fp
->fa2_blocks
= txdr_unsigned(vap
->va_bytes
/ NFS_FABLKSIZE
);
1893 fp
->fa2_fsid
= txdr_unsigned(vap
->va_fsid
);
1894 fp
->fa2_fileid
= txdr_unsigned(vap
->va_fileid
);
1895 txdr_nfsv2time(&vap
->va_atime
, &fp
->fa2_atime
);
1896 txdr_nfsv2time(&vap
->va_mtime
, &fp
->fa2_mtime
);
1897 txdr_nfsv2time(&vap
->va_ctime
, &fp
->fa2_ctime
);
1902 * nfsrv_fhtovp() - convert a fh to a vnode ptr (optionally locked)
1903 * - look up fsid in mount list (if not found ret error)
1904 * - get vp and export rights by calling VFS_FHTOVP()
1905 * - if cred->cr_uid == 0 or MNT_EXPORTANON set it to credanon
1906 * - if not lockflag unlock it with VOP_UNLOCK()
1909 nfsrv_fhtovp(fhp
, lockflag
, vpp
, cred
, slp
, nam
, rdonlyp
, kerbflag
, pubflag
)
1914 struct nfssvc_sock
*slp
;
1920 struct proc
*p
= current_proc(); /* XXX */
1921 register struct mount
*mp
;
1923 struct ucred
*credanon
;
1926 *vpp
= (struct vnode
*)0;
1928 /* XXX CSM 12/4/97 Revisit when enabling WebNFS */
1930 if (nfs_ispublicfh(fhp
)) {
1931 if (!pubflag
|| !nfs_pub
.np_valid
)
1933 fhp
= &nfs_pub
.np_handle
;
1937 mp
= vfs_getvfs(&fhp
->fh_fsid
);
1940 error
= VFS_FHTOVP(mp
, &fhp
->fh_fid
, nam
, vpp
, &exflags
, &credanon
);
1943 /* vnode pointer should be good at this point or ... */
1947 * Check/setup credentials.
1949 if (exflags
& MNT_EXKERB
) {
1952 return (NFSERR_AUTHERR
| AUTH_TOOWEAK
);
1954 } else if (kerbflag
) {
1956 return (NFSERR_AUTHERR
| AUTH_TOOWEAK
);
1957 } else if (cred
->cr_uid
== 0 || (exflags
& MNT_EXPORTANON
)) {
1958 cred
->cr_uid
= credanon
->cr_uid
;
1959 for (i
= 0; i
< credanon
->cr_ngroups
&& i
< NGROUPS
; i
++)
1960 cred
->cr_groups
[i
] = credanon
->cr_groups
[i
];
1961 cred
->cr_ngroups
= i
;
1963 if (exflags
& MNT_EXRDONLY
)
1968 nfsrv_object_create(*vpp
);
1971 VOP_UNLOCK(*vpp
, 0, p
);
1977 * WebNFS: check if a filehandle is a public filehandle. For v3, this
1978 * means a length of 0, for v2 it means all zeroes. nfsm_srvmtofh has
1979 * transformed this to all zeroes in both cases, so check for it.
1985 char *cp
= (char *)fhp
;
1988 for (i
= 0; i
< NFSX_V3FH
; i
++)
1994 #endif /* NFS_NOSERVER */
1996 * This function compares two net addresses by family and returns TRUE
1997 * if they are the same host.
1998 * If there is any doubt, return FALSE.
1999 * The AF_INET family is handled as a special case so that address mbufs
2000 * don't need to be saved to store "struct in_addr", which is only 4 bytes.
2003 netaddr_match(family
, haddr
, nam
)
2005 union nethostaddr
*haddr
;
2008 register struct sockaddr_in
*inetaddr
;
2012 inetaddr
= mtod(nam
, struct sockaddr_in
*);
2013 if (inetaddr
->sin_family
== AF_INET
&&
2014 inetaddr
->sin_addr
.s_addr
== haddr
->had_inetaddr
)
2020 register struct sockaddr_iso
*isoaddr1
, *isoaddr2
;
2022 isoaddr1
= mtod(nam
, struct sockaddr_iso
*);
2023 isoaddr2
= mtod(haddr
->had_nam
, struct sockaddr_iso
*);
2024 if (isoaddr1
->siso_family
== AF_ISO
&&
2025 isoaddr1
->siso_nlen
> 0 &&
2026 isoaddr1
->siso_nlen
== isoaddr2
->siso_nlen
&&
2027 SAME_ISOADDR(isoaddr1
, isoaddr2
))
2038 static nfsuint64 nfs_nullcookie
= { 0, 0 };
2040 * This function finds the directory cookie that corresponds to the
2041 * logical byte offset given.
2044 nfs_getcookie(np
, off
, add
)
2045 register struct nfsnode
*np
;
2049 register struct nfsdmap
*dp
, *dp2
;
2052 pos
= off
/ NFS_DIRBLKSIZ
;
2056 panic("nfs getcookie add at 0");
2058 return (&nfs_nullcookie
);
2061 dp
= np
->n_cookies
.lh_first
;
2064 MALLOC_ZONE(dp
, struct nfsdmap
*,
2065 sizeof (struct nfsdmap
),
2066 M_NFSDIROFF
, M_WAITOK
);
2067 dp
->ndm_eocookie
= 0;
2068 LIST_INSERT_HEAD(&np
->n_cookies
, dp
, ndm_list
);
2070 return ((nfsuint64
*)0);
2072 while (pos
>= NFSNUMCOOKIES
) {
2073 pos
-= NFSNUMCOOKIES
;
2074 if (dp
->ndm_list
.le_next
) {
2075 if (!add
&& dp
->ndm_eocookie
< NFSNUMCOOKIES
&&
2076 pos
>= dp
->ndm_eocookie
)
2077 return ((nfsuint64
*)0);
2078 dp
= dp
->ndm_list
.le_next
;
2080 MALLOC_ZONE(dp2
, struct nfsdmap
*,
2081 sizeof (struct nfsdmap
),
2082 M_NFSDIROFF
, M_WAITOK
);
2083 dp2
->ndm_eocookie
= 0;
2084 LIST_INSERT_AFTER(dp
, dp2
, ndm_list
);
2087 return ((nfsuint64
*)0);
2089 if (pos
>= dp
->ndm_eocookie
) {
2091 dp
->ndm_eocookie
= pos
+ 1;
2093 return ((nfsuint64
*)0);
2095 return (&dp
->ndm_cookies
[pos
]);
2099 * Invalidate cached directory information, except for the actual directory
2100 * blocks (which are invalidated separately).
2101 * Done mainly to avoid the use of stale offset cookies.
2105 register struct vnode
*vp
;
2107 register struct nfsnode
*np
= VTONFS(vp
);
2110 if (vp
->v_type
!= VDIR
)
2111 panic("nfs: invaldir not dir");
2113 np
->n_direofoffset
= 0;
2114 np
->n_cookieverf
.nfsuquad
[0] = 0;
2115 np
->n_cookieverf
.nfsuquad
[1] = 0;
2116 if (np
->n_cookies
.lh_first
)
2117 np
->n_cookies
.lh_first
->ndm_eocookie
= 0;
2121 * The write verifier has changed (probably due to a server reboot), so all
2122 * B_NEEDCOMMIT blocks will have to be written again. Since they are on the
2123 * dirty block list as B_DELWRI, all this takes is clearing the B_NEEDCOMMIT
2124 * flag. Once done the new write verifier can be set for the mount point.
2130 register struct vnode
*vp
, *nvp
;
2131 register struct buf
*bp
, *nbp
;
2136 for (vp
= mp
->mnt_vnodelist
.lh_first
; vp
; vp
= nvp
) {
2137 if (vp
->v_mount
!= mp
) /* Paranoia */
2139 nvp
= vp
->v_mntvnodes
.le_next
;
2140 for (bp
= vp
->v_dirtyblkhd
.lh_first
; bp
; bp
= nbp
) {
2141 nbp
= bp
->b_vnbufs
.le_next
;
2142 if ((bp
->b_flags
& (B_BUSY
| B_DELWRI
| B_NEEDCOMMIT
))
2143 == (B_DELWRI
| B_NEEDCOMMIT
))
2144 bp
->b_flags
&= ~B_NEEDCOMMIT
;
2150 #ifndef NFS_NOSERVER
2152 * Map errnos to NFS error numbers. For Version 3 also filter out error
2153 * numbers not specified for the associated procedure.
2156 nfsrv_errmap(nd
, err
)
2157 struct nfsrv_descript
*nd
;
2160 register short *defaulterrp
, *errp
;
2162 if (nd
->nd_flag
& ND_NFSV3
) {
2163 if (nd
->nd_procnum
<= NFSPROC_COMMIT
) {
2164 errp
= defaulterrp
= nfsrv_v3errmap
[nd
->nd_procnum
];
2168 else if (*errp
> err
)
2171 return ((int)*defaulterrp
);
2173 return (err
& 0xffff);
2176 return ((int)nfsrv_v2errmap
[err
- 1]);
2180 /* XXX CSM 11/25/97 Revisit when Ramesh merges vm with buffer cache */
2181 #define vfs_object_create(v, p, c, l) (0)
2184 nfsrv_object_create(struct vnode
*vp
) {
2185 struct proc
*curproc
= current_proc();
2187 if ((vp
== NULL
) || (vp
->v_type
!= VREG
))
2189 return vfs_object_create(vp
, curproc
, curproc
?curproc
->p_ucred
:NULL
, 1);
2191 #endif /* NFS_NOSERVER */