nfs_srvsubs.c revision 1.3.2.3 1 1.3.2.3 yamt /* $NetBSD: nfs_srvsubs.c,v 1.3.2.3 2010/03/11 15:04:31 yamt Exp $ */
2 1.3.2.2 yamt
3 1.3.2.2 yamt /*
4 1.3.2.2 yamt * Copyright (c) 1989, 1993
5 1.3.2.2 yamt * The Regents of the University of California. All rights reserved.
6 1.3.2.2 yamt *
7 1.3.2.2 yamt * This code is derived from software contributed to Berkeley by
8 1.3.2.2 yamt * Rick Macklem at The University of Guelph.
9 1.3.2.2 yamt *
10 1.3.2.2 yamt * Redistribution and use in source and binary forms, with or without
11 1.3.2.2 yamt * modification, are permitted provided that the following conditions
12 1.3.2.2 yamt * are met:
13 1.3.2.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.3.2.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.3.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
16 1.3.2.2 yamt * notice, this list of conditions and the following disclaimer in the
17 1.3.2.2 yamt * documentation and/or other materials provided with the distribution.
18 1.3.2.2 yamt * 3. Neither the name of the University nor the names of its contributors
19 1.3.2.2 yamt * may be used to endorse or promote products derived from this software
20 1.3.2.2 yamt * without specific prior written permission.
21 1.3.2.2 yamt *
22 1.3.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.3.2.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.3.2.2 yamt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.3.2.2 yamt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.3.2.2 yamt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.3.2.2 yamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.3.2.2 yamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.3.2.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.3.2.2 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.3.2.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.3.2.2 yamt * SUCH DAMAGE.
33 1.3.2.2 yamt *
34 1.3.2.2 yamt * @(#)nfs_subs.c 8.8 (Berkeley) 5/22/95
35 1.3.2.2 yamt */
36 1.3.2.2 yamt
37 1.3.2.2 yamt /*
38 1.3.2.2 yamt * Copyright 2000 Wasabi Systems, Inc.
39 1.3.2.2 yamt * All rights reserved.
40 1.3.2.2 yamt *
41 1.3.2.2 yamt * Written by Frank van der Linden for Wasabi Systems, Inc.
42 1.3.2.2 yamt *
43 1.3.2.2 yamt * Redistribution and use in source and binary forms, with or without
44 1.3.2.2 yamt * modification, are permitted provided that the following conditions
45 1.3.2.2 yamt * are met:
46 1.3.2.2 yamt * 1. Redistributions of source code must retain the above copyright
47 1.3.2.2 yamt * notice, this list of conditions and the following disclaimer.
48 1.3.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
49 1.3.2.2 yamt * notice, this list of conditions and the following disclaimer in the
50 1.3.2.2 yamt * documentation and/or other materials provided with the distribution.
51 1.3.2.2 yamt * 3. All advertising materials mentioning features or use of this software
52 1.3.2.2 yamt * must display the following acknowledgement:
53 1.3.2.2 yamt * This product includes software developed for the NetBSD Project by
54 1.3.2.2 yamt * Wasabi Systems, Inc.
55 1.3.2.2 yamt * 4. The name of Wasabi Systems, Inc. may not be used to endorse
56 1.3.2.2 yamt * or promote products derived from this software without specific prior
57 1.3.2.2 yamt * written permission.
58 1.3.2.2 yamt *
59 1.3.2.2 yamt * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
60 1.3.2.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
61 1.3.2.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
62 1.3.2.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
63 1.3.2.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
64 1.3.2.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
65 1.3.2.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
66 1.3.2.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
67 1.3.2.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
68 1.3.2.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
69 1.3.2.2 yamt * POSSIBILITY OF SUCH DAMAGE.
70 1.3.2.2 yamt */
71 1.3.2.2 yamt
72 1.3.2.2 yamt #include <sys/cdefs.h>
73 1.3.2.3 yamt __KERNEL_RCSID(0, "$NetBSD: nfs_srvsubs.c,v 1.3.2.3 2010/03/11 15:04:31 yamt Exp $");
74 1.3.2.2 yamt
75 1.3.2.2 yamt #include <sys/param.h>
76 1.3.2.2 yamt #include <sys/proc.h>
77 1.3.2.2 yamt #include <sys/systm.h>
78 1.3.2.2 yamt #include <sys/kernel.h>
79 1.3.2.2 yamt #include <sys/kmem.h>
80 1.3.2.2 yamt #include <sys/mount.h>
81 1.3.2.2 yamt #include <sys/vnode.h>
82 1.3.2.2 yamt #include <sys/namei.h>
83 1.3.2.2 yamt #include <sys/mbuf.h>
84 1.3.2.2 yamt #include <sys/socket.h>
85 1.3.2.2 yamt #include <sys/stat.h>
86 1.3.2.2 yamt #include <sys/filedesc.h>
87 1.3.2.2 yamt #include <sys/time.h>
88 1.3.2.2 yamt #include <sys/dirent.h>
89 1.3.2.2 yamt #include <sys/once.h>
90 1.3.2.2 yamt #include <sys/kauth.h>
91 1.3.2.2 yamt #include <sys/atomic.h>
92 1.3.2.2 yamt
93 1.3.2.2 yamt #include <uvm/uvm_extern.h>
94 1.3.2.2 yamt
95 1.3.2.2 yamt #include <nfs/rpcv2.h>
96 1.3.2.2 yamt #include <nfs/nfsproto.h>
97 1.3.2.2 yamt #include <nfs/nfsnode.h>
98 1.3.2.2 yamt #include <nfs/nfs.h>
99 1.3.2.2 yamt #include <nfs/xdr_subs.h>
100 1.3.2.2 yamt #include <nfs/nfsm_subs.h>
101 1.3.2.2 yamt #include <nfs/nfsmount.h>
102 1.3.2.2 yamt #include <nfs/nfsrtt.h>
103 1.3.2.2 yamt #include <nfs/nfs_var.h>
104 1.3.2.2 yamt
105 1.3.2.2 yamt #include <miscfs/specfs/specdev.h>
106 1.3.2.2 yamt
107 1.3.2.2 yamt #include <netinet/in.h>
108 1.3.2.2 yamt
109 1.3.2.2 yamt /*
110 1.3.2.2 yamt * Set up nameidata for a lookup() call and do it.
111 1.3.2.2 yamt *
112 1.3.2.2 yamt * If pubflag is set, this call is done for a lookup operation on the
113 1.3.2.2 yamt * public filehandle. In that case we allow crossing mountpoints and
114 1.3.2.2 yamt * absolute pathnames. However, the caller is expected to check that
115 1.3.2.2 yamt * the lookup result is within the public fs, and deny access if
116 1.3.2.2 yamt * it is not.
117 1.3.2.2 yamt */
118 1.3.2.2 yamt int
119 1.3.2.2 yamt nfs_namei(struct nameidata *ndp, nfsrvfh_t *nsfh, uint32_t len, struct nfssvc_sock *slp, struct mbuf *nam, struct mbuf **mdp, char **dposp, struct vnode **retdirp, struct lwp *l, int kerbflag, int pubflag)
120 1.3.2.2 yamt {
121 1.3.2.2 yamt int i, rem;
122 1.3.2.2 yamt struct mbuf *md;
123 1.3.2.2 yamt char *fromcp, *tocp, *cp;
124 1.3.2.2 yamt struct vnode *dp;
125 1.3.2.3 yamt int error, rdonly;
126 1.3.2.3 yamt int neverfollow;
127 1.3.2.2 yamt struct componentname *cnp = &ndp->ni_cnd;
128 1.3.2.2 yamt
129 1.3.2.2 yamt *retdirp = NULL;
130 1.3.2.2 yamt
131 1.3.2.2 yamt if ((len + 1) > MAXPATHLEN)
132 1.3.2.2 yamt return (ENAMETOOLONG);
133 1.3.2.2 yamt if (len == 0)
134 1.3.2.2 yamt return (EACCES);
135 1.3.2.2 yamt cnp->cn_pnbuf = PNBUF_GET();
136 1.3.2.2 yamt
137 1.3.2.2 yamt /*
138 1.3.2.2 yamt * Copy the name from the mbuf list to ndp->ni_pnbuf
139 1.3.2.2 yamt * and set the various ndp fields appropriately.
140 1.3.2.2 yamt */
141 1.3.2.2 yamt fromcp = *dposp;
142 1.3.2.2 yamt tocp = cnp->cn_pnbuf;
143 1.3.2.2 yamt md = *mdp;
144 1.3.2.2 yamt rem = mtod(md, char *) + md->m_len - fromcp;
145 1.3.2.2 yamt for (i = 0; i < len; i++) {
146 1.3.2.2 yamt while (rem == 0) {
147 1.3.2.2 yamt md = md->m_next;
148 1.3.2.2 yamt if (md == NULL) {
149 1.3.2.2 yamt error = EBADRPC;
150 1.3.2.2 yamt goto out;
151 1.3.2.2 yamt }
152 1.3.2.2 yamt fromcp = mtod(md, void *);
153 1.3.2.2 yamt rem = md->m_len;
154 1.3.2.2 yamt }
155 1.3.2.2 yamt if (*fromcp == '\0' || (!pubflag && *fromcp == '/')) {
156 1.3.2.2 yamt error = EACCES;
157 1.3.2.2 yamt goto out;
158 1.3.2.2 yamt }
159 1.3.2.2 yamt *tocp++ = *fromcp++;
160 1.3.2.2 yamt rem--;
161 1.3.2.2 yamt }
162 1.3.2.2 yamt *tocp = '\0';
163 1.3.2.2 yamt *mdp = md;
164 1.3.2.2 yamt *dposp = fromcp;
165 1.3.2.2 yamt len = nfsm_rndup(len)-len;
166 1.3.2.2 yamt if (len > 0) {
167 1.3.2.2 yamt if (rem >= len)
168 1.3.2.2 yamt *dposp += len;
169 1.3.2.2 yamt else if ((error = nfs_adv(mdp, dposp, len, rem)) != 0)
170 1.3.2.2 yamt goto out;
171 1.3.2.2 yamt }
172 1.3.2.2 yamt
173 1.3.2.2 yamt /*
174 1.3.2.2 yamt * Extract and set starting directory.
175 1.3.2.2 yamt */
176 1.3.2.2 yamt error = nfsrv_fhtovp(nsfh, false, &dp, ndp->ni_cnd.cn_cred, slp,
177 1.3.2.2 yamt nam, &rdonly, kerbflag, pubflag);
178 1.3.2.2 yamt if (error)
179 1.3.2.2 yamt goto out;
180 1.3.2.2 yamt if (dp->v_type != VDIR) {
181 1.3.2.2 yamt vrele(dp);
182 1.3.2.2 yamt error = ENOTDIR;
183 1.3.2.2 yamt goto out;
184 1.3.2.2 yamt }
185 1.3.2.2 yamt
186 1.3.2.2 yamt if (rdonly)
187 1.3.2.2 yamt cnp->cn_flags |= RDONLY;
188 1.3.2.2 yamt
189 1.3.2.2 yamt *retdirp = dp;
190 1.3.2.2 yamt
191 1.3.2.2 yamt if (pubflag) {
192 1.3.2.2 yamt /*
193 1.3.2.2 yamt * Oh joy. For WebNFS, handle those pesky '%' escapes,
194 1.3.2.2 yamt * and the 'native path' indicator.
195 1.3.2.2 yamt */
196 1.3.2.2 yamt cp = PNBUF_GET();
197 1.3.2.2 yamt fromcp = cnp->cn_pnbuf;
198 1.3.2.2 yamt tocp = cp;
199 1.3.2.2 yamt if ((unsigned char)*fromcp >= WEBNFS_SPECCHAR_START) {
200 1.3.2.2 yamt switch ((unsigned char)*fromcp) {
201 1.3.2.2 yamt case WEBNFS_NATIVE_CHAR:
202 1.3.2.2 yamt /*
203 1.3.2.2 yamt * 'Native' path for us is the same
204 1.3.2.2 yamt * as a path according to the NFS spec,
205 1.3.2.2 yamt * just skip the escape char.
206 1.3.2.2 yamt */
207 1.3.2.2 yamt fromcp++;
208 1.3.2.2 yamt break;
209 1.3.2.2 yamt /*
210 1.3.2.2 yamt * More may be added in the future, range 0x80-0xff
211 1.3.2.2 yamt */
212 1.3.2.2 yamt default:
213 1.3.2.2 yamt error = EIO;
214 1.3.2.2 yamt vrele(dp);
215 1.3.2.2 yamt PNBUF_PUT(cp);
216 1.3.2.2 yamt goto out;
217 1.3.2.2 yamt }
218 1.3.2.2 yamt }
219 1.3.2.2 yamt /*
220 1.3.2.2 yamt * Translate the '%' escapes, URL-style.
221 1.3.2.2 yamt */
222 1.3.2.2 yamt while (*fromcp != '\0') {
223 1.3.2.2 yamt if (*fromcp == WEBNFS_ESC_CHAR) {
224 1.3.2.2 yamt if (fromcp[1] != '\0' && fromcp[2] != '\0') {
225 1.3.2.2 yamt fromcp++;
226 1.3.2.2 yamt *tocp++ = HEXSTRTOI(fromcp);
227 1.3.2.2 yamt fromcp += 2;
228 1.3.2.2 yamt continue;
229 1.3.2.2 yamt } else {
230 1.3.2.2 yamt error = ENOENT;
231 1.3.2.2 yamt vrele(dp);
232 1.3.2.2 yamt PNBUF_PUT(cp);
233 1.3.2.2 yamt goto out;
234 1.3.2.2 yamt }
235 1.3.2.2 yamt } else
236 1.3.2.2 yamt *tocp++ = *fromcp++;
237 1.3.2.2 yamt }
238 1.3.2.2 yamt *tocp = '\0';
239 1.3.2.2 yamt PNBUF_PUT(cnp->cn_pnbuf);
240 1.3.2.2 yamt cnp->cn_pnbuf = cp;
241 1.3.2.2 yamt }
242 1.3.2.2 yamt
243 1.3.2.2 yamt ndp->ni_pathlen = (tocp - cnp->cn_pnbuf) + 1;
244 1.3.2.2 yamt ndp->ni_segflg = UIO_SYSSPACE;
245 1.3.2.2 yamt ndp->ni_rootdir = rootvnode;
246 1.3.2.2 yamt ndp->ni_erootdir = NULL;
247 1.3.2.2 yamt
248 1.3.2.2 yamt if (pubflag) {
249 1.3.2.2 yamt ndp->ni_loopcnt = 0;
250 1.3.2.2 yamt if (cnp->cn_pnbuf[0] == '/')
251 1.3.2.2 yamt dp = rootvnode;
252 1.3.2.2 yamt } else {
253 1.3.2.2 yamt cnp->cn_flags |= NOCROSSMOUNT;
254 1.3.2.2 yamt }
255 1.3.2.2 yamt
256 1.3.2.3 yamt neverfollow = !pubflag;
257 1.3.2.2 yamt
258 1.3.2.2 yamt /*
259 1.3.2.2 yamt * And call lookup() to do the real work
260 1.3.2.2 yamt */
261 1.3.2.3 yamt error = lookup_for_nfsd(ndp, dp, neverfollow);
262 1.3.2.2 yamt if (error) {
263 1.3.2.2 yamt return (error);
264 1.3.2.2 yamt }
265 1.3.2.3 yamt return 0;
266 1.3.2.2 yamt
267 1.3.2.2 yamt out:
268 1.3.2.2 yamt PNBUF_PUT(cnp->cn_pnbuf);
269 1.3.2.2 yamt return (error);
270 1.3.2.2 yamt }
271 1.3.2.2 yamt
272 1.3.2.2 yamt /*
273 1.3.2.2 yamt * nfsrv_fhtovp() - convert a fh to a vnode ptr (optionally locked)
274 1.3.2.2 yamt * - look up fsid in mount list (if not found ret error)
275 1.3.2.2 yamt * - get vp and export rights by calling VFS_FHTOVP()
276 1.3.2.2 yamt * - if cred->cr_uid == 0 or MNT_EXPORTANON set it to credanon
277 1.3.2.2 yamt * - if not lockflag unlock it with VOP_UNLOCK()
278 1.3.2.2 yamt */
279 1.3.2.2 yamt int
280 1.3.2.2 yamt nfsrv_fhtovp(nfsrvfh_t *nsfh, int lockflag, struct vnode **vpp,
281 1.3.2.2 yamt kauth_cred_t cred, struct nfssvc_sock *slp, struct mbuf *nam, int *rdonlyp,
282 1.3.2.2 yamt int kerbflag, int pubflag)
283 1.3.2.2 yamt {
284 1.3.2.2 yamt struct mount *mp;
285 1.3.2.2 yamt kauth_cred_t credanon;
286 1.3.2.2 yamt int error, exflags;
287 1.3.2.2 yamt struct sockaddr_in *saddr;
288 1.3.2.2 yamt fhandle_t *fhp;
289 1.3.2.2 yamt
290 1.3.2.2 yamt fhp = NFSRVFH_FHANDLE(nsfh);
291 1.3.2.2 yamt *vpp = (struct vnode *)0;
292 1.3.2.2 yamt
293 1.3.2.2 yamt if (nfs_ispublicfh(nsfh)) {
294 1.3.2.2 yamt if (!pubflag || !nfs_pub.np_valid)
295 1.3.2.2 yamt return (ESTALE);
296 1.3.2.2 yamt fhp = nfs_pub.np_handle;
297 1.3.2.2 yamt }
298 1.3.2.2 yamt
299 1.3.2.2 yamt error = netexport_check(&fhp->fh_fsid, nam, &mp, &exflags, &credanon);
300 1.3.2.2 yamt if (error) {
301 1.3.2.2 yamt return error;
302 1.3.2.2 yamt }
303 1.3.2.2 yamt
304 1.3.2.2 yamt error = VFS_FHTOVP(mp, &fhp->fh_fid, vpp);
305 1.3.2.2 yamt if (error)
306 1.3.2.2 yamt return (error);
307 1.3.2.2 yamt
308 1.3.2.2 yamt if (!(exflags & (MNT_EXNORESPORT|MNT_EXPUBLIC))) {
309 1.3.2.2 yamt saddr = mtod(nam, struct sockaddr_in *);
310 1.3.2.2 yamt if ((saddr->sin_family == AF_INET) &&
311 1.3.2.2 yamt ntohs(saddr->sin_port) >= IPPORT_RESERVED) {
312 1.3.2.2 yamt vput(*vpp);
313 1.3.2.2 yamt return (NFSERR_AUTHERR | AUTH_TOOWEAK);
314 1.3.2.2 yamt }
315 1.3.2.2 yamt if ((saddr->sin_family == AF_INET6) &&
316 1.3.2.2 yamt ntohs(saddr->sin_port) >= IPV6PORT_RESERVED) {
317 1.3.2.2 yamt vput(*vpp);
318 1.3.2.2 yamt return (NFSERR_AUTHERR | AUTH_TOOWEAK);
319 1.3.2.2 yamt }
320 1.3.2.2 yamt }
321 1.3.2.2 yamt /*
322 1.3.2.2 yamt * Check/setup credentials.
323 1.3.2.2 yamt */
324 1.3.2.2 yamt if (exflags & MNT_EXKERB) {
325 1.3.2.2 yamt if (!kerbflag) {
326 1.3.2.2 yamt vput(*vpp);
327 1.3.2.2 yamt return (NFSERR_AUTHERR | AUTH_TOOWEAK);
328 1.3.2.2 yamt }
329 1.3.2.2 yamt } else if (kerbflag) {
330 1.3.2.2 yamt vput(*vpp);
331 1.3.2.2 yamt return (NFSERR_AUTHERR | AUTH_TOOWEAK);
332 1.3.2.2 yamt } else if (kauth_cred_geteuid(cred) == 0 || /* NFS maproot, see below */
333 1.3.2.2 yamt (exflags & MNT_EXPORTANON)) {
334 1.3.2.2 yamt /*
335 1.3.2.2 yamt * This is used by the NFS maproot option. While we can change
336 1.3.2.2 yamt * the secmodel on our own host, we can't change it on the
337 1.3.2.2 yamt * clients. As means of least surprise, we're doing the
338 1.3.2.2 yamt * traditional thing here.
339 1.3.2.2 yamt * Should look into adding a "mapprivileged" or similar where
340 1.3.2.2 yamt * the users can be explicitly specified...
341 1.3.2.2 yamt * [elad, yamt 2008-03-05]
342 1.3.2.2 yamt */
343 1.3.2.2 yamt kauth_cred_clone(credanon, cred);
344 1.3.2.2 yamt }
345 1.3.2.2 yamt if (exflags & MNT_EXRDONLY)
346 1.3.2.2 yamt *rdonlyp = 1;
347 1.3.2.2 yamt else
348 1.3.2.2 yamt *rdonlyp = 0;
349 1.3.2.2 yamt if (!lockflag)
350 1.3.2.2 yamt VOP_UNLOCK(*vpp, 0);
351 1.3.2.2 yamt return (0);
352 1.3.2.2 yamt }
353 1.3.2.2 yamt
354 1.3.2.2 yamt /*
355 1.3.2.2 yamt * WebNFS: check if a filehandle is a public filehandle. For v3, this
356 1.3.2.2 yamt * means a length of 0, for v2 it means all zeroes.
357 1.3.2.2 yamt */
358 1.3.2.2 yamt int
359 1.3.2.2 yamt nfs_ispublicfh(const nfsrvfh_t *nsfh)
360 1.3.2.2 yamt {
361 1.3.2.2 yamt const char *cp = (const void *)(NFSRVFH_DATA(nsfh));
362 1.3.2.2 yamt int i;
363 1.3.2.2 yamt
364 1.3.2.2 yamt if (NFSRVFH_SIZE(nsfh) == 0) {
365 1.3.2.2 yamt return true;
366 1.3.2.2 yamt }
367 1.3.2.2 yamt if (NFSRVFH_SIZE(nsfh) != NFSX_V2FH) {
368 1.3.2.2 yamt return false;
369 1.3.2.2 yamt }
370 1.3.2.2 yamt for (i = 0; i < NFSX_V2FH; i++)
371 1.3.2.2 yamt if (*cp++ != 0)
372 1.3.2.2 yamt return false;
373 1.3.2.2 yamt return true;
374 1.3.2.2 yamt }
375 1.3.2.2 yamt
376 1.3.2.2 yamt int
377 1.3.2.2 yamt nfsrv_composefh(struct vnode *vp, nfsrvfh_t *nsfh, bool v3)
378 1.3.2.2 yamt {
379 1.3.2.2 yamt int error;
380 1.3.2.2 yamt size_t fhsize;
381 1.3.2.2 yamt
382 1.3.2.2 yamt fhsize = NFSD_MAXFHSIZE;
383 1.3.2.2 yamt error = vfs_composefh(vp, (void *)NFSRVFH_DATA(nsfh), &fhsize);
384 1.3.2.2 yamt if (NFSX_FHTOOBIG_P(fhsize, v3)) {
385 1.3.2.2 yamt error = EOPNOTSUPP;
386 1.3.2.2 yamt }
387 1.3.2.2 yamt if (error != 0) {
388 1.3.2.2 yamt return error;
389 1.3.2.2 yamt }
390 1.3.2.2 yamt if (!v3 && fhsize < NFSX_V2FH) {
391 1.3.2.2 yamt memset((char *)NFSRVFH_DATA(nsfh) + fhsize, 0,
392 1.3.2.2 yamt NFSX_V2FH - fhsize);
393 1.3.2.2 yamt fhsize = NFSX_V2FH;
394 1.3.2.2 yamt }
395 1.3.2.2 yamt if ((fhsize % NFSX_UNSIGNED) != 0) {
396 1.3.2.2 yamt return EOPNOTSUPP;
397 1.3.2.2 yamt }
398 1.3.2.2 yamt nsfh->nsfh_size = fhsize;
399 1.3.2.2 yamt return 0;
400 1.3.2.2 yamt }
401 1.3.2.2 yamt
402 1.3.2.2 yamt int
403 1.3.2.2 yamt nfsrv_comparefh(const nfsrvfh_t *fh1, const nfsrvfh_t *fh2)
404 1.3.2.2 yamt {
405 1.3.2.2 yamt
406 1.3.2.2 yamt if (NFSRVFH_SIZE(fh1) != NFSRVFH_SIZE(fh2)) {
407 1.3.2.2 yamt return NFSRVFH_SIZE(fh2) - NFSRVFH_SIZE(fh1);
408 1.3.2.2 yamt }
409 1.3.2.2 yamt return memcmp(NFSRVFH_DATA(fh1), NFSRVFH_DATA(fh2), NFSRVFH_SIZE(fh1));
410 1.3.2.2 yamt }
411 1.3.2.2 yamt
412 1.3.2.2 yamt void
413 1.3.2.2 yamt nfsrv_copyfh(nfsrvfh_t *fh1, const nfsrvfh_t *fh2)
414 1.3.2.2 yamt {
415 1.3.2.2 yamt size_t size;
416 1.3.2.2 yamt
417 1.3.2.2 yamt fh1->nsfh_size = size = NFSRVFH_SIZE(fh2);
418 1.3.2.2 yamt memcpy(NFSRVFH_DATA(fh1), NFSRVFH_DATA(fh2), size);
419 1.3.2.2 yamt }
420