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