DEV messaging stage 1/4: Rearrange struct cdevsw and add a message port
[dragonfly.git] / sys / vfs / coda / coda_vnops.c
1 /*
2  * 
3  *             Coda: an Experimental Distributed File System
4  *                              Release 3.1
5  * 
6  *           Copyright (c) 1987-1998 Carnegie Mellon University
7  *                          All Rights Reserved
8  * 
9  * Permission  to  use, copy, modify and distribute this software and its
10  * documentation is hereby granted,  provided  that  both  the  copyright
11  * notice  and  this  permission  notice  appear  in  all  copies  of the
12  * software, derivative works or  modified  versions,  and  any  portions
13  * thereof, and that both notices appear in supporting documentation, and
14  * that credit is given to Carnegie Mellon University  in  all  documents
15  * and publicity pertaining to direct or indirect use of this code or its
16  * derivatives.
17  * 
18  * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS  KNOWN  TO  HAVE  BUGS,
19  * SOME  OF  WHICH MAY HAVE SERIOUS CONSEQUENCES.  CARNEGIE MELLON ALLOWS
20  * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.   CARNEGIE  MELLON
21  * DISCLAIMS  ANY  LIABILITY  OF  ANY  KIND  FOR  ANY  DAMAGES WHATSOEVER
22  * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE  OR  OF
23  * ANY DERIVATIVE WORK.
24  * 
25  * Carnegie  Mellon  encourages  users  of  this  software  to return any
26  * improvements or extensions that  they  make,  and  to  grant  Carnegie
27  * Mellon the rights to redistribute these changes without encumbrance.
28  * 
29  *      @(#) src/sys/coda/coda_vnops.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
30  * $FreeBSD: src/sys/coda/coda_vnops.c,v 1.22.2.1 2001/06/29 16:26:22 shafeeq Exp $
31  * $DragonFly: src/sys/vfs/coda/Attic/coda_vnops.c,v 1.7 2003/07/19 21:14:15 dillon Exp $
32  * 
33  */
34
35 /* 
36  * Mach Operating System
37  * Copyright (c) 1990 Carnegie-Mellon University
38  * Copyright (c) 1989 Carnegie-Mellon University
39  * All rights reserved.  The CMU software License Agreement specifies
40  * the terms and conditions for use and redistribution.
41  */
42
43 /*
44  * This code was written for the Coda file system at Carnegie Mellon
45  * University.  Contributers include David Steere, James Kistler, and
46  * M. Satyanarayanan.  
47  */
48
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/kernel.h>
52 #include <sys/proc.h>
53 #include <sys/malloc.h>
54 #include <sys/mount.h>
55 #include <sys/errno.h>
56 #include <sys/acct.h>
57 #include <sys/file.h>
58 #include <sys/fcntl.h>
59 #include <sys/uio.h>
60 #include <sys/namei.h>
61 #include <sys/ioccom.h>
62 #include <sys/select.h>
63
64 #include <vm/vm.h>
65 #include <vm/vm_object.h>
66 #include <vm/vm_extern.h>
67 #include <vm/vm_zone.h>
68
69 #include <coda/coda.h>
70 #include <coda/cnode.h>
71 #include <coda/coda_vnops.h>
72 #include <coda/coda_venus.h>
73 #include <coda/coda_opstats.h>
74 #include <coda/coda_subr.h>
75 #include <coda/coda_namecache.h>
76 #include <coda/coda_pioctl.h>
77
78 /* 
79  * These flags select various performance enhancements.
80  */
81 int coda_attr_cache  = 1;       /* Set to cache attributes in the kernel */
82 int coda_symlink_cache = 1;     /* Set to cache symbolic link information */
83 int coda_access_cache = 1;      /* Set to handle some access checks directly */
84
85 /* structure to keep track of vfs calls */
86
87 struct coda_op_stats coda_vnodeopstats[CODA_VNODEOPS_SIZE];
88
89 #define MARK_ENTRY(op) (coda_vnodeopstats[op].entries++)
90 #define MARK_INT_SAT(op) (coda_vnodeopstats[op].sat_intrn++)
91 #define MARK_INT_FAIL(op) (coda_vnodeopstats[op].unsat_intrn++)
92 #define MARK_INT_GEN(op) (coda_vnodeopstats[op].gen_intrn++)
93
94 /* What we are delaying for in printf */
95 int coda_printf_delay = 0;  /* in microseconds */
96 int coda_vnop_print_entry = 0;
97 static int coda_lockdebug = 0;
98
99 /* Definition of the vfs operation vector */
100
101 /*
102  * Some NetBSD details:
103  * 
104  *   coda_start is called at the end of the mount syscall.
105  *   coda_init is called at boot time.
106  */
107
108 #define ENTRY  if(coda_vnop_print_entry) myprintf(("Entered %s\n",__FUNCTION__))
109
110 /* Definition of the vnode operation vector */
111
112 struct vnodeopv_entry_desc coda_vnodeop_entries[] = {
113     { &vop_default_desc, coda_vop_error },
114     { &vop_lookup_desc, coda_lookup },          /* lookup */
115     { &vop_create_desc, coda_create },          /* create */
116     { &vop_mknod_desc, coda_vop_error },        /* mknod */
117     { &vop_open_desc, coda_open },              /* open */
118     { &vop_close_desc, coda_close },            /* close */
119     { &vop_access_desc, coda_access },          /* access */
120     { &vop_getattr_desc, coda_getattr },        /* getattr */
121     { &vop_setattr_desc, coda_setattr },        /* setattr */
122     { &vop_read_desc, coda_read },              /* read */
123     { &vop_write_desc, coda_write },            /* write */
124     { &vop_ioctl_desc, coda_ioctl },            /* ioctl */
125     { &vop_mmap_desc, coda_vop_error },         /* mmap */
126     { &vop_fsync_desc, coda_fsync },            /* fsync */
127     { &vop_remove_desc, coda_remove },          /* remove */
128     { &vop_link_desc, coda_link },              /* link */
129     { &vop_rename_desc, coda_rename },          /* rename */
130     { &vop_mkdir_desc, coda_mkdir },            /* mkdir */
131     { &vop_rmdir_desc, coda_rmdir },            /* rmdir */
132     { &vop_symlink_desc, coda_symlink },        /* symlink */
133     { &vop_readdir_desc, coda_readdir },        /* readdir */
134     { &vop_readlink_desc, coda_readlink },      /* readlink */
135     { &vop_inactive_desc, coda_inactive },      /* inactive */
136     { &vop_reclaim_desc, coda_reclaim },        /* reclaim */
137     { &vop_lock_desc, coda_lock },              /* lock */
138     { &vop_unlock_desc, coda_unlock },          /* unlock */
139     { &vop_bmap_desc, coda_bmap },              /* bmap */
140     { &vop_strategy_desc, coda_strategy },      /* strategy */
141     { &vop_print_desc, coda_vop_error },        /* print */
142     { &vop_islocked_desc, coda_islocked },      /* islocked */
143     { &vop_pathconf_desc, coda_vop_error },     /* pathconf */
144     { &vop_advlock_desc, coda_vop_nop },        /* advlock */
145     { &vop_bwrite_desc, coda_vop_error },       /* bwrite */
146     { &vop_lease_desc, coda_vop_nop },          /* lease */
147     { &vop_poll_desc, (vop_t *) vop_stdpoll },
148     { &vop_getpages_desc, coda_fbsd_getpages }, /* pager intf.*/
149     { &vop_putpages_desc, coda_fbsd_putpages }, /* pager intf.*/
150     { &vop_createvobject_desc,      (vop_t *) vop_stdcreatevobject },
151     { &vop_destroyvobject_desc,     (vop_t *) vop_stddestroyvobject },
152     { &vop_getvobject_desc,         (vop_t *) vop_stdgetvobject },
153
154 #if     0
155
156     we need to define these someday
157 #define UFS_BLKATOFF(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_blkatoff(aa, bb, cc, dd)
158 #define UFS_VALLOC(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_valloc(aa, bb, cc, dd)
159 #define UFS_VFREE(aa, bb, cc) VFSTOUFS((aa)->v_mount)->um_vfree(aa, bb, cc)
160 #define UFS_TRUNCATE(aa, bb, cc, dd, ee) VFSTOUFS((aa)->v_mount)->um_truncate(aa, bb, cc, dd, ee)
161 #define UFS_UPDATE(aa, bb) VFSTOUFS((aa)->v_mount)->um_update(aa, bb)
162
163     missing
164     { &vop_reallocblks_desc,    (vop_t *) ufs_missingop },
165     { &vop_cachedlookup_desc,   (vop_t *) ufs_lookup },
166     { &vop_whiteout_desc,       (vop_t *) ufs_whiteout },
167 #endif
168     { (struct vnodeop_desc*)NULL, (int(*)(void *))NULL }
169 };
170
171 static struct vnodeopv_desc coda_vnodeop_opv_desc =
172                 { &coda_vnodeop_p, coda_vnodeop_entries };
173
174 VNODEOP_SET(coda_vnodeop_opv_desc);
175
176 /* A generic panic: we were called with something we didn't define yet */
177 int
178 coda_vop_error(void *anon) {
179     struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
180
181     myprintf(("coda_vop_error: Vnode operation %s called, but not defined.\n",
182               (*desc)->vdesc_name));
183     /*
184     panic("coda_vop_error");
185     */
186     return EIO;
187 }
188
189 /* A generic do-nothing.  For lease_check, advlock */
190 int
191 coda_vop_nop(void *anon) {
192     struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
193
194     if (codadebug) {
195         myprintf(("Vnode operation %s called, but unsupported\n",
196                   (*desc)->vdesc_name));
197     } 
198    return (0);
199 }
200
201 int
202 coda_vnodeopstats_init(void)
203 {
204         register int i;
205         
206         for(i=0;i<CODA_VNODEOPS_SIZE;i++) {
207                 coda_vnodeopstats[i].opcode = i;
208                 coda_vnodeopstats[i].entries = 0;
209                 coda_vnodeopstats[i].sat_intrn = 0;
210                 coda_vnodeopstats[i].unsat_intrn = 0;
211                 coda_vnodeopstats[i].gen_intrn = 0;
212         }
213         return 0;
214 }
215                 
216 /* 
217  * coda_open calls Venus to return the device, inode pair of the cache
218  * file holding the data. Using iget, coda_open finds the vnode of the
219  * cache file, and then opens it.
220  */
221 int
222 coda_open(v)
223     void *v;
224 {
225     /* 
226      * NetBSD can pass the O_EXCL flag in mode, even though the check
227      * has already happened.  Venus defensively assumes that if open
228      * is passed the EXCL, it must be a bug.  We strip the flag here.
229      */
230 /* true args */
231     struct vop_open_args *ap = v;
232     register struct vnode **vpp = &(ap->a_vp);
233     struct cnode *cp = VTOC(*vpp);
234     int flag = ap->a_mode & (~O_EXCL);
235     struct ucred *cred = ap->a_cred;
236     struct thread *td = ap->a_td;
237 /* locals */
238     int error;
239     struct vnode *vp;
240     dev_t dev;
241     ino_t inode;
242
243     MARK_ENTRY(CODA_OPEN_STATS);
244
245     /* Check for open of control file. */
246     if (IS_CTL_VP(*vpp)) {
247         /* XXX */
248         /* if (WRITEABLE(flag)) */ 
249         if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) {
250             MARK_INT_FAIL(CODA_OPEN_STATS);
251             return(EACCES);
252         }
253         MARK_INT_SAT(CODA_OPEN_STATS);
254         return(0);
255     }
256
257     error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, td, &dev, &inode);
258     if (error)
259         return (error);
260     if (!error) {
261         CODADEBUG( CODA_OPEN,myprintf(("open: dev %#lx inode %lu result %d\n",
262                                        (u_long)dev2udev(dev), (u_long)inode,
263                                        error)); )
264     }
265
266     /* Translate the <device, inode> pair for the cache file into
267        an inode pointer. */
268     error = coda_grab_vnode(dev, inode, &vp);
269     if (error)
270         return (error);
271
272     /* We get the vnode back locked.  Needs unlocked */
273     VOP_UNLOCK(vp, 0, td);
274     /* Keep a reference until the close comes in. */
275     vref(*vpp);                
276
277     /* Save the vnode pointer for the cache file. */
278     if (cp->c_ovp == NULL) {
279         cp->c_ovp = vp;
280     } else {
281         if (cp->c_ovp != vp)
282             panic("coda_open:  cp->c_ovp != ITOV(ip)");
283     }
284     cp->c_ocount++;
285
286     /* Flush the attribute cached if writing the file. */
287     if (flag & FWRITE) {
288         cp->c_owrite++;
289         cp->c_flags &= ~C_VATTR;
290     }
291
292     /* Save the <device, inode> pair for the cache file to speed
293        up subsequent page_read's. */
294     cp->c_device = dev;
295     cp->c_inode = inode;
296
297     /* Open the cache file. */
298     error = VOP_OPEN(vp, flag, cred, td); 
299     if (error) {
300         printf("coda_open: VOP_OPEN on container failed %d\n", error);
301         return (error);
302     }
303 /* grab (above) does this when it calls newvnode unless it's in the cache*/
304     if (vp->v_type == VREG) {
305         error = vfs_object_create(vp, td);
306         if (error != 0) {
307             printf("coda_open: vfs_object_create() returns %d\n", error);
308             vput(vp);
309         }
310     }
311
312     return(error);
313 }
314
315 /*
316  * Close the cache file used for I/O and notify Venus.
317  */
318 int
319 coda_close(v)
320     void *v;
321 {
322 /* true args */
323     struct vop_close_args *ap = v;
324     struct vnode *vp = ap->a_vp;
325     struct cnode *cp = VTOC(vp);
326     int flag = ap->a_fflag;
327     struct thread *td = ap->a_td;
328 /* locals */
329     int error;
330
331     MARK_ENTRY(CODA_CLOSE_STATS);
332
333     /* Check for close of control file. */
334     if (IS_CTL_VP(vp)) {
335         MARK_INT_SAT(CODA_CLOSE_STATS);
336         return(0);
337     }
338
339     if (IS_UNMOUNTING(cp)) {
340         if (cp->c_ovp) {
341 #ifdef  CODA_VERBOSE
342             printf("coda_close: destroying container ref %d, ufs vp %p of vp %p/cp %p\n",
343                     vp->v_usecount, cp->c_ovp, vp, cp);
344 #endif
345 #ifdef  hmm
346             vgone(cp->c_ovp);
347 #else
348             VOP_CLOSE(cp->c_ovp, flag, td); /* Do errors matter here? */
349             vrele(cp->c_ovp);
350 #endif
351         } else {
352 #ifdef  CODA_VERBOSE
353             printf("coda_close: NO container vp %p/cp %p\n", vp, cp);
354 #endif
355         }
356         return ENODEV;
357     } else {
358         VOP_CLOSE(cp->c_ovp, flag, td); /* Do errors matter here? */
359         vrele(cp->c_ovp);
360     }
361
362     if (--cp->c_ocount == 0)
363         cp->c_ovp = NULL;
364
365     if (flag & FWRITE)                    /* file was opened for write */
366         --cp->c_owrite;
367
368     error = venus_close(vtomi(vp), &cp->c_fid, flag, proc0.p_ucred, td);
369     vrele(CTOV(cp));
370
371     CODADEBUG(CODA_CLOSE, myprintf(("close: result %d\n",error)); )
372     return(error);
373 }
374
375 int
376 coda_read(v)
377     void *v;
378 {
379     struct vop_read_args *ap = v;
380
381     ENTRY;
382     return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ,
383                     ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
384 }
385
386 int
387 coda_write(v)
388     void *v;
389 {
390     struct vop_write_args *ap = v;
391
392     ENTRY;
393     return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE,
394                     ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
395 }
396
397 int
398 coda_rdwr(vp, uiop, rw, ioflag, cred, td)
399     struct vnode *vp;
400     struct uio *uiop;
401     enum uio_rw rw;
402     int ioflag;
403     struct ucred *cred;
404     struct thread *td;
405
406 /* upcall decl */
407   /* NOTE: container file operation!!! */
408 /* locals */
409     struct cnode *cp = VTOC(vp);
410     struct vnode *cfvp = cp->c_ovp;
411     int igot_internally = 0;
412     int opened_internally = 0;
413     int error = 0;
414
415     MARK_ENTRY(CODA_RDWR_STATS);
416
417     CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %d, %lld, %d)\n", rw, 
418                               (void *)uiop->uio_iov->iov_base, uiop->uio_resid, 
419                               (long long)uiop->uio_offset, uiop->uio_segflg)); )
420         
421     /* Check for rdwr of control object. */
422     if (IS_CTL_VP(vp)) {
423         MARK_INT_FAIL(CODA_RDWR_STATS);
424         return(EINVAL);
425     }
426
427     /* 
428      * If file is not already open this must be a page
429      * {read,write} request.  Iget the cache file's inode
430      * pointer if we still have its <device, inode> pair.
431      * Otherwise, we must do an internal open to derive the
432      * pair. 
433      */
434     if (cfvp == NULL) {
435         /* 
436          * If we're dumping core, do the internal open. Otherwise
437          * venus won't have the correct size of the core when
438          * it's completely written.
439          */
440         if (cp->c_inode != 0 && (ioflag & IO_CORE) == 0) { 
441             igot_internally = 1;
442             error = coda_grab_vnode(cp->c_device, cp->c_inode, &cfvp);
443             if (error) {
444                 MARK_INT_FAIL(CODA_RDWR_STATS);
445                 return(error);
446             }
447             /* 
448              * We get the vnode back locked in both Mach and
449              * NetBSD.  Needs unlocked 
450              */
451             VOP_UNLOCK(cfvp, 0, td);
452         }
453         else {
454             opened_internally = 1;
455             MARK_INT_GEN(CODA_OPEN_STATS);
456             error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE), 
457                              cred, td);
458 printf("coda_rdwr: Internally Opening %p\n", vp);
459             if (error) {
460                 printf("coda_rdwr: VOP_OPEN on container failed %d\n", error);
461                 return (error);
462             }
463             if (vp->v_type == VREG) {
464                 error = vfs_object_create(vp, td);
465                 if (error != 0) {
466                     printf("coda_rdwr: vfs_object_create() returns %d\n", error);
467                     vput(vp);
468                 }
469             }
470             if (error) {
471                 MARK_INT_FAIL(CODA_RDWR_STATS);
472                 return(error);
473             }
474             cfvp = cp->c_ovp;
475         }
476     }
477
478     /* Have UFS handle the call. */
479     CODADEBUG(CODA_RDWR, myprintf(("indirect rdwr: fid = (%lx.%lx.%lx), refcnt = %d\n",
480                               cp->c_fid.Volume, cp->c_fid.Vnode, 
481                               cp->c_fid.Unique, CTOV(cp)->v_usecount)); )
482
483
484     if (rw == UIO_READ) {
485         error = VOP_READ(cfvp, uiop, ioflag, cred);
486     } else {
487         error = VOP_WRITE(cfvp, uiop, ioflag, cred);
488         /* ufs_write updates the vnode_pager_setsize for the vnode/object */
489
490         {   struct vattr attr;
491
492             if (VOP_GETATTR(cfvp, &attr, td) == 0) {
493                 vnode_pager_setsize(vp, attr.va_size);
494             }
495         }
496     }
497
498     if (error)
499         MARK_INT_FAIL(CODA_RDWR_STATS);
500     else
501         MARK_INT_SAT(CODA_RDWR_STATS);
502
503     /* Do an internal close if necessary. */
504     if (opened_internally) {
505         MARK_INT_GEN(CODA_CLOSE_STATS);
506         (void)VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE), td);
507     }
508
509     /* Invalidate cached attributes if writing. */
510     if (rw == UIO_WRITE)
511         cp->c_flags &= ~C_VATTR;
512     return(error);
513 }
514
515 int
516 coda_ioctl(v)
517     void *v;
518 {
519 /* true args */
520     struct vop_ioctl_args *ap = v;
521     struct vnode *vp = ap->a_vp;
522     int com = ap->a_command;
523     caddr_t data = ap->a_data;
524     int flag = ap->a_fflag;
525     struct ucred *cred = ap->a_cred;
526     struct thread *td = ap->a_td;
527 /* locals */
528     int error;
529     struct vnode *tvp;
530     struct nameidata ndp;
531     struct PioctlData *iap = (struct PioctlData *)data;
532
533     MARK_ENTRY(CODA_IOCTL_STATS);
534
535     CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));)
536         
537     /* Don't check for operation on a dying object, for ctlvp it
538        shouldn't matter */
539         
540     /* Must be control object to succeed. */
541     if (!IS_CTL_VP(vp)) {
542         MARK_INT_FAIL(CODA_IOCTL_STATS);
543         CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != ctlvp"));)
544             return (EOPNOTSUPP);
545     }
546     /* Look up the pathname. */
547
548     /* Should we use the name cache here? It would get it from
549        lookupname sooner or later anyway, right? */
550
551     NDINIT(&ndp, LOOKUP, (iap->follow ? FOLLOW : NOFOLLOW), UIO_USERSPACE, iap->path, td);
552     error = namei(&ndp);
553     tvp = ndp.ni_vp;
554
555     if (error) {
556         MARK_INT_FAIL(CODA_IOCTL_STATS);
557         CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup returns %d\n",
558                                    error));)
559         return(error);
560     }
561
562     /* 
563      * Make sure this is a coda style cnode, but it may be a
564      * different vfsp 
565      */
566     if (tvp->v_op != coda_vnodeop_p) {
567         vrele(tvp);
568         NDFREE(&ndp, NDF_ONLY_PNBUF);
569         MARK_INT_FAIL(CODA_IOCTL_STATS);
570         CODADEBUG(CODA_IOCTL, 
571                  myprintf(("coda_ioctl error: %s not a coda object\n", 
572                         iap->path));)
573         return(EINVAL);
574     }
575
576     if (iap->vi.in_size > VC_MAXDATASIZE) {
577         NDFREE(&ndp, 0);
578         return(EINVAL);
579     }
580     error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data, cred, td);
581
582     if (error)
583         MARK_INT_FAIL(CODA_IOCTL_STATS);
584     else
585         CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); )
586
587     vrele(tvp);
588     NDFREE(&ndp, NDF_ONLY_PNBUF);
589     return(error);
590 }
591
592 /*
593  * To reduce the cost of a user-level venus;we cache attributes in
594  * the kernel.  Each cnode has storage allocated for an attribute. If
595  * c_vattr is valid, return a reference to it. Otherwise, get the
596  * attributes from venus and store them in the cnode.  There is some
597  * question if this method is a security leak. But I think that in
598  * order to make this call, the user must have done a lookup and
599  * opened the file, and therefore should already have access.  
600  */
601 int
602 coda_getattr(v)
603     void *v;
604 {
605 /* true args */
606     struct vop_getattr_args *ap = v;
607     struct vnode *vp = ap->a_vp;
608     struct cnode *cp = VTOC(vp);
609     struct vattr *vap = ap->a_vap;
610     struct thread *td = ap->a_td;
611 /* locals */
612     int error;
613
614     MARK_ENTRY(CODA_GETATTR_STATS);
615
616     if (IS_UNMOUNTING(cp))
617         return ENODEV;
618
619     /* Check for getattr of control object. */
620     if (IS_CTL_VP(vp)) {
621         MARK_INT_FAIL(CODA_GETATTR_STATS);
622         return(ENOENT);
623     }
624
625     /* Check to see if the attributes have already been cached */
626     if (VALID_VATTR(cp)) { 
627         CODADEBUG(CODA_GETATTR, { myprintf(("attr cache hit: (%lx.%lx.%lx)\n",
628                                        cp->c_fid.Volume,
629                                        cp->c_fid.Vnode,
630                                        cp->c_fid.Unique));});
631         CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
632                  print_vattr(&cp->c_vattr); );
633         
634         *vap = cp->c_vattr;
635         MARK_INT_SAT(CODA_GETATTR_STATS);
636         return(0);
637     }
638
639     error = venus_getattr(vtomi(vp), &cp->c_fid, proc0.p_ucred, td, vap);
640
641     if (!error) {
642         CODADEBUG(CODA_GETATTR, myprintf(("getattr miss (%lx.%lx.%lx): result %d\n",
643                                      cp->c_fid.Volume,
644                                      cp->c_fid.Vnode,
645                                      cp->c_fid.Unique,
646                                      error)); )
647             
648         CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
649                  print_vattr(vap);      );
650         
651     {   int size = vap->va_size;
652         struct vnode *convp = cp->c_ovp;
653         if (convp != (struct vnode *)0) {
654             vnode_pager_setsize(convp, size);
655         }
656     }
657         /* If not open for write, store attributes in cnode */   
658         if ((cp->c_owrite == 0) && (coda_attr_cache)) {  
659             cp->c_vattr = *vap;
660             cp->c_flags |= C_VATTR; 
661         }
662         
663     }
664     return(error);
665 }
666
667 int
668 coda_setattr(v)
669     void *v;
670 {
671 /* true args */
672     struct vop_setattr_args *ap = v;
673     register struct vnode *vp = ap->a_vp;
674     struct cnode *cp = VTOC(vp);
675     register struct vattr *vap = ap->a_vap;
676     struct ucred *cred = ap->a_cred;
677     struct thread *td = ap->a_td;
678 /* locals */
679     int error;
680
681     MARK_ENTRY(CODA_SETATTR_STATS);
682
683     /* Check for setattr of control object. */
684     if (IS_CTL_VP(vp)) {
685         MARK_INT_FAIL(CODA_SETATTR_STATS);
686         return(ENOENT);
687     }
688
689     if (codadebug & CODADBGMSK(CODA_SETATTR)) {
690         print_vattr(vap);
691     }
692     error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, td);
693
694     if (!error)
695         cp->c_flags &= ~C_VATTR;
696
697     {   int size = vap->va_size;
698         struct vnode *convp = cp->c_ovp;
699         if (size != VNOVAL && convp != (struct vnode *)0) {
700             vnode_pager_setsize(convp, size);
701         }
702     }
703     CODADEBUG(CODA_SETATTR,     myprintf(("setattr %d\n", error)); )
704     return(error);
705 }
706
707 int
708 coda_access(v)
709     void *v;
710 {
711 /* true args */
712     struct vop_access_args *ap = v;
713     struct vnode *vp = ap->a_vp;
714     struct cnode *cp = VTOC(vp);
715     int mode = ap->a_mode;
716     struct ucred *cred = ap->a_cred;
717     struct thread *td = ap->a_td;
718 /* locals */
719     int error;
720
721     MARK_ENTRY(CODA_ACCESS_STATS);
722
723     /* Check for access of control object.  Only read access is
724        allowed on it. */
725     if (IS_CTL_VP(vp)) {
726         /* bogus hack - all will be marked as successes */
727         MARK_INT_SAT(CODA_ACCESS_STATS);
728         return(((mode & VREAD) && !(mode & (VWRITE | VEXEC))) 
729                ? 0 : EACCES);
730     }
731
732     /*
733      * if the file is a directory, and we are checking exec (eg lookup) 
734      * access, and the file is in the namecache, then the user must have 
735      * lookup access to it.
736      */
737     if (coda_access_cache) {
738         if ((vp->v_type == VDIR) && (mode & VEXEC)) {
739             if (coda_nc_lookup(cp, ".", 1, cred)) {
740                 MARK_INT_SAT(CODA_ACCESS_STATS);
741                 return(0);                     /* it was in the cache */
742             }
743         }
744     }
745
746     error = venus_access(vtomi(vp), &cp->c_fid, mode, cred, td);
747
748     return(error);
749 }
750
751 int
752 coda_readlink(v)
753     void *v;
754 {
755 /* true args */
756     struct vop_readlink_args *ap = v;
757     struct vnode *vp = ap->a_vp;
758     struct cnode *cp = VTOC(vp);
759     struct uio *uiop = ap->a_uio;
760     struct ucred *cred = ap->a_cred;
761     struct thread *td = ap->a_uio->uio_td;
762 /* locals */
763     int error;
764     char *str;
765     int len;
766
767     MARK_ENTRY(CODA_READLINK_STATS);
768
769     /* Check for readlink of control object. */
770     if (IS_CTL_VP(vp)) {
771         MARK_INT_FAIL(CODA_READLINK_STATS);
772         return(ENOENT);
773     }
774
775     if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { /* symlink was cached */
776         uiop->uio_rw = UIO_READ;
777         error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop);
778         if (error)
779             MARK_INT_FAIL(CODA_READLINK_STATS);
780         else
781             MARK_INT_SAT(CODA_READLINK_STATS);
782         return(error);
783     }
784
785     error = venus_readlink(vtomi(vp), &cp->c_fid, cred, td, &str, &len);
786
787     if (!error) {
788         uiop->uio_rw = UIO_READ;
789         error = uiomove(str, len, uiop);
790
791         if (coda_symlink_cache) {
792             cp->c_symlink = str;
793             cp->c_symlen = len;
794             cp->c_flags |= C_SYMLINK;
795         } else
796             CODA_FREE(str, len);
797     }
798
799     CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n",error));)
800     return(error);
801 }
802
803 int
804 coda_fsync(v)
805     void *v;
806 {
807 /* true args */
808     struct vop_fsync_args *ap = v;
809     struct vnode *vp = ap->a_vp;
810     struct cnode *cp = VTOC(vp);
811     struct thread *td = ap->a_td;
812 /* locals */
813     struct vnode *convp = cp->c_ovp;
814     int error;
815    
816     MARK_ENTRY(CODA_FSYNC_STATS);
817
818     /* Check for fsync on an unmounting object */
819     /* The NetBSD kernel, in it's infinite wisdom, can try to fsync
820      * after an unmount has been initiated.  This is a Bad Thing,
821      * which we have to avoid.  Not a legitimate failure for stats.
822      */
823     if (IS_UNMOUNTING(cp)) {
824         return(ENODEV);
825     }
826
827     /* Check for fsync of control object. */
828     if (IS_CTL_VP(vp)) {
829         MARK_INT_SAT(CODA_FSYNC_STATS);
830         return(0);
831     }
832
833     if (convp)
834         VOP_FSYNC(convp, MNT_WAIT, td);
835
836     /*
837      * We see fsyncs with usecount == 1 then usecount == 0.
838      * For now we ignore them.
839      */
840     /*
841     if (!vp->v_usecount) {
842         printf("coda_fsync on vnode %p with %d usecount.  c_flags = %x (%x)\n",
843                 vp, vp->v_usecount, cp->c_flags, cp->c_flags&C_PURGING);
844     }
845     */
846
847     /*
848      * We can expect fsync on any vnode at all if venus is pruging it.
849      * Venus can't very well answer the fsync request, now can it?
850      * Hopefully, it won't have to, because hopefully, venus preserves
851      * the (possibly untrue) invariant that it never purges an open
852      * vnode.  Hopefully.
853      */
854     if (cp->c_flags & C_PURGING) {
855         return(0);
856     }
857
858     /* needs research */
859     return 0;
860     error = venus_fsync(vtomi(vp), &cp->c_fid, proc0.p_ucred, td);
861
862     CODADEBUG(CODA_FSYNC, myprintf(("in fsync result %d\n",error)); );
863     return(error);
864 }
865
866 int
867 coda_inactive(v)
868     void *v;
869 {
870     /* XXX - at the moment, inactive doesn't look at cred, and doesn't
871        have a proc pointer.  Oops. */
872 /* true args */
873     struct vop_inactive_args *ap = v;
874     struct vnode *vp = ap->a_vp;
875     struct cnode *cp = VTOC(vp);
876     struct ucred *cred __attribute__((unused)) = NULL;
877     struct thread *td = curthread;
878 /* upcall decl */
879 /* locals */
880
881     /* We don't need to send inactive to venus - DCS */
882     MARK_ENTRY(CODA_INACTIVE_STATS);
883
884     if (IS_CTL_VP(vp)) {
885         MARK_INT_SAT(CODA_INACTIVE_STATS);
886         return 0;
887     }
888
889     CODADEBUG(CODA_INACTIVE, myprintf(("in inactive, %lx.%lx.%lx. vfsp %p\n",
890                                   cp->c_fid.Volume, cp->c_fid.Vnode, 
891                                   cp->c_fid.Unique, vp->v_mount));)
892
893     /* If an array has been allocated to hold the symlink, deallocate it */
894     if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) {
895         if (cp->c_symlink == NULL)
896             panic("coda_inactive: null symlink pointer in cnode");
897         
898         CODA_FREE(cp->c_symlink, cp->c_symlen);
899         cp->c_flags &= ~C_SYMLINK;
900         cp->c_symlen = 0;
901     }
902
903     /* Remove it from the table so it can't be found. */
904     coda_unsave(cp);
905     if ((struct coda_mntinfo *)(vp->v_mount->mnt_data) == NULL) {
906         myprintf(("Help! vfsp->vfs_data was NULL, but vnode %p wasn't dying\n", vp));
907         panic("badness in coda_inactive\n");
908     }
909
910     if (IS_UNMOUNTING(cp)) {
911 #ifdef  DEBUG
912         printf("coda_inactive: IS_UNMOUNTING use %d: vp %p, cp %p\n", vp->v_usecount, vp, cp);
913         if (cp->c_ovp != NULL)
914             printf("coda_inactive: cp->ovp != NULL use %d: vp %p, cp %p\n",
915                    vp->v_usecount, vp, cp);
916 #endif
917         lockmgr(&cp->c_lock, LK_RELEASE, &vp->v_interlock, td);
918     } else {
919 #ifdef OLD_DIAGNOSTIC
920         if (CTOV(cp)->v_usecount) {
921             panic("coda_inactive: nonzero reference count");
922         }
923         if (cp->c_ovp != NULL) {
924             panic("coda_inactive:  cp->ovp != NULL");
925         }
926 #endif
927         VOP_UNLOCK(vp, 0, td);
928         vgone(vp);
929     }
930
931     MARK_INT_SAT(CODA_INACTIVE_STATS);
932     return(0);
933 }
934
935 /*
936  * Remote file system operations having to do with directory manipulation.
937  */
938
939 /* 
940  * It appears that in NetBSD, lookup is supposed to return the vnode locked
941  */
942 int
943 coda_lookup(v)
944     void *v;
945 {
946 /* true args */
947     struct vop_lookup_args *ap = v;
948     struct vnode *dvp = ap->a_dvp;
949     struct cnode *dcp = VTOC(dvp);
950     struct vnode **vpp = ap->a_vpp;
951     /* 
952      * It looks as though ap->a_cnp->ni_cnd->cn_nameptr holds the rest
953      * of the string to xlate, and that we must try to get at least
954      * ap->a_cnp->ni_cnd->cn_namelen of those characters to macth.  I
955      * could be wrong. 
956      */
957     struct componentname  *cnp = ap->a_cnp;
958     struct ucred *cred = cnp->cn_cred;
959     struct thread *td = cnp->cn_td;
960 /* locals */
961     struct cnode *cp;
962     const char *nm = cnp->cn_nameptr;
963     int len = cnp->cn_namelen;
964     ViceFid VFid;
965     int vtype;
966     int error = 0;
967
968     MARK_ENTRY(CODA_LOOKUP_STATS);
969
970     CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s in %lx.%lx.%lx\n",
971                                    nm, dcp->c_fid.Volume,
972                                    dcp->c_fid.Vnode, dcp->c_fid.Unique)););
973
974     /* Check for lookup of control object. */
975     if (IS_CTL_NAME(dvp, nm, len)) {
976         *vpp = coda_ctlvp;
977         vref(*vpp);
978         MARK_INT_SAT(CODA_LOOKUP_STATS);
979         goto exit;
980     }
981
982     if (len+1 > CODA_MAXNAMLEN) {
983         MARK_INT_FAIL(CODA_LOOKUP_STATS);
984         CODADEBUG(CODA_LOOKUP, myprintf(("name too long: lookup, %lx.%lx.%lx(%s)\n",
985                                     dcp->c_fid.Volume, dcp->c_fid.Vnode,
986                                     dcp->c_fid.Unique, nm)););
987         *vpp = (struct vnode *)0;
988         error = EINVAL;
989         goto exit;
990     }
991     /* First try to look the file up in the cfs name cache */
992     /* lock the parent vnode? */
993     cp = coda_nc_lookup(dcp, nm, len, cred);
994     if (cp) {
995         *vpp = CTOV(cp);
996         vref(*vpp);
997         CODADEBUG(CODA_LOOKUP, 
998                  myprintf(("lookup result %d vpp %p\n",error,*vpp));)
999     } else {
1000         
1001         /* The name wasn't cached, so we need to contact Venus */
1002         error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, td, &VFid, &vtype);
1003         
1004         if (error) {
1005             MARK_INT_FAIL(CODA_LOOKUP_STATS);
1006             CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on %lx.%lx.%lx(%s)%d\n",
1007                                         dcp->c_fid.Volume, dcp->c_fid.Vnode, dcp->c_fid.Unique, nm, error));)
1008             *vpp = (struct vnode *)0;
1009         } else {
1010             MARK_INT_SAT(CODA_LOOKUP_STATS);
1011             CODADEBUG(CODA_LOOKUP, 
1012                      myprintf(("lookup: vol %lx vno %lx uni %lx type %o result %d\n",
1013                             VFid.Volume, VFid.Vnode, VFid.Unique, vtype,
1014                             error)); )
1015                 
1016             cp = make_coda_node(&VFid, dvp->v_mount, vtype);
1017             *vpp = CTOV(cp);
1018             
1019             /* enter the new vnode in the Name Cache only if the top bit isn't set */
1020             /* And don't enter a new vnode for an invalid one! */
1021             if (!(vtype & CODA_NOCACHE))
1022                 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1023         }
1024     }
1025
1026  exit:
1027     /* 
1028      * If we are creating, and this was the last name to be looked up,
1029      * and the error was ENOENT, then there really shouldn't be an
1030      * error and we can make the leaf NULL and return success.  Since
1031      * this is supposed to work under Mach as well as NetBSD, we're
1032      * leaving this fn wrapped.  We also must tell lookup/namei that
1033      * we need to save the last component of the name.  (Create will
1034      * have to free the name buffer later...lucky us...)
1035      */
1036     if (((cnp->cn_nameiop == CREATE) || (cnp->cn_nameiop == RENAME))
1037         && (cnp->cn_flags & ISLASTCN)
1038         && (error == ENOENT))
1039     {
1040         error = EJUSTRETURN;
1041         cnp->cn_flags |= SAVENAME;
1042         *ap->a_vpp = NULL;
1043     }
1044
1045     /* 
1046      * If we are removing, and we are at the last element, and we
1047      * found it, then we need to keep the name around so that the
1048      * removal will go ahead as planned.  Unfortunately, this will
1049      * probably also lock the to-be-removed vnode, which may or may
1050      * not be a good idea.  I'll have to look at the bits of
1051      * coda_remove to make sure.  We'll only save the name if we did in
1052      * fact find the name, otherwise coda_remove won't have a chance
1053      * to free the pathname.  
1054      */
1055     if ((cnp->cn_nameiop == DELETE)
1056         && (cnp->cn_flags & ISLASTCN)
1057         && !error)
1058     {
1059         cnp->cn_flags |= SAVENAME;
1060     }
1061
1062     /* 
1063      * If the lookup went well, we need to (potentially?) unlock the
1064      * parent, and lock the child.  We are only responsible for
1065      * checking to see if the parent is supposed to be unlocked before
1066      * we return.  We must always lock the child (provided there is
1067      * one, and (the parent isn't locked or it isn't the same as the
1068      * parent.)  Simple, huh?  We can never leave the parent locked unless
1069      * we are ISLASTCN
1070      */
1071     if (!error || (error == EJUSTRETURN)) {
1072         if (!(cnp->cn_flags & LOCKPARENT) || !(cnp->cn_flags & ISLASTCN)) {
1073             if ((error = VOP_UNLOCK(dvp, 0, td))) {
1074                 return error; 
1075             }       
1076             /* 
1077              * The parent is unlocked.  As long as there is a child,
1078              * lock it without bothering to check anything else. 
1079              */
1080             if (*ap->a_vpp) {
1081                 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) {
1082                     printf("coda_lookup: ");
1083                     panic("unlocked parent but couldn't lock child");
1084                 }
1085             }
1086         } else {
1087             /* The parent is locked, and may be the same as the child */
1088             if (*ap->a_vpp && (*ap->a_vpp != dvp)) {
1089                 /* Different, go ahead and lock it. */
1090                 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) {
1091                     printf("coda_lookup: ");
1092                     panic("unlocked parent but couldn't lock child");
1093                 }
1094             }
1095         }
1096     } else {
1097         /* If the lookup failed, we need to ensure that the leaf is NULL */
1098         /* Don't change any locking? */
1099         *ap->a_vpp = NULL;
1100     }
1101     return(error);
1102 }
1103
1104 /*ARGSUSED*/
1105 int
1106 coda_create(v)
1107     void *v;
1108 {
1109 /* true args */
1110     struct vop_create_args *ap = v;
1111     struct vnode *dvp = ap->a_dvp;
1112     struct cnode *dcp = VTOC(dvp);
1113     struct vattr *va = ap->a_vap;
1114     int exclusive = 1;
1115     int mode = ap->a_vap->va_mode;
1116     struct vnode **vpp = ap->a_vpp;
1117     struct componentname  *cnp = ap->a_cnp;
1118     struct ucred *cred = cnp->cn_cred;
1119     struct thread *td = cnp->cn_td;
1120 /* locals */
1121     int error;
1122     struct cnode *cp;
1123     const char *nm = cnp->cn_nameptr;
1124     int len = cnp->cn_namelen;
1125     ViceFid VFid;
1126     struct vattr attr;
1127
1128     MARK_ENTRY(CODA_CREATE_STATS);
1129
1130     /* All creates are exclusive XXX */
1131     /* I'm assuming the 'mode' argument is the file mode bits XXX */
1132
1133     /* Check for create of control object. */
1134     if (IS_CTL_NAME(dvp, nm, len)) {
1135         *vpp = (struct vnode *)0;
1136         MARK_INT_FAIL(CODA_CREATE_STATS);
1137         return(EACCES);
1138     }
1139
1140     error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, td, &VFid, &attr);
1141
1142     if (!error) {
1143         
1144         /* If this is an exclusive create, panic if the file already exists. */
1145         /* Venus should have detected the file and reported EEXIST. */
1146
1147         if ((exclusive == 1) &&
1148             (coda_find(&VFid) != NULL))
1149             panic("cnode existed for newly created file!");
1150         
1151         cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type);
1152         *vpp = CTOV(cp);
1153         
1154         /* Update va to reflect the new attributes. */
1155         (*va) = attr;
1156         
1157         /* Update the attribute cache and mark it as valid */
1158         if (coda_attr_cache) {
1159             VTOC(*vpp)->c_vattr = attr;
1160             VTOC(*vpp)->c_flags |= C_VATTR;       
1161         }
1162
1163         /* Invalidate the parent's attr cache, the modification time has changed */
1164         VTOC(dvp)->c_flags &= ~C_VATTR;
1165         
1166         /* enter the new vnode in the Name Cache */
1167         coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1168         
1169         CODADEBUG(CODA_CREATE, 
1170                  myprintf(("create: (%lx.%lx.%lx), result %d\n",
1171                         VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1172     } else {
1173         *vpp = (struct vnode *)0;
1174         CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", error));)
1175     }
1176
1177     if (!error) {
1178         if (cnp->cn_flags & LOCKLEAF) {
1179             if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) {
1180                 printf("coda_create: ");
1181                 panic("unlocked parent but couldn't lock child");
1182             }
1183         }
1184 #ifdef OLD_DIAGNOSTIC
1185         else {
1186             printf("coda_create: LOCKLEAF not set!\n");
1187         }
1188 #endif
1189     }
1190     return(error);
1191 }
1192
1193 int
1194 coda_remove(v)
1195     void *v;
1196 {
1197 /* true args */
1198     struct vop_remove_args *ap = v;
1199     struct vnode *dvp = ap->a_dvp;
1200     struct cnode *cp = VTOC(dvp);
1201     struct componentname  *cnp = ap->a_cnp;
1202     struct ucred *cred = cnp->cn_cred;
1203     struct thread *td = cnp->cn_td;
1204 /* locals */
1205     int error;
1206     const char *nm = cnp->cn_nameptr;
1207     int len = cnp->cn_namelen;
1208     struct cnode *tp;
1209
1210     MARK_ENTRY(CODA_REMOVE_STATS);
1211
1212     CODADEBUG(CODA_REMOVE, myprintf(("remove: %s in %lx.%lx.%lx\n",
1213                                    nm, cp->c_fid.Volume, cp->c_fid.Vnode,
1214                                    cp->c_fid.Unique)););
1215
1216     /* Remove the file's entry from the CODA Name Cache */
1217     /* We're being conservative here, it might be that this person
1218      * doesn't really have sufficient access to delete the file
1219      * but we feel zapping the entry won't really hurt anyone -- dcs
1220      */
1221     /* I'm gonna go out on a limb here. If a file and a hardlink to it
1222      * exist, and one is removed, the link count on the other will be
1223      * off by 1. We could either invalidate the attrs if cached, or
1224      * fix them. I'll try to fix them. DCS 11/8/94
1225      */
1226     tp = coda_nc_lookup(VTOC(dvp), nm, len, cred);
1227     if (tp) {
1228         if (VALID_VATTR(tp)) {  /* If attrs are cached */
1229             if (tp->c_vattr.va_nlink > 1) {     /* If it's a hard link */
1230                 tp->c_vattr.va_nlink--;
1231             }
1232         }
1233         
1234         coda_nc_zapfile(VTOC(dvp), nm, len); 
1235         /* No need to flush it if it doesn't exist! */
1236     }
1237     /* Invalidate the parent's attr cache, the modification time has changed */
1238     VTOC(dvp)->c_flags &= ~C_VATTR;
1239
1240     /* Check for remove of control object. */
1241     if (IS_CTL_NAME(dvp, nm, len)) {
1242         MARK_INT_FAIL(CODA_REMOVE_STATS);
1243         return(ENOENT);
1244     }
1245
1246     error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, td);
1247
1248     CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error)); )
1249
1250     return(error);
1251 }
1252
1253 int
1254 coda_link(v)
1255     void *v;
1256 {
1257 /* true args */
1258     struct vop_link_args *ap = v;
1259     struct vnode *vp = ap->a_vp;
1260     struct cnode *cp = VTOC(vp);
1261     struct vnode *tdvp = ap->a_tdvp;
1262     struct cnode *tdcp = VTOC(tdvp);
1263     struct componentname *cnp = ap->a_cnp;
1264     struct ucred *cred = cnp->cn_cred;
1265     struct thread *td = cnp->cn_td;
1266 /* locals */
1267     int error;
1268     const char *nm = cnp->cn_nameptr;
1269     int len = cnp->cn_namelen;
1270
1271     MARK_ENTRY(CODA_LINK_STATS);
1272
1273     if (codadebug & CODADBGMSK(CODA_LINK)) {
1274
1275         myprintf(("nb_link:   vp fid: (%lx.%lx.%lx)\n",
1276                   cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1277         myprintf(("nb_link: tdvp fid: (%lx.%lx.%lx)\n",
1278                   tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1279         
1280     }
1281     if (codadebug & CODADBGMSK(CODA_LINK)) {
1282         myprintf(("link:   vp fid: (%lx.%lx.%lx)\n",
1283                   cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1284         myprintf(("link: tdvp fid: (%lx.%lx.%lx)\n",
1285                   tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1286
1287     }
1288
1289     /* Check for link to/from control object. */
1290     if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) {
1291         MARK_INT_FAIL(CODA_LINK_STATS);
1292         return(EACCES);
1293     }
1294
1295     error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, cred, td);
1296
1297     /* Invalidate the parent's attr cache, the modification time has changed */
1298     VTOC(tdvp)->c_flags &= ~C_VATTR;
1299     VTOC(vp)->c_flags &= ~C_VATTR;
1300
1301     CODADEBUG(CODA_LINK,        myprintf(("in link result %d\n",error)); )
1302
1303     return(error);
1304 }
1305
1306 int
1307 coda_rename(v)
1308     void *v;
1309 {
1310 /* true args */
1311     struct vop_rename_args *ap = v;
1312     struct vnode *odvp = ap->a_fdvp;
1313     struct cnode *odcp = VTOC(odvp);
1314     struct componentname  *fcnp = ap->a_fcnp;
1315     struct vnode *ndvp = ap->a_tdvp;
1316     struct cnode *ndcp = VTOC(ndvp);
1317     struct componentname  *tcnp = ap->a_tcnp;
1318     struct ucred *cred = fcnp->cn_cred;
1319     struct thread *td = fcnp->cn_td;
1320 /* true args */
1321     int error;
1322     const char *fnm = fcnp->cn_nameptr;
1323     int flen = fcnp->cn_namelen;
1324     const char *tnm = tcnp->cn_nameptr;
1325     int tlen = tcnp->cn_namelen;
1326
1327     MARK_ENTRY(CODA_RENAME_STATS);
1328
1329     /* Hmmm.  The vnodes are already looked up.  Perhaps they are locked?
1330        This could be Bad. XXX */
1331 #ifdef OLD_DIAGNOSTIC
1332     if ((fcnp->cn_cred != tcnp->cn_cred) || (fcnp->cn_td != tcnp->cn_td))
1333     {
1334         panic("coda_rename: component names don't agree");
1335     }
1336 #endif
1337
1338     /* Check for rename involving control object. */ 
1339     if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) {
1340         MARK_INT_FAIL(CODA_RENAME_STATS);
1341         return(EACCES);
1342     }
1343
1344     /* Problem with moving directories -- need to flush entry for .. */
1345     if (odvp != ndvp) {
1346         struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred);
1347         if (ovcp) {
1348             struct vnode *ovp = CTOV(ovcp);
1349             if ((ovp) &&
1350                 (ovp->v_type == VDIR)) /* If it's a directory */
1351                 coda_nc_zapfile(VTOC(ovp),"..", 2);
1352         }
1353     }
1354
1355     /* Remove the entries for both source and target files */
1356     coda_nc_zapfile(VTOC(odvp), fnm, flen);
1357     coda_nc_zapfile(VTOC(ndvp), tnm, tlen);
1358
1359     /* Invalidate the parent's attr cache, the modification time has changed */
1360     VTOC(odvp)->c_flags &= ~C_VATTR;
1361     VTOC(ndvp)->c_flags &= ~C_VATTR;
1362
1363     if (flen+1 > CODA_MAXNAMLEN) {
1364         MARK_INT_FAIL(CODA_RENAME_STATS);
1365         error = EINVAL;
1366         goto exit;
1367     }
1368
1369     if (tlen+1 > CODA_MAXNAMLEN) {
1370         MARK_INT_FAIL(CODA_RENAME_STATS);
1371         error = EINVAL;
1372         goto exit;
1373     }
1374
1375     error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, td);
1376
1377  exit:
1378     CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));)
1379     /* XXX - do we need to call cache pureg on the moved vnode? */
1380     cache_purge(ap->a_fvp);
1381
1382     /* It seems to be incumbent on us to drop locks on all four vnodes */
1383     /* From-vnodes are not locked, only ref'd.  To-vnodes are locked. */
1384
1385     vrele(ap->a_fvp);
1386     vrele(odvp);
1387
1388     if (ap->a_tvp) {
1389         if (ap->a_tvp == ndvp) {
1390             vrele(ap->a_tvp);
1391         } else {
1392             vput(ap->a_tvp);
1393         }
1394     }
1395
1396     vput(ndvp);
1397     return(error);
1398 }
1399
1400 int
1401 coda_mkdir(v)
1402     void *v;
1403 {
1404 /* true args */
1405     struct vop_mkdir_args *ap = v;
1406     struct vnode *dvp = ap->a_dvp;
1407     struct cnode *dcp = VTOC(dvp);      
1408     struct componentname  *cnp = ap->a_cnp;
1409     register struct vattr *va = ap->a_vap;
1410     struct vnode **vpp = ap->a_vpp;
1411     struct ucred *cred = cnp->cn_cred;
1412     struct thread *td = cnp->cn_td;
1413 /* locals */
1414     int error;
1415     const char *nm = cnp->cn_nameptr;
1416     int len = cnp->cn_namelen;
1417     struct cnode *cp;
1418     ViceFid VFid;
1419     struct vattr ova;
1420
1421     MARK_ENTRY(CODA_MKDIR_STATS);
1422
1423     /* Check for mkdir of target object. */
1424     if (IS_CTL_NAME(dvp, nm, len)) {
1425         *vpp = (struct vnode *)0;
1426         MARK_INT_FAIL(CODA_MKDIR_STATS);
1427         return(EACCES);
1428     }
1429
1430     if (len+1 > CODA_MAXNAMLEN) {
1431         *vpp = (struct vnode *)0;
1432         MARK_INT_FAIL(CODA_MKDIR_STATS);
1433         return(EACCES);
1434     }
1435
1436     error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, td, &VFid, &ova);
1437
1438     if (!error) {
1439         if (coda_find(&VFid) != NULL)
1440             panic("cnode existed for newly created directory!");
1441         
1442         
1443         cp =  make_coda_node(&VFid, dvp->v_mount, va->va_type);
1444         *vpp = CTOV(cp);
1445         
1446         /* enter the new vnode in the Name Cache */
1447         coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1448
1449         /* as a side effect, enter "." and ".." for the directory */
1450         coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp));
1451         coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp));
1452
1453         if (coda_attr_cache) {
1454             VTOC(*vpp)->c_vattr = ova;          /* update the attr cache */
1455             VTOC(*vpp)->c_flags |= C_VATTR;     /* Valid attributes in cnode */
1456         }
1457
1458         /* Invalidate the parent's attr cache, the modification time has changed */
1459         VTOC(dvp)->c_flags &= ~C_VATTR;
1460         
1461         CODADEBUG( CODA_MKDIR, myprintf(("mkdir: (%lx.%lx.%lx) result %d\n",
1462                                     VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1463     } else {
1464         *vpp = (struct vnode *)0;
1465         CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));)
1466     }
1467
1468     return(error);
1469 }
1470
1471 int
1472 coda_rmdir(v)
1473     void *v;
1474 {
1475 /* true args */
1476     struct vop_rmdir_args *ap = v;
1477     struct vnode *dvp = ap->a_dvp;
1478     struct cnode *dcp = VTOC(dvp);
1479     struct componentname  *cnp = ap->a_cnp;
1480     struct ucred *cred = cnp->cn_cred;
1481     struct thread *td = cnp->cn_td;
1482 /* true args */
1483     int error;
1484     const char *nm = cnp->cn_nameptr;
1485     int len = cnp->cn_namelen;
1486     struct cnode *cp;
1487    
1488     MARK_ENTRY(CODA_RMDIR_STATS);
1489
1490     /* Check for rmdir of control object. */
1491     if (IS_CTL_NAME(dvp, nm, len)) {
1492         MARK_INT_FAIL(CODA_RMDIR_STATS);
1493         return(ENOENT);
1494     }
1495
1496     /* We're being conservative here, it might be that this person
1497      * doesn't really have sufficient access to delete the file
1498      * but we feel zapping the entry won't really hurt anyone -- dcs
1499      */
1500     /*
1501      * As a side effect of the rmdir, remove any entries for children of
1502      * the directory, especially "." and "..".
1503      */
1504     cp = coda_nc_lookup(dcp, nm, len, cred);
1505     if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL);
1506
1507     /* Remove the file's entry from the CODA Name Cache */
1508     coda_nc_zapfile(dcp, nm, len);
1509
1510     /* Invalidate the parent's attr cache, the modification time has changed */
1511     dcp->c_flags &= ~C_VATTR;
1512
1513     error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, td);
1514
1515     CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); )
1516
1517     return(error);
1518 }
1519
1520 int
1521 coda_symlink(v)
1522     void *v;
1523 {
1524 /* true args */
1525     struct vop_symlink_args *ap = v;
1526     struct vnode *tdvp = ap->a_dvp;
1527     struct cnode *tdcp = VTOC(tdvp);    
1528     struct componentname *cnp = ap->a_cnp;
1529     struct vattr *tva = ap->a_vap;
1530     char *path = ap->a_target;
1531     struct ucred *cred = cnp->cn_cred;
1532     struct thread *td = cnp->cn_td;
1533     struct vnode **vpp = ap->a_vpp;
1534 /* locals */
1535     int error;
1536     /* 
1537      * XXX I'm assuming the following things about coda_symlink's
1538      * arguments: 
1539      *       t(foo) is the new name/parent/etc being created.
1540      *       lname is the contents of the new symlink. 
1541      */
1542     char *nm = cnp->cn_nameptr;
1543     int len = cnp->cn_namelen;
1544     int plen = strlen(path);
1545
1546     /* 
1547      * Here's the strategy for the moment: perform the symlink, then
1548      * do a lookup to grab the resulting vnode.  I know this requires
1549      * two communications with Venus for a new sybolic link, but
1550      * that's the way the ball bounces.  I don't yet want to change
1551      * the way the Mach symlink works.  When Mach support is
1552      * deprecated, we should change symlink so that the common case
1553      * returns the resultant vnode in a vpp argument.
1554      */
1555
1556     MARK_ENTRY(CODA_SYMLINK_STATS);
1557
1558     /* Check for symlink of control object. */
1559     if (IS_CTL_NAME(tdvp, nm, len)) {
1560         MARK_INT_FAIL(CODA_SYMLINK_STATS);
1561         return(EACCES);
1562     }
1563
1564     if (plen+1 > CODA_MAXPATHLEN) {
1565         MARK_INT_FAIL(CODA_SYMLINK_STATS);
1566         return(EINVAL);
1567     }
1568
1569     if (len+1 > CODA_MAXNAMLEN) {
1570         MARK_INT_FAIL(CODA_SYMLINK_STATS);
1571         error = EINVAL;
1572         goto exit;
1573     }
1574
1575     error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, tva, cred, td);
1576
1577     /* Invalidate the parent's attr cache, the modification time has changed */
1578     tdcp->c_flags &= ~C_VATTR;
1579
1580     if (error == 0)
1581         error = VOP_LOOKUP(tdvp, vpp, cnp);
1582
1583  exit:    
1584     CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); )
1585     return(error);
1586 }
1587
1588 /*
1589  * Read directory entries.
1590  */
1591 int
1592 coda_readdir(v)
1593     void *v;
1594 {
1595 /* true args */
1596     struct vop_readdir_args *ap = v;
1597     struct vnode *vp = ap->a_vp;
1598     struct cnode *cp = VTOC(vp);
1599     register struct uio *uiop = ap->a_uio;
1600     struct ucred *cred = ap->a_cred;
1601     int *eofflag = ap->a_eofflag;
1602     u_long **cookies = ap->a_cookies;
1603     int *ncookies = ap->a_ncookies;
1604     struct thread *td = ap->a_uio->uio_td;
1605 /* upcall decl */
1606 /* locals */
1607     int error = 0;
1608
1609     MARK_ENTRY(CODA_READDIR_STATS);
1610
1611     CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %d, %lld, %d)\n",
1612                                       (void *)uiop->uio_iov->iov_base,
1613                                       uiop->uio_resid,
1614                                       (long long)uiop->uio_offset,
1615                                       uiop->uio_segflg)); )
1616         
1617     /* Check for readdir of control object. */
1618     if (IS_CTL_VP(vp)) {
1619         MARK_INT_FAIL(CODA_READDIR_STATS);
1620         return(ENOENT);
1621     }
1622
1623     {
1624         /* If directory is not already open do an "internal open" on it. */
1625         int opened_internally = 0;
1626         if (cp->c_ovp == NULL) {
1627             opened_internally = 1;
1628             MARK_INT_GEN(CODA_OPEN_STATS);
1629             error = VOP_OPEN(vp, FREAD, cred, td);
1630 printf("coda_readdir: Internally Opening %p\n", vp);
1631             if (error) {
1632                 printf("coda_readdir: VOP_OPEN on container failed %d\n", error);
1633                 return (error);
1634             }
1635             if (vp->v_type == VREG) {
1636                 error = vfs_object_create(vp, td);
1637                 if (error != 0) {
1638                     printf("coda_readdir: vfs_object_create() returns %d\n", error);
1639                     vput(vp);
1640                 }
1641             }
1642             if (error) return(error);
1643         }
1644         
1645         /* Have UFS handle the call. */
1646         CODADEBUG(CODA_READDIR, myprintf(("indirect readdir: fid = (%lx.%lx.%lx), refcnt = %d\n",cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique, vp->v_usecount)); )
1647         error = VOP_READDIR(cp->c_ovp, uiop, cred, eofflag, ncookies,
1648                                cookies);
1649         
1650         if (error)
1651             MARK_INT_FAIL(CODA_READDIR_STATS);
1652         else
1653             MARK_INT_SAT(CODA_READDIR_STATS);
1654         
1655         /* Do an "internal close" if necessary. */ 
1656         if (opened_internally) {
1657             MARK_INT_GEN(CODA_CLOSE_STATS);
1658             (void)VOP_CLOSE(vp, FREAD, td);
1659         }
1660     }
1661
1662     return(error);
1663 }
1664
1665 /*
1666  * Convert from file system blocks to device blocks
1667  */
1668 int
1669 coda_bmap(v)
1670     void *v;
1671 {
1672     /* XXX on the global proc */
1673 /* true args */
1674     struct vop_bmap_args *ap = v;
1675     struct vnode *vp __attribute__((unused)) = ap->a_vp;        /* file's vnode */
1676     daddr_t bn __attribute__((unused)) = ap->a_bn;      /* fs block number */
1677     struct vnode **vpp = ap->a_vpp;                     /* RETURN vp of device */
1678     daddr_t *bnp __attribute__((unused)) = ap->a_bnp;   /* RETURN device block number */
1679 /* upcall decl */
1680 /* locals */
1681
1682         int ret = 0;
1683         struct cnode *cp;
1684
1685         cp = VTOC(vp);
1686         if (cp->c_ovp) {
1687                 return EINVAL;
1688                 ret =  VOP_BMAP(cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb);
1689 #if     0
1690                 printf("VOP_BMAP(cp->c_ovp %p, bn %p, vpp %p, bnp %p, ap->a_runp %p, ap->a_runb %p) = %d\n",
1691                         cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb, ret);
1692 #endif
1693                 return ret;
1694         } else {
1695 #if     0
1696                 printf("coda_bmap: no container\n");
1697 #endif
1698                 return(EOPNOTSUPP);
1699         }
1700 }
1701
1702 /*
1703  * I don't think the following two things are used anywhere, so I've
1704  * commented them out 
1705  * 
1706  * struct buf *async_bufhead; 
1707  * int async_daemon_count;
1708  */
1709 int
1710 coda_strategy(v)
1711     void *v;
1712 {
1713 /* true args */
1714     struct vop_strategy_args *ap = v;
1715     register struct buf *bp __attribute__((unused)) = ap->a_bp;
1716 /* upcall decl */
1717 /* locals */
1718
1719         printf("coda_strategy: called ???\n");
1720         return(EOPNOTSUPP);
1721 }
1722
1723 int
1724 coda_reclaim(v) 
1725     void *v;
1726 {
1727 /* true args */
1728     struct vop_reclaim_args *ap = v;
1729     struct vnode *vp = ap->a_vp;
1730     struct cnode *cp = VTOC(vp);
1731 /* upcall decl */
1732 /* locals */
1733
1734 /*
1735  * Forced unmount/flush will let vnodes with non zero use be destroyed!
1736  */
1737     ENTRY;
1738
1739     if (IS_UNMOUNTING(cp)) {
1740 #ifdef  DEBUG
1741         if (VTOC(vp)->c_ovp) {
1742             if (IS_UNMOUNTING(cp))
1743                 printf("coda_reclaim: c_ovp not void: vp %p, cp %p\n", vp, cp);
1744         }
1745 #endif
1746     } else {
1747 #ifdef OLD_DIAGNOSTIC
1748         if (vp->v_usecount != 0) 
1749             print("coda_reclaim: pushing active %p\n", vp);
1750         if (VTOC(vp)->c_ovp) {
1751             panic("coda_reclaim: c_ovp not void");
1752     }
1753 #endif
1754     }   
1755     cache_purge(vp);
1756     coda_free(VTOC(vp));
1757     VTOC(vp) = NULL;
1758     return (0);
1759 }
1760
1761 int
1762 coda_lock(v)
1763     void *v;
1764 {
1765 /* true args */
1766     struct vop_lock_args *ap = v;
1767     struct vnode *vp = ap->a_vp;
1768     struct cnode *cp = VTOC(vp);
1769     struct thread *td = ap->a_td;
1770 /* upcall decl */
1771 /* locals */
1772
1773     ENTRY;
1774
1775     if (coda_lockdebug) {
1776         myprintf(("Attempting lock on %lx.%lx.%lx\n",
1777                   cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1778     }
1779
1780 #ifndef DEBUG_LOCKS
1781     return (lockmgr(&cp->c_lock, ap->a_flags, &vp->v_interlock, td));
1782 #else
1783     return (debuglockmgr(&cp->c_lock, ap->a_flags, &vp->v_interlock, td,
1784                          "coda_lock", vp->filename, vp->line));
1785 #endif
1786 }
1787
1788 int
1789 coda_unlock(v)
1790     void *v;
1791 {
1792 /* true args */
1793     struct vop_unlock_args *ap = v;
1794     struct vnode *vp = ap->a_vp;
1795     struct cnode *cp = VTOC(vp);
1796     struct thread *td = ap->a_td;
1797 /* upcall decl */
1798 /* locals */
1799
1800     ENTRY;
1801     if (coda_lockdebug) {
1802         myprintf(("Attempting unlock on %lx.%lx.%lx\n",
1803                   cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1804     }
1805
1806     return (lockmgr(&cp->c_lock, ap->a_flags | LK_RELEASE, &vp->v_interlock, td));
1807 }
1808
1809 int
1810 coda_islocked(v)
1811     void *v;
1812 {
1813 /* true args */
1814     struct vop_islocked_args *ap = v;
1815     struct cnode *cp = VTOC(ap->a_vp);
1816     ENTRY;
1817
1818     return (lockstatus(&cp->c_lock, ap->a_td));
1819 }
1820
1821 /* How one looks up a vnode given a device/inode pair: */
1822 int
1823 coda_grab_vnode(dev_t dev, ino_t ino, struct vnode **vpp)
1824 {
1825     /* This is like VFS_VGET() or igetinode()! */
1826     int           error;
1827     struct mount *mp;
1828
1829     if (!(mp = devtomp(dev))) {
1830         myprintf(("coda_grab_vnode: devtomp(%#lx) returns NULL\n",
1831                   (u_long)dev2udev(dev)));
1832         return(ENXIO);
1833     }
1834
1835     /* XXX - ensure that nonzero-return means failure */
1836     error = VFS_VGET(mp,ino,vpp);
1837     if (error) {
1838         myprintf(("coda_grab_vnode: iget/vget(%lx, %lu) returns %p, err %d\n", 
1839                   (u_long)dev2udev(dev), (u_long)ino, (void *)*vpp, error));
1840         return(ENOENT);
1841     }
1842     return(0);
1843 }
1844
1845 void
1846 print_vattr( attr )
1847         struct vattr *attr;
1848 {
1849     char *typestr;
1850
1851     switch (attr->va_type) {
1852     case VNON:
1853         typestr = "VNON";
1854         break;
1855     case VREG:
1856         typestr = "VREG";
1857         break;
1858     case VDIR:
1859         typestr = "VDIR";
1860         break;
1861     case VBLK:
1862         typestr = "VBLK";
1863         break;
1864     case VCHR:
1865         typestr = "VCHR";
1866         break;
1867     case VLNK:
1868         typestr = "VLNK";
1869         break;
1870     case VSOCK:
1871         typestr = "VSCK";
1872         break;
1873     case VFIFO:
1874         typestr = "VFFO";
1875         break;
1876     case VBAD:
1877         typestr = "VBAD";
1878         break;
1879     default:
1880         typestr = "????";
1881         break;
1882     }
1883
1884
1885     myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n",
1886               typestr, (int)attr->va_mode, (int)attr->va_uid,
1887               (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev));
1888
1889     myprintf(("      fileid %d nlink %d size %d blocksize %d bytes %d\n",
1890               (int)attr->va_fileid, (int)attr->va_nlink, 
1891               (int)attr->va_size,
1892               (int)attr->va_blocksize,(int)attr->va_bytes));
1893     myprintf(("      gen %ld flags %ld vaflags %d\n",
1894               attr->va_gen, attr->va_flags, attr->va_vaflags));
1895     myprintf(("      atime sec %d nsec %d\n",
1896               (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec));
1897     myprintf(("      mtime sec %d nsec %d\n",
1898               (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec));
1899     myprintf(("      ctime sec %d nsec %d\n",
1900               (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec));
1901 }
1902
1903 /* How to print a ucred */
1904 void
1905 print_cred(cred)
1906         struct ucred *cred;
1907 {
1908
1909         int i;
1910
1911         myprintf(("ref %d\tuid %d\n",cred->cr_ref,cred->cr_uid));
1912
1913         for (i=0; i < cred->cr_ngroups; i++)
1914                 myprintf(("\tgroup %d: (%d)\n",i,cred->cr_groups[i]));
1915         myprintf(("\n"));
1916
1917 }
1918
1919 /*
1920  * Return a vnode for the given fid.
1921  * If no cnode exists for this fid create one and put it
1922  * in a table hashed by fid.Volume and fid.Vnode.  If the cnode for
1923  * this fid is already in the table return it (ref count is
1924  * incremented by coda_find.  The cnode will be flushed from the
1925  * table when coda_inactive calls coda_unsave.
1926  */
1927 struct cnode *
1928 make_coda_node(fid, vfsp, type)
1929      ViceFid *fid; struct mount *vfsp; short type;
1930 {
1931     struct cnode *cp;
1932     int          err;
1933
1934     if ((cp = coda_find(fid)) == NULL) {
1935         struct vnode *vp;
1936         
1937         cp = coda_alloc();
1938         lockinit(&cp->c_lock, 0, "cnode", 0, 0);
1939         cp->c_fid = *fid;
1940         
1941         err = getnewvnode(VT_CODA, vfsp, coda_vnodeop_p, &vp);  
1942         if (err) {                                                
1943             panic("coda: getnewvnode returned error %d\n", err);   
1944         }                                                         
1945         vp->v_data = cp;                                          
1946         vp->v_type = type;                                      
1947         cp->c_vnode = vp;                                         
1948         coda_save(cp);
1949         
1950     } else {
1951         vref(CTOV(cp));
1952     }
1953
1954     return cp;
1955 }