openafs-kill-dead-code-20050403
[openafs.git] / src / afs / FBSD / osi_vnodeops.c
1 /*
2  * A large chunk of this file appears to be copied directly from
3  * sys/nfsclient/nfs_bio.c, which has the following license:
4  */
5 /*
6  * Copyright (c) 1989, 1993
7  *      The Regents of the University of California.  All rights reserved.
8  *
9  * This code is derived from software contributed to Berkeley by
10  * Rick Macklem at The University of Guelph.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. All advertising materials mentioning features or use of this software
21  *    must display the following acknowledgement:
22  *      This product includes software developed by the University of
23  *      California, Berkeley and its contributors.
24  * 4. Neither the name of the University nor the names of its contributors
25  *    may be used to endorse or promote products derived from this software
26  *    without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38  * SUCH DAMAGE.
39  *
40  *      @(#)nfs_bio.c   8.9 (Berkeley) 3/30/95
41  */
42 /*
43  * Pursuant to a statement of U.C. Berkeley dated 1999-07-22, this license
44  * is amended to drop clause (3) above.
45  */
46
47 #include <afsconfig.h>
48 #include <afs/param.h>
49
50 RCSID
51     ("$Header$");
52
53 #include <afs/sysincludes.h>    /* Standard vendor system headers */
54 #include <afsincludes.h>        /* Afs-based standard headers */
55 #include <afs/afs_stats.h>      /* statistics */
56 #include <sys/malloc.h>
57 #include <sys/namei.h>
58 #include <sys/unistd.h>
59 #ifndef AFS_FBSD50_ENV
60 #include <vm/vm_zone.h>
61 #endif
62 #include <vm/vm_page.h>
63 #include <vm/vm_object.h>
64 #include <vm/vm_pager.h>
65 #include <vm/vnode_pager.h>
66 extern int afs_pbuf_freecnt;
67
68 int afs_vop_lookup(struct vop_lookup_args *);
69 int afs_vop_create(struct vop_create_args *);
70 int afs_vop_mknod(struct vop_mknod_args *);
71 int afs_vop_open(struct vop_open_args *);
72 int afs_vop_close(struct vop_close_args *);
73 int afs_vop_access(struct vop_access_args *);
74 int afs_vop_getattr(struct vop_getattr_args *);
75 int afs_vop_setattr(struct vop_setattr_args *);
76 int afs_vop_read(struct vop_read_args *);
77 int afs_vop_write(struct vop_write_args *);
78 int afs_vop_getpages(struct vop_getpages_args *);
79 int afs_vop_putpages(struct vop_putpages_args *);
80 int afs_vop_ioctl(struct vop_ioctl_args *);
81 static int afs_vop_pathconf(struct vop_pathconf_args *);
82 int afs_vop_poll(struct vop_poll_args *);
83 #ifndef AFS_FBSD50_ENV
84 int afs_vop_mmap(struct vop_mmap_args *);
85 #endif
86 int afs_vop_fsync(struct vop_fsync_args *);
87 int afs_vop_remove(struct vop_remove_args *);
88 int afs_vop_link(struct vop_link_args *);
89 int afs_vop_rename(struct vop_rename_args *);
90 int afs_vop_mkdir(struct vop_mkdir_args *);
91 int afs_vop_rmdir(struct vop_rmdir_args *);
92 int afs_vop_symlink(struct vop_symlink_args *);
93 int afs_vop_readdir(struct vop_readdir_args *);
94 int afs_vop_readlink(struct vop_readlink_args *);
95 int afs_vop_inactive(struct vop_inactive_args *);
96 int afs_vop_reclaim(struct vop_reclaim_args *);
97 int afs_vop_lock(struct vop_lock_args *);
98 int afs_vop_unlock(struct vop_unlock_args *);
99 int afs_vop_bmap(struct vop_bmap_args *);
100 int afs_vop_strategy(struct vop_strategy_args *);
101 int afs_vop_print(struct vop_print_args *);
102 int afs_vop_islocked(struct vop_islocked_args *);
103 int afs_vop_advlock(struct vop_advlock_args *);
104
105
106
107 /* Global vfs data structures for AFS. */
108 vop_t **afs_vnodeop_p;
109 struct vnodeopv_entry_desc afs_vnodeop_entries[] = {
110     {&vop_default_desc, (vop_t *) vop_defaultop},
111     {&vop_access_desc, (vop_t *) afs_vop_access},       /* access */
112     {&vop_advlock_desc, (vop_t *) afs_vop_advlock},     /* advlock */
113     {&vop_bmap_desc, (vop_t *) afs_vop_bmap},   /* bmap */
114 #ifndef AFS_FBSD50_ENV
115     {&vop_bwrite_desc, (vop_t *) vop_stdbwrite},
116 #endif
117     {&vop_close_desc, (vop_t *) afs_vop_close}, /* close */
118     {&vop_createvobject_desc, (vop_t *) vop_stdcreatevobject},
119     {&vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject},
120     {&vop_create_desc, (vop_t *) afs_vop_create},       /* create */
121     {&vop_fsync_desc, (vop_t *) afs_vop_fsync}, /* fsync */
122     {&vop_getattr_desc, (vop_t *) afs_vop_getattr},     /* getattr */
123     {&vop_getpages_desc, (vop_t *) afs_vop_getpages},   /* read */
124     {&vop_getvobject_desc, (vop_t *) vop_stdgetvobject},
125     {&vop_putpages_desc, (vop_t *) afs_vop_putpages},   /* write */
126     {&vop_inactive_desc, (vop_t *) afs_vop_inactive},   /* inactive */
127     {&vop_lease_desc, (vop_t *) vop_null},
128     {&vop_link_desc, (vop_t *) afs_vop_link},   /* link */
129     {&vop_lookup_desc, (vop_t *) afs_vop_lookup},       /* lookup */
130     {&vop_mkdir_desc, (vop_t *) afs_vop_mkdir}, /* mkdir */
131     {&vop_mknod_desc, (vop_t *) afs_vop_mknod}, /* mknod */
132 #ifndef AFS_FBSD50_ENV
133     {&vop_mmap_desc, (vop_t *) afs_vop_mmap},   /* mmap */
134 #endif
135     {&vop_open_desc, (vop_t *) afs_vop_open},   /* open */
136     {&vop_pathconf_desc, (vop_t *) afs_vop_pathconf},   /* pathconf */
137     {&vop_poll_desc, (vop_t *) afs_vop_poll},   /* select */
138     {&vop_print_desc, (vop_t *) afs_vop_print}, /* print */
139     {&vop_read_desc, (vop_t *) afs_vop_read},   /* read */
140     {&vop_readdir_desc, (vop_t *) afs_vop_readdir},     /* readdir */
141     {&vop_readlink_desc, (vop_t *) afs_vop_readlink},   /* readlink */
142     {&vop_reclaim_desc, (vop_t *) afs_vop_reclaim},     /* reclaim */
143     {&vop_remove_desc, (vop_t *) afs_vop_remove},       /* remove */
144     {&vop_rename_desc, (vop_t *) afs_vop_rename},       /* rename */
145     {&vop_rmdir_desc, (vop_t *) afs_vop_rmdir}, /* rmdir */
146     {&vop_setattr_desc, (vop_t *) afs_vop_setattr},     /* setattr */
147     {&vop_strategy_desc, (vop_t *) afs_vop_strategy},   /* strategy */
148     {&vop_symlink_desc, (vop_t *) afs_vop_symlink},     /* symlink */
149     {&vop_write_desc, (vop_t *) afs_vop_write}, /* write */
150     {&vop_ioctl_desc, (vop_t *) afs_vop_ioctl}, /* XXX ioctl */
151     /*{ &vop_seek_desc, afs_vop_seek }, *//* seek */
152     {NULL, NULL}
153 };
154 struct vnodeopv_desc afs_vnodeop_opv_desc =
155     { &afs_vnodeop_p, afs_vnodeop_entries };
156
157 #define GETNAME()       \
158     struct componentname *cnp = ap->a_cnp; \
159     char *name; \
160     MALLOC(name, char *, cnp->cn_namelen+1, M_TEMP, M_WAITOK); \
161     memcpy(name, cnp->cn_nameptr, cnp->cn_namelen); \
162     name[cnp->cn_namelen] = '\0'
163
164 #define DROPNAME() FREE(name, M_TEMP)
165
166 /* This is a bit of a cheat... */
167 #ifdef AFS_FBSD50_ENV
168 #define a_p a_td
169 #endif
170
171 /*
172  * Mosty copied from sys/ufs/ufs/ufs_vnops.c:ufs_pathconf().
173  * We should know the correct answers to these questions with
174  * respect to the AFS protocol (which may differ from the UFS
175  * values) but for the moment this will do.
176  */
177 static int
178 afs_vop_pathconf(struct vop_pathconf_args *ap)
179 {
180         int error;
181
182         error = 0;
183         switch (ap->a_name) {
184         case _PC_LINK_MAX:
185                 *ap->a_retval = LINK_MAX;
186                 break;
187         case _PC_NAME_MAX:
188                 *ap->a_retval = NAME_MAX;
189                 break;
190         case _PC_PATH_MAX:
191                 *ap->a_retval = PATH_MAX;
192                 break;
193         case _PC_PIPE_BUF:
194                 *ap->a_retval = PIPE_BUF;
195                 break;
196         case _PC_CHOWN_RESTRICTED:
197                 *ap->a_retval = 1;
198                 break;
199         case _PC_NO_TRUNC:
200                 *ap->a_retval = 1;
201                 break;
202 #ifdef _PC_ACL_EXTENDED
203         case _PC_ACL_EXTENDED:
204                 *ap->a_retval = 0;
205                 break;
206         case _PC_ACL_PATH_MAX:
207                 *ap->a_retval = 3;
208                 break;
209 #endif
210 #ifdef _PC_MAC_PRESENT
211         case _PC_MAC_PRESENT:
212                 *ap->a_retval = 0;
213                 break;
214 #endif
215 #ifdef _PC_ASYNC_IO
216         case _PC_ASYNC_IO:
217                 /* _PC_ASYNC_IO should have been handled by upper layers. */
218                 KASSERT(0, ("_PC_ASYNC_IO should not get here"));
219                 error = EINVAL;
220                 break;
221         case _PC_PRIO_IO:
222                 *ap->a_retval = 0;
223                 break;
224         case _PC_SYNC_IO:
225                 *ap->a_retval = 0;
226                 break;
227 #endif
228 #ifdef _PC_ALLOC_SIZE_MIN
229         case _PC_ALLOC_SIZE_MIN:
230                 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_bsize;
231                 break;
232 #endif
233 #ifdef _PC_FILESIZEBITS
234         case _PC_FILESIZEBITS:
235                 *ap->a_retval = 32; /* XXX */
236                 break;
237 #endif
238 #ifdef _PC_REC_INCR_XFER_SIZE
239         case _PC_REC_INCR_XFER_SIZE:
240                 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
241                 break;
242         case _PC_REC_MAX_XFER_SIZE:
243                 *ap->a_retval = -1; /* means ``unlimited'' */
244                 break;
245         case _PC_REC_MIN_XFER_SIZE:
246                 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
247                 break;
248         case _PC_REC_XFER_ALIGN:
249                 *ap->a_retval = PAGE_SIZE;
250                 break;
251 #endif
252 #ifdef _PC_SYMLINK_MAX
253         case _PC_SYMLINK_MAX:
254                 *ap->a_retval = MAXPATHLEN;
255                 break;
256 #endif
257         default:
258                 error = EINVAL;
259                 break;
260         }
261         return (error);
262 }
263
264 int
265 afs_vop_lookup(ap)
266      struct vop_lookup_args     /* {
267                                  * struct vnodeop_desc * a_desc;
268                                  * struct vnode *a_dvp;
269                                  * struct vnode **a_vpp;
270                                  * struct componentname *a_cnp;
271                                  * } */ *ap;
272 {
273     int error;
274     struct vcache *vcp;
275     struct vnode *vp, *dvp;
276     register int flags = ap->a_cnp->cn_flags;
277     int lockparent;             /* 1 => lockparent flag is set */
278     int wantparent;             /* 1 => wantparent or lockparent flag */
279 #ifdef AFS_FBSD50_ENV
280     struct thread *p = ap->a_cnp->cn_thread;
281 #else
282     struct proc *p = ap->a_cnp->cn_proc;
283 #endif
284     GETNAME();
285
286     lockparent = flags & LOCKPARENT;
287     wantparent = flags & (LOCKPARENT | WANTPARENT);
288
289     if (ap->a_dvp->v_type != VDIR) {
290         *ap->a_vpp = 0;
291         DROPNAME();
292         return ENOTDIR;
293     }
294     dvp = ap->a_dvp;
295     if (flags & ISDOTDOT)
296         VOP_UNLOCK(dvp, 0, p);
297     AFS_GLOCK();
298     error = afs_lookup(VTOAFS(dvp), name, &vcp, cnp->cn_cred);
299     AFS_GUNLOCK();
300     if (error) {
301         if (flags & ISDOTDOT)
302             VOP_LOCK(dvp, LK_EXCLUSIVE | LK_RETRY, p);
303         if ((cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME)
304             && (flags & ISLASTCN) && error == ENOENT)
305             error = EJUSTRETURN;
306         if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))
307             cnp->cn_flags |= SAVENAME;
308         DROPNAME();
309         *ap->a_vpp = 0;
310         return (error);
311     }
312     vp = AFSTOV(vcp);           /* always get a node if no error */
313
314     /* The parent directory comes in locked.  We unlock it on return
315      * unless the caller wants it left locked.
316      * we also always return the vnode locked. */
317
318     if (flags & ISDOTDOT) {
319         vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
320         /* always return the child locked */
321         if (lockparent && (flags & ISLASTCN)
322             && (error = vn_lock(dvp, LK_EXCLUSIVE, p))) {
323             vput(vp);
324             DROPNAME();
325             return (error);
326         }
327     } else if (vp == dvp) {
328         /* they're the same; afs_lookup() already ref'ed the leaf.
329          * It came in locked, so we don't need to ref OR lock it */
330     } else {
331         if (!lockparent || !(flags & ISLASTCN))
332             VOP_UNLOCK(dvp, 0, p);      /* done with parent. */
333         vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
334         /* always return the child locked */
335     }
336     *ap->a_vpp = vp;
337
338     if ((cnp->cn_nameiop == RENAME && wantparent && (flags & ISLASTCN))
339         || (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN)))
340         cnp->cn_flags |= SAVENAME;
341
342     DROPNAME();
343     return error;
344 }
345
346 int
347 afs_vop_create(ap)
348      struct vop_create_args     /* {
349                                  * struct vnode *a_dvp;
350                                  * struct vnode **a_vpp;
351                                  * struct componentname *a_cnp;
352                                  * struct vattr *a_vap;
353                                  * } */ *ap;
354 {
355     int error = 0;
356     struct vcache *vcp;
357     register struct vnode *dvp = ap->a_dvp;
358 #ifdef AFS_FBSD50_ENV
359     struct thread *p = ap->a_cnp->cn_thread;
360 #else
361     struct proc *p = ap->a_cnp->cn_proc;
362 #endif
363     GETNAME();
364
365     AFS_GLOCK();
366     error =
367         afs_create(VTOAFS(dvp), name, ap->a_vap,
368                    ap->a_vap->va_vaflags & VA_EXCLUSIVE ? EXCL : NONEXCL,
369                    ap->a_vap->va_mode, &vcp, cnp->cn_cred);
370     AFS_GUNLOCK();
371     if (error) {
372         DROPNAME();
373         return (error);
374     }
375
376     if (vcp) {
377         *ap->a_vpp = AFSTOV(vcp);
378         vn_lock(AFSTOV(vcp), LK_EXCLUSIVE | LK_RETRY, p);
379     } else
380         *ap->a_vpp = 0;
381
382     DROPNAME();
383     return error;
384 }
385
386 int
387 afs_vop_mknod(ap)
388      struct vop_mknod_args      /* {
389                                  * struct vnode *a_dvp;
390                                  * struct vnode **a_vpp;
391                                  * struct componentname *a_cnp;
392                                  * struct vattr *a_vap;
393                                  * } */ *ap;
394 {
395     return (ENODEV);
396 }
397
398 #if 0
399 static int
400 validate_vops(struct vnode *vp, int after)
401 {
402     int ret = 0;
403     struct vnodeopv_entry_desc *this;
404     for (this = afs_vnodeop_entries; this->opve_op; this++) {
405         if (vp->v_op[this->opve_op->vdesc_offset] != this->opve_impl) {
406             if (!ret) {
407                 printf("v_op %d ", after);
408                 vprint("check", vp);
409             }
410             ret = 1;
411             printf("For oper %d (%s), func is %p, not %p",
412                    this->opve_op->vdesc_offset, this->opve_op->vdesc_name,
413                    vp->v_op[this->opve_op->vdesc_offset], this->opve_impl);
414         }
415     }
416     return ret;
417 }
418 #endif
419 int
420 afs_vop_open(ap)
421      struct vop_open_args       /* {
422                                  * struct vnode *a_vp;
423                                  * int  a_mode;
424                                  * struct ucred *a_cred;
425                                  * struct proc *a_p;
426                                  * } */ *ap;
427 {
428     int error;
429     int bad;
430     struct vcache *vc = VTOAFS(ap->a_vp);
431     bad = 0;
432     AFS_GLOCK();
433     error = afs_open(&vc, ap->a_mode, ap->a_cred);
434 #ifdef DIAGNOSTIC
435     if (AFSTOV(vc) != ap->a_vp)
436         panic("AFS open changed vnode!");
437 #endif
438     osi_FlushPages(vc, ap->a_cred);
439     AFS_GUNLOCK();
440     return error;
441 }
442
443 int
444 afs_vop_close(ap)
445      struct vop_close_args      /* {
446                                  * struct vnode *a_vp;
447                                  * int  a_fflag;
448                                  * struct ucred *a_cred;
449                                  * struct proc *a_p;
450                                  * } */ *ap;
451 {
452     int code;
453     struct vcache *avc = VTOAFS(ap->a_vp);
454     AFS_GLOCK();
455     if (ap->a_cred)
456         code = afs_close(avc, ap->a_fflag, ap->a_cred);
457     else
458         code = afs_close(avc, ap->a_fflag, afs_osi_credp);
459     osi_FlushPages(avc, ap->a_cred);    /* hold bozon lock, but not basic vnode lock */
460     AFS_GUNLOCK();
461     return code;
462 }
463
464 int
465 afs_vop_access(ap)
466      struct vop_access_args     /* {
467                                  * struct vnode *a_vp;
468                                  * int  a_mode;
469                                  * struct ucred *a_cred;
470                                  * struct proc *a_p;
471                                  * } */ *ap;
472 {
473     int code;
474     AFS_GLOCK();
475     code = afs_access(VTOAFS(ap->a_vp), ap->a_mode, ap->a_cred);
476     AFS_GUNLOCK();
477     return code;
478 }
479
480 int
481 afs_vop_getattr(ap)
482      struct vop_getattr_args    /* {
483                                  * struct vnode *a_vp;
484                                  * struct vattr *a_vap;
485                                  * struct ucred *a_cred;
486                                  * struct proc *a_p;
487                                  * } */ *ap;
488 {
489     int code;
490     AFS_GLOCK();
491     code = afs_getattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred);
492     AFS_GUNLOCK();
493     return code;
494 }
495
496 int
497 afs_vop_setattr(ap)
498      struct vop_setattr_args    /* {
499                                  * struct vnode *a_vp;
500                                  * struct vattr *a_vap;
501                                  * struct ucred *a_cred;
502                                  * struct proc *a_p;
503                                  * } */ *ap;
504 {
505     int code;
506     AFS_GLOCK();
507     code = afs_setattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred);
508     AFS_GUNLOCK();
509     return code;
510 }
511
512 int
513 afs_vop_read(ap)
514      struct vop_read_args       /* {
515                                  * struct vnode *a_vp;
516                                  * struct uio *a_uio;
517                                  * int a_ioflag;
518                                  * struct ucred *a_cred;
519                                  * 
520                                  * } */ *ap;
521 {
522     int code;
523     struct vcache *avc = VTOAFS(ap->a_vp);
524     AFS_GLOCK();
525     osi_FlushPages(avc, ap->a_cred);    /* hold bozon lock, but not basic vnode lock */
526     code = afs_read(avc, ap->a_uio, ap->a_cred, 0, 0, 0);
527     AFS_GUNLOCK();
528     return code;
529 }
530
531 /* struct vop_getpages_args {
532  *      struct vnode *a_vp;
533  *      vm_page_t *a_m;
534  *      int a_count;
535  *      int a_reqpage;
536  *      vm_oofset_t a_offset;
537  * };
538  */
539 int
540 afs_vop_getpages(struct vop_getpages_args *ap)
541 {
542     int code;
543     int i, nextoff, size, toff, npages;
544     struct uio uio;
545     struct iovec iov;
546     struct buf *bp;
547     vm_offset_t kva;
548     vm_object_t object;
549     struct vnode *vp;
550     struct vcache *avc;
551
552 #ifdef AFS_FBSD50_ENV
553     GIANT_REQUIRED;
554 #endif
555     vp = ap->a_vp;
556     avc = VTOAFS(vp);
557     if ((object = vp->v_object) == NULL) {
558         printf("afs_getpages: called with non-merged cache vnode??\n");
559         return VM_PAGER_ERROR;
560     }
561     npages = btoc(ap->a_count);
562     /*
563      * If the requested page is partially valid, just return it and
564      * allow the pager to zero-out the blanks.  Partially valid pages
565      * can only occur at the file EOF.
566      */
567
568     {
569         vm_page_t m = ap->a_m[ap->a_reqpage];
570
571 #ifdef AFS_FBSD50_ENV
572         VM_OBJECT_LOCK(object);
573         vm_page_lock_queues();
574 #endif
575         if (m->valid != 0) {
576             /* handled by vm_fault now        */
577             /* vm_page_zero_invalid(m, TRUE); */
578             for (i = 0; i < npages; ++i) {
579                 if (i != ap->a_reqpage)
580                     vm_page_free(ap->a_m[i]);
581             }
582 #ifdef AFS_FBSD50_ENV
583             vm_page_unlock_queues();
584             VM_OBJECT_UNLOCK(object);
585 #endif
586             return (0);
587         }
588 #ifdef AFS_FBSD50_ENV
589         vm_page_unlock_queues();
590         VM_OBJECT_UNLOCK(object);
591 #endif
592     }
593     bp = getpbuf(&afs_pbuf_freecnt);
594
595     kva = (vm_offset_t) bp->b_data;
596     pmap_qenter(kva, ap->a_m, npages);
597 #ifdef AFS_FBSD50_ENV
598     cnt.v_vnodein++;
599     cnt.v_vnodepgsin += npages;
600 #endif
601
602     iov.iov_base = (caddr_t) kva;
603     iov.iov_len = ap->a_count;
604     uio.uio_iov = &iov;
605     uio.uio_iovcnt = 1;
606     uio.uio_offset = IDX_TO_OFF(ap->a_m[0]->pindex);
607     uio.uio_resid = ap->a_count;
608     uio.uio_segflg = UIO_SYSSPACE;
609     uio.uio_rw = UIO_READ;
610 #ifdef AFS_FBSD50_ENV
611     uio.uio_td = curthread;
612 #else
613     uio.uio_procp = curproc;
614 #endif
615
616     AFS_GLOCK();
617     osi_FlushPages(avc, osi_curcred()); /* hold bozon lock, but not basic vnode lock */
618     code = afs_read(avc, &uio, osi_curcred(), 0, 0, 0);
619     AFS_GUNLOCK();
620     pmap_qremove(kva, npages);
621
622     relpbuf(bp, &afs_pbuf_freecnt);
623
624     if (code && (uio.uio_resid == ap->a_count)) {
625 #ifdef AFS_FBSD50_ENV
626         VM_OBJECT_LOCK(object);
627         vm_page_lock_queues();
628 #endif
629         for (i = 0; i < npages; ++i) {
630             if (i != ap->a_reqpage)
631                 vm_page_free(ap->a_m[i]);
632         }
633 #ifdef AFS_FBSD50_ENV
634         vm_page_unlock_queues();
635         VM_OBJECT_UNLOCK(object);
636 #endif
637         return VM_PAGER_ERROR;
638     }
639
640     size = ap->a_count - uio.uio_resid;
641 #ifdef AFS_FBSD50_ENV
642     VM_OBJECT_LOCK(object);
643     vm_page_lock_queues();
644 #endif
645     for (i = 0, toff = 0; i < npages; i++, toff = nextoff) {
646         vm_page_t m;
647         nextoff = toff + PAGE_SIZE;
648         m = ap->a_m[i];
649
650         m->flags &= ~PG_ZERO;
651
652         if (nextoff <= size) {
653             /*
654              * Read operation filled an entire page
655              */
656             m->valid = VM_PAGE_BITS_ALL;
657             vm_page_undirty(m);
658         } else if (size > toff) {
659             /*
660              * Read operation filled a partial page.
661              */
662             m->valid = 0;
663             vm_page_set_validclean(m, 0, size - toff);
664             /* handled by vm_fault now        */
665             /* vm_page_zero_invalid(m, TRUE); */
666         }
667
668         if (i != ap->a_reqpage) {
669             /*
670              * Whether or not to leave the page activated is up in
671              * the air, but we should put the page on a page queue
672              * somewhere (it already is in the object).  Result:
673              * It appears that emperical results show that
674              * deactivating pages is best.
675              */
676
677             /*
678              * Just in case someone was asking for this page we
679              * now tell them that it is ok to use.
680              */
681             if (!code) {
682                 if (m->flags & PG_WANTED)
683                     vm_page_activate(m);
684                 else
685                     vm_page_deactivate(m);
686                 vm_page_wakeup(m);
687             } else {
688                 vm_page_free(m);
689             }
690         }
691     }
692 #ifdef AFS_FBSD50_ENV
693     vm_page_unlock_queues();
694     VM_OBJECT_UNLOCK(object);
695 #endif
696     return 0;
697 }
698
699 int
700 afs_vop_write(ap)
701      struct vop_write_args      /* {
702                                  * struct vnode *a_vp;
703                                  * struct uio *a_uio;
704                                  * int a_ioflag;
705                                  * struct ucred *a_cred;
706                                  * } */ *ap;
707 {
708     int code;
709     struct vcache *avc = VTOAFS(ap->a_vp);
710     AFS_GLOCK();
711     osi_FlushPages(avc, ap->a_cred);    /* hold bozon lock, but not basic vnode lock */
712     code =
713         afs_write(VTOAFS(ap->a_vp), ap->a_uio, ap->a_ioflag, ap->a_cred, 0);
714     AFS_GUNLOCK();
715     return code;
716 }
717
718 /*-
719  * struct vop_putpages_args {
720  *      struct vnode *a_vp;
721  *      vm_page_t *a_m;
722  *      int a_count;
723  *      int a_sync;
724  *      int *a_rtvals;
725  *      vm_oofset_t a_offset;
726  * };
727  */
728 /*
729  * All of the pages passed to us in ap->a_m[] are already marked as busy,
730  * so there is no additional locking required to set their flags.  -GAW
731  */
732 int
733 afs_vop_putpages(struct vop_putpages_args *ap)
734 {
735     int code;
736     int i, size, npages, sync;
737     struct uio uio;
738     struct iovec iov;
739     struct buf *bp;
740     vm_offset_t kva;
741     struct vnode *vp;
742     struct vcache *avc;
743
744 #ifdef AFS_FBSD50_ENV
745     GIANT_REQUIRED;
746 #endif
747
748     vp = ap->a_vp;
749     avc = VTOAFS(vp);
750     /* Perhaps these two checks should just be KASSERTs instead... */
751     if (vp->v_object == NULL) {
752         printf("afs_putpages: called with non-merged cache vnode??\n");
753         return VM_PAGER_ERROR;  /* XXX I think this is insufficient */
754     }
755     if (vType(avc) != VREG) {
756         printf("afs_putpages: not VREG");
757         return VM_PAGER_ERROR;  /* XXX I think this is insufficient */
758     }
759     npages = btoc(ap->a_count);
760     for (i = 0; i < npages; i++)
761         ap->a_rtvals[i] = VM_PAGER_AGAIN;
762     bp = getpbuf(&afs_pbuf_freecnt);
763
764     kva = (vm_offset_t) bp->b_data;
765     pmap_qenter(kva, ap->a_m, npages);
766 #ifdef AFS_FBSD50_ENV
767     cnt.v_vnodeout++;
768     cnt.v_vnodepgsout += ap->a_count;
769 #endif
770
771     iov.iov_base = (caddr_t) kva;
772     iov.iov_len = ap->a_count;
773     uio.uio_iov = &iov;
774     uio.uio_iovcnt = 1;
775     uio.uio_offset = IDX_TO_OFF(ap->a_m[0]->pindex);
776     uio.uio_resid = ap->a_count;
777     uio.uio_segflg = UIO_SYSSPACE;
778     uio.uio_rw = UIO_WRITE;
779 #ifdef AFS_FBSD50_ENV
780     uio.uio_td = curthread;
781 #else
782     uio.uio_procp = curproc;
783 #endif
784     sync = IO_VMIO;
785     if (ap->a_sync & VM_PAGER_PUT_SYNC)
786         sync |= IO_SYNC;
787     /*if (ap->a_sync & VM_PAGER_PUT_INVAL)
788      * sync |= IO_INVAL; */
789
790     AFS_GLOCK();
791     code = afs_write(avc, &uio, sync, osi_curcred(), 0);
792     AFS_GUNLOCK();
793
794     pmap_qremove(kva, npages);
795     relpbuf(bp, &afs_pbuf_freecnt);
796
797     if (!code) {
798         size = ap->a_count - uio.uio_resid;
799         for (i = 0; i < round_page(size) / PAGE_SIZE; i++) {
800             ap->a_rtvals[i] = VM_PAGER_OK;
801             vm_page_undirty(ap->a_m[i]);
802         }
803     }
804     return ap->a_rtvals[0];
805 }
806
807 int
808 afs_vop_ioctl(ap)
809      struct vop_ioctl_args      /* {
810                                  * struct vnode *a_vp;
811                                  * int  a_command;
812                                  * caddr_t  a_data;
813                                  * int  a_fflag;
814                                  * struct ucred *a_cred;
815                                  * struct proc *a_p;
816                                  * } */ *ap;
817 {
818     struct vcache *tvc = VTOAFS(ap->a_vp);
819     int error = 0;
820
821     /* in case we ever get in here... */
822
823     AFS_STATCNT(afs_ioctl);
824     if (((ap->a_command >> 8) & 0xff) == 'V') {
825         /* This is a VICEIOCTL call */
826         AFS_GLOCK();
827         error = HandleIoctl(tvc, NULL /*Not used */ ,
828                             ap->a_command, ap->a_data);
829         AFS_GUNLOCK();
830         return (error);
831     } else {
832         /* No-op call; just return. */
833         return (ENOTTY);
834     }
835 }
836
837 /* ARGSUSED */
838 int
839 afs_vop_poll(ap)
840      struct vop_poll_args       /* {
841                                  * struct vnode *a_vp;
842                                  * int  a_events;
843                                  * struct ucred *a_cred;
844                                  * struct proc *a_p;
845                                  * } */ *ap;
846 {
847     /*
848      * We should really check to see if I/O is possible.
849      */
850     return (1);
851 }
852
853 /*
854  * Mmap a file
855  *
856  * NB Currently unsupported.
857  */
858 /* ARGSUSED */
859 int
860 afs_vop_mmap(ap)
861      struct vop_mmap_args       /* {
862                                  * struct vnode *a_vp;
863                                  * int  a_fflags;
864                                  * struct ucred *a_cred;
865                                  * struct proc *a_p;
866                                  * } */ *ap;
867 {
868     return (EINVAL);
869 }
870
871 int
872 afs_vop_fsync(ap)
873      struct vop_fsync_args      /* {
874                                  * struct vnode *a_vp;
875                                  * struct ucred *a_cred;
876                                  * int a_waitfor;
877                                  * struct proc *a_p;
878                                  * } */ *ap;
879 {
880     int error;
881     register struct vnode *vp = ap->a_vp;
882
883     AFS_GLOCK();
884     /*vflushbuf(vp, wait); */
885     if (ap->a_cred)
886         error = afs_fsync(VTOAFS(vp), ap->a_cred);
887     else
888         error = afs_fsync(VTOAFS(vp), afs_osi_credp);
889     AFS_GUNLOCK();
890     return error;
891 }
892
893 int
894 afs_vop_remove(ap)
895      struct vop_remove_args     /* {
896                                  * struct vnode *a_dvp;
897                                  * struct vnode *a_vp;
898                                  * struct componentname *a_cnp;
899                                  * } */ *ap;
900 {
901     int error = 0;
902     register struct vnode *vp = ap->a_vp;
903     register struct vnode *dvp = ap->a_dvp;
904
905     GETNAME();
906     AFS_GLOCK();
907     error = afs_remove(VTOAFS(dvp), name, cnp->cn_cred);
908     AFS_GUNLOCK();
909     cache_purge(vp);
910     DROPNAME();
911     return error;
912 }
913
914 int
915 afs_vop_link(ap)
916      struct vop_link_args       /* {
917                                  * struct vnode *a_vp;
918                                  * struct vnode *a_tdvp;
919                                  * struct componentname *a_cnp;
920                                  * } */ *ap;
921 {
922     int error = 0;
923     register struct vnode *dvp = ap->a_tdvp;
924     register struct vnode *vp = ap->a_vp;
925 #ifdef AFS_FBSD50_ENV
926     struct thread *p = ap->a_cnp->cn_thread;
927 #else
928     struct proc *p = ap->a_cnp->cn_proc;
929 #endif
930
931     GETNAME();
932     if (dvp->v_mount != vp->v_mount) {
933         error = EXDEV;
934         goto out;
935     }
936     if (vp->v_type == VDIR) {
937         error = EISDIR;
938         goto out;
939     }
940     if ((error = vn_lock(vp, LK_EXCLUSIVE, p)) != 0) {
941         goto out;
942     }
943     AFS_GLOCK();
944     error = afs_link(VTOAFS(vp), VTOAFS(dvp), name, cnp->cn_cred);
945     AFS_GUNLOCK();
946     if (dvp != vp)
947         VOP_UNLOCK(vp, 0, p);
948   out:
949     DROPNAME();
950     return error;
951 }
952
953 int
954 afs_vop_rename(ap)
955      struct vop_rename_args     /* {
956                                  * struct vnode *a_fdvp;
957                                  * struct vnode *a_fvp;
958                                  * struct componentname *a_fcnp;
959                                  * struct vnode *a_tdvp;
960                                  * struct vnode *a_tvp;
961                                  * struct componentname *a_tcnp;
962                                  * } */ *ap;
963 {
964     int error = 0;
965     struct componentname *fcnp = ap->a_fcnp;
966     char *fname;
967     struct componentname *tcnp = ap->a_tcnp;
968     char *tname;
969     struct vnode *tvp = ap->a_tvp;
970     register struct vnode *tdvp = ap->a_tdvp;
971     struct vnode *fvp = ap->a_fvp;
972     register struct vnode *fdvp = ap->a_fdvp;
973 #ifdef AFS_FBSD50_ENV
974     struct thread *p = fcnp->cn_thread;
975 #else
976     struct proc *p = fcnp->cn_proc;
977 #endif
978
979     /*
980      * Check for cross-device rename.
981      */
982     if ((fvp->v_mount != tdvp->v_mount)
983         || (tvp && (fvp->v_mount != tvp->v_mount))) {
984         error = EXDEV;
985       abortit:
986         if (tdvp == tvp)
987             vrele(tdvp);
988         else
989             vput(tdvp);
990         if (tvp)
991             vput(tvp);
992         vrele(fdvp);
993         vrele(fvp);
994         return (error);
995     }
996     /*
997      * if fvp == tvp, we're just removing one name of a pair of
998      * directory entries for the same element.  convert call into rename.
999      ( (pinched from FreeBSD 4.4's ufs_rename())
1000      
1001      */
1002     if (fvp == tvp) {
1003         if (fvp->v_type == VDIR) {
1004             error = EINVAL;
1005             goto abortit;
1006         }
1007
1008         /* Release destination completely. */
1009         vput(tdvp);
1010         vput(tvp);
1011
1012         /* Delete source. */
1013         vrele(fdvp);
1014         vrele(fvp);
1015         fcnp->cn_flags &= ~MODMASK;
1016         fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
1017         if ((fcnp->cn_flags & SAVESTART) == 0)
1018             panic("afs_rename: lost from startdir");
1019         fcnp->cn_nameiop = DELETE;
1020         VREF(fdvp);
1021         error = relookup(fdvp, &fvp, fcnp);
1022         if (error == 0)
1023             vrele(fdvp);
1024         if (fvp == NULL) {
1025             return (ENOENT);
1026         }
1027
1028         error = VOP_REMOVE(fdvp, fvp, fcnp);
1029         if (fdvp == fvp)
1030             vrele(fdvp);
1031         else
1032             vput(fdvp);
1033         vput(fvp);
1034         return (error);
1035     }
1036     if ((error = vn_lock(fvp, LK_EXCLUSIVE, p)) != 0)
1037         goto abortit;
1038
1039     MALLOC(fname, char *, fcnp->cn_namelen + 1, M_TEMP, M_WAITOK);
1040     memcpy(fname, fcnp->cn_nameptr, fcnp->cn_namelen);
1041     fname[fcnp->cn_namelen] = '\0';
1042     MALLOC(tname, char *, tcnp->cn_namelen + 1, M_TEMP, M_WAITOK);
1043     memcpy(tname, tcnp->cn_nameptr, tcnp->cn_namelen);
1044     tname[tcnp->cn_namelen] = '\0';
1045
1046
1047     AFS_GLOCK();
1048     /* XXX use "from" or "to" creds? NFS uses "to" creds */
1049     error =
1050         afs_rename(VTOAFS(fdvp), fname, VTOAFS(tdvp), tname, tcnp->cn_cred);
1051     AFS_GUNLOCK();
1052
1053     FREE(fname, M_TEMP);
1054     FREE(tname, M_TEMP);
1055     if (tdvp == tvp)
1056         vrele(tdvp);
1057     else
1058         vput(tdvp);
1059     if (tvp)
1060         vput(tvp);
1061     vrele(fdvp);
1062     vput(fvp);
1063     return error;
1064 }
1065
1066 int
1067 afs_vop_mkdir(ap)
1068      struct vop_mkdir_args      /* {
1069                                  * struct vnode *a_dvp;
1070                                  * struct vnode **a_vpp;
1071                                  * struct componentname *a_cnp;
1072                                  * struct vattr *a_vap;
1073                                  * } */ *ap;
1074 {
1075     register struct vnode *dvp = ap->a_dvp;
1076     register struct vattr *vap = ap->a_vap;
1077     int error = 0;
1078     struct vcache *vcp;
1079 #ifdef AFS_FBSD50_ENV
1080     struct thread *p = ap->a_cnp->cn_thread;
1081 #else
1082     struct proc *p = ap->a_cnp->cn_proc;
1083 #endif
1084
1085     GETNAME();
1086 #ifdef DIAGNOSTIC
1087     if ((cnp->cn_flags & HASBUF) == 0)
1088         panic("afs_vop_mkdir: no name");
1089 #endif
1090     AFS_GLOCK();
1091     error = afs_mkdir(VTOAFS(dvp), name, vap, &vcp, cnp->cn_cred);
1092     AFS_GUNLOCK();
1093     if (error) {
1094         DROPNAME();
1095         return (error);
1096     }
1097     if (vcp) {
1098         *ap->a_vpp = AFSTOV(vcp);
1099         vn_lock(AFSTOV(vcp), LK_EXCLUSIVE | LK_RETRY, p);
1100     } else
1101         *ap->a_vpp = 0;
1102     DROPNAME();
1103     return error;
1104 }
1105
1106 int
1107 afs_vop_rmdir(ap)
1108      struct vop_rmdir_args      /* {
1109                                  * struct vnode *a_dvp;
1110                                  * struct vnode *a_vp;
1111                                  * struct componentname *a_cnp;
1112                                  * } */ *ap;
1113 {
1114     int error = 0;
1115     register struct vnode *dvp = ap->a_dvp;
1116
1117     GETNAME();
1118     AFS_GLOCK();
1119     error = afs_rmdir(VTOAFS(dvp), name, cnp->cn_cred);
1120     AFS_GUNLOCK();
1121     DROPNAME();
1122     return error;
1123 }
1124
1125 /* struct vop_symlink_args {
1126  *      struct vnode *a_dvp;
1127  *      struct vnode **a_vpp;
1128  *      struct componentname *a_cnp;
1129  *      struct vattr *a_vap;
1130  *      char *a_target;
1131  * };
1132  */
1133 int
1134 afs_vop_symlink(struct vop_symlink_args *ap)
1135 {
1136     struct vnode *dvp;
1137     struct vnode *newvp;
1138     struct vcache *vcp;
1139     int error;
1140
1141     GETNAME();
1142     AFS_GLOCK();
1143
1144     dvp = ap->a_dvp;
1145     newvp = NULL;
1146
1147     error =
1148         afs_symlink(VTOAFS(dvp), name, ap->a_vap, ap->a_target, cnp->cn_cred);
1149     if (error == 0) {
1150         error = afs_lookup(VTOAFS(dvp), name, &vcp, cnp->cn_cred);
1151         if (error == 0) {
1152             newvp = AFSTOV(vcp);
1153 #ifdef AFS_FBSD50_ENV
1154             vn_lock(newvp, LK_EXCLUSIVE | LK_RETRY, cnp->cn_thread);
1155 #else
1156             vn_lock(newvp, LK_EXCLUSIVE | LK_RETRY, cnp->cn_proc);
1157 #endif
1158         }
1159     }
1160     AFS_GUNLOCK();
1161     DROPNAME();
1162     *(ap->a_vpp) = newvp;
1163     return error;
1164 }
1165
1166 int
1167 afs_vop_readdir(ap)
1168      struct vop_readdir_args    /* {
1169                                  * struct vnode *a_vp;
1170                                  * struct uio *a_uio;
1171                                  * struct ucred *a_cred;
1172                                  * int *a_eofflag;
1173                                  * u_long *a_cookies;
1174                                  * int ncookies;
1175                                  * } */ *ap;
1176 {
1177     int error;
1178     off_t off;
1179 /*    printf("readdir %x cookies %x ncookies %d\n", ap->a_vp, ap->a_cookies,
1180            ap->a_ncookies); */
1181     off = ap->a_uio->uio_offset;
1182     AFS_GLOCK();
1183     error =
1184         afs_readdir(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred, ap->a_eofflag);
1185     AFS_GUNLOCK();
1186     if (!error && ap->a_ncookies != NULL) {
1187         struct uio *uio = ap->a_uio;
1188         const struct dirent *dp, *dp_start, *dp_end;
1189         int ncookies;
1190         u_long *cookies, *cookiep;
1191
1192         if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
1193             panic("afs_readdir: burned cookies");
1194         dp = (const struct dirent *)
1195             ((const char *)uio->uio_iov->iov_base - (uio->uio_offset - off));
1196
1197         dp_end = (const struct dirent *)uio->uio_iov->iov_base;
1198         for (dp_start = dp, ncookies = 0; dp < dp_end;
1199              dp = (const struct dirent *)((const char *)dp + dp->d_reclen))
1200             ncookies++;
1201
1202         MALLOC(cookies, u_long *, ncookies * sizeof(u_long), M_TEMP,
1203                M_WAITOK);
1204         for (dp = dp_start, cookiep = cookies; dp < dp_end;
1205              dp = (const struct dirent *)((const char *)dp + dp->d_reclen)) {
1206             off += dp->d_reclen;
1207             *cookiep++ = off;
1208         }
1209         *ap->a_cookies = cookies;
1210         *ap->a_ncookies = ncookies;
1211     }
1212
1213     return error;
1214 }
1215
1216 int
1217 afs_vop_readlink(ap)
1218      struct vop_readlink_args   /* {
1219                                  * struct vnode *a_vp;
1220                                  * struct uio *a_uio;
1221                                  * struct ucred *a_cred;
1222                                  * } */ *ap;
1223 {
1224     int error;
1225 /*    printf("readlink %x\n", ap->a_vp);*/
1226     AFS_GLOCK();
1227     error = afs_readlink(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred);
1228     AFS_GUNLOCK();
1229     return error;
1230 }
1231
1232 extern int prtactive;
1233
1234 int
1235 afs_vop_inactive(ap)
1236      struct vop_inactive_args   /* {
1237                                  * struct vnode *a_vp;
1238                                  * struct proc *a_p;
1239                                  * } */ *ap;
1240 {
1241     register struct vnode *vp = ap->a_vp;
1242
1243     if (prtactive && vp->v_usecount != 0)
1244         vprint("afs_vop_inactive(): pushing active", vp);
1245
1246     AFS_GLOCK();
1247     afs_InactiveVCache(VTOAFS(vp), 0);  /* decrs ref counts */
1248     AFS_GUNLOCK();
1249     VOP_UNLOCK(vp, 0, ap->a_p);
1250     return 0;
1251 }
1252
1253 /*
1254  * struct vop_reclaim_args {
1255  *      struct vnode *a_vp;
1256  * };
1257  */
1258 int
1259 afs_vop_reclaim(struct vop_reclaim_args *ap)
1260 {
1261     /* copied from ../OBSD/osi_vnodeops.c:afs_nbsd_reclaim() */
1262     int code, slept;
1263     struct vnode *vp = ap->a_vp;
1264     struct vcache *avc = VTOAFS(vp);
1265     int haveGlock = ISAFS_GLOCK();
1266     int haveVlock = CheckLock(&afs_xvcache);
1267
1268     if (!haveGlock)
1269         AFS_GLOCK();
1270     if (!haveVlock)
1271         ObtainWriteLock(&afs_xvcache, 901);
1272 #ifndef AFS_DISCON_ENV
1273     code = afs_FlushVCache(avc, &slept);        /* tosses our stuff from vnode */
1274 #else
1275     /* reclaim the vnode and the in-memory vcache, but keep the on-disk vcache */
1276     code = afs_FlushVS(avc);
1277 #endif
1278     if (!haveVlock)
1279         ReleaseWriteLock(&afs_xvcache);
1280     if (!haveGlock)
1281         AFS_GUNLOCK();
1282
1283     /*
1284      * XXX Pretend it worked, to prevent panic on shutdown
1285      * Garrett, please fix - Jim Rees
1286      */
1287     if (code)
1288         printf("afs_vop_reclaim: afs_FlushVCache failed code %d\n", code);
1289     return 0;
1290 }
1291
1292 int
1293 afs_vop_bmap(ap)
1294      struct vop_bmap_args       /* {
1295                                  * struct vnode *a_vp;
1296                                  * daddr_t  a_bn;
1297                                  * struct vnode **a_vpp;
1298                                  * daddr_t *a_bnp;
1299                                  * int *a_runp;
1300                                  * int *a_runb;
1301                                  * } */ *ap;
1302 {
1303     if (ap->a_bnp) {
1304         *ap->a_bnp = ap->a_bn * (PAGE_SIZE / DEV_BSIZE);
1305     }
1306     if (ap->a_vpp) {
1307         *ap->a_vpp = ap->a_vp;
1308     }
1309     if (ap->a_runp != NULL)
1310         *ap->a_runp = 0;
1311     if (ap->a_runb != NULL)
1312         *ap->a_runb = 0;
1313
1314     return 0;
1315 }
1316
1317 int
1318 afs_vop_strategy(ap)
1319      struct vop_strategy_args   /* {
1320                                  * struct buf *a_bp;
1321                                  * } */ *ap;
1322 {
1323     int error;
1324     AFS_GLOCK();
1325     error = afs_ustrategy(ap->a_bp);
1326     AFS_GUNLOCK();
1327     return error;
1328 }
1329
1330 int
1331 afs_vop_print(ap)
1332      struct vop_print_args      /* {
1333                                  * struct vnode *a_vp;
1334                                  * } */ *ap;
1335 {
1336     register struct vnode *vp = ap->a_vp;
1337     register struct vcache *vc = VTOAFS(ap->a_vp);
1338     int s = vc->states;
1339
1340 #ifdef AFS_FBSD50_ENV
1341     printf("tag %s, fid: %d.%x.%x.%x, opens %d, writers %d", vp->v_tag,
1342            (int)vc->fid.Cell, (u_int) vc->fid.Fid.Volume,
1343            (u_int) vc->fid.Fid.Vnode, (u_int) vc->fid.Fid.Unique, vc->opens,
1344            vc->execsOrWriters);
1345 #else
1346     printf("tag %d, fid: %ld.%x.%x.%x, opens %d, writers %d", vp->v_tag,
1347            vc->fid.Cell, (u_int) vc->fid.Fid.Volume,
1348            (u_int) vc->fid.Fid.Vnode, (u_int) vc->fid.Fid.Unique, vc->opens,
1349            vc->execsOrWriters);
1350 #endif
1351     printf("\n  states%s%s%s%s%s", (s & CStatd) ? " statd" : "",
1352            (s & CRO) ? " readonly" : "", (s & CDirty) ? " dirty" : "",
1353            (s & CMAPPED) ? " mapped" : "",
1354            (s & CVFlushed) ? " flush in progress" : "");
1355     printf("\n");
1356     return 0;
1357 }
1358
1359 /*
1360  * Advisory record locking support (fcntl() POSIX style)
1361  */
1362 int
1363 afs_vop_advlock(ap)
1364      struct vop_advlock_args    /* {
1365                                  * struct vnode *a_vp;
1366                                  * caddr_t  a_id;
1367                                  * int  a_op;
1368                                  * struct flock *a_fl;
1369                                  * int  a_flags;
1370                                  * } */ *ap;
1371 {
1372     int error;
1373     struct ucred cr = *osi_curcred();
1374
1375     AFS_GLOCK();
1376     error =
1377         afs_lockctl(VTOAFS(ap->a_vp), ap->a_fl, ap->a_op, &cr, (int)ap->a_id);
1378     AFS_GUNLOCK();
1379     return error;
1380 }