Commit | Line | Data |
---|---|---|
23aa42f4 WJ |
1 | /* |
2 | * Copyright (c) 1989 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * This code is derived from software contributed to Berkeley by | |
6 | * Rick Macklem at The University of Guelph. | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | |
15 | * documentation and/or other materials provided with the distribution. | |
16 | * 3. All advertising materials mentioning features or use of this software | |
17 | * must display the following acknowledgement: | |
18 | * This product includes software developed by the University of | |
19 | * California, Berkeley and its contributors. | |
20 | * 4. Neither the name of the University nor the names of its contributors | |
21 | * may be used to endorse or promote products derived from this software | |
22 | * without specific prior written permission. | |
23 | * | |
24 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
34 | * SUCH DAMAGE. | |
35 | * | |
36 | * @(#)nfs_vnops.c 7.60 (Berkeley) 5/24/91 | |
37 | */ | |
38 | ||
39 | /* | |
40 | * vnode op calls for sun nfs version 2 | |
41 | */ | |
42 | ||
43 | #include "param.h" | |
44 | #include "proc.h" | |
45 | #include "kernel.h" | |
46 | #include "systm.h" | |
47 | #include "mount.h" | |
48 | #include "buf.h" | |
49 | #include "malloc.h" | |
50 | #include "mbuf.h" | |
51 | #include "conf.h" | |
52 | #include "namei.h" | |
53 | #include "vnode.h" | |
54 | #include "specdev.h" | |
55 | #include "fifo.h" | |
56 | ||
57 | #include "../ufs/quota.h" | |
58 | #include "../ufs/inode.h" | |
59 | #include "../ufs/dir.h" | |
60 | ||
61 | #include "nfsv2.h" | |
62 | #include "nfs.h" | |
63 | #include "nfsnode.h" | |
64 | #include "nfsmount.h" | |
65 | #include "xdr_subs.h" | |
66 | #include "nfsm_subs.h" | |
67 | #include "nfsiom.h" | |
68 | ||
69 | /* Defs */ | |
70 | #define TRUE 1 | |
71 | #define FALSE 0 | |
72 | ||
73 | /* | |
74 | * Global vfs data structures for nfs | |
75 | */ | |
76 | struct vnodeops nfsv2_vnodeops = { | |
77 | nfs_lookup, /* lookup */ | |
78 | nfs_create, /* create */ | |
79 | nfs_mknod, /* mknod */ | |
80 | nfs_open, /* open */ | |
81 | nfs_close, /* close */ | |
82 | nfs_access, /* access */ | |
83 | nfs_getattr, /* getattr */ | |
84 | nfs_setattr, /* setattr */ | |
85 | nfs_read, /* read */ | |
86 | nfs_write, /* write */ | |
87 | nfs_ioctl, /* ioctl */ | |
88 | nfs_select, /* select */ | |
89 | nfs_mmap, /* mmap */ | |
90 | nfs_fsync, /* fsync */ | |
91 | nfs_seek, /* seek */ | |
92 | nfs_remove, /* remove */ | |
93 | nfs_link, /* link */ | |
94 | nfs_rename, /* rename */ | |
95 | nfs_mkdir, /* mkdir */ | |
96 | nfs_rmdir, /* rmdir */ | |
97 | nfs_symlink, /* symlink */ | |
98 | nfs_readdir, /* readdir */ | |
99 | nfs_readlink, /* readlink */ | |
100 | nfs_abortop, /* abortop */ | |
101 | nfs_inactive, /* inactive */ | |
102 | nfs_reclaim, /* reclaim */ | |
103 | nfs_lock, /* lock */ | |
104 | nfs_unlock, /* unlock */ | |
105 | nfs_bmap, /* bmap */ | |
106 | nfs_strategy, /* strategy */ | |
107 | nfs_print, /* print */ | |
108 | nfs_islocked, /* islocked */ | |
109 | nfs_advlock, /* advlock */ | |
110 | }; | |
111 | ||
112 | /* | |
113 | * Special device vnode ops | |
114 | */ | |
115 | struct vnodeops spec_nfsv2nodeops = { | |
116 | spec_lookup, /* lookup */ | |
117 | spec_create, /* create */ | |
118 | spec_mknod, /* mknod */ | |
119 | spec_open, /* open */ | |
120 | spec_close, /* close */ | |
121 | nfs_access, /* access */ | |
122 | nfs_getattr, /* getattr */ | |
123 | nfs_setattr, /* setattr */ | |
124 | spec_read, /* read */ | |
125 | spec_write, /* write */ | |
126 | spec_ioctl, /* ioctl */ | |
127 | spec_select, /* select */ | |
128 | spec_mmap, /* mmap */ | |
129 | spec_fsync, /* fsync */ | |
130 | spec_seek, /* seek */ | |
131 | spec_remove, /* remove */ | |
132 | spec_link, /* link */ | |
133 | spec_rename, /* rename */ | |
134 | spec_mkdir, /* mkdir */ | |
135 | spec_rmdir, /* rmdir */ | |
136 | spec_symlink, /* symlink */ | |
137 | spec_readdir, /* readdir */ | |
138 | spec_readlink, /* readlink */ | |
139 | spec_abortop, /* abortop */ | |
140 | nfs_inactive, /* inactive */ | |
141 | nfs_reclaim, /* reclaim */ | |
142 | nfs_lock, /* lock */ | |
143 | nfs_unlock, /* unlock */ | |
144 | spec_bmap, /* bmap */ | |
145 | spec_strategy, /* strategy */ | |
146 | nfs_print, /* print */ | |
147 | nfs_islocked, /* islocked */ | |
148 | spec_advlock, /* advlock */ | |
149 | }; | |
150 | ||
151 | #ifdef FIFO | |
152 | struct vnodeops fifo_nfsv2nodeops = { | |
153 | fifo_lookup, /* lookup */ | |
154 | fifo_create, /* create */ | |
155 | fifo_mknod, /* mknod */ | |
156 | fifo_open, /* open */ | |
157 | fifo_close, /* close */ | |
158 | nfs_access, /* access */ | |
159 | nfs_getattr, /* getattr */ | |
160 | nfs_setattr, /* setattr */ | |
161 | fifo_read, /* read */ | |
162 | fifo_write, /* write */ | |
163 | fifo_ioctl, /* ioctl */ | |
164 | fifo_select, /* select */ | |
165 | fifo_mmap, /* mmap */ | |
166 | fifo_fsync, /* fsync */ | |
167 | fifo_seek, /* seek */ | |
168 | fifo_remove, /* remove */ | |
169 | fifo_link, /* link */ | |
170 | fifo_rename, /* rename */ | |
171 | fifo_mkdir, /* mkdir */ | |
172 | fifo_rmdir, /* rmdir */ | |
173 | fifo_symlink, /* symlink */ | |
174 | fifo_readdir, /* readdir */ | |
175 | fifo_readlink, /* readlink */ | |
176 | fifo_abortop, /* abortop */ | |
177 | nfs_inactive, /* inactive */ | |
178 | nfs_reclaim, /* reclaim */ | |
179 | nfs_lock, /* lock */ | |
180 | nfs_unlock, /* unlock */ | |
181 | fifo_bmap, /* bmap */ | |
182 | fifo_badop, /* strategy */ | |
183 | nfs_print, /* print */ | |
184 | nfs_islocked, /* islocked */ | |
185 | fifo_advlock, /* advlock */ | |
186 | }; | |
187 | #endif /* FIFO */ | |
188 | ||
189 | /* | |
190 | * Global vars | |
191 | */ | |
192 | extern u_long nfs_procids[NFS_NPROCS]; | |
193 | extern u_long nfs_prog, nfs_vers; | |
194 | extern char nfsiobuf[MAXPHYS+NBPG]; | |
195 | struct buf nfs_bqueue; /* Queue head for nfsiod's */ | |
196 | struct proc *nfs_iodwant[NFS_MAXASYNCDAEMON]; | |
197 | int nfs_numasync = 0; | |
198 | ||
199 | /* | |
200 | * nfs null call from vfs. | |
201 | */ | |
202 | nfs_null(vp, cred, p) | |
203 | struct vnode *vp; | |
204 | struct ucred *cred; | |
205 | struct proc *p; | |
206 | { | |
207 | caddr_t bpos, dpos; | |
208 | u_long xid; | |
209 | int error = 0; | |
210 | struct mbuf *mreq, *mrep, *md, *mb; | |
211 | ||
212 | nfsm_reqhead(nfs_procids[NFSPROC_NULL], cred, 0); | |
213 | nfsm_request(vp, NFSPROC_NULL, p, 0); | |
214 | nfsm_reqdone; | |
215 | return (error); | |
216 | } | |
217 | ||
218 | /* | |
219 | * nfs access vnode op. | |
220 | * Essentially just get vattr and then imitate iaccess() | |
221 | */ | |
222 | nfs_access(vp, mode, cred, p) | |
223 | struct vnode *vp; | |
224 | int mode; | |
225 | register struct ucred *cred; | |
226 | struct proc *p; | |
227 | { | |
228 | register struct vattr *vap; | |
229 | register gid_t *gp; | |
230 | struct vattr vattr; | |
231 | register int i; | |
232 | int error; | |
233 | ||
234 | /* | |
235 | * If you're the super-user, | |
236 | * you always get access. | |
237 | */ | |
238 | if (cred->cr_uid == 0) | |
239 | return (0); | |
240 | vap = &vattr; | |
241 | if (error = nfs_dogetattr(vp, vap, cred, 0, p)) | |
242 | return (error); | |
243 | /* | |
244 | * Access check is based on only one of owner, group, public. | |
245 | * If not owner, then check group. If not a member of the | |
246 | * group, then check public access. | |
247 | */ | |
248 | if (cred->cr_uid != vap->va_uid) { | |
249 | mode >>= 3; | |
250 | gp = cred->cr_groups; | |
251 | for (i = 0; i < cred->cr_ngroups; i++, gp++) | |
252 | if (vap->va_gid == *gp) | |
253 | goto found; | |
254 | mode >>= 3; | |
255 | found: | |
256 | ; | |
257 | } | |
258 | if ((vap->va_mode & mode) != 0) | |
259 | return (0); | |
260 | return (EACCES); | |
261 | } | |
262 | ||
263 | /* | |
264 | * nfs open vnode op | |
265 | * Just check to see if the type is ok | |
266 | */ | |
267 | /* ARGSUSED */ | |
268 | nfs_open(vp, mode, cred, p) | |
269 | struct vnode *vp; | |
270 | int mode; | |
271 | struct ucred *cred; | |
272 | struct proc *p; | |
273 | { | |
274 | register enum vtype vtyp; | |
275 | ||
276 | vtyp = vp->v_type; | |
277 | if (vtyp == VREG || vtyp == VDIR || vtyp == VLNK) | |
278 | return (0); | |
279 | else | |
280 | return (EACCES); | |
281 | } | |
282 | ||
283 | /* | |
284 | * nfs close vnode op | |
285 | * For reg files, invalidate any buffer cache entries. | |
286 | */ | |
287 | /* ARGSUSED */ | |
288 | nfs_close(vp, fflags, cred, p) | |
289 | register struct vnode *vp; | |
290 | int fflags; | |
291 | struct ucred *cred; | |
292 | struct proc *p; | |
293 | { | |
294 | register struct nfsnode *np = VTONFS(vp); | |
295 | int error = 0; | |
296 | ||
297 | if (vp->v_type == VREG && (np->n_flag & NMODIFIED)) { | |
298 | nfs_lock(vp); | |
299 | np->n_flag &= ~NMODIFIED; | |
300 | vinvalbuf(vp, TRUE); | |
301 | np->n_attrstamp = 0; | |
302 | if (np->n_flag & NWRITEERR) { | |
303 | np->n_flag &= ~NWRITEERR; | |
304 | error = np->n_error; | |
305 | } | |
306 | nfs_unlock(vp); | |
307 | } | |
308 | return (error); | |
309 | } | |
310 | ||
311 | /* | |
312 | * nfs getattr call from vfs. | |
313 | */ | |
314 | nfs_getattr(vp, vap, cred, p) | |
315 | register struct vnode *vp; | |
316 | struct vattr *vap; | |
317 | struct ucred *cred; | |
318 | struct proc *p; | |
319 | { | |
320 | return (nfs_dogetattr(vp, vap, cred, 0, p)); | |
321 | } | |
322 | ||
323 | nfs_dogetattr(vp, vap, cred, tryhard, p) | |
324 | register struct vnode *vp; | |
325 | struct vattr *vap; | |
326 | struct ucred *cred; | |
327 | int tryhard; | |
328 | struct proc *p; | |
329 | { | |
330 | register caddr_t cp; | |
331 | register long t1; | |
332 | caddr_t bpos, dpos; | |
333 | u_long xid; | |
334 | int error = 0; | |
335 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
336 | ||
337 | /* First look in the cache.. */ | |
338 | if (nfs_getattrcache(vp, vap) == 0) | |
339 | return (0); | |
340 | nfsstats.rpccnt[NFSPROC_GETATTR]++; | |
341 | nfsm_reqhead(nfs_procids[NFSPROC_GETATTR], cred, NFSX_FH); | |
342 | nfsm_fhtom(vp); | |
343 | nfsm_request(vp, NFSPROC_GETATTR, p, tryhard); | |
344 | nfsm_loadattr(vp, vap); | |
345 | nfsm_reqdone; | |
346 | return (error); | |
347 | } | |
348 | ||
349 | /* | |
350 | * nfs setattr call. | |
351 | */ | |
352 | nfs_setattr(vp, vap, cred, p) | |
353 | register struct vnode *vp; | |
354 | register struct vattr *vap; | |
355 | struct ucred *cred; | |
356 | struct proc *p; | |
357 | { | |
358 | register struct nfsv2_sattr *sp; | |
359 | register caddr_t cp; | |
360 | register long t1; | |
361 | caddr_t bpos, dpos; | |
362 | u_long xid; | |
363 | int error = 0; | |
364 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
365 | struct nfsnode *np; | |
366 | ||
367 | nfsstats.rpccnt[NFSPROC_SETATTR]++; | |
368 | nfsm_reqhead(nfs_procids[NFSPROC_SETATTR], cred, NFSX_FH+NFSX_SATTR); | |
369 | nfsm_fhtom(vp); | |
370 | nfsm_build(sp, struct nfsv2_sattr *, NFSX_SATTR); | |
371 | if (vap->va_mode == 0xffff) | |
372 | sp->sa_mode = VNOVAL; | |
373 | else | |
374 | sp->sa_mode = vtonfs_mode(vp->v_type, vap->va_mode); | |
375 | if (vap->va_uid == 0xffff) | |
376 | sp->sa_uid = VNOVAL; | |
377 | else | |
378 | sp->sa_uid = txdr_unsigned(vap->va_uid); | |
379 | if (vap->va_gid == 0xffff) | |
380 | sp->sa_gid = VNOVAL; | |
381 | else | |
382 | sp->sa_gid = txdr_unsigned(vap->va_gid); | |
383 | sp->sa_size = txdr_unsigned(vap->va_size); | |
384 | sp->sa_atime.tv_sec = txdr_unsigned(vap->va_atime.tv_sec); | |
385 | sp->sa_atime.tv_usec = txdr_unsigned(vap->va_flags); | |
386 | txdr_time(&vap->va_mtime, &sp->sa_mtime); | |
387 | if (vap->va_size != VNOVAL || vap->va_mtime.tv_sec != VNOVAL || | |
388 | vap->va_atime.tv_sec != VNOVAL) { | |
389 | np = VTONFS(vp); | |
390 | if (np->n_flag & NMODIFIED) { | |
391 | np->n_flag &= ~NMODIFIED; | |
392 | if (vap->va_size == 0) | |
393 | vinvalbuf(vp, FALSE); | |
394 | else | |
395 | vinvalbuf(vp, TRUE); | |
396 | np->n_attrstamp = 0; | |
397 | } | |
398 | } | |
399 | nfsm_request(vp, NFSPROC_SETATTR, p, 1); | |
400 | nfsm_loadattr(vp, (struct vattr *)0); | |
401 | /* should we fill in any vap fields ?? */ | |
402 | nfsm_reqdone; | |
403 | return (error); | |
404 | } | |
405 | ||
406 | /* | |
407 | * nfs lookup call, one step at a time... | |
408 | * First look in cache | |
409 | * If not found, unlock the directory nfsnode and do the rpc | |
410 | */ | |
411 | nfs_lookup(vp, ndp, p) | |
412 | register struct vnode *vp; | |
413 | register struct nameidata *ndp; | |
414 | struct proc *p; | |
415 | { | |
416 | register struct vnode *vdp; | |
417 | register u_long *tl; | |
418 | register caddr_t cp; | |
419 | register long t1, t2; | |
420 | caddr_t bpos, dpos, cp2; | |
421 | u_long xid; | |
422 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
423 | struct vnode *newvp; | |
424 | long len; | |
425 | nfsv2fh_t *fhp; | |
426 | struct nfsnode *np; | |
427 | int lockparent, wantparent, flag, error = 0; | |
428 | ||
429 | ndp->ni_dvp = vp; | |
430 | ndp->ni_vp = NULL; | |
431 | if (vp->v_type != VDIR) | |
432 | return (ENOTDIR); | |
433 | lockparent = ndp->ni_nameiop & LOCKPARENT; | |
434 | flag = ndp->ni_nameiop & OPMASK; | |
435 | wantparent = ndp->ni_nameiop & (LOCKPARENT|WANTPARENT); | |
436 | if ((error = cache_lookup(ndp)) && error != ENOENT) { | |
437 | struct vattr vattr; | |
438 | int vpid; | |
439 | ||
440 | vdp = ndp->ni_vp; | |
441 | vpid = vdp->v_id; | |
442 | /* | |
443 | * See the comment starting `Step through' in ufs/ufs_lookup.c | |
444 | * for an explanation of the locking protocol | |
445 | */ | |
446 | if (vp == vdp) { | |
447 | VREF(vdp); | |
448 | error = 0; | |
449 | } else if (ndp->ni_isdotdot) { | |
450 | nfs_unlock(vp); | |
451 | error = vget(vdp); | |
452 | if (!error && lockparent && *ndp->ni_next == '\0') | |
453 | nfs_lock(vp); | |
454 | } else { | |
455 | error = vget(vdp); | |
456 | if (!lockparent || error || *ndp->ni_next != '\0') | |
457 | nfs_unlock(vp); | |
458 | } | |
459 | if (!error) { | |
460 | if (vpid == vdp->v_id) { | |
461 | if (!nfs_dogetattr(vdp, &vattr, ndp->ni_cred, 0, p)&& | |
462 | vattr.va_ctime.tv_sec == VTONFS(vdp)->n_ctime) { | |
463 | nfsstats.lookupcache_hits++; | |
464 | if (flag != LOOKUP && *ndp->ni_next == 0) | |
465 | ndp->ni_nameiop |= SAVENAME; | |
466 | return (0); | |
467 | } | |
468 | cache_purge(vdp); | |
469 | } | |
470 | nfs_nput(vdp); | |
471 | if (lockparent && vdp != vp && *ndp->ni_next == '\0') | |
472 | nfs_unlock(vp); | |
473 | } | |
474 | ndp->ni_vp = NULLVP; | |
475 | } else | |
476 | nfs_unlock(vp); | |
477 | error = 0; | |
478 | nfsstats.lookupcache_misses++; | |
479 | nfsstats.rpccnt[NFSPROC_LOOKUP]++; | |
480 | len = ndp->ni_namelen; | |
481 | nfsm_reqhead(nfs_procids[NFSPROC_LOOKUP], ndp->ni_cred, NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(len)); | |
482 | nfsm_fhtom(vp); | |
483 | nfsm_strtom(ndp->ni_ptr, len, NFS_MAXNAMLEN); | |
484 | nfsm_request(vp, NFSPROC_LOOKUP, p, 0); | |
485 | nfsmout: | |
486 | if (error) { | |
487 | if (lockparent || (flag != CREATE && flag != RENAME) || | |
488 | *ndp->ni_next != 0) | |
489 | nfs_lock(vp); | |
490 | if (flag != LOOKUP && *ndp->ni_next == 0) | |
491 | ndp->ni_nameiop |= SAVENAME; | |
492 | return (error); | |
493 | } | |
494 | nfsm_disect(fhp,nfsv2fh_t *,NFSX_FH); | |
495 | ||
496 | /* | |
497 | * Handle DELETE and RENAME cases... | |
498 | */ | |
499 | if (flag == DELETE && *ndp->ni_next == 0) { | |
500 | if (!bcmp(VTONFS(vp)->n_fh.fh_bytes, (caddr_t)fhp, NFSX_FH)) { | |
501 | VREF(vp); | |
502 | newvp = vp; | |
503 | np = VTONFS(vp); | |
504 | } else { | |
505 | if (error = nfs_nget(vp->v_mount, fhp, &np)) { | |
506 | nfs_lock(vp); | |
507 | m_freem(mrep); | |
508 | return (error); | |
509 | } | |
510 | newvp = NFSTOV(np); | |
511 | } | |
512 | if (error = | |
513 | nfs_loadattrcache(&newvp, &md, &dpos, (struct vattr *)0)) { | |
514 | nfs_lock(vp); | |
515 | if (newvp != vp) | |
516 | nfs_nput(newvp); | |
517 | else | |
518 | vrele(vp); | |
519 | m_freem(mrep); | |
520 | return (error); | |
521 | } | |
522 | ndp->ni_vp = newvp; | |
523 | if (lockparent || vp == newvp) | |
524 | nfs_lock(vp); | |
525 | m_freem(mrep); | |
526 | ndp->ni_nameiop |= SAVENAME; | |
527 | return (0); | |
528 | } | |
529 | ||
530 | if (flag == RENAME && wantparent && *ndp->ni_next == 0) { | |
531 | if (!bcmp(VTONFS(vp)->n_fh.fh_bytes, (caddr_t)fhp, NFSX_FH)) { | |
532 | nfs_lock(vp); | |
533 | m_freem(mrep); | |
534 | return (EISDIR); | |
535 | } | |
536 | if (error = nfs_nget(vp->v_mount, fhp, &np)) { | |
537 | nfs_lock(vp); | |
538 | m_freem(mrep); | |
539 | return (error); | |
540 | } | |
541 | newvp = NFSTOV(np); | |
542 | if (error = | |
543 | nfs_loadattrcache(&newvp, &md, &dpos, (struct vattr *)0)) { | |
544 | nfs_lock(vp); | |
545 | nfs_nput(newvp); | |
546 | m_freem(mrep); | |
547 | return (error); | |
548 | } | |
549 | ndp->ni_vp = newvp; | |
550 | if (lockparent) | |
551 | nfs_lock(vp); | |
552 | m_freem(mrep); | |
553 | ndp->ni_nameiop |= SAVENAME; | |
554 | return (0); | |
555 | } | |
556 | ||
557 | if (!bcmp(VTONFS(vp)->n_fh.fh_bytes, (caddr_t)fhp, NFSX_FH)) { | |
558 | VREF(vp); | |
559 | newvp = vp; | |
560 | np = VTONFS(vp); | |
561 | } else if (ndp->ni_isdotdot) { | |
562 | if (error = nfs_nget(vp->v_mount, fhp, &np)) { | |
563 | nfs_lock(vp); | |
564 | m_freem(mrep); | |
565 | return (error); | |
566 | } | |
567 | newvp = NFSTOV(np); | |
568 | } else { | |
569 | if (error = nfs_nget(vp->v_mount, fhp, &np)) { | |
570 | nfs_lock(vp); | |
571 | m_freem(mrep); | |
572 | return (error); | |
573 | } | |
574 | newvp = NFSTOV(np); | |
575 | } | |
576 | if (error = nfs_loadattrcache(&newvp, &md, &dpos, (struct vattr *)0)) { | |
577 | nfs_lock(vp); | |
578 | if (newvp != vp) | |
579 | nfs_nput(newvp); | |
580 | else | |
581 | vrele(vp); | |
582 | m_freem(mrep); | |
583 | return (error); | |
584 | } | |
585 | m_freem(mrep); | |
586 | ||
587 | if (vp == newvp || (lockparent && *ndp->ni_next == '\0')) | |
588 | nfs_lock(vp); | |
589 | ndp->ni_vp = newvp; | |
590 | if (flag != LOOKUP && *ndp->ni_next == 0) | |
591 | ndp->ni_nameiop |= SAVENAME; | |
592 | if (error == 0 && ndp->ni_makeentry) { | |
593 | np->n_ctime = np->n_vattr.va_ctime.tv_sec; | |
594 | cache_enter(ndp); | |
595 | } | |
596 | return (error); | |
597 | } | |
598 | ||
599 | /* | |
600 | * nfs read call. | |
601 | * Just call nfs_bioread() to do the work. | |
602 | */ | |
603 | nfs_read(vp, uiop, ioflag, cred) | |
604 | register struct vnode *vp; | |
605 | struct uio *uiop; | |
606 | int ioflag; | |
607 | struct ucred *cred; | |
608 | { | |
609 | if (vp->v_type != VREG) | |
610 | return (EPERM); | |
611 | return (nfs_bioread(vp, uiop, ioflag, cred)); | |
612 | } | |
613 | ||
614 | /* | |
615 | * nfs readlink call | |
616 | */ | |
617 | nfs_readlink(vp, uiop, cred) | |
618 | struct vnode *vp; | |
619 | struct uio *uiop; | |
620 | struct ucred *cred; | |
621 | { | |
622 | if (vp->v_type != VLNK) | |
623 | return (EPERM); | |
624 | return (nfs_bioread(vp, uiop, 0, cred)); | |
625 | } | |
626 | ||
627 | /* | |
628 | * Do a readlink rpc. | |
629 | * Called by nfs_doio() from below the buffer cache. | |
630 | */ | |
631 | nfs_readlinkrpc(vp, uiop, cred) | |
632 | register struct vnode *vp; | |
633 | struct uio *uiop; | |
634 | struct ucred *cred; | |
635 | { | |
636 | register u_long *tl; | |
637 | register caddr_t cp; | |
638 | register long t1; | |
639 | caddr_t bpos, dpos, cp2; | |
640 | u_long xid; | |
641 | int error = 0; | |
642 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
643 | long len; | |
644 | ||
645 | nfsstats.rpccnt[NFSPROC_READLINK]++; | |
646 | nfsm_reqhead(nfs_procids[NFSPROC_READLINK], cred, NFSX_FH); | |
647 | nfsm_fhtom(vp); | |
648 | nfsm_request(vp, NFSPROC_READLINK, uiop->uio_procp, 0); | |
649 | nfsm_strsiz(len, NFS_MAXPATHLEN); | |
650 | nfsm_mtouio(uiop, len); | |
651 | nfsm_reqdone; | |
652 | return (error); | |
653 | } | |
654 | ||
655 | /* | |
656 | * nfs read rpc call | |
657 | * Ditto above | |
658 | */ | |
659 | nfs_readrpc(vp, uiop, cred) | |
660 | register struct vnode *vp; | |
661 | struct uio *uiop; | |
662 | struct ucred *cred; | |
663 | { | |
664 | register u_long *tl; | |
665 | register caddr_t cp; | |
666 | register long t1; | |
667 | caddr_t bpos, dpos, cp2; | |
668 | u_long xid; | |
669 | int error = 0; | |
670 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
671 | struct nfsmount *nmp; | |
672 | long len, retlen, tsiz; | |
673 | ||
674 | nmp = VFSTONFS(vp->v_mount); | |
675 | tsiz = uiop->uio_resid; | |
676 | while (tsiz > 0) { | |
677 | nfsstats.rpccnt[NFSPROC_READ]++; | |
678 | len = (tsiz > nmp->nm_rsize) ? nmp->nm_rsize : tsiz; | |
679 | nfsm_reqhead(nfs_procids[NFSPROC_READ], cred, NFSX_FH+NFSX_UNSIGNED*3); | |
680 | nfsm_fhtom(vp); | |
681 | nfsm_build(tl, u_long *, NFSX_UNSIGNED*3); | |
682 | *tl++ = txdr_unsigned(uiop->uio_offset); | |
683 | *tl++ = txdr_unsigned(len); | |
684 | *tl = 0; | |
685 | nfsm_request(vp, NFSPROC_READ, uiop->uio_procp, 1); | |
686 | nfsm_loadattr(vp, (struct vattr *)0); | |
687 | nfsm_strsiz(retlen, nmp->nm_rsize); | |
688 | nfsm_mtouio(uiop, retlen); | |
689 | m_freem(mrep); | |
690 | if (retlen < len) | |
691 | tsiz = 0; | |
692 | else | |
693 | tsiz -= len; | |
694 | } | |
695 | nfsmout: | |
696 | return (error); | |
697 | } | |
698 | ||
699 | /* | |
700 | * nfs write call | |
701 | */ | |
702 | nfs_writerpc(vp, uiop, cred) | |
703 | register struct vnode *vp; | |
704 | struct uio *uiop; | |
705 | struct ucred *cred; | |
706 | { | |
707 | register u_long *tl; | |
708 | register caddr_t cp; | |
709 | register long t1; | |
710 | caddr_t bpos, dpos; | |
711 | u_long xid; | |
712 | int error = 0; | |
713 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
714 | struct nfsmount *nmp; | |
715 | long len, tsiz; | |
716 | ||
717 | nmp = VFSTONFS(vp->v_mount); | |
718 | tsiz = uiop->uio_resid; | |
719 | while (tsiz > 0) { | |
720 | nfsstats.rpccnt[NFSPROC_WRITE]++; | |
721 | len = (tsiz > nmp->nm_wsize) ? nmp->nm_wsize : tsiz; | |
722 | nfsm_reqhead(nfs_procids[NFSPROC_WRITE], cred, | |
723 | NFSX_FH+NFSX_UNSIGNED*4); | |
724 | nfsm_fhtom(vp); | |
725 | nfsm_build(tl, u_long *, NFSX_UNSIGNED*4); | |
726 | *(tl+1) = txdr_unsigned(uiop->uio_offset); | |
727 | *(tl+3) = txdr_unsigned(len); | |
728 | nfsm_uiotom(uiop, len); | |
729 | nfsm_request(vp, NFSPROC_WRITE, uiop->uio_procp, 1); | |
730 | nfsm_loadattr(vp, (struct vattr *)0); | |
731 | m_freem(mrep); | |
732 | tsiz -= len; | |
733 | } | |
734 | nfsmout: | |
735 | return (error); | |
736 | } | |
737 | ||
738 | /* | |
739 | * nfs mknod call | |
740 | * This is a kludge. Use a create rpc but with the IFMT bits of the mode | |
741 | * set to specify the file type and the size field for rdev. | |
742 | */ | |
743 | /* ARGSUSED */ | |
744 | nfs_mknod(ndp, vap, cred, p) | |
745 | struct nameidata *ndp; | |
746 | struct ucred *cred; | |
747 | register struct vattr *vap; | |
748 | struct proc *p; | |
749 | { | |
750 | register struct nfsv2_sattr *sp; | |
751 | register u_long *tl; | |
752 | register caddr_t cp; | |
753 | register long t1, t2; | |
754 | caddr_t bpos, dpos; | |
755 | u_long xid; | |
756 | int error = 0; | |
757 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
758 | u_long rdev; | |
759 | ||
760 | if (vap->va_type == VCHR || vap->va_type == VBLK) | |
761 | rdev = txdr_unsigned(vap->va_rdev); | |
762 | #ifdef FIFO | |
763 | else if (vap->va_type == VFIFO) | |
764 | rdev = 0xffffffff; | |
765 | #endif /* FIFO */ | |
766 | else { | |
767 | VOP_ABORTOP(ndp); | |
768 | vput(ndp->ni_dvp); | |
769 | return (EOPNOTSUPP); | |
770 | } | |
771 | nfsstats.rpccnt[NFSPROC_CREATE]++; | |
772 | nfsm_reqhead(nfs_procids[NFSPROC_CREATE], ndp->ni_cred, | |
773 | NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(ndp->ni_namelen)+NFSX_SATTR); | |
774 | nfsm_fhtom(ndp->ni_dvp); | |
775 | nfsm_strtom(ndp->ni_ptr, ndp->ni_namelen, NFS_MAXNAMLEN); | |
776 | nfsm_build(sp, struct nfsv2_sattr *, NFSX_SATTR); | |
777 | sp->sa_mode = vtonfs_mode(vap->va_type, vap->va_mode); | |
778 | sp->sa_uid = txdr_unsigned(ndp->ni_cred->cr_uid); | |
779 | sp->sa_gid = txdr_unsigned(ndp->ni_cred->cr_gid); | |
780 | sp->sa_size = rdev; | |
781 | /* or should these be VNOVAL ?? */ | |
782 | txdr_time(&vap->va_atime, &sp->sa_atime); | |
783 | txdr_time(&vap->va_mtime, &sp->sa_mtime); | |
784 | nfsm_request(ndp->ni_dvp, NFSPROC_CREATE, p, 1); | |
785 | nfsm_reqdone; | |
786 | FREE(ndp->ni_pnbuf, M_NAMEI); | |
787 | VTONFS(ndp->ni_dvp)->n_flag |= NMODIFIED; | |
788 | nfs_nput(ndp->ni_dvp); | |
789 | return (error); | |
790 | } | |
791 | ||
792 | /* | |
793 | * nfs file create call | |
794 | */ | |
795 | nfs_create(ndp, vap, p) | |
796 | register struct nameidata *ndp; | |
797 | register struct vattr *vap; | |
798 | struct proc *p; | |
799 | { | |
800 | register struct nfsv2_sattr *sp; | |
801 | register u_long *tl; | |
802 | register caddr_t cp; | |
803 | register long t1, t2; | |
804 | caddr_t bpos, dpos, cp2; | |
805 | u_long xid; | |
806 | int error = 0; | |
807 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
808 | ||
809 | nfsstats.rpccnt[NFSPROC_CREATE]++; | |
810 | nfsm_reqhead(nfs_procids[NFSPROC_CREATE], ndp->ni_cred, | |
811 | NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(ndp->ni_namelen)+NFSX_SATTR); | |
812 | nfsm_fhtom(ndp->ni_dvp); | |
813 | nfsm_strtom(ndp->ni_ptr, ndp->ni_namelen, NFS_MAXNAMLEN); | |
814 | nfsm_build(sp, struct nfsv2_sattr *, NFSX_SATTR); | |
815 | sp->sa_mode = vtonfs_mode(vap->va_type, vap->va_mode); | |
816 | sp->sa_uid = txdr_unsigned(ndp->ni_cred->cr_uid); | |
817 | sp->sa_gid = txdr_unsigned(ndp->ni_cred->cr_gid); | |
818 | sp->sa_size = txdr_unsigned(0); | |
819 | /* or should these be VNOVAL ?? */ | |
820 | txdr_time(&vap->va_atime, &sp->sa_atime); | |
821 | txdr_time(&vap->va_mtime, &sp->sa_mtime); | |
822 | nfsm_request(ndp->ni_dvp, NFSPROC_CREATE, p, 1); | |
823 | nfsm_mtofh(ndp->ni_dvp, ndp->ni_vp); | |
824 | nfsm_reqdone; | |
825 | FREE(ndp->ni_pnbuf, M_NAMEI); | |
826 | VTONFS(ndp->ni_dvp)->n_flag |= NMODIFIED; | |
827 | nfs_nput(ndp->ni_dvp); | |
828 | return (error); | |
829 | } | |
830 | ||
831 | /* | |
832 | * nfs file remove call | |
833 | * To try and make nfs semantics closer to ufs semantics, a file that has | |
834 | * other processes using the vnode is renamed instead of removed and then | |
835 | * removed later on the last close. | |
836 | * - If v_usecount > 1 | |
837 | * If a rename is not already in the works | |
838 | * call nfs_sillyrename() to set it up | |
839 | * else | |
840 | * do the remove rpc | |
841 | */ | |
842 | nfs_remove(ndp, p) | |
843 | register struct nameidata *ndp; | |
844 | struct proc *p; | |
845 | { | |
846 | register struct vnode *vp = ndp->ni_vp; | |
847 | register struct nfsnode *np = VTONFS(ndp->ni_vp); | |
848 | register u_long *tl; | |
849 | register caddr_t cp; | |
850 | register long t1, t2; | |
851 | caddr_t bpos, dpos; | |
852 | u_long xid; | |
853 | int error = 0; | |
854 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
855 | ||
856 | if (vp->v_usecount > 1) { | |
857 | if (!np->n_sillyrename) | |
858 | error = nfs_sillyrename(ndp, p); | |
859 | } else { | |
860 | nfsstats.rpccnt[NFSPROC_REMOVE]++; | |
861 | nfsm_reqhead(nfs_procids[NFSPROC_REMOVE], ndp->ni_cred, | |
862 | NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(ndp->ni_namelen)); | |
863 | nfsm_fhtom(ndp->ni_dvp); | |
864 | nfsm_strtom(ndp->ni_ptr, ndp->ni_namelen, NFS_MAXNAMLEN); | |
865 | nfsm_request(ndp->ni_dvp, NFSPROC_REMOVE, p, 1); | |
866 | nfsm_reqdone; | |
867 | FREE(ndp->ni_pnbuf, M_NAMEI); | |
868 | VTONFS(ndp->ni_dvp)->n_flag |= NMODIFIED; | |
869 | /* | |
870 | * Kludge City: If the first reply to the remove rpc is lost.. | |
871 | * the reply to the retransmitted request will be ENOENT | |
872 | * since the file was in fact removed | |
873 | * Therefore, we cheat and return success. | |
874 | */ | |
875 | if (error == ENOENT) | |
876 | error = 0; | |
877 | } | |
878 | np->n_attrstamp = 0; | |
879 | if (ndp->ni_dvp == vp) | |
880 | vrele(vp); | |
881 | else | |
882 | nfs_nput(ndp->ni_dvp); | |
883 | nfs_nput(vp); | |
884 | return (error); | |
885 | } | |
886 | ||
887 | /* | |
888 | * nfs file remove rpc called from nfs_inactive | |
889 | */ | |
890 | nfs_removeit(sp, p) | |
891 | register struct sillyrename *sp; | |
892 | struct proc *p; | |
893 | { | |
894 | register u_long *tl; | |
895 | register caddr_t cp; | |
896 | register long t1, t2; | |
897 | caddr_t bpos, dpos; | |
898 | u_long xid; | |
899 | int error = 0; | |
900 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
901 | ||
902 | nfsstats.rpccnt[NFSPROC_REMOVE]++; | |
903 | nfsm_reqhead(nfs_procids[NFSPROC_REMOVE], sp->s_cred, | |
904 | NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(sp->s_namlen)); | |
905 | nfsm_fhtom(sp->s_dvp); | |
906 | nfsm_strtom(sp->s_name, sp->s_namlen, NFS_MAXNAMLEN); | |
907 | nfsm_request(sp->s_dvp, NFSPROC_REMOVE, p, 1); | |
908 | nfsm_reqdone; | |
909 | VTONFS(sp->s_dvp)->n_flag |= NMODIFIED; | |
910 | return (error); | |
911 | } | |
912 | ||
913 | /* | |
914 | * nfs file rename call | |
915 | */ | |
916 | nfs_rename(sndp, tndp, p) | |
917 | register struct nameidata *sndp, *tndp; | |
918 | struct proc *p; | |
919 | { | |
920 | register u_long *tl; | |
921 | register caddr_t cp; | |
922 | register long t1, t2; | |
923 | caddr_t bpos, dpos; | |
924 | u_long xid; | |
925 | int error = 0; | |
926 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
927 | ||
928 | nfsstats.rpccnt[NFSPROC_RENAME]++; | |
929 | nfsm_reqhead(nfs_procids[NFSPROC_RENAME], tndp->ni_cred, | |
930 | (NFSX_FH+NFSX_UNSIGNED)*2+nfsm_rndup(sndp->ni_namelen) + | |
931 | nfsm_rndup(tndp->ni_namelen)); /* or sndp->ni_cred?*/ | |
932 | nfsm_fhtom(sndp->ni_dvp); | |
933 | nfsm_strtom(sndp->ni_ptr, sndp->ni_namelen, NFS_MAXNAMLEN); | |
934 | nfsm_fhtom(tndp->ni_dvp); | |
935 | nfsm_strtom(tndp->ni_ptr, tndp->ni_namelen, NFS_MAXNAMLEN); | |
936 | nfsm_request(sndp->ni_dvp, NFSPROC_RENAME, p, 1); | |
937 | nfsm_reqdone; | |
938 | VTONFS(sndp->ni_dvp)->n_flag |= NMODIFIED; | |
939 | VTONFS(tndp->ni_dvp)->n_flag |= NMODIFIED; | |
940 | if (sndp->ni_vp->v_type == VDIR) { | |
941 | if (tndp->ni_vp != NULL && tndp->ni_vp->v_type == VDIR) | |
942 | cache_purge(tndp->ni_dvp); | |
943 | cache_purge(sndp->ni_dvp); | |
944 | } | |
945 | if (tndp->ni_dvp == tndp->ni_vp) | |
946 | vrele(tndp->ni_dvp); | |
947 | else | |
948 | vput(tndp->ni_dvp); | |
949 | if (tndp->ni_vp) | |
950 | vput(tndp->ni_vp); | |
951 | vrele(sndp->ni_dvp); | |
952 | vrele(sndp->ni_vp); | |
953 | /* | |
954 | * Kludge: Map ENOENT => 0 assuming that it is a reply to a retry. | |
955 | */ | |
956 | if (error == ENOENT) | |
957 | error = 0; | |
958 | return (error); | |
959 | } | |
960 | ||
961 | /* | |
962 | * nfs file rename rpc called from nfs_remove() above | |
963 | */ | |
964 | nfs_renameit(sndp, sp, p) | |
965 | register struct nameidata *sndp; | |
966 | register struct sillyrename *sp; | |
967 | struct proc *p; | |
968 | { | |
969 | register u_long *tl; | |
970 | register caddr_t cp; | |
971 | register long t1, t2; | |
972 | caddr_t bpos, dpos; | |
973 | u_long xid; | |
974 | int error = 0; | |
975 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
976 | ||
977 | nfsstats.rpccnt[NFSPROC_RENAME]++; | |
978 | nfsm_reqhead(nfs_procids[NFSPROC_RENAME], sp->s_cred, | |
979 | (NFSX_FH+NFSX_UNSIGNED)*2+nfsm_rndup(sndp->ni_namelen) + | |
980 | nfsm_rndup(sp->s_namlen)); /* or sndp->ni_cred?*/ | |
981 | nfsm_fhtom(sndp->ni_dvp); | |
982 | nfsm_strtom(sndp->ni_ptr, sndp->ni_namelen, NFS_MAXNAMLEN); | |
983 | nfsm_fhtom(sp->s_dvp); | |
984 | nfsm_strtom(sp->s_name, sp->s_namlen, NFS_MAXNAMLEN); | |
985 | nfsm_request(sndp->ni_dvp, NFSPROC_RENAME, p, 1); | |
986 | nfsm_reqdone; | |
987 | FREE(sndp->ni_pnbuf, M_NAMEI); | |
988 | VTONFS(sndp->ni_dvp)->n_flag |= NMODIFIED; | |
989 | VTONFS(sp->s_dvp)->n_flag |= NMODIFIED; | |
990 | return (error); | |
991 | } | |
992 | ||
993 | /* | |
994 | * nfs hard link create call | |
995 | */ | |
996 | nfs_link(vp, ndp, p) | |
997 | register struct vnode *vp; | |
998 | register struct nameidata *ndp; | |
999 | struct proc *p; | |
1000 | { | |
1001 | register u_long *tl; | |
1002 | register caddr_t cp; | |
1003 | register long t1, t2; | |
1004 | caddr_t bpos, dpos; | |
1005 | u_long xid; | |
1006 | int error = 0; | |
1007 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
1008 | ||
1009 | if (ndp->ni_dvp != vp) | |
1010 | nfs_lock(vp); | |
1011 | nfsstats.rpccnt[NFSPROC_LINK]++; | |
1012 | nfsm_reqhead(nfs_procids[NFSPROC_LINK], ndp->ni_cred, | |
1013 | NFSX_FH*2+NFSX_UNSIGNED+nfsm_rndup(ndp->ni_namelen)); | |
1014 | nfsm_fhtom(vp); | |
1015 | nfsm_fhtom(ndp->ni_dvp); | |
1016 | nfsm_strtom(ndp->ni_ptr, ndp->ni_namelen, NFS_MAXNAMLEN); | |
1017 | nfsm_request(vp, NFSPROC_LINK, p, 1); | |
1018 | nfsm_reqdone; | |
1019 | FREE(ndp->ni_pnbuf, M_NAMEI); | |
1020 | VTONFS(vp)->n_attrstamp = 0; | |
1021 | VTONFS(ndp->ni_dvp)->n_flag |= NMODIFIED; | |
1022 | if (ndp->ni_dvp != vp) | |
1023 | nfs_unlock(vp); | |
1024 | nfs_nput(ndp->ni_dvp); | |
1025 | /* | |
1026 | * Kludge: Map EEXIST => 0 assuming that it is a reply to a retry. | |
1027 | */ | |
1028 | if (error == EEXIST) | |
1029 | error = 0; | |
1030 | return (error); | |
1031 | } | |
1032 | ||
1033 | /* | |
1034 | * nfs symbolic link create call | |
1035 | */ | |
1036 | nfs_symlink(ndp, vap, nm, p) | |
1037 | struct nameidata *ndp; | |
1038 | struct vattr *vap; | |
1039 | char *nm; /* is this the path ?? */ | |
1040 | struct proc *p; | |
1041 | { | |
1042 | register struct nfsv2_sattr *sp; | |
1043 | register u_long *tl; | |
1044 | register caddr_t cp; | |
1045 | register long t1, t2; | |
1046 | caddr_t bpos, dpos; | |
1047 | u_long xid; | |
1048 | int error = 0; | |
1049 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
1050 | ||
1051 | nfsstats.rpccnt[NFSPROC_SYMLINK]++; | |
1052 | nfsm_reqhead(nfs_procids[NFSPROC_SYMLINK], ndp->ni_cred, | |
1053 | NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(ndp->ni_namelen)+NFSX_UNSIGNED); | |
1054 | nfsm_fhtom(ndp->ni_dvp); | |
1055 | nfsm_strtom(ndp->ni_ptr, ndp->ni_namelen, NFS_MAXNAMLEN); | |
1056 | nfsm_strtom(nm, strlen(nm), NFS_MAXPATHLEN); | |
1057 | nfsm_build(sp, struct nfsv2_sattr *, NFSX_SATTR); | |
1058 | sp->sa_mode = vtonfs_mode(VLNK, vap->va_mode); | |
1059 | sp->sa_uid = txdr_unsigned(ndp->ni_cred->cr_uid); | |
1060 | sp->sa_gid = txdr_unsigned(ndp->ni_cred->cr_gid); | |
1061 | sp->sa_size = txdr_unsigned(VNOVAL); | |
1062 | txdr_time(&vap->va_atime, &sp->sa_atime); /* or VNOVAL ?? */ | |
1063 | txdr_time(&vap->va_mtime, &sp->sa_mtime); /* or VNOVAL ?? */ | |
1064 | nfsm_request(ndp->ni_dvp, NFSPROC_SYMLINK, p, 1); | |
1065 | nfsm_reqdone; | |
1066 | FREE(ndp->ni_pnbuf, M_NAMEI); | |
1067 | VTONFS(ndp->ni_dvp)->n_flag |= NMODIFIED; | |
1068 | nfs_nput(ndp->ni_dvp); | |
1069 | /* | |
1070 | * Kludge: Map EEXIST => 0 assuming that it is a reply to a retry. | |
1071 | */ | |
1072 | if (error == EEXIST) | |
1073 | error = 0; | |
1074 | return (error); | |
1075 | } | |
1076 | ||
1077 | /* | |
1078 | * nfs make dir call | |
1079 | */ | |
1080 | nfs_mkdir(ndp, vap, p) | |
1081 | register struct nameidata *ndp; | |
1082 | struct vattr *vap; | |
1083 | struct proc *p; | |
1084 | { | |
1085 | register struct nfsv2_sattr *sp; | |
1086 | register u_long *tl; | |
1087 | register caddr_t cp; | |
1088 | register long t1, t2; | |
1089 | register int len; | |
1090 | caddr_t bpos, dpos, cp2; | |
1091 | u_long xid; | |
1092 | int error = 0, firsttry = 1; | |
1093 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
1094 | ||
1095 | len = ndp->ni_namelen; | |
1096 | nfsstats.rpccnt[NFSPROC_MKDIR]++; | |
1097 | nfsm_reqhead(nfs_procids[NFSPROC_MKDIR], ndp->ni_cred, | |
1098 | NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(len)+NFSX_SATTR); | |
1099 | nfsm_fhtom(ndp->ni_dvp); | |
1100 | nfsm_strtom(ndp->ni_ptr, len, NFS_MAXNAMLEN); | |
1101 | nfsm_build(sp, struct nfsv2_sattr *, NFSX_SATTR); | |
1102 | sp->sa_mode = vtonfs_mode(VDIR, vap->va_mode); | |
1103 | sp->sa_uid = txdr_unsigned(ndp->ni_cred->cr_uid); | |
1104 | sp->sa_gid = txdr_unsigned(ndp->ni_cred->cr_gid); | |
1105 | sp->sa_size = txdr_unsigned(VNOVAL); | |
1106 | txdr_time(&vap->va_atime, &sp->sa_atime); /* or VNOVAL ?? */ | |
1107 | txdr_time(&vap->va_mtime, &sp->sa_mtime); /* or VNOVAL ?? */ | |
1108 | nfsm_request(ndp->ni_dvp, NFSPROC_MKDIR, p, 1); | |
1109 | nfsm_mtofh(ndp->ni_dvp, ndp->ni_vp); | |
1110 | nfsm_reqdone; | |
1111 | VTONFS(ndp->ni_dvp)->n_flag |= NMODIFIED; | |
1112 | /* | |
1113 | * Kludge: Map EEXIST => 0 assuming that you have a reply to a retry | |
1114 | * if we can succeed in looking up the directory. | |
1115 | * "firsttry" is necessary since the macros may "goto nfsmout" which | |
1116 | * is above the if on errors. (Ugh) | |
1117 | */ | |
1118 | if (error == EEXIST && firsttry) { | |
1119 | firsttry = 0; | |
1120 | error = 0; | |
1121 | nfsstats.rpccnt[NFSPROC_LOOKUP]++; | |
1122 | ndp->ni_vp = NULL; | |
1123 | nfsm_reqhead(nfs_procids[NFSPROC_LOOKUP], ndp->ni_cred, | |
1124 | NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(len)); | |
1125 | nfsm_fhtom(ndp->ni_dvp); | |
1126 | nfsm_strtom(ndp->ni_ptr, len, NFS_MAXNAMLEN); | |
1127 | nfsm_request(ndp->ni_dvp, NFSPROC_LOOKUP, p, 1); | |
1128 | nfsm_mtofh(ndp->ni_dvp, ndp->ni_vp); | |
1129 | if (ndp->ni_vp->v_type != VDIR) { | |
1130 | vput(ndp->ni_vp); | |
1131 | error = EEXIST; | |
1132 | } | |
1133 | m_freem(mrep); | |
1134 | } | |
1135 | FREE(ndp->ni_pnbuf, M_NAMEI); | |
1136 | nfs_nput(ndp->ni_dvp); | |
1137 | return (error); | |
1138 | } | |
1139 | ||
1140 | /* | |
1141 | * nfs remove directory call | |
1142 | */ | |
1143 | nfs_rmdir(ndp, p) | |
1144 | register struct nameidata *ndp; | |
1145 | struct proc *p; | |
1146 | { | |
1147 | register u_long *tl; | |
1148 | register caddr_t cp; | |
1149 | register long t1, t2; | |
1150 | caddr_t bpos, dpos; | |
1151 | u_long xid; | |
1152 | int error = 0; | |
1153 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
1154 | ||
1155 | if (ndp->ni_dvp == ndp->ni_vp) { | |
1156 | vrele(ndp->ni_dvp); | |
1157 | nfs_nput(ndp->ni_dvp); | |
1158 | return (EINVAL); | |
1159 | } | |
1160 | nfsstats.rpccnt[NFSPROC_RMDIR]++; | |
1161 | nfsm_reqhead(nfs_procids[NFSPROC_RMDIR], ndp->ni_cred, | |
1162 | NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(ndp->ni_namelen)); | |
1163 | nfsm_fhtom(ndp->ni_dvp); | |
1164 | nfsm_strtom(ndp->ni_ptr, ndp->ni_namelen, NFS_MAXNAMLEN); | |
1165 | nfsm_request(ndp->ni_dvp, NFSPROC_RMDIR, p, 1); | |
1166 | nfsm_reqdone; | |
1167 | FREE(ndp->ni_pnbuf, M_NAMEI); | |
1168 | VTONFS(ndp->ni_dvp)->n_flag |= NMODIFIED; | |
1169 | cache_purge(ndp->ni_dvp); | |
1170 | cache_purge(ndp->ni_vp); | |
1171 | nfs_nput(ndp->ni_vp); | |
1172 | nfs_nput(ndp->ni_dvp); | |
1173 | /* | |
1174 | * Kludge: Map ENOENT => 0 assuming that you have a reply to a retry. | |
1175 | */ | |
1176 | if (error == ENOENT) | |
1177 | error = 0; | |
1178 | return (error); | |
1179 | } | |
1180 | ||
1181 | /* | |
1182 | * nfs readdir call | |
1183 | * Although cookie is defined as opaque, I translate it to/from net byte | |
1184 | * order so that it looks more sensible. This appears consistent with the | |
1185 | * Ultrix implementation of NFS. | |
1186 | */ | |
1187 | nfs_readdir(vp, uiop, cred, eofflagp) | |
1188 | register struct vnode *vp; | |
1189 | struct uio *uiop; | |
1190 | struct ucred *cred; | |
1191 | int *eofflagp; | |
1192 | { | |
1193 | register struct nfsnode *np = VTONFS(vp); | |
1194 | int tresid, error; | |
1195 | struct vattr vattr; | |
1196 | ||
1197 | if (vp->v_type != VDIR) | |
1198 | return (EPERM); | |
1199 | /* | |
1200 | * First, check for hit on the EOF offset cache | |
1201 | */ | |
1202 | if (uiop->uio_offset != 0 && uiop->uio_offset == np->n_direofoffset && | |
1203 | (np->n_flag & NMODIFIED) == 0 && | |
1204 | nfs_dogetattr(vp, &vattr, cred, 0, uiop->uio_procp) == 0 && | |
1205 | np->n_mtime == vattr.va_mtime.tv_sec) { | |
1206 | *eofflagp = 1; | |
1207 | nfsstats.direofcache_hits++; | |
1208 | return (0); | |
1209 | } | |
1210 | ||
1211 | /* | |
1212 | * Call nfs_bioread() to do the real work. | |
1213 | */ | |
1214 | tresid = uiop->uio_resid; | |
1215 | error = nfs_bioread(vp, uiop, 0, cred); | |
1216 | ||
1217 | if (!error && uiop->uio_resid == tresid) { | |
1218 | *eofflagp = 1; | |
1219 | nfsstats.direofcache_misses++; | |
1220 | } else | |
1221 | *eofflagp = 0; | |
1222 | return (error); | |
1223 | } | |
1224 | ||
1225 | /* | |
1226 | * Readdir rpc call. | |
1227 | * Called from below the buffer cache by nfs_doio(). | |
1228 | */ | |
1229 | nfs_readdirrpc(vp, uiop, cred) | |
1230 | register struct vnode *vp; | |
1231 | struct uio *uiop; | |
1232 | struct ucred *cred; | |
1233 | { | |
1234 | register long len; | |
1235 | register struct direct *dp; | |
1236 | register u_long *tl; | |
1237 | register caddr_t cp; | |
1238 | register long t1; | |
1239 | long tlen, lastlen; | |
1240 | caddr_t bpos, dpos, cp2; | |
1241 | u_long xid; | |
1242 | int error = 0; | |
1243 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
1244 | struct mbuf *md2; | |
1245 | caddr_t dpos2; | |
1246 | int siz; | |
1247 | int more_dirs = 1; | |
1248 | off_t off, savoff; | |
1249 | struct direct *savdp; | |
1250 | struct nfsmount *nmp; | |
1251 | struct nfsnode *np = VTONFS(vp); | |
1252 | long tresid; | |
1253 | ||
1254 | nmp = VFSTONFS(vp->v_mount); | |
1255 | tresid = uiop->uio_resid; | |
1256 | /* | |
1257 | * Loop around doing readdir rpc's of size uio_resid or nm_rsize, | |
1258 | * whichever is smaller, truncated to a multiple of NFS_DIRBLKSIZ. | |
1259 | * The stopping criteria is EOF or buffer full. | |
1260 | */ | |
1261 | while (more_dirs && uiop->uio_resid >= NFS_DIRBLKSIZ) { | |
1262 | nfsstats.rpccnt[NFSPROC_READDIR]++; | |
1263 | nfsm_reqhead(nfs_procids[NFSPROC_READDIR], cred, xid); | |
1264 | nfsm_fhtom(vp); | |
1265 | nfsm_build(tl, u_long *, 2*NFSX_UNSIGNED); | |
1266 | *tl++ = txdr_unsigned(uiop->uio_offset); | |
1267 | *tl = txdr_unsigned(((uiop->uio_resid > nmp->nm_rsize) ? | |
1268 | nmp->nm_rsize : uiop->uio_resid) & ~(NFS_DIRBLKSIZ-1)); | |
1269 | nfsm_request(vp, NFSPROC_READDIR, uiop->uio_procp, 0); | |
1270 | siz = 0; | |
1271 | nfsm_disect(tl, u_long *, NFSX_UNSIGNED); | |
1272 | more_dirs = fxdr_unsigned(int, *tl); | |
1273 | ||
1274 | /* Save the position so that we can do nfsm_mtouio() later */ | |
1275 | dpos2 = dpos; | |
1276 | md2 = md; | |
1277 | ||
1278 | /* loop thru the dir entries, doctoring them to 4bsd form */ | |
1279 | off = uiop->uio_offset; | |
1280 | #ifdef lint | |
1281 | dp = (struct direct *)0; | |
1282 | #endif /* lint */ | |
1283 | while (more_dirs && siz < uiop->uio_resid) { | |
1284 | savoff = off; /* Hold onto offset and dp */ | |
1285 | savdp = dp; | |
1286 | nfsm_disecton(tl, u_long *, 2*NFSX_UNSIGNED); | |
1287 | dp = (struct direct *)tl; | |
1288 | dp->d_ino = fxdr_unsigned(u_long, *tl++); | |
1289 | len = fxdr_unsigned(int, *tl); | |
1290 | if (len <= 0 || len > NFS_MAXNAMLEN) { | |
1291 | error = EBADRPC; | |
1292 | m_freem(mrep); | |
1293 | goto nfsmout; | |
1294 | } | |
1295 | dp->d_namlen = (u_short)len; | |
1296 | nfsm_adv(len); /* Point past name */ | |
1297 | tlen = nfsm_rndup(len); | |
1298 | /* | |
1299 | * This should not be necessary, but some servers have | |
1300 | * broken XDR such that these bytes are not null filled. | |
1301 | */ | |
1302 | if (tlen != len) { | |
1303 | *dpos = '\0'; /* Null-terminate */ | |
1304 | nfsm_adv(tlen - len); | |
1305 | len = tlen; | |
1306 | } | |
1307 | nfsm_disecton(tl, u_long *, 2*NFSX_UNSIGNED); | |
1308 | off = fxdr_unsigned(off_t, *tl); | |
1309 | *tl++ = 0; /* Ensures null termination of name */ | |
1310 | more_dirs = fxdr_unsigned(int, *tl); | |
1311 | dp->d_reclen = len+4*NFSX_UNSIGNED; | |
1312 | siz += dp->d_reclen; | |
1313 | } | |
1314 | /* | |
1315 | * If at end of rpc data, get the eof boolean | |
1316 | */ | |
1317 | if (!more_dirs) { | |
1318 | nfsm_disecton(tl, u_long *, NFSX_UNSIGNED); | |
1319 | more_dirs = (fxdr_unsigned(int, *tl) == 0); | |
1320 | ||
1321 | /* | |
1322 | * If at EOF, cache directory offset | |
1323 | */ | |
1324 | if (!more_dirs) | |
1325 | np->n_direofoffset = off; | |
1326 | } | |
1327 | /* | |
1328 | * If there is too much to fit in the data buffer, use savoff and | |
1329 | * savdp to trim off the last record. | |
1330 | * --> we are not at eof | |
1331 | */ | |
1332 | if (siz > uiop->uio_resid) { | |
1333 | off = savoff; | |
1334 | siz -= dp->d_reclen; | |
1335 | dp = savdp; | |
1336 | more_dirs = 0; /* Paranoia */ | |
1337 | } | |
1338 | if (siz > 0) { | |
1339 | lastlen = dp->d_reclen; | |
1340 | md = md2; | |
1341 | dpos = dpos2; | |
1342 | nfsm_mtouio(uiop, siz); | |
1343 | uiop->uio_offset = off; | |
1344 | } else | |
1345 | more_dirs = 0; /* Ugh, never happens, but in case.. */ | |
1346 | m_freem(mrep); | |
1347 | } | |
1348 | /* | |
1349 | * Fill last record, iff any, out to a multiple of NFS_DIRBLKSIZ | |
1350 | * by increasing d_reclen for the last record. | |
1351 | */ | |
1352 | if (uiop->uio_resid < tresid) { | |
1353 | len = uiop->uio_resid & (NFS_DIRBLKSIZ - 1); | |
1354 | if (len > 0) { | |
1355 | dp = (struct direct *) | |
1356 | (uiop->uio_iov->iov_base - lastlen); | |
1357 | dp->d_reclen += len; | |
1358 | uiop->uio_iov->iov_base += len; | |
1359 | uiop->uio_iov->iov_len -= len; | |
1360 | uiop->uio_resid -= len; | |
1361 | } | |
1362 | } | |
1363 | nfsmout: | |
1364 | return (error); | |
1365 | } | |
1366 | ||
1367 | static char hextoasc[] = "0123456789abcdef"; | |
1368 | ||
1369 | /* | |
1370 | * Silly rename. To make the NFS filesystem that is stateless look a little | |
1371 | * more like the "ufs" a remove of an active vnode is translated to a rename | |
1372 | * to a funny looking filename that is removed by nfs_inactive on the | |
1373 | * nfsnode. There is the potential for another process on a different client | |
1374 | * to create the same funny name between the nfs_lookitup() fails and the | |
1375 | * nfs_rename() completes, but... | |
1376 | */ | |
1377 | nfs_sillyrename(ndp, p) | |
1378 | register struct nameidata *ndp; | |
1379 | struct proc *p; | |
1380 | { | |
1381 | register struct nfsnode *np; | |
1382 | register struct sillyrename *sp; | |
1383 | int error; | |
1384 | short pid; | |
1385 | ||
1386 | np = VTONFS(ndp->ni_dvp); | |
1387 | cache_purge(ndp->ni_dvp); | |
1388 | MALLOC(sp, struct sillyrename *, sizeof (struct sillyrename), | |
1389 | M_NFSREQ, M_WAITOK); | |
1390 | bcopy((caddr_t)&np->n_fh, (caddr_t)&sp->s_fh, NFSX_FH); | |
1391 | np = VTONFS(ndp->ni_vp); | |
1392 | sp->s_cred = crdup(ndp->ni_cred); | |
1393 | sp->s_dvp = ndp->ni_dvp; | |
1394 | VREF(sp->s_dvp); | |
1395 | ||
1396 | /* Fudge together a funny name */ | |
1397 | pid = p->p_pid; | |
1398 | bcopy(".nfsAxxxx4.4", sp->s_name, 13); | |
1399 | sp->s_namlen = 12; | |
1400 | sp->s_name[8] = hextoasc[pid & 0xf]; | |
1401 | sp->s_name[7] = hextoasc[(pid >> 4) & 0xf]; | |
1402 | sp->s_name[6] = hextoasc[(pid >> 8) & 0xf]; | |
1403 | sp->s_name[5] = hextoasc[(pid >> 12) & 0xf]; | |
1404 | ||
1405 | /* Try lookitups until we get one that isn't there */ | |
1406 | while (nfs_lookitup(sp, (nfsv2fh_t *)0, p) == 0) { | |
1407 | sp->s_name[4]++; | |
1408 | if (sp->s_name[4] > 'z') { | |
1409 | error = EINVAL; | |
1410 | goto bad; | |
1411 | } | |
1412 | } | |
1413 | if (error = nfs_renameit(ndp, sp, p)) | |
1414 | goto bad; | |
1415 | nfs_lookitup(sp, &np->n_fh, p); | |
1416 | np->n_sillyrename = sp; | |
1417 | return (0); | |
1418 | bad: | |
1419 | vrele(sp->s_dvp); | |
1420 | crfree(sp->s_cred); | |
1421 | free((caddr_t)sp, M_NFSREQ); | |
1422 | return (error); | |
1423 | } | |
1424 | ||
1425 | /* | |
1426 | * Look up a file name for silly rename stuff. | |
1427 | * Just like nfs_lookup() except that it doesn't load returned values | |
1428 | * into the nfsnode table. | |
1429 | * If fhp != NULL it copies the returned file handle out | |
1430 | */ | |
1431 | nfs_lookitup(sp, fhp, p) | |
1432 | register struct sillyrename *sp; | |
1433 | nfsv2fh_t *fhp; | |
1434 | struct proc *p; | |
1435 | { | |
1436 | register struct vnode *vp = sp->s_dvp; | |
1437 | register u_long *tl; | |
1438 | register caddr_t cp; | |
1439 | register long t1, t2; | |
1440 | caddr_t bpos, dpos, cp2; | |
1441 | u_long xid; | |
1442 | int error = 0; | |
1443 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
1444 | long len; | |
1445 | ||
1446 | nfsstats.rpccnt[NFSPROC_LOOKUP]++; | |
1447 | len = sp->s_namlen; | |
1448 | nfsm_reqhead(nfs_procids[NFSPROC_LOOKUP], sp->s_cred, NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(len)); | |
1449 | nfsm_fhtom(vp); | |
1450 | nfsm_strtom(sp->s_name, len, NFS_MAXNAMLEN); | |
1451 | nfsm_request(vp, NFSPROC_LOOKUP, p, 1); | |
1452 | if (fhp != NULL) { | |
1453 | nfsm_disect(cp, caddr_t, NFSX_FH); | |
1454 | bcopy(cp, (caddr_t)fhp, NFSX_FH); | |
1455 | } | |
1456 | nfsm_reqdone; | |
1457 | return (error); | |
1458 | } | |
1459 | ||
1460 | /* | |
1461 | * Kludge City.. | |
1462 | * - make nfs_bmap() essentially a no-op that does no translation | |
1463 | * - do nfs_strategy() by faking physical I/O with nfs_readrpc/nfs_writerpc | |
1464 | * after mapping the physical addresses into Kernel Virtual space in the | |
1465 | * nfsiobuf area. | |
1466 | * (Maybe I could use the process's page mapping, but I was concerned that | |
1467 | * Kernel Write might not be enabled and also figured copyout() would do | |
1468 | * a lot more work than bcopy() and also it currently happens in the | |
1469 | * context of the swapper process (2). | |
1470 | */ | |
1471 | nfs_bmap(vp, bn, vpp, bnp) | |
1472 | struct vnode *vp; | |
1473 | daddr_t bn; | |
1474 | struct vnode **vpp; | |
1475 | daddr_t *bnp; | |
1476 | { | |
1477 | if (vpp != NULL) | |
1478 | *vpp = vp; | |
1479 | if (bnp != NULL) | |
1480 | *bnp = bn * btodb(vp->v_mount->mnt_stat.f_bsize); | |
1481 | return (0); | |
1482 | } | |
1483 | ||
1484 | /* | |
1485 | * Strategy routine for phys. i/o | |
1486 | * If the biod's are running, queue a request | |
1487 | * otherwise just call nfs_doio() to get it done | |
1488 | */ | |
1489 | nfs_strategy(bp) | |
1490 | register struct buf *bp; | |
1491 | { | |
1492 | register struct buf *dp; | |
1493 | register int i; | |
1494 | int error = 0; | |
1495 | int fnd = 0; | |
1496 | ||
1497 | /* | |
1498 | * Set b_proc. It seems a bit silly to do it here, but since bread() | |
1499 | * doesn't set it, I will. | |
1500 | * Set b_proc == NULL for asynchronous ops, since these may still | |
1501 | * be hanging about after the process terminates. | |
1502 | */ | |
1503 | if ((bp->b_flags & B_PHYS) == 0) { | |
1504 | if (bp->b_flags & B_ASYNC) | |
1505 | bp->b_proc = (struct proc *)0; | |
1506 | else | |
1507 | bp->b_proc = curproc; | |
1508 | } | |
1509 | /* | |
1510 | * If the op is asynchronous and an i/o daemon is waiting | |
1511 | * queue the request, wake it up and wait for completion | |
1512 | * otherwise just do it ourselves. | |
1513 | */ | |
1514 | if ((bp->b_flags & B_ASYNC) == 0 || nfs_numasync == 0) | |
1515 | return (nfs_doio(bp)); | |
1516 | for (i = 0; i < NFS_MAXASYNCDAEMON; i++) { | |
1517 | if (nfs_iodwant[i]) { | |
1518 | dp = &nfs_bqueue; | |
1519 | if (dp->b_actf == NULL) { | |
1520 | dp->b_actl = bp; | |
1521 | bp->b_actf = dp; | |
1522 | } else { | |
1523 | dp->b_actf->b_actl = bp; | |
1524 | bp->b_actf = dp->b_actf; | |
1525 | } | |
1526 | dp->b_actf = bp; | |
1527 | bp->b_actl = dp; | |
1528 | fnd++; | |
1529 | wakeup((caddr_t)&nfs_iodwant[i]); | |
1530 | break; | |
1531 | } | |
1532 | } | |
1533 | if (!fnd) | |
1534 | error = nfs_doio(bp); | |
1535 | return (error); | |
1536 | } | |
1537 | ||
1538 | /* | |
1539 | * Fun and games with i/o | |
1540 | * Essentially play ubasetup() and disk interrupt service routine by | |
1541 | * mapping the data buffer into kernel virtual space and doing the | |
1542 | * nfs read or write rpc's from it. | |
1543 | * If the nfsiod's are not running, this is just called from nfs_strategy(), | |
1544 | * otherwise it is called by the nfsiods to do what would normally be | |
1545 | * partially disk interrupt driven. | |
1546 | */ | |
1547 | nfs_doio(bp) | |
1548 | register struct buf *bp; | |
1549 | { | |
1550 | register struct uio *uiop; | |
1551 | register struct vnode *vp; | |
1552 | struct nfsnode *np; | |
1553 | struct ucred *cr; | |
1554 | int error; | |
1555 | struct uio uio; | |
1556 | struct iovec io; | |
1557 | #if !defined(hp300) && !defined(i386) | |
1558 | register struct pte *pte, *ppte; | |
1559 | register caddr_t vaddr; | |
1560 | int npf, npf2; | |
1561 | int reg, o; | |
1562 | caddr_t vbase; | |
1563 | unsigned v; | |
1564 | #endif | |
1565 | ||
1566 | vp = bp->b_vp; | |
1567 | np = VTONFS(vp); | |
1568 | uiop = &uio; | |
1569 | uiop->uio_iov = &io; | |
1570 | uiop->uio_iovcnt = 1; | |
1571 | uiop->uio_segflg = UIO_SYSSPACE; | |
1572 | uiop->uio_procp = (struct proc *)0; | |
1573 | ||
1574 | /* | |
1575 | * For phys i/o, map the b_addr into kernel virtual space using | |
1576 | * the Nfsiomap pte's | |
1577 | * Also, add a temporary b_rcred for reading using the process's uid | |
1578 | * and a guess at a group | |
1579 | */ | |
1580 | if (bp->b_flags & B_PHYS) { | |
1581 | if (bp->b_flags & B_DIRTY) | |
1582 | uiop->uio_procp = pageproc; | |
1583 | cr = crcopy(uiop->uio_procp->p_ucred); | |
1584 | /* mapping was already done by vmapbuf */ | |
1585 | io.iov_base = bp->b_un.b_addr; | |
1586 | ||
1587 | /* | |
1588 | * And do the i/o rpc | |
1589 | */ | |
1590 | io.iov_len = uiop->uio_resid = bp->b_bcount; | |
1591 | uiop->uio_offset = bp->b_blkno * DEV_BSIZE; | |
1592 | if (bp->b_flags & B_READ) { | |
1593 | uiop->uio_rw = UIO_READ; | |
1594 | nfsstats.read_physios++; | |
1595 | bp->b_error = error = nfs_readrpc(vp, uiop, cr); | |
1596 | (void) vnode_pager_uncache(vp); | |
1597 | } else { | |
1598 | uiop->uio_rw = UIO_WRITE; | |
1599 | nfsstats.write_physios++; | |
1600 | bp->b_error = error = nfs_writerpc(vp, uiop, cr); | |
1601 | } | |
1602 | ||
1603 | /* | |
1604 | * Finally, release pte's used by physical i/o | |
1605 | */ | |
1606 | crfree(cr); | |
1607 | } else { | |
1608 | if (bp->b_flags & B_READ) { | |
1609 | io.iov_len = uiop->uio_resid = bp->b_bcount; | |
1610 | io.iov_base = bp->b_un.b_addr; | |
1611 | uiop->uio_rw = UIO_READ; | |
1612 | switch (vp->v_type) { | |
1613 | case VREG: | |
1614 | uiop->uio_offset = bp->b_blkno * DEV_BSIZE; | |
1615 | nfsstats.read_bios++; | |
1616 | error = nfs_readrpc(vp, uiop, bp->b_rcred); | |
1617 | break; | |
1618 | case VLNK: | |
1619 | uiop->uio_offset = 0; | |
1620 | nfsstats.readlink_bios++; | |
1621 | error = nfs_readlinkrpc(vp, uiop, bp->b_rcred); | |
1622 | break; | |
1623 | case VDIR: | |
1624 | uiop->uio_offset = bp->b_lblkno; | |
1625 | nfsstats.readdir_bios++; | |
1626 | error = nfs_readdirrpc(vp, uiop, bp->b_rcred); | |
1627 | /* | |
1628 | * Save offset cookie in b_blkno. | |
1629 | */ | |
1630 | bp->b_blkno = uiop->uio_offset; | |
1631 | break; | |
1632 | }; | |
1633 | bp->b_error = error; | |
1634 | } else { | |
1635 | io.iov_len = uiop->uio_resid = bp->b_dirtyend | |
1636 | - bp->b_dirtyoff; | |
1637 | uiop->uio_offset = (bp->b_blkno * DEV_BSIZE) | |
1638 | + bp->b_dirtyoff; | |
1639 | io.iov_base = bp->b_un.b_addr + bp->b_dirtyoff; | |
1640 | uiop->uio_rw = UIO_WRITE; | |
1641 | nfsstats.write_bios++; | |
1642 | bp->b_error = error = nfs_writerpc(vp, uiop, | |
1643 | bp->b_wcred); | |
1644 | if (error) { | |
1645 | np->n_error = error; | |
1646 | np->n_flag |= NWRITEERR; | |
1647 | } | |
1648 | bp->b_dirtyoff = bp->b_dirtyend = 0; | |
1649 | } | |
1650 | } | |
1651 | if (error) | |
1652 | bp->b_flags |= B_ERROR; | |
1653 | bp->b_resid = uiop->uio_resid; | |
1654 | biodone(bp); | |
1655 | return (error); | |
1656 | } | |
1657 | ||
1658 | /* | |
1659 | * Mmap a file | |
1660 | * | |
1661 | * NB Currently unsupported. | |
1662 | */ | |
1663 | /* ARGSUSED */ | |
1664 | nfs_mmap(vp, fflags, cred, p) | |
1665 | struct vnode *vp; | |
1666 | int fflags; | |
1667 | struct ucred *cred; | |
1668 | struct proc *p; | |
1669 | { | |
1670 | ||
1671 | return (EINVAL); | |
1672 | } | |
1673 | ||
1674 | /* | |
1675 | * Flush all the blocks associated with a vnode. | |
1676 | * Walk through the buffer pool and push any dirty pages | |
1677 | * associated with the vnode. | |
1678 | */ | |
1679 | /* ARGSUSED */ | |
1680 | nfs_fsync(vp, fflags, cred, waitfor, p) | |
1681 | register struct vnode *vp; | |
1682 | int fflags; | |
1683 | struct ucred *cred; | |
1684 | int waitfor; | |
1685 | struct proc *p; | |
1686 | { | |
1687 | register struct nfsnode *np = VTONFS(vp); | |
1688 | int error = 0; | |
1689 | ||
1690 | if (np->n_flag & NMODIFIED) { | |
1691 | np->n_flag &= ~NMODIFIED; | |
1692 | vflushbuf(vp, waitfor == MNT_WAIT ? B_SYNC : 0); | |
1693 | } | |
1694 | if (!error && (np->n_flag & NWRITEERR)) | |
1695 | error = np->n_error; | |
1696 | return (error); | |
1697 | } | |
1698 | ||
1699 | /* | |
1700 | * NFS advisory byte-level locks. | |
1701 | * Currently unsupported. | |
1702 | */ | |
1703 | nfs_advlock(vp, id, op, fl, flags) | |
1704 | struct vnode *vp; | |
1705 | caddr_t id; | |
1706 | int op; | |
1707 | struct flock *fl; | |
1708 | int flags; | |
1709 | { | |
1710 | ||
1711 | return (EOPNOTSUPP); | |
1712 | } | |
1713 | ||
1714 | /* | |
1715 | * Print out the contents of an nfsnode. | |
1716 | */ | |
1717 | nfs_print(vp) | |
1718 | struct vnode *vp; | |
1719 | { | |
1720 | register struct nfsnode *np = VTONFS(vp); | |
1721 | ||
1722 | printf("tag VT_NFS, fileid %d fsid 0x%x", | |
1723 | np->n_vattr.va_fileid, np->n_vattr.va_fsid); | |
1724 | #ifdef FIFO | |
1725 | if (vp->v_type == VFIFO) | |
1726 | fifo_printinfo(vp); | |
1727 | #endif /* FIFO */ | |
1728 | printf("%s\n", (np->n_flag & NLOCKED) ? " (LOCKED)" : ""); | |
1729 | if (np->n_lockholder == 0) | |
1730 | return; | |
1731 | printf("\towner pid %d", np->n_lockholder); | |
1732 | if (np->n_lockwaiter) | |
1733 | printf(" waiting pid %d", np->n_lockwaiter); | |
1734 | printf("\n"); | |
1735 | } |