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>
107 #include <sys/kdebug.h>
109 #define FSDBG(A, B, C, D, E) \
110 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, (A))) | DBG_FUNC_NONE, \
111 (int)(B), (int)(C), (int)(D), (int)(E), 0)
112 #define FSDBG_TOP(A, B, C, D, E) \
113 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, (A))) | DBG_FUNC_START, \
114 (int)(B), (int)(C), (int)(D), (int)(E), 0)
115 #define FSDBG_BOT(A, B, C, D, E) \
116 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW, (A))) | DBG_FUNC_END, \
117 (int)(B), (int)(C), (int)(D), (int)(E), 0)
119 * Data items converted to xdr at startup, since they are constant
120 * This is kinda hokey, but may save a little time doing byte swaps
123 u_long rpc_call
, rpc_vers
, rpc_reply
, rpc_msgdenied
, rpc_autherr
,
124 rpc_mismatch
, rpc_auth_unix
, rpc_msgaccepted
,
126 u_long nfs_prog
, nqnfs_prog
, nfs_true
, nfs_false
;
128 /* And other global data */
129 static u_long nfs_xid
= 0;
130 u_long nfs_xidwrap
= 0; /* to build a (non-wwrapping) 64 bit xid */
131 static enum vtype nv2tov_type
[8]= {
132 VNON
, VREG
, VDIR
, VBLK
, VCHR
, VLNK
, VNON
, VNON
134 enum vtype nv3tov_type
[8]= {
135 VNON
, VREG
, VDIR
, VBLK
, VCHR
, VLNK
, VSOCK
, VFIFO
141 struct nfs_reqq nfs_reqq
;
142 struct nfssvc_sockhead nfssvc_sockhead
;
143 int nfssvc_sockhead_flag
;
144 struct nfsd_head nfsd_head
;
146 struct nfs_bufq nfs_bufq
;
147 struct nqtimerhead nqtimerhead
;
148 struct nqfhhashhead
*nqfhhashtbl
;
153 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
155 int nfsv3_procid
[NFS_NPROCS
] = {
184 #endif /* NFS_NOSERVER */
186 * and the reverse mapping from generic to Version 2 procedure numbers
188 int nfsv2_procid
[NFS_NPROCS
] = {
219 * Maps errno values to nfs error numbers.
220 * Use NFSERR_IO as the catch all for ones not specifically defined in
223 static u_char nfsrv_v2errmap
[ELAST
] = {
224 NFSERR_PERM
, NFSERR_NOENT
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
225 NFSERR_NXIO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
226 NFSERR_IO
, NFSERR_IO
, NFSERR_ACCES
, NFSERR_IO
, NFSERR_IO
,
227 NFSERR_IO
, NFSERR_EXIST
, NFSERR_IO
, NFSERR_NODEV
, NFSERR_NOTDIR
,
228 NFSERR_ISDIR
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
229 NFSERR_IO
, NFSERR_FBIG
, NFSERR_NOSPC
, NFSERR_IO
, NFSERR_ROFS
,
230 NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
231 NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
232 NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
233 NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
234 NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
235 NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
236 NFSERR_IO
, NFSERR_IO
, NFSERR_NAMETOL
, NFSERR_IO
, NFSERR_IO
,
237 NFSERR_NOTEMPTY
, NFSERR_IO
, NFSERR_IO
, NFSERR_DQUOT
, NFSERR_STALE
,
238 NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
239 NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
240 NFSERR_IO
, NFSERR_IO
, NFSERR_IO
, NFSERR_IO
,
244 * Maps errno values to nfs error numbers.
245 * Although it is not obvious whether or not NFS clients really care if
246 * a returned error value is in the specified list for the procedure, the
247 * safest thing to do is filter them appropriately. For Version 2, the
248 * X/Open XNFS document is the only specification that defines error values
249 * for each RPC (The RFC simply lists all possible error values for all RPCs),
250 * so I have decided to not do this for Version 2.
251 * The first entry is the default error return and the rest are the valid
252 * errors for that RPC in increasing numeric order.
254 static short nfsv3err_null
[] = {
259 static short nfsv3err_getattr
[] = {
268 static short nfsv3err_setattr
[] = {
284 static short nfsv3err_lookup
[] = {
297 static short nfsv3err_access
[] = {
306 static short nfsv3err_readlink
[] = {
318 static short nfsv3err_read
[] = {
330 static short nfsv3err_write
[] = {
345 static short nfsv3err_create
[] = {
362 static short nfsv3err_mkdir
[] = {
379 static short nfsv3err_symlink
[] = {
396 static short nfsv3err_mknod
[] = {
414 static short nfsv3err_remove
[] = {
428 static short nfsv3err_rmdir
[] = {
446 static short nfsv3err_rename
[] = {
469 static short nfsv3err_link
[] = {
489 static short nfsv3err_readdir
[] = {
502 static short nfsv3err_readdirplus
[] = {
516 static short nfsv3err_fsstat
[] = {
525 static short nfsv3err_fsinfo
[] = {
533 static short nfsv3err_pathconf
[] = {
541 static short nfsv3err_commit
[] = {
550 static short *nfsrv_v3errmap
[] = {
568 nfsv3err_readdirplus
,
575 #endif /* NFS_NOSERVER */
577 extern struct nfsrtt nfsrtt
;
578 extern time_t nqnfsstarttime
;
579 extern int nqsrv_clockskew
;
580 extern int nqsrv_writeslack
;
581 extern int nqsrv_maxlease
;
582 extern struct nfsstats nfsstats
;
583 extern int nqnfs_piggy
[NFS_NPROCS
];
584 extern nfstype nfsv2_type
[9];
585 extern nfstype nfsv3_type
[9];
586 extern struct nfsnodehashhead
*nfsnodehashtbl
;
587 extern u_long nfsnodehash
;
590 extern int getfh(struct proc
*, struct getfh_args
*, int *);
592 extern int nfssvc(struct proc
*, struct nfssvc_args
*, int *);
594 LIST_HEAD(nfsnodehashhead
, nfsnode
);
596 int nfs_webnamei
__P((struct nameidata
*, struct vnode
*, struct proc
*));
599 * Create the header for an rpc request packet
600 * The hsiz is the size of the rest of the nfs request header.
601 * (just used to decide if a cluster is a good idea)
604 nfsm_reqh(vp
, procid
, hsiz
, bposp
)
610 register struct mbuf
*mb
;
612 register caddr_t bpos
;
614 struct nfsmount
*nmp
;
617 MGET(mb
, M_WAIT
, MT_DATA
);
618 if (hsiz
>= MINCLSIZE
)
621 bpos
= mtod(mb
, caddr_t
);
624 * For NQNFS, add lease request.
627 nmp
= VFSTONFS(vp
->v_mount
);
628 if (nmp
->nm_flag
& NFSMNT_NQNFS
) {
629 nqflag
= NQNFS_NEEDLEASE(vp
, procid
);
631 nfsm_build(tl
, u_long
*, 2*NFSX_UNSIGNED
);
632 *tl
++ = txdr_unsigned(nqflag
);
633 *tl
= txdr_unsigned(nmp
->nm_leaseterm
);
635 nfsm_build(tl
, u_long
*, NFSX_UNSIGNED
);
640 /* Finally, return values */
646 * Build the RPC header and fill in the authorization info.
647 * The authorization string argument is only used when the credentials
648 * come from outside of the kernel.
649 * Returns the head of the mbuf list.
652 nfsm_rpchead(cr
, nmflag
, procid
, auth_type
, auth_len
, auth_str
, verf_len
,
653 verf_str
, mrest
, mrest_len
, mbp
, xidp
)
654 register struct ucred
*cr
;
667 register struct mbuf
*mb
;
669 register caddr_t bpos
;
671 struct mbuf
*mreq
, *mb2
;
672 int siz
, grpsiz
, authsiz
;
676 authsiz
= nfsm_rndup(auth_len
);
677 MGETHDR(mb
, M_WAIT
, MT_DATA
);
678 if ((authsiz
+ 10 * NFSX_UNSIGNED
) >= MINCLSIZE
) {
680 } else if ((authsiz
+ 10 * NFSX_UNSIGNED
) < MHLEN
) {
681 MH_ALIGN(mb
, authsiz
+ 10 * NFSX_UNSIGNED
);
683 MH_ALIGN(mb
, 8 * NFSX_UNSIGNED
);
687 bpos
= mtod(mb
, caddr_t
);
690 * First the RPC header.
692 nfsm_build(tl
, u_long
*, 8 * NFSX_UNSIGNED
);
695 * derive initial xid from system time
696 * XXX time is invalid if root not yet mounted
698 if (!base
&& (rootvp
)) {
700 base
= tv
.tv_sec
<< 12;
704 * Skip zero xid if it should ever happen.
706 if (++nfs_xid
== 0) {
711 *tl
++ = *xidp
= txdr_unsigned(nfs_xid
);
714 if (nmflag
& NFSMNT_NQNFS
) {
715 *tl
++ = txdr_unsigned(NQNFS_PROG
);
716 *tl
++ = txdr_unsigned(NQNFS_VER3
);
718 *tl
++ = txdr_unsigned(NFS_PROG
);
719 if (nmflag
& NFSMNT_NFSV3
)
720 *tl
++ = txdr_unsigned(NFS_VER3
);
722 *tl
++ = txdr_unsigned(NFS_VER2
);
724 if (nmflag
& NFSMNT_NFSV3
)
725 *tl
++ = txdr_unsigned(procid
);
727 *tl
++ = txdr_unsigned(nfsv2_procid
[procid
]);
730 * And then the authorization cred.
732 *tl
++ = txdr_unsigned(auth_type
);
733 *tl
= txdr_unsigned(authsiz
);
736 nfsm_build(tl
, u_long
*, auth_len
);
737 *tl
++ = 0; /* stamp ?? */
738 *tl
++ = 0; /* NULL hostname */
739 *tl
++ = txdr_unsigned(cr
->cr_uid
);
740 *tl
++ = txdr_unsigned(cr
->cr_groups
[0]);
741 grpsiz
= (auth_len
>> 2) - 5;
742 *tl
++ = txdr_unsigned(grpsiz
);
743 for (i
= 1; i
<= grpsiz
; i
++)
744 *tl
++ = txdr_unsigned(cr
->cr_groups
[i
]);
749 if (M_TRAILINGSPACE(mb
) == 0) {
750 MGET(mb2
, M_WAIT
, MT_DATA
);
751 if (siz
>= MINCLSIZE
)
756 bpos
= mtod(mb
, caddr_t
);
758 i
= min(siz
, M_TRAILINGSPACE(mb
));
759 bcopy(auth_str
, bpos
, i
);
765 if ((siz
= (nfsm_rndup(auth_len
) - auth_len
)) > 0) {
766 for (i
= 0; i
< siz
; i
++)
774 * And the verifier...
776 nfsm_build(tl
, u_long
*, 2 * NFSX_UNSIGNED
);
778 *tl
++ = txdr_unsigned(RPCAUTH_KERB4
);
779 *tl
= txdr_unsigned(verf_len
);
782 if (M_TRAILINGSPACE(mb
) == 0) {
783 MGET(mb2
, M_WAIT
, MT_DATA
);
784 if (siz
>= MINCLSIZE
)
789 bpos
= mtod(mb
, caddr_t
);
791 i
= min(siz
, M_TRAILINGSPACE(mb
));
792 bcopy(verf_str
, bpos
, i
);
798 if ((siz
= (nfsm_rndup(verf_len
) - verf_len
)) > 0) {
799 for (i
= 0; i
< siz
; i
++)
804 *tl
++ = txdr_unsigned(RPCAUTH_NULL
);
808 mreq
->m_pkthdr
.len
= authsiz
+ 10 * NFSX_UNSIGNED
+ mrest_len
;
809 mreq
->m_pkthdr
.rcvif
= (struct ifnet
*)0;
815 * copies mbuf chain to the uio scatter/gather list
818 nfsm_mbuftouio(mrep
, uiop
, siz
, dpos
)
820 register struct uio
*uiop
;
824 register char *mbufcp
, *uiocp
;
825 register int xfer
, left
, len
;
826 register struct mbuf
*mp
;
832 len
= mtod(mp
, caddr_t
)+mp
->m_len
-mbufcp
;
833 rem
= nfsm_rndup(siz
)-siz
;
835 if (uiop
->uio_iovcnt
<= 0 || uiop
->uio_iov
== NULL
)
837 left
= uiop
->uio_iov
->iov_len
;
838 uiocp
= uiop
->uio_iov
->iov_base
;
847 mbufcp
= mtod(mp
, caddr_t
);
850 xfer
= (left
> len
) ? len
: left
;
853 if (uiop
->uio_iov
->iov_op
!= NULL
)
854 (*(uiop
->uio_iov
->iov_op
))
855 (mbufcp
, uiocp
, xfer
);
858 if (uiop
->uio_segflg
== UIO_SYSSPACE
)
859 bcopy(mbufcp
, uiocp
, xfer
);
861 copyout(mbufcp
, uiocp
, xfer
);
866 uiop
->uio_offset
+= xfer
;
867 uiop
->uio_resid
-= xfer
;
869 if (uiop
->uio_iov
->iov_len
<= siz
) {
873 uiop
->uio_iov
->iov_base
+= uiosiz
;
874 uiop
->uio_iov
->iov_len
-= uiosiz
;
882 error
= nfs_adv(mrep
, dpos
, rem
, len
);
890 * copies a uio scatter/gather list to an mbuf chain.
891 * NOTE: can ony handle iovcnt == 1
894 nfsm_uiotombuf(uiop
, mq
, siz
, bpos
)
895 register struct uio
*uiop
;
900 register char *uiocp
;
901 register struct mbuf
*mp
, *mp2
;
902 register int xfer
, left
, mlen
;
903 int uiosiz
, clflg
, rem
;
906 if (uiop
->uio_iovcnt
!= 1)
907 panic("nfsm_uiotombuf: iovcnt != 1");
909 if (siz
> MLEN
) /* or should it >= MCLBYTES ?? */
913 rem
= nfsm_rndup(siz
)-siz
;
916 left
= uiop
->uio_iov
->iov_len
;
917 uiocp
= uiop
->uio_iov
->iov_base
;
922 mlen
= M_TRAILINGSPACE(mp
);
924 MGET(mp
, M_WAIT
, MT_DATA
);
930 mlen
= M_TRAILINGSPACE(mp
);
932 xfer
= (left
> mlen
) ? mlen
: left
;
935 if (uiop
->uio_iov
->iov_op
!= NULL
)
936 (*(uiop
->uio_iov
->iov_op
))
937 (uiocp
, mtod(mp
, caddr_t
)+mp
->m_len
, xfer
);
940 if (uiop
->uio_segflg
== UIO_SYSSPACE
)
941 bcopy(uiocp
, mtod(mp
, caddr_t
)+mp
->m_len
, xfer
);
943 copyin(uiocp
, mtod(mp
, caddr_t
)+mp
->m_len
, xfer
);
947 uiop
->uio_offset
+= xfer
;
948 uiop
->uio_resid
-= xfer
;
950 uiop
->uio_iov
->iov_base
+= uiosiz
;
951 uiop
->uio_iov
->iov_len
-= uiosiz
;
955 if (rem
> M_TRAILINGSPACE(mp
)) {
956 MGET(mp
, M_WAIT
, MT_DATA
);
960 cp
= mtod(mp
, caddr_t
)+mp
->m_len
;
961 for (left
= 0; left
< rem
; left
++)
966 *bpos
= mtod(mp
, caddr_t
)+mp
->m_len
;
972 * Help break down an mbuf chain by setting the first siz bytes contiguous
973 * pointed to by returned val.
974 * This is used by the macros nfsm_dissect and nfsm_dissecton for tough
975 * cases. (The macros use the vars. dpos and dpos2)
978 nfsm_disct(mdp
, dposp
, siz
, left
, cp2
)
985 register struct mbuf
*mp
, *mp2
;
986 register int siz2
, xfer
;
991 *mdp
= mp
= mp
->m_next
;
995 *dposp
= mtod(mp
, caddr_t
);
1000 } else if (mp
->m_next
== NULL
) {
1002 } else if (siz
> MHLEN
) {
1003 panic("nfs S too big");
1005 MGET(mp2
, M_WAIT
, MT_DATA
);
1006 mp2
->m_next
= mp
->m_next
;
1010 *cp2
= p
= mtod(mp
, caddr_t
);
1011 bcopy(*dposp
, p
, left
); /* Copy what was left */
1015 /* Loop around copying up the siz2 bytes */
1019 xfer
= (siz2
> mp2
->m_len
) ? mp2
->m_len
: siz2
;
1021 bcopy(mtod(mp2
, caddr_t
), p
, xfer
);
1032 *dposp
= mtod(mp2
, caddr_t
);
1038 * Advance the position in the mbuf chain.
1041 nfs_adv(mdp
, dposp
, offs
, left
)
1047 register struct mbuf
*m
;
1060 *dposp
= mtod(m
, caddr_t
)+offs
;
1065 * Copy a string into mbufs for the hard cases...
1068 nfsm_strtmbuf(mb
, bpos
, cp
, siz
)
1074 register struct mbuf
*m1
= 0, *m2
;
1075 long left
, xfer
, len
, tlen
;
1081 left
= M_TRAILINGSPACE(m2
);
1083 tl
= ((u_long
*)(*bpos
));
1084 *tl
++ = txdr_unsigned(siz
);
1086 left
-= NFSX_UNSIGNED
;
1087 m2
->m_len
+= NFSX_UNSIGNED
;
1089 bcopy(cp
, (caddr_t
) tl
, left
);
1096 /* Loop around adding mbufs */
1098 MGET(m1
, M_WAIT
, MT_DATA
);
1101 m1
->m_len
= NFSMSIZ(m1
);
1104 tl
= mtod(m1
, u_long
*);
1107 *tl
++ = txdr_unsigned(siz
);
1108 m1
->m_len
-= NFSX_UNSIGNED
;
1109 tlen
= NFSX_UNSIGNED
;
1112 if (siz
< m1
->m_len
) {
1113 len
= nfsm_rndup(siz
);
1116 *(tl
+(xfer
>>2)) = 0;
1118 xfer
= len
= m1
->m_len
;
1120 bcopy(cp
, (caddr_t
) tl
, xfer
);
1121 m1
->m_len
= len
+tlen
;
1126 *bpos
= mtod(m1
, caddr_t
)+m1
->m_len
;
1131 * Called once to initialize data structures...
1135 struct vfsconf
*vfsp
;
1140 * Check to see if major data structures haven't bloated.
1142 if (sizeof (struct nfsnode
) > NFS_NODEALLOC
) {
1143 printf("struct nfsnode bloated (> %dbytes)\n", NFS_NODEALLOC
);
1144 printf("Try reducing NFS_SMALLFH\n");
1146 if (sizeof (struct nfsmount
) > NFS_MNTALLOC
) {
1147 printf("struct nfsmount bloated (> %dbytes)\n", NFS_MNTALLOC
);
1148 printf("Try reducing NFS_MUIDHASHSIZ\n");
1150 if (sizeof (struct nfssvc_sock
) > NFS_SVCALLOC
) {
1151 printf("struct nfssvc_sock bloated (> %dbytes)\n",NFS_SVCALLOC
);
1152 printf("Try reducing NFS_UIDHASHSIZ\n");
1154 if (sizeof (struct nfsuid
) > NFS_UIDALLOC
) {
1155 printf("struct nfsuid bloated (> %dbytes)\n",NFS_UIDALLOC
);
1156 printf("Try unionizing the nu_nickname and nu_flag fields\n");
1158 nfs_mount_type
= vfsp
->vfc_typenum
;
1160 rpc_vers
= txdr_unsigned(RPC_VER2
);
1161 rpc_call
= txdr_unsigned(RPC_CALL
);
1162 rpc_reply
= txdr_unsigned(RPC_REPLY
);
1163 rpc_msgdenied
= txdr_unsigned(RPC_MSGDENIED
);
1164 rpc_msgaccepted
= txdr_unsigned(RPC_MSGACCEPTED
);
1165 rpc_mismatch
= txdr_unsigned(RPC_MISMATCH
);
1166 rpc_autherr
= txdr_unsigned(RPC_AUTHERR
);
1167 rpc_auth_unix
= txdr_unsigned(RPCAUTH_UNIX
);
1168 rpc_auth_kerb
= txdr_unsigned(RPCAUTH_KERB4
);
1169 nfs_prog
= txdr_unsigned(NFS_PROG
);
1170 nqnfs_prog
= txdr_unsigned(NQNFS_PROG
);
1171 nfs_true
= txdr_unsigned(TRUE
);
1172 nfs_false
= txdr_unsigned(FALSE
);
1173 nfs_xdrneg1
= txdr_unsigned(-1);
1174 nfs_ticks
= (hz
* NFS_TICKINTVL
+ 500) / 1000;
1177 /* Ensure async daemons disabled */
1178 for (i
= 0; i
< NFS_MAXASYNCDAEMON
; i
++) {
1179 nfs_iodwant
[i
] = (struct proc
*)0;
1180 nfs_iodmount
[i
] = (struct nfsmount
*)0;
1182 nfs_nhinit(); /* Init the nfsnode table */
1183 #ifndef NFS_NOSERVER
1184 nfsrv_init(0); /* Init server data structures */
1185 nfsrv_initcache(); /* Init the server request cache */
1189 * Initialize the nqnfs server stuff.
1191 if (nqnfsstarttime
== 0) {
1192 nqnfsstarttime
= boottime
.tv_sec
+ nqsrv_maxlease
1193 + nqsrv_clockskew
+ nqsrv_writeslack
;
1194 NQLOADNOVRAM(nqnfsstarttime
);
1195 CIRCLEQ_INIT(&nqtimerhead
);
1196 nqfhhashtbl
= hashinit(NQLCHSZ
, M_NQLEASE
, &nqfhhash
);
1200 * Initialize reply list and start timer
1202 TAILQ_INIT(&nfs_reqq
);
1207 /* XXX CSM 12/4/97 Where are these declared in FreeBSD? */
1210 * Set up lease_check and lease_updatetime so that other parts
1211 * of the system can call us, if we are loadable.
1213 #ifndef NFS_NOSERVER
1214 default_vnodeop_p
[VOFFSET(vop_lease
)] = (vop_t
*)nqnfs_vop_lease_check
;
1216 lease_updatetime
= nfs_lease_updatetime
;
1218 vfsp
->vfc_refcount
++; /* make us non-unloadable */
1219 sysent
[SYS_nfssvc
].sy_narg
= 2;
1220 sysent
[SYS_nfssvc
].sy_call
= nfssvc
;
1221 #ifndef NFS_NOSERVER
1222 sysent
[SYS_getfh
].sy_narg
= 2;
1223 sysent
[SYS_getfh
].sy_call
= getfh
;
1230 * Attribute cache routines.
1231 * nfs_loadattrcache() - loads or updates the cache contents from attributes
1232 * that are on the mbuf list
1233 * nfs_getattrcache() - returns valid attributes if found in cache, returns
1238 * Load the attribute cache (that lives in the nfsnode entry) with
1239 * the values on the mbuf list and
1241 * copy the attributes to *vaper
1244 nfs_loadattrcache(vpp
, mdp
, dposp
, vaper
, dontshrink
, xidp
)
1248 struct vattr
*vaper
;
1252 register struct vnode
*vp
= *vpp
;
1253 register struct vattr
*vap
;
1254 register struct nfs_fattr
*fp
;
1255 register struct nfsnode
*np
;
1258 int error
= 0, rdev
;
1262 struct timespec mtime
;
1266 FSDBG_TOP(527, vp
, 0, *xidp
>> 32, *xidp
);
1268 * this routine is a good place to check for VBAD again. We caught
1269 * most of them in nfsm_request, but postprocessing may indirectly get
1270 * here, so check again.
1272 if (vp
->v_type
== VBAD
) {
1273 FSDBG_BOT(527, EINVAL
, 1, 0, *xidp
);
1279 t1
= (mtod(md
, caddr_t
) + md
->m_len
) - *dposp
;
1280 if ((error
= nfsm_disct(mdp
, dposp
, NFSX_FATTR(v3
), t1
, &cp2
))) {
1281 FSDBG_BOT(527, error
, 2, 0, *xidp
);
1284 fp
= (struct nfs_fattr
*)cp2
;
1286 vtyp
= nfsv3tov_type(fp
->fa_type
);
1287 vmode
= fxdr_unsigned(u_short
, fp
->fa_mode
);
1288 rdev
= makedev(fxdr_unsigned(int, fp
->fa3_rdev
.specdata1
),
1289 fxdr_unsigned(int, fp
->fa3_rdev
.specdata2
));
1290 fxdr_nfsv3time(&fp
->fa3_mtime
, &mtime
);
1292 vtyp
= nfsv2tov_type(fp
->fa_type
);
1293 vmode
= fxdr_unsigned(u_short
, fp
->fa_mode
);
1297 * The duplicate information returned in fa_type and fa_mode
1298 * is an ambiguity in the NFS version 2 protocol.
1300 * VREG should be taken literally as a regular file. If a
1301 * server intents to return some type information differently
1302 * in the upper bits of the mode field (e.g. for sockets, or
1303 * FIFOs), NFSv2 mandates fa_type to be VNON. Anyway, we
1304 * leave the examination of the mode bits even in the VREG
1305 * case to avoid breakage for bogus servers, but we make sure
1306 * that there are actually type bits set in the upper part of
1307 * fa_mode (and failing that, trust the va_type field).
1309 * NFSv3 cleared the issue, and requires fa_mode to not
1310 * contain any type information (while also introduing sockets
1311 * and FIFOs for fa_type).
1313 if (vtyp
== VNON
|| (vtyp
== VREG
&& (vmode
& S_IFMT
) != 0))
1314 vtyp
= IFTOVT(vmode
);
1315 rdev
= fxdr_unsigned(long, fp
->fa2_rdev
);
1316 fxdr_nfsv2time(&fp
->fa2_mtime
, &mtime
);
1319 * Really ugly NFSv2 kludge.
1321 if (vtyp
== VCHR
&& rdev
== 0xffffffff)
1326 * If v_type == VNON it is a new node, so fill in the v_type,
1327 * n_mtime fields. Check to see if it represents a special
1328 * device, and if so, check for a possible alias. Once the
1329 * correct vnode has been obtained, fill in the rest of the
1333 if (*xidp
< np
->n_xid
) {
1335 * We have already updated attributes with a response from
1336 * a later request. The attributes we have here are probably
1337 * stale so we drop them (just return). However, our
1338 * out-of-order receipt could be correct - if the requests were
1339 * processed out of order at the server. Given the uncertainty
1340 * we invalidate our cached attributes. *xidp is zeroed here
1341 * to indicate the attributes were dropped - only getattr
1342 * cares - it needs to retry the rpc.
1344 np
->n_attrstamp
= 0;
1345 FSDBG_BOT(527, 0, np
, np
->n_xid
, *xidp
);
1349 if (vp
->v_type
!= vtyp
) {
1352 if (UBCINFOMISSING(vp
) || UBCINFORECLAIMED(vp
))
1353 if ((error
= ubc_info_init(vp
))) { /* VREG */
1354 FSDBG_BOT(527, error
, 3, 0, *xidp
);
1358 if (vp
->v_type
== VFIFO
) {
1359 vp
->v_op
= fifo_nfsv2nodeop_p
;
1361 if (vp
->v_type
== VCHR
|| vp
->v_type
== VBLK
) {
1362 vp
->v_op
= spec_nfsv2nodeop_p
;
1363 nvp
= checkalias(vp
, (dev_t
)rdev
, vp
->v_mount
);
1366 * Discard unneeded vnode, but save its nfsnode.
1367 * Since the nfsnode does not have a lock, its
1368 * vnode lock has to be carried over.
1370 nvp
->v_vnlock
= vp
->v_vnlock
;
1371 vp
->v_vnlock
= NULL
;
1372 nvp
->v_data
= vp
->v_data
;
1374 vp
->v_op
= spec_vnodeop_p
;
1378 * Reinitialize aliased node.
1384 np
->n_mtime
= mtime
.tv_sec
;
1385 FSDBG(527, vp
, np
->n_mtime
, 0, 0);
1389 vap
->va_type
= vtyp
;
1390 vap
->va_mode
= (vmode
& 07777);
1391 vap
->va_rdev
= (dev_t
)rdev
;
1392 vap
->va_mtime
= mtime
;
1393 vap
->va_fsid
= vp
->v_mount
->mnt_stat
.f_fsid
.val
[0];
1395 vap
->va_nlink
= fxdr_unsigned(u_short
, fp
->fa_nlink
);
1396 vap
->va_uid
= fxdr_unsigned(uid_t
, fp
->fa_uid
);
1397 vap
->va_gid
= fxdr_unsigned(gid_t
, fp
->fa_gid
);
1398 fxdr_hyper(&fp
->fa3_size
, &vap
->va_size
);
1399 vap
->va_blocksize
= NFS_FABLKSIZE
;
1400 fxdr_hyper(&fp
->fa3_used
, &vap
->va_bytes
);
1401 vap
->va_fileid
= fxdr_unsigned(int, fp
->fa3_fileid
.nfsuquad
[1]);
1402 fxdr_nfsv3time(&fp
->fa3_atime
, &vap
->va_atime
);
1403 fxdr_nfsv3time(&fp
->fa3_ctime
, &vap
->va_ctime
);
1405 vap
->va_filerev
= 0;
1407 vap
->va_nlink
= fxdr_unsigned(u_short
, fp
->fa_nlink
);
1408 vap
->va_uid
= fxdr_unsigned(uid_t
, fp
->fa_uid
);
1409 vap
->va_gid
= fxdr_unsigned(gid_t
, fp
->fa_gid
);
1410 vap
->va_size
= fxdr_unsigned(u_long
, fp
->fa2_size
);
1411 vap
->va_blocksize
= fxdr_unsigned(long, fp
->fa2_blocksize
);
1412 vap
->va_bytes
= fxdr_unsigned(long, fp
->fa2_blocks
) * NFS_FABLKSIZE
;
1413 vap
->va_fileid
= fxdr_unsigned(long, fp
->fa2_fileid
);
1414 fxdr_nfsv2time(&fp
->fa2_atime
, &vap
->va_atime
);
1416 vap
->va_ctime
.tv_sec
= fxdr_unsigned(long, fp
->fa2_ctime
.nfsv2_sec
);
1417 vap
->va_ctime
.tv_nsec
= 0;
1418 vap
->va_gen
= fxdr_unsigned(u_long
, fp
->fa2_ctime
.nfsv2_usec
);
1419 vap
->va_filerev
= 0;
1422 np
->n_attrstamp
= time
.tv_sec
;
1423 if (vap
->va_size
!= np
->n_size
) {
1424 FSDBG(527, vp
, vap
->va_size
, np
->n_size
,
1425 (vap
->va_type
== VREG
) |
1426 (np
->n_flag
& NMODIFIED
? 6 : 4));
1427 if (vap
->va_type
== VREG
) {
1430 orig_size
= np
->n_size
;
1431 if (np
->n_flag
& NMODIFIED
) {
1432 if (vap
->va_size
< np
->n_size
)
1433 vap
->va_size
= np
->n_size
;
1435 np
->n_size
= vap
->va_size
;
1437 np
->n_size
= vap
->va_size
;
1438 if (dontshrink
&& UBCISVALID(vp
) &&
1439 np
->n_size
< ubc_getsize(vp
)) {
1440 vap
->va_size
= np
->n_size
= orig_size
;
1441 np
->n_attrstamp
= 0;
1443 ubc_setsize(vp
, (off_t
)np
->n_size
); /* XXX */
1445 np
->n_size
= vap
->va_size
;
1448 if (vaper
!= NULL
) {
1449 bcopy((caddr_t
)vap
, (caddr_t
)vaper
, sizeof(*vap
));
1450 if (np
->n_flag
& NCHG
) {
1451 if (np
->n_flag
& NACC
)
1452 vaper
->va_atime
= np
->n_atim
;
1453 if (np
->n_flag
& NUPD
)
1454 vaper
->va_mtime
= np
->n_mtim
;
1457 FSDBG_BOT(527, 0, np
, 0, *xidp
);
1462 * Check the time stamp
1463 * If the cache is valid, copy contents to *vap and return 0
1464 * otherwise return an error
1467 nfs_getattrcache(vp
, vaper
)
1468 register struct vnode
*vp
;
1469 struct vattr
*vaper
;
1471 register struct nfsnode
*np
= VTONFS(vp
);
1472 register struct vattr
*vap
;
1474 if ((time
.tv_sec
- np
->n_attrstamp
) >= NFS_ATTRTIMEO(np
)) {
1475 FSDBG(528, vp
, 0, 0, 1);
1476 nfsstats
.attrcache_misses
++;
1479 FSDBG(528, vp
, 0, 0, 2);
1480 nfsstats
.attrcache_hits
++;
1483 if (vap
->va_size
!= np
->n_size
) {
1484 FSDBG(528, vp
, vap
->va_size
, np
->n_size
,
1485 (vap
->va_type
== VREG
) |
1486 (np
->n_flag
& NMODIFIED
? 6 : 4));
1487 if (vap
->va_type
== VREG
) {
1488 if (np
->n_flag
& NMODIFIED
) {
1489 if (vap
->va_size
< np
->n_size
)
1490 vap
->va_size
= np
->n_size
;
1492 np
->n_size
= vap
->va_size
;
1494 np
->n_size
= vap
->va_size
;
1495 ubc_setsize(vp
, (off_t
)np
->n_size
); /* XXX */
1497 np
->n_size
= vap
->va_size
;
1500 bcopy((caddr_t
)vap
, (caddr_t
)vaper
, sizeof(struct vattr
));
1501 if (np
->n_flag
& NCHG
) {
1502 if (np
->n_flag
& NACC
)
1503 vaper
->va_atime
= np
->n_atim
;
1504 if (np
->n_flag
& NUPD
)
1505 vaper
->va_mtime
= np
->n_mtim
;
1510 #ifndef NFS_NOSERVER
1512 * Set up nameidata for a lookup() call and do it.
1514 * If pubflag is set, this call is done for a lookup operation on the
1515 * public filehandle. In that case we allow crossing mountpoints and
1516 * absolute pathnames. However, the caller is expected to check that
1517 * the lookup result is within the public fs, and deny access if
1521 nfs_namei(ndp
, fhp
, len
, slp
, nam
, mdp
, dposp
, retdirp
, p
, kerbflag
, pubflag
)
1522 register struct nameidata
*ndp
;
1525 struct nfssvc_sock
*slp
;
1529 struct vnode
**retdirp
;
1531 int kerbflag
, pubflag
;
1533 register int i
, rem
;
1534 register struct mbuf
*md
;
1535 register char *fromcp
, *tocp
, *cp
;
1539 int error
, rdonly
, linklen
;
1540 struct componentname
*cnp
= &ndp
->ni_cnd
;
1543 *retdirp
= (struct vnode
*)0;
1544 MALLOC_ZONE(cnp
->cn_pnbuf
, char *, len
+ 1, M_NAMEI
, M_WAITOK
);
1545 cnp
->cn_pnlen
= len
+ 1;
1548 * Copy the name from the mbuf list to ndp->ni_pnbuf
1549 * and set the various ndp fields appropriately.
1552 tocp
= cnp
->cn_pnbuf
;
1554 rem
= mtod(md
, caddr_t
) + md
->m_len
- fromcp
;
1556 for (i
= 1; i
<= len
; i
++) {
1563 fromcp
= mtod(md
, caddr_t
);
1566 /* XXX CSM 12/4/97 Revisit when enabling WebNFS */
1568 if (*fromcp
== '\0' || (!pubflag
&& *fromcp
== '/')) {
1570 if (*fromcp
== '\0' || *fromcp
== '/') {
1575 cnp
->cn_hash
+= (unsigned char)*fromcp
* i
;
1576 *tocp
++ = *fromcp
++;
1582 len
= nfsm_rndup(len
)-len
;
1586 else if ((error
= nfs_adv(mdp
, dposp
, len
, rem
)) != 0)
1591 * Extract and set starting directory.
1593 error
= nfsrv_fhtovp(fhp
, FALSE
, &dp
, ndp
->ni_cnd
.cn_cred
, slp
,
1594 nam
, &rdonly
, kerbflag
, pubflag
);
1597 if (dp
->v_type
!= VDIR
) {
1604 cnp
->cn_flags
|= RDONLY
;
1608 /* XXX CSM 12/4/97 Revisit when enabling WebNFS */
1609 /* XXX debo 12/15/97 Need to fix M_NAMEI allocations to use zone protocol */
1613 * Oh joy. For WebNFS, handle those pesky '%' escapes,
1614 * and the 'native path' indicator.
1616 MALLOC(cp
, char *, olen
+ 1, M_NAMEI
, M_WAITOK
);
1617 fromcp
= cnp
->cn_pnbuf
;
1619 if ((unsigned char)*fromcp
>= WEBNFS_SPECCHAR_START
) {
1620 switch ((unsigned char)*fromcp
) {
1621 case WEBNFS_NATIVE_CHAR
:
1623 * 'Native' path for us is the same
1624 * as a path according to the NFS spec,
1625 * just skip the escape char.
1630 * More may be added in the future, range 0x80-0xff
1639 * Translate the '%' escapes, URL-style.
1641 while (*fromcp
!= '\0') {
1642 if (*fromcp
== WEBNFS_ESC_CHAR
) {
1643 if (fromcp
[1] != '\0' && fromcp
[2] != '\0') {
1645 *tocp
++ = HEXSTRTOI(fromcp
);
1654 *tocp
++ = *fromcp
++;
1657 FREE(cnp
->cn_pnbuf
, M_NAMEI
);
1662 ndp
->ni_pathlen
= (tocp
- cnp
->cn_pnbuf
) + 1;
1663 ndp
->ni_segflg
= UIO_SYSSPACE
;
1665 /* XXX CSM 12/4/97 Revisit when enabling WebNFS */
1668 ndp
->ni_rootdir
= rootvnode
;
1669 ndp
->ni_loopcnt
= 0;
1670 if (cnp
->cn_pnbuf
[0] == '/')
1673 cnp
->cn_flags
|= NOCROSSMOUNT
;
1676 cnp
->cn_flags
|= NOCROSSMOUNT
;
1683 cnp
->cn_nameptr
= cnp
->cn_pnbuf
;
1684 ndp
->ni_startdir
= dp
;
1686 * And call lookup() to do the real work
1688 error
= lookup(ndp
);
1692 * Check for encountering a symbolic link
1694 if ((cnp
->cn_flags
& ISSYMLINK
) == 0) {
1695 nfsrv_object_create(ndp
->ni_vp
);
1696 if (cnp
->cn_flags
& (SAVENAME
| SAVESTART
)) {
1697 cnp
->cn_flags
|= HASBUF
;
1702 if ((cnp
->cn_flags
& LOCKPARENT
) && ndp
->ni_pathlen
== 1)
1703 VOP_UNLOCK(ndp
->ni_dvp
, 0, p
);
1704 /* XXX CSM 12/4/97 Revisit when enabling WebNFS */
1713 /* XXX CSM 12/4/97 Revisit when enabling WebNFS */
1714 /* XXX debo 12/15/97 Need to fix M_NAMEI allocations to use zone protocol */
1718 if (ndp
->ni_loopcnt
++ >= MAXSYMLINKS
) {
1722 if (ndp
->ni_pathlen
> 1)
1723 MALLOC(cp
, char *, olen
+ 1, M_NAMEI
, M_WAITOK
);
1727 aiov
.iov_len
= MAXPATHLEN
;
1728 auio
.uio_iov
= &aiov
;
1729 auio
.uio_iovcnt
= 1;
1730 auio
.uio_offset
= 0;
1731 auio
.uio_rw
= UIO_READ
;
1732 auio
.uio_segflg
= UIO_SYSSPACE
;
1733 auio
.uio_procp
= (struct proc
*)0;
1734 auio
.uio_resid
= MAXPATHLEN
;
1735 error
= VOP_READLINK(ndp
->ni_vp
, &auio
, cnp
->cn_cred
);
1738 if (ndp
->ni_pathlen
> 1)
1742 linklen
= MAXPATHLEN
- auio
.uio_resid
;
1747 if (linklen
+ ndp
->ni_pathlen
>= MAXPATHLEN
) {
1748 error
= ENAMETOOLONG
;
1751 if (ndp
->ni_pathlen
> 1) {
1752 bcopy(ndp
->ni_next
, cp
+ linklen
, ndp
->ni_pathlen
);
1753 FREE(cnp
->cn_pnbuf
, M_NAMEI
);
1756 cnp
->cn_pnbuf
[linklen
] = '\0';
1757 ndp
->ni_pathlen
+= linklen
;
1761 * Check if root directory should replace current directory.
1763 if (cnp
->cn_pnbuf
[0] == '/') {
1765 dp
= ndp
->ni_rootdir
;
1772 FREE_ZONE(cnp
->cn_pnbuf
, cnp
->cn_pnlen
, M_NAMEI
);
1777 * A fiddled version of m_adj() that ensures null fill to a long
1778 * boundary and only trims off the back end
1781 nfsm_adj(mp
, len
, nul
)
1786 register struct mbuf
*m
;
1787 register int count
, i
;
1791 * Trim from tail. Scan the mbuf chain,
1792 * calculating its length and finding the last mbuf.
1793 * If the adjustment only affects this mbuf, then just
1794 * adjust and return. Otherwise, rescan and truncate
1795 * after the remaining size.
1801 if (m
->m_next
== (struct mbuf
*)0)
1805 if (m
->m_len
> len
) {
1808 cp
= mtod(m
, caddr_t
)+m
->m_len
-nul
;
1809 for (i
= 0; i
< nul
; i
++)
1818 * Correct length for chain is "count".
1819 * Find the mbuf with last data, adjust its length,
1820 * and toss data from remaining mbufs on chain.
1822 for (m
= mp
; m
; m
= m
->m_next
) {
1823 if (m
->m_len
>= count
) {
1826 cp
= mtod(m
, caddr_t
)+m
->m_len
-nul
;
1827 for (i
= 0; i
< nul
; i
++)
1834 for (m
= m
->m_next
;m
;m
= m
->m_next
)
1839 * Make these functions instead of macros, so that the kernel text size
1840 * doesn't get too big...
1843 nfsm_srvwcc(nfsd
, before_ret
, before_vap
, after_ret
, after_vap
, mbp
, bposp
)
1844 struct nfsrv_descript
*nfsd
;
1846 register struct vattr
*before_vap
;
1848 struct vattr
*after_vap
;
1852 register struct mbuf
*mb
= *mbp
, *mb2
;
1853 register char *bpos
= *bposp
;
1854 register u_long
*tl
;
1857 nfsm_build(tl
, u_long
*, NFSX_UNSIGNED
);
1860 nfsm_build(tl
, u_long
*, 7 * NFSX_UNSIGNED
);
1862 txdr_hyper(&(before_vap
->va_size
), tl
);
1864 txdr_nfsv3time(&(before_vap
->va_mtime
), tl
);
1866 txdr_nfsv3time(&(before_vap
->va_ctime
), tl
);
1870 nfsm_srvpostopattr(nfsd
, after_ret
, after_vap
, mbp
, bposp
);
1874 nfsm_srvpostopattr(nfsd
, after_ret
, after_vap
, mbp
, bposp
)
1875 struct nfsrv_descript
*nfsd
;
1877 struct vattr
*after_vap
;
1881 register struct mbuf
*mb
= *mbp
, *mb2
;
1882 register char *bpos
= *bposp
;
1883 register u_long
*tl
;
1884 register struct nfs_fattr
*fp
;
1887 nfsm_build(tl
, u_long
*, NFSX_UNSIGNED
);
1890 nfsm_build(tl
, u_long
*, NFSX_UNSIGNED
+ NFSX_V3FATTR
);
1892 fp
= (struct nfs_fattr
*)tl
;
1893 nfsm_srvfattr(nfsd
, after_vap
, fp
);
1900 nfsm_srvfattr(nfsd
, vap
, fp
)
1901 register struct nfsrv_descript
*nfsd
;
1902 register struct vattr
*vap
;
1903 register struct nfs_fattr
*fp
;
1906 fp
->fa_nlink
= txdr_unsigned(vap
->va_nlink
);
1907 fp
->fa_uid
= txdr_unsigned(vap
->va_uid
);
1908 fp
->fa_gid
= txdr_unsigned(vap
->va_gid
);
1909 if (nfsd
->nd_flag
& ND_NFSV3
) {
1910 fp
->fa_type
= vtonfsv3_type(vap
->va_type
);
1911 fp
->fa_mode
= vtonfsv3_mode(vap
->va_mode
);
1912 txdr_hyper(&vap
->va_size
, &fp
->fa3_size
);
1913 txdr_hyper(&vap
->va_bytes
, &fp
->fa3_used
);
1914 fp
->fa3_rdev
.specdata1
= txdr_unsigned(major(vap
->va_rdev
));
1915 fp
->fa3_rdev
.specdata2
= txdr_unsigned(minor(vap
->va_rdev
));
1916 fp
->fa3_fsid
.nfsuquad
[0] = 0;
1917 fp
->fa3_fsid
.nfsuquad
[1] = txdr_unsigned(vap
->va_fsid
);
1918 fp
->fa3_fileid
.nfsuquad
[0] = 0;
1919 fp
->fa3_fileid
.nfsuquad
[1] = txdr_unsigned(vap
->va_fileid
);
1920 txdr_nfsv3time(&vap
->va_atime
, &fp
->fa3_atime
);
1921 txdr_nfsv3time(&vap
->va_mtime
, &fp
->fa3_mtime
);
1922 txdr_nfsv3time(&vap
->va_ctime
, &fp
->fa3_ctime
);
1924 fp
->fa_type
= vtonfsv2_type(vap
->va_type
);
1925 fp
->fa_mode
= vtonfsv2_mode(vap
->va_type
, vap
->va_mode
);
1926 fp
->fa2_size
= txdr_unsigned(vap
->va_size
);
1927 fp
->fa2_blocksize
= txdr_unsigned(vap
->va_blocksize
);
1928 if (vap
->va_type
== VFIFO
)
1929 fp
->fa2_rdev
= 0xffffffff;
1931 fp
->fa2_rdev
= txdr_unsigned(vap
->va_rdev
);
1932 fp
->fa2_blocks
= txdr_unsigned(vap
->va_bytes
/ NFS_FABLKSIZE
);
1933 fp
->fa2_fsid
= txdr_unsigned(vap
->va_fsid
);
1934 fp
->fa2_fileid
= txdr_unsigned(vap
->va_fileid
);
1935 txdr_nfsv2time(&vap
->va_atime
, &fp
->fa2_atime
);
1936 txdr_nfsv2time(&vap
->va_mtime
, &fp
->fa2_mtime
);
1937 txdr_nfsv2time(&vap
->va_ctime
, &fp
->fa2_ctime
);
1942 * nfsrv_fhtovp() - convert a fh to a vnode ptr (optionally locked)
1943 * - look up fsid in mount list (if not found ret error)
1944 * - get vp and export rights by calling VFS_FHTOVP()
1945 * - if cred->cr_uid == 0 or MNT_EXPORTANON set it to credanon
1946 * - if not lockflag unlock it with VOP_UNLOCK()
1949 nfsrv_fhtovp(fhp
, lockflag
, vpp
, cred
, slp
, nam
, rdonlyp
, kerbflag
, pubflag
)
1954 struct nfssvc_sock
*slp
;
1960 struct proc
*p
= current_proc(); /* XXX */
1961 register struct mount
*mp
;
1963 struct ucred
*credanon
;
1966 *vpp
= (struct vnode
*)0;
1968 /* XXX CSM 12/4/97 Revisit when enabling WebNFS */
1970 if (nfs_ispublicfh(fhp
)) {
1971 if (!pubflag
|| !nfs_pub
.np_valid
)
1973 fhp
= &nfs_pub
.np_handle
;
1977 mp
= vfs_getvfs(&fhp
->fh_fsid
);
1980 error
= VFS_FHTOVP(mp
, &fhp
->fh_fid
, nam
, vpp
, &exflags
, &credanon
);
1983 /* vnode pointer should be good at this point or ... */
1987 * Check/setup credentials.
1989 if (exflags
& MNT_EXKERB
) {
1992 return (NFSERR_AUTHERR
| AUTH_TOOWEAK
);
1994 } else if (kerbflag
) {
1996 return (NFSERR_AUTHERR
| AUTH_TOOWEAK
);
1997 } else if (cred
->cr_uid
== 0 || (exflags
& MNT_EXPORTANON
)) {
1998 cred
->cr_uid
= credanon
->cr_uid
;
1999 for (i
= 0; i
< credanon
->cr_ngroups
&& i
< NGROUPS
; i
++)
2000 cred
->cr_groups
[i
] = credanon
->cr_groups
[i
];
2001 cred
->cr_ngroups
= i
;
2003 if (exflags
& MNT_EXRDONLY
)
2008 nfsrv_object_create(*vpp
);
2011 VOP_UNLOCK(*vpp
, 0, p
);
2017 * WebNFS: check if a filehandle is a public filehandle. For v3, this
2018 * means a length of 0, for v2 it means all zeroes. nfsm_srvmtofh has
2019 * transformed this to all zeroes in both cases, so check for it.
2025 char *cp
= (char *)fhp
;
2028 for (i
= 0; i
< NFSX_V3FH
; i
++)
2034 #endif /* NFS_NOSERVER */
2036 * This function compares two net addresses by family and returns TRUE
2037 * if they are the same host.
2038 * If there is any doubt, return FALSE.
2039 * The AF_INET family is handled as a special case so that address mbufs
2040 * don't need to be saved to store "struct in_addr", which is only 4 bytes.
2043 netaddr_match(family
, haddr
, nam
)
2045 union nethostaddr
*haddr
;
2048 register struct sockaddr_in
*inetaddr
;
2052 inetaddr
= mtod(nam
, struct sockaddr_in
*);
2053 if (inetaddr
->sin_family
== AF_INET
&&
2054 inetaddr
->sin_addr
.s_addr
== haddr
->had_inetaddr
)
2060 register struct sockaddr_iso
*isoaddr1
, *isoaddr2
;
2062 isoaddr1
= mtod(nam
, struct sockaddr_iso
*);
2063 isoaddr2
= mtod(haddr
->had_nam
, struct sockaddr_iso
*);
2064 if (isoaddr1
->siso_family
== AF_ISO
&&
2065 isoaddr1
->siso_nlen
> 0 &&
2066 isoaddr1
->siso_nlen
== isoaddr2
->siso_nlen
&&
2067 SAME_ISOADDR(isoaddr1
, isoaddr2
))
2078 static nfsuint64 nfs_nullcookie
= { 0, 0 };
2080 * This function finds the directory cookie that corresponds to the
2081 * logical byte offset given.
2084 nfs_getcookie(np
, off
, add
)
2085 register struct nfsnode
*np
;
2089 register struct nfsdmap
*dp
, *dp2
;
2092 pos
= off
/ NFS_DIRBLKSIZ
;
2096 panic("nfs getcookie add at 0");
2098 return (&nfs_nullcookie
);
2101 dp
= np
->n_cookies
.lh_first
;
2104 MALLOC_ZONE(dp
, struct nfsdmap
*,
2105 sizeof (struct nfsdmap
),
2106 M_NFSDIROFF
, M_WAITOK
);
2107 dp
->ndm_eocookie
= 0;
2108 LIST_INSERT_HEAD(&np
->n_cookies
, dp
, ndm_list
);
2110 return ((nfsuint64
*)0);
2112 while (pos
>= NFSNUMCOOKIES
) {
2113 pos
-= NFSNUMCOOKIES
;
2114 if (dp
->ndm_list
.le_next
) {
2115 if (!add
&& dp
->ndm_eocookie
< NFSNUMCOOKIES
&&
2116 pos
>= dp
->ndm_eocookie
)
2117 return ((nfsuint64
*)0);
2118 dp
= dp
->ndm_list
.le_next
;
2120 MALLOC_ZONE(dp2
, struct nfsdmap
*,
2121 sizeof (struct nfsdmap
),
2122 M_NFSDIROFF
, M_WAITOK
);
2123 dp2
->ndm_eocookie
= 0;
2124 LIST_INSERT_AFTER(dp
, dp2
, ndm_list
);
2127 return ((nfsuint64
*)0);
2129 if (pos
>= dp
->ndm_eocookie
) {
2131 dp
->ndm_eocookie
= pos
+ 1;
2133 return ((nfsuint64
*)0);
2135 return (&dp
->ndm_cookies
[pos
]);
2139 * Invalidate cached directory information, except for the actual directory
2140 * blocks (which are invalidated separately).
2141 * Done mainly to avoid the use of stale offset cookies.
2145 register struct vnode
*vp
;
2147 register struct nfsnode
*np
= VTONFS(vp
);
2150 if (vp
->v_type
!= VDIR
)
2151 panic("nfs: invaldir not dir");
2153 np
->n_direofoffset
= 0;
2154 np
->n_cookieverf
.nfsuquad
[0] = 0;
2155 np
->n_cookieverf
.nfsuquad
[1] = 0;
2156 if (np
->n_cookies
.lh_first
)
2157 np
->n_cookies
.lh_first
->ndm_eocookie
= 0;
2161 * The write verifier has changed (probably due to a server reboot), so all
2162 * B_NEEDCOMMIT blocks will have to be written again. Since they are on the
2163 * dirty block list as B_DELWRI, all this takes is clearing the B_NEEDCOMMIT
2164 * flag. Once done the new write verifier can be set for the mount point.
2170 register struct vnode
*vp
, *nvp
;
2171 register struct buf
*bp
, *nbp
;
2176 for (vp
= mp
->mnt_vnodelist
.lh_first
; vp
; vp
= nvp
) {
2177 if (vp
->v_mount
!= mp
) /* Paranoia */
2179 nvp
= vp
->v_mntvnodes
.le_next
;
2180 for (bp
= vp
->v_dirtyblkhd
.lh_first
; bp
; bp
= nbp
) {
2181 nbp
= bp
->b_vnbufs
.le_next
;
2182 if ((bp
->b_flags
& (B_BUSY
| B_DELWRI
| B_NEEDCOMMIT
))
2183 == (B_DELWRI
| B_NEEDCOMMIT
))
2184 bp
->b_flags
&= ~B_NEEDCOMMIT
;
2190 #ifndef NFS_NOSERVER
2192 * Map errnos to NFS error numbers. For Version 3 also filter out error
2193 * numbers not specified for the associated procedure.
2196 nfsrv_errmap(nd
, err
)
2197 struct nfsrv_descript
*nd
;
2200 register short *defaulterrp
, *errp
;
2202 if (nd
->nd_flag
& ND_NFSV3
) {
2203 if (nd
->nd_procnum
<= NFSPROC_COMMIT
) {
2204 errp
= defaulterrp
= nfsrv_v3errmap
[nd
->nd_procnum
];
2208 else if (*errp
> err
)
2211 return ((int)*defaulterrp
);
2213 return (err
& 0xffff);
2216 return ((int)nfsrv_v2errmap
[err
- 1]);
2220 /* XXX CSM 11/25/97 Revisit when Ramesh merges vm with buffer cache */
2221 #define vfs_object_create(v, p, c, l) (0)
2224 nfsrv_object_create(struct vnode
*vp
) {
2225 struct proc
*curproc
= current_proc();
2227 if ((vp
== NULL
) || (vp
->v_type
!= VREG
))
2229 return vfs_object_create(vp
, curproc
, curproc
?curproc
->p_ucred
:NULL
, 1);
2231 #endif /* NFS_NOSERVER */