1 #include <afs/param.h> /* Should be always first */
2 #include <afs/sysincludes.h> /* Standard vendor system headers */
3 #include <afs/afsincludes.h> /* Afs-based standard headers */
4 #include <afs/afs_stats.h> /* statistics */
5 #include <sys/malloc.h>
9 int afs_vop_lookup(struct vop_lookup_args *);
10 int afs_vop_create(struct vop_create_args *);
11 int afs_vop_mknod(struct vop_mknod_args *);
12 int afs_vop_open(struct vop_open_args *);
13 int afs_vop_close(struct vop_close_args *);
14 int afs_vop_access(struct vop_access_args *);
15 int afs_vop_getattr(struct vop_getattr_args *);
16 int afs_vop_setattr(struct vop_setattr_args *);
17 int afs_vop_read(struct vop_read_args *);
18 int afs_vop_write(struct vop_write_args *);
19 int afs_vop_pagein(struct vop_pagein_args *);
20 int afs_vop_pageout(struct vop_pageout_args *);
21 int afs_vop_ioctl(struct vop_ioctl_args *);
22 int afs_vop_select(struct vop_select_args *);
23 int afs_vop_mmap(struct vop_mmap_args *);
24 int afs_vop_fsync(struct vop_fsync_args *);
25 int afs_vop_seek(struct vop_seek_args *);
26 int afs_vop_remove(struct vop_remove_args *);
27 int afs_vop_link(struct vop_link_args *);
28 int afs_vop_rename(struct vop_rename_args *);
29 int afs_vop_mkdir(struct vop_mkdir_args *);
30 int afs_vop_rmdir(struct vop_rmdir_args *);
31 int afs_vop_symlink(struct vop_symlink_args *);
32 int afs_vop_readdir(struct vop_readdir_args *);
33 int afs_vop_readlink(struct vop_readlink_args *);
34 extern int ufs_abortop(struct vop_abortop_args *);
35 int afs_vop_inactive(struct vop_inactive_args *);
36 int afs_vop_reclaim(struct vop_reclaim_args *);
37 int afs_vop_lock(struct vop_lock_args *);
38 int afs_vop_unlock(struct vop_unlock_args *);
39 int afs_vop_bmap(struct vop_bmap_args *);
40 int afs_vop_strategy(struct vop_strategy_args *);
41 int afs_vop_print(struct vop_print_args *);
42 int afs_vop_islocked(struct vop_islocked_args *);
43 int afs_vop_pathconf(struct vop_pathconf_args *);
44 int afs_vop_advlock(struct vop_advlock_args *);
45 int afs_vop_truncate(struct vop_truncate_args *);
46 int afs_vop_update(struct vop_update_args *);
47 int afs_vop_blktooff __P((struct vop_blktooff_args *));
48 int afs_vop_offtoblk __P((struct vop_offtoblk_args *));
49 int afs_vop_cmap __P((struct vop_cmap_args *));
52 #define afs_vop_opnotsupp \
53 ((int (*) __P((struct vop_reallocblks_args *)))eopnotsupp)
54 #define afs_vop_valloc afs_vop_opnotsupp
55 #define afs_vop_vfree afs_vop_opnotsupp
56 #define afs_vop_blkatoff afs_vop_opnotsupp
57 #define afs_vop_reallocblks afs_vop_opnotsupp
59 /* Global vfs data structures for AFS. */
60 int (**afs_vnodeop_p)();
61 struct vnodeopv_entry_desc afs_vnodeop_entries[] = {
62 { &vop_default_desc, vn_default_error },
63 { &vop_lookup_desc, afs_vop_lookup }, /* lookup */
64 { &vop_create_desc, afs_vop_create }, /* create */
65 { &vop_mknod_desc, afs_vop_mknod }, /* mknod */
66 { &vop_open_desc, afs_vop_open }, /* open */
67 { &vop_close_desc, afs_vop_close }, /* close */
68 { &vop_access_desc, afs_vop_access }, /* access */
69 { &vop_getattr_desc, afs_vop_getattr }, /* getattr */
70 { &vop_setattr_desc, afs_vop_setattr }, /* setattr */
71 { &vop_read_desc, afs_vop_read }, /* read */
72 { &vop_write_desc, afs_vop_write }, /* write */
73 { &vop_pagein_desc, afs_vop_pagein }, /* read */
74 { &vop_pageout_desc, afs_vop_pageout }, /* write */
75 { &vop_ioctl_desc, afs_vop_ioctl }, /* XXX ioctl */
76 { &vop_select_desc, afs_vop_select }, /* select */
77 { &vop_mmap_desc, afs_vop_mmap }, /* mmap */
78 { &vop_fsync_desc, afs_vop_fsync }, /* fsync */
79 { &vop_seek_desc, afs_vop_seek }, /* seek */
80 { &vop_remove_desc, afs_vop_remove }, /* remove */
81 { &vop_link_desc, afs_vop_link }, /* link */
82 { &vop_rename_desc, afs_vop_rename }, /* rename */
83 { &vop_mkdir_desc, afs_vop_mkdir }, /* mkdir */
84 { &vop_rmdir_desc, afs_vop_rmdir }, /* rmdir */
85 { &vop_symlink_desc, afs_vop_symlink }, /* symlink */
86 { &vop_readdir_desc, afs_vop_readdir }, /* readdir */
87 { &vop_readlink_desc, afs_vop_readlink }, /* readlink */
88 /* Yes, we use the ufs_abortop call. It just releases the namei
90 { &vop_abortop_desc, ufs_abortop }, /* abortop */
91 { &vop_inactive_desc, afs_vop_inactive }, /* inactive */
92 { &vop_reclaim_desc, afs_vop_reclaim }, /* reclaim */
93 { &vop_lock_desc, afs_vop_lock }, /* lock */
94 { &vop_unlock_desc, afs_vop_unlock }, /* unlock */
95 { &vop_bmap_desc, afs_vop_bmap }, /* bmap */
96 { &vop_strategy_desc, afs_vop_strategy }, /* strategy */
97 { &vop_print_desc, afs_vop_print }, /* print */
98 { &vop_islocked_desc, afs_vop_islocked }, /* islocked */
99 { &vop_pathconf_desc, afs_vop_pathconf }, /* pathconf */
100 { &vop_advlock_desc, afs_vop_advlock }, /* advlock */
101 { &vop_blkatoff_desc, afs_vop_blkatoff }, /* blkatoff */
102 { &vop_valloc_desc, afs_vop_valloc }, /* valloc */
103 { &vop_reallocblks_desc, afs_vop_reallocblks }, /* reallocblks */
104 { &vop_vfree_desc, afs_vop_vfree }, /* vfree */
105 { &vop_truncate_desc, afs_vop_truncate }, /* truncate */
106 { &vop_update_desc, afs_vop_update }, /* update */
107 { &vop_blktooff_desc, afs_vop_blktooff }, /* blktooff */
108 { &vop_offtoblk_desc, afs_vop_offtoblk }, /* offtoblk */
109 { &vop_cmap_desc, afs_vop_cmap }, /* cmap */
110 { &vop_bwrite_desc, vn_bwrite },
111 { (struct vnodeop_desc*)NULL, (int(*)())NULL }
113 struct vnodeopv_desc afs_vnodeop_opv_desc =
114 { &afs_vnodeop_p, afs_vnodeop_entries };
117 struct componentname *cnp = ap->a_cnp; \
119 MALLOC(name, char *, cnp->cn_namelen+1, M_TEMP, M_WAITOK); \
120 bcopy(cnp->cn_nameptr, name, cnp->cn_namelen); \
121 name[cnp->cn_namelen] = '\0'
123 #define DROPNAME() FREE(name, M_TEMP)
129 struct vop_lookup_args /* {
130 struct vnodeop_desc * a_desc;
132 struct vnode **a_vpp;
133 struct componentname *a_cnp;
138 struct vnode *vp, *dvp;
139 register int flags = ap->a_cnp->cn_flags;
140 int lockparent; /* 1 => lockparent flag is set */
141 int wantparent; /* 1 => wantparent or lockparent flag */
145 lockparent = flags & LOCKPARENT;
146 wantparent = flags & (LOCKPARENT|WANTPARENT);
148 if (ap->a_dvp->v_type != VDIR) {
154 if (flags & ISDOTDOT)
155 VOP_UNLOCK(dvp, 0, p);
157 error = afs_lookup((struct vcache *)dvp, name, &vcp, cnp->cn_cred);
160 if (flags & ISDOTDOT)
161 VOP_LOCK(dvp, LK_EXCLUSIVE | LK_RETRY, p);
162 if ((cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME) &&
163 (flags & ISLASTCN) && error == ENOENT)
165 if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))
166 cnp->cn_flags |= SAVENAME;
171 vp = (struct vnode *)vcp; /* always get a node if no error */
173 /* The parent directory comes in locked. We unlock it on return
174 unless the caller wants it left locked.
175 we also always return the vnode locked. */
177 if (flags & ISDOTDOT) {
178 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
179 /* always return the child locked */
180 if (lockparent && (flags & ISLASTCN) &&
181 (error = vn_lock(dvp, LK_EXCLUSIVE, p))) {
186 } else if (vp == dvp) {
187 /* they're the same; afs_lookup() already ref'ed the leaf.
188 It came in locked, so we don't need to ref OR lock it */
190 if (!lockparent || !(flags & ISLASTCN))
191 VOP_UNLOCK(dvp, 0, p); /* done with parent. */
192 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
193 /* always return the child locked */
197 if ((cnp->cn_nameiop == RENAME && wantparent && (flags & ISLASTCN) ||
198 (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))))
199 cnp->cn_flags |= SAVENAME;
207 struct vop_create_args /* {
209 struct vnode **a_vpp;
210 struct componentname *a_cnp;
216 register struct vnode *dvp = ap->a_dvp;
221 /* vnode layer handles excl/nonexcl */
223 error = afs_create((struct vcache *)dvp, name, ap->a_vap, NONEXCL,
224 ap->a_vap->va_mode, &vcp,
228 VOP_ABORTOP(dvp, cnp);
235 *ap->a_vpp = (struct vnode *)vcp;
236 vn_lock((struct vnode *)vcp, LK_EXCLUSIVE| LK_RETRY, p);
237 if (UBCINFOMISSING((struct vnode *)vcp) ||
238 UBCINFORECLAIMED((struct vnode *)vcp))
239 ubc_info_init((struct vnode *)vcp);
243 if ((cnp->cn_flags & SAVESTART) == 0)
244 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
252 struct vop_mknod_args /* {
254 struct vnode **a_vpp;
255 struct componentname *a_cnp;
259 FREE_ZONE(ap->a_cnp->cn_pnbuf, ap->a_cnp->cn_pnlen, M_NAMEI);
266 struct vop_open_args /* {
269 struct ucred *a_cred;
274 struct vcache *vc = (struct vcache *)ap->a_vp;
276 error = afs_open(&vc, ap->a_mode, ap->a_cred);
278 if ((struct vnode *)vc != ap->a_vp)
279 panic("AFS open changed vnode!");
281 afs_BozonLock(&vc->pvnLock, vc);
283 afs_BozonUnlock(&vc->pvnLock, vc);
290 struct vop_close_args /* {
293 struct ucred *a_cred;
298 struct vcache *avc=ap->a_vp;
301 code=afs_close(avc, ap->a_fflag, ap->a_cred, ap->a_p);
303 code=afs_close(avc, ap->a_fflag, &afs_osi_cred, ap->a_p);
304 afs_BozonLock(&avc->pvnLock, avc);
305 osi_FlushPages(avc); /* hold bozon lock, but not basic vnode lock */
306 afs_BozonUnlock(&avc->pvnLock, avc);
313 struct vop_access_args /* {
316 struct ucred *a_cred;
322 code=afs_access((struct vcache *)ap->a_vp, ap->a_mode, ap->a_cred);
328 struct vop_getattr_args /* {
331 struct ucred *a_cred;
337 code=afs_getattr((struct vcache *)ap->a_vp, ap->a_vap, ap->a_cred);
343 struct vop_setattr_args /* {
346 struct ucred *a_cred;
352 code=afs_setattr((struct vcache *)ap->a_vp, ap->a_vap, ap->a_cred);
358 struct vop_read_args /* {
362 struct ucred *a_cred;
366 struct vcache *avc=(struct vcache *)ap->a_vp;
368 afs_BozonLock(&avc->pvnLock, avc);
369 osi_FlushPages(avc); /* hold bozon lock, but not basic vnode lock */
370 code=afs_read(avc, ap->a_uio, ap->a_cred, 0, 0, 0);
371 afs_BozonUnlock(&avc->pvnLock, avc);
377 struct vop_pagein_args /* {
380 vm_offset_t a_pl_offset;
383 struct ucred *a_cred;
387 register struct vnode *vp = ap->a_vp;
389 size_t size= ap->a_size;
390 off_t f_offset = ap->a_f_offset;
391 vm_offset_t pl_offset = ap->a_pl_offset;
392 int flags = ap->a_flags;
397 struct uio * uio = &auio;
398 int nocommit = flags & UPL_NOCOMMIT;
401 struct vcache *tvc=(struct vcache *)vp;
403 if (UBCINVALID(vp)) {
405 panic("afs_vop_pagein: invalid vp");
406 #endif /* DIAGNOSTIC */
410 UBCINFOCHECK("afs_vop_pagein", vp);
411 if(pl == (upl_t)NULL) {
412 panic("afs_vop_pagein: no upl");
415 cred = ubc_getcred(vp);
421 kernel_upl_abort_range(pl, pl_offset, size,
422 UPL_ABORT_ERROR | UPL_ABORT_FREE_ON_EMPTY);
427 kernel_upl_abort_range(pl, pl_offset, size,
428 UPL_ABORT_ERROR | UPL_ABORT_FREE_ON_EMPTY);
431 if (f_offset & PAGE_MASK)
432 panic("afs_vop_pagein: offset not page aligned");
434 auio.uio_iov = &aiov;
436 auio.uio_offset = f_offset;
437 auio.uio_segflg = UIO_SYSSPACE;
438 auio.uio_rw = UIO_READ;
439 auio.uio_procp = NULL;
440 kernel_upl_map(kernel_map, pl, &ioaddr);
442 auio.uio_resid = aiov.iov_len = size;
443 aiov.iov_base = (caddr_t)ioaddr;
445 afs_BozonLock(&tvc->pvnLock, tvc);
446 osi_FlushPages(tvc); /* hold bozon lock, but not basic vnode lock */
447 code=afs_read(tvc, uio, cred, 0, 0, 0);
449 ObtainWriteLock(&tvc->lock, 2);
450 tvc->states |= CMAPPED;
451 ReleaseWriteLock(&tvc->lock);
453 afs_BozonUnlock(&tvc->pvnLock, tvc);
455 kernel_upl_unmap(kernel_map, pl);
458 kernel_upl_abort_range(pl, pl_offset, size,
459 UPL_ABORT_ERROR | UPL_ABORT_FREE_ON_EMPTY);
461 kernel_upl_commit_range(pl, pl_offset, size,
462 UPL_COMMIT_CLEAR_DIRTY | UPL_COMMIT_FREE_ON_EMPTY,
463 UPL_GET_INTERNAL_PAGE_LIST(pl), MAX_UPL_TRANSFER);
470 struct vop_write_args /* {
474 struct ucred *a_cred;
478 struct vcache *avc=(struct vcache *)ap->a_vp;
481 afs_BozonLock(&avc->pvnLock, avc);
482 osi_FlushPages(avc); /* hold bozon lock, but not basic vnode lock */
483 if (UBCINFOEXISTS(ap->a_vp))
484 ubc_clean(ap->a_vp, 1);
485 if (UBCINFOEXISTS(ap->a_vp))
486 osi_VM_NukePages(ap->a_vp, ap->a_uio->uio_offset, ap->a_uio->uio_resid);
487 code=afs_write((struct vcache *)ap->a_vp, ap->a_uio, ap->a_ioflag, ap->a_cred, 0);
488 afs_BozonUnlock(&avc->pvnLock, avc);
495 struct vop_pageout_args /* {
498 vm_offset_t a_pl_offset,
501 struct ucred *a_cred,
505 register struct vnode *vp = ap->a_vp;
507 size_t size= ap->a_size;
508 off_t f_offset = ap->a_f_offset;
509 vm_offset_t pl_offset = ap->a_pl_offset;
510 int flags = ap->a_flags;
515 struct uio * uio = &auio;
516 int nocommit = flags & UPL_NOCOMMIT;
519 struct vcache *tvc=(struct vcache *)vp;
521 if (UBCINVALID(vp)) {
523 panic("afs_vop_pageout: invalid vp");
524 #endif /* DIAGNOSTIC */
528 UBCINFOCHECK("afs_vop_pageout", vp);
529 if(pl == (upl_t)NULL) {
530 panic("afs_vop_pageout: no upl");
533 { int lbn, iosize, s;
535 int biosize = DEV_BSIZE;
537 lbn = f_offset / DEV_BSIZE;
539 for (iosize = size; iosize > 0; iosize -= biosize, lbn++) {
542 if (bp = incore(vp, lbn)) {
543 if (ISSET(bp->b_flags, B_BUSY))
544 panic("nfs_pageout: found BUSY buffer incore\n")
548 SET(bp->b_flags, (B_BUSY | B_INVAL));
555 cred = ubc_getcred(vp);
561 kernel_upl_abort_range(pl, pl_offset, size,
562 UPL_ABORT_FREE_ON_EMPTY);
565 if (flags & (IO_APPEND | IO_SYNC))
566 panic("nfs_pageout: (IO_APPEND | IO_SYNC)");
569 kernel_upl_abort_range(pl, pl_offset, size,
570 UPL_ABORT_FREE_ON_EMPTY);
573 if (f_offset >= tvc->m.Length) {
575 kernel_upl_abort_range(pl, pl_offset, size,
576 UPL_ABORT_FREE_ON_EMPTY);
580 if (f_offset & PAGE_MASK)
581 panic("afs_vop_pageout: offset not page aligned");
583 auio.uio_iov = &aiov;
585 auio.uio_offset = f_offset;
586 auio.uio_segflg = UIO_SYSSPACE;
587 auio.uio_rw = UIO_WRITE;
588 auio.uio_procp = NULL;
589 kernel_upl_map(kernel_map, pl, &ioaddr);
591 auio.uio_resid = aiov.iov_len = size;
592 aiov.iov_base = (caddr_t)ioaddr;
596 * check for partial page and clear the
597 * contents past end of the file before
598 * releasing it in the VM page cache
600 if ((f_offset < tvc->m.Length) && (f_offset + size) > tvc->m.Length) {
601 size_t io = tvc->m.Length - f_offset;
603 bzero((caddr_t)(ioaddr + pl_offset + io), size - io);
609 afs_BozonLock(&tvc->pvnLock, tvc);
610 osi_FlushPages(tvc); /* hold bozon lock, but not basic vnode lock */
611 ObtainWriteLock(&tvc->lock, 1);
613 ReleaseWriteLock(&tvc->lock);
615 code=afs_write(tvc, uio, flags, cred, 0);
617 ObtainWriteLock(&tvc->lock, 1);
618 afs_FakeClose(tvc, cred);
619 ReleaseWriteLock(&tvc->lock);
620 afs_BozonUnlock(&tvc->pvnLock, tvc);
622 kernel_upl_unmap(kernel_map, pl);
625 kernel_upl_abort_range(pl, pl_offset, size,
626 UPL_ABORT_FREE_ON_EMPTY);
628 kernel_upl_commit_range(pl, pl_offset, size,
629 UPL_COMMIT_CLEAR_DIRTY | UPL_COMMIT_FREE_ON_EMPTY,
630 UPL_GET_INTERNAL_PAGE_LIST(pl), MAX_UPL_TRANSFER);
637 struct vop_ioctl_args /* {
642 struct ucred *a_cred;
646 struct vcache *tvc = (struct vcache *)ap->a_vp;
647 struct afs_ioctl data;
650 /* in case we ever get in here... */
652 AFS_STATCNT(afs_ioctl);
653 if (((ap->a_command >> 8) & 0xff) == 'V') {
654 /* This is a VICEIOCTL call */
656 error = HandleIoctl(tvc, (struct file *)0/*Not used*/,
657 ap->a_command, ap->a_data);
661 /* No-op call; just return. */
669 struct vop_select_args /* {
673 struct ucred *a_cred;
678 * We should really check to see if I/O is possible.
685 * NB Currently unsupported.
690 struct vop_mmap_args /* {
693 struct ucred *a_cred;
702 struct vop_fsync_args /* {
704 struct ucred *a_cred;
709 int wait = ap->a_waitfor == MNT_WAIT;
711 register struct vnode *vp = ap->a_vp;
714 /*vflushbuf(vp, wait);*/
716 error=afs_fsync((struct vcache *)vp, ap->a_cred);
718 error=afs_fsync((struct vcache *)vp, &afs_osi_cred);
725 struct vop_seek_args /* {
729 struct ucred *a_cred;
732 if (ap->a_newoff > ULONG_MAX) /* AFS doesn't support 64-bit offsets */
739 struct vop_remove_args /* {
742 struct componentname *a_cnp;
746 register struct vnode *vp = ap->a_vp;
747 register struct vnode *dvp = ap->a_dvp;
751 error = afs_remove((struct vcache *)dvp, name, cnp->cn_cred);
759 if (UBCINFOEXISTS(vp)) {
760 int wasmapped=ubc_issetflags(vp, UI_WASMAPPED);
761 int hasobjref=ubc_issetflags(vp, UI_HASOBJREF);
763 (void) ubc_uncache(vp);
766 /* WARNING vp may not be valid after this */
769 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
776 struct vop_link_args /* {
778 struct vnode *a_tdvp;
779 struct componentname *a_cnp;
783 register struct vnode *dvp = ap->a_tdvp;
784 register struct vnode *vp = ap->a_vp;
789 if (dvp->v_mount != vp->v_mount) {
790 VOP_ABORTOP(vp, cnp);
794 if (vp->v_type == VDIR) {
795 VOP_ABORTOP(vp, cnp);
799 if (error = vn_lock(vp, LK_EXCLUSIVE, p)) {
800 VOP_ABORTOP(dvp, cnp);
804 error = afs_link((struct vcache *)vp, (struct vcache *)dvp, name, cnp->cn_cred);
806 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
817 struct vop_rename_args /* {
818 struct vnode *a_fdvp;
820 struct componentname *a_fcnp;
821 struct vnode *a_tdvp;
823 struct componentname *a_tcnp;
827 struct componentname *fcnp = ap->a_fcnp;
829 struct componentname *tcnp = ap->a_tcnp;
831 struct vnode *tvp = ap->a_tvp;
832 register struct vnode *tdvp = ap->a_tdvp;
833 struct vnode *fvp = ap->a_fvp;
834 register struct vnode *fdvp = ap->a_fdvp;
835 struct proc *p=fcnp->cn_proc;
838 * Check for cross-device rename.
840 if ((fvp->v_mount != tdvp->v_mount) ||
841 (tvp && (fvp->v_mount != tvp->v_mount))) {
844 VOP_ABORTOP(tdvp, tcnp); /* XXX, why not in NFS? */
851 VOP_ABORTOP(fdvp, fcnp); /* XXX, why not in NFS? */
857 * if fvp == tvp, we're just removing one name of a pair of
858 * directory entries for the same element. convert call into rename.
859 ( (pinched from NetBSD 1.0's ufs_rename())
862 if (fvp->v_type == VDIR) {
867 /* Release destination completely. */
868 VOP_ABORTOP(tdvp, tcnp);
875 fcnp->cn_flags &= ~MODMASK;
876 fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
877 if ((fcnp->cn_flags & SAVESTART) == 0)
878 panic("afs_rename: lost from startdir");
879 fcnp->cn_nameiop = DELETE;
880 (void) relookup(fdvp, &fvp, fcnp);
881 return (VOP_REMOVE(fdvp, fvp, fcnp));
883 if (error = vn_lock(fvp, LK_EXCLUSIVE, p))
886 MALLOC(fname, char *, fcnp->cn_namelen+1, M_TEMP, M_WAITOK);
887 bcopy(fcnp->cn_nameptr, fname, fcnp->cn_namelen);
888 fname[fcnp->cn_namelen] = '\0';
889 MALLOC(tname, char *, tcnp->cn_namelen+1, M_TEMP, M_WAITOK);
890 bcopy(tcnp->cn_nameptr, tname, tcnp->cn_namelen);
891 tname[tcnp->cn_namelen] = '\0';
895 /* XXX use "from" or "to" creds? NFS uses "to" creds */
896 error = afs_rename((struct vcache *)fdvp, fname, (struct vcache *)tdvp, tname, tcnp->cn_cred);
899 VOP_UNLOCK(fvp, 0, p);
903 goto abortit; /* XXX */
917 struct vop_mkdir_args /* {
919 struct vnode **a_vpp;
920 struct componentname *a_cnp;
924 register struct vnode *dvp = ap->a_dvp;
925 register struct vattr *vap = ap->a_vap;
933 if ((cnp->cn_flags & HASBUF) == 0)
934 panic("afs_vop_mkdir: no name");
937 error = afs_mkdir((struct vcache *)dvp, name, vap, &vcp, cnp->cn_cred);
940 VOP_ABORTOP(dvp, cnp);
946 *ap->a_vpp = (struct vnode *)vcp;
947 vn_lock((struct vnode *)vcp, LK_EXCLUSIVE|LK_RETRY, p);
951 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
958 struct vop_rmdir_args /* {
961 struct componentname *a_cnp;
965 register struct vnode *vp = ap->a_vp;
966 register struct vnode *dvp = ap->a_dvp;
972 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
978 error = afs_rmdir((struct vcache *)dvp, name, cnp->cn_cred);
988 struct vop_symlink_args /* {
990 struct vnode **a_vpp;
991 struct componentname *a_cnp;
996 register struct vnode *dvp = ap->a_dvp;
998 /* NFS ignores a_vpp; so do we. */
1002 error = afs_symlink((struct vcache *)dvp, name, ap->a_vap, ap->a_target,
1006 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
1013 struct vop_readdir_args /* {
1016 struct ucred *a_cred;
1024 /* printf("readdir %x cookies %x ncookies %d\n", ap->a_vp, ap->a_cookies,
1026 off=ap->a_uio->uio_offset;
1028 error= afs_readdir((struct vcache *)ap->a_vp, ap->a_uio, ap->a_cred,
1031 if (!error && ap->a_ncookies != NULL) {
1032 struct uio *uio = ap->a_uio;
1033 const struct dirent *dp, *dp_start, *dp_end;
1035 u_long *cookies, *cookiep;
1037 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
1038 panic("afs_readdir: burned cookies");
1039 dp = (const struct dirent *)
1040 ((const char *)uio->uio_iov->iov_base - (uio->uio_offset - off));
1042 dp_end = (const struct dirent *) uio->uio_iov->iov_base;
1043 for (dp_start = dp, ncookies = 0;
1045 dp = (const struct dirent *)((const char *) dp + dp->d_reclen))
1048 MALLOC(cookies, u_long *, ncookies * sizeof(u_long),
1050 for (dp = dp_start, cookiep = cookies;
1052 dp = (const struct dirent *)((const char *) dp + dp->d_reclen)) {
1053 off += dp->d_reclen;
1056 *ap->a_cookies = cookies;
1057 *ap->a_ncookies = ncookies;
1064 afs_vop_readlink(ap)
1065 struct vop_readlink_args /* {
1068 struct ucred *a_cred;
1072 /* printf("readlink %x\n", ap->a_vp);*/
1074 error= afs_readlink((struct vcache *)ap->a_vp, ap->a_uio, ap->a_cred);
1079 extern int prtactive;
1082 afs_vop_inactive(ap)
1083 struct vop_inactive_args /* {
1088 register struct vnode *vp = ap->a_vp;
1090 if (prtactive && vp->v_usecount != 0)
1091 vprint("afs_vop_inactive(): pushing active", vp);
1094 afs_InactiveVCache((struct vcache *)vp, 0); /* decrs ref counts */
1096 VOP_UNLOCK(vp, 0, ap->a_p);
1102 struct vop_reclaim_args /* {
1108 register struct vnode *vp = ap->a_vp;
1110 cache_purge(vp); /* just in case... */
1114 error = afs_FlushVCache((struct vcache *)vp, &sl); /* tosses our stuff from vnode */
1117 if (!error && vp->v_data)
1118 panic("afs_reclaim: vnode not cleaned");
1121 if (vp->v_usecount == 2) {
1122 vprint("reclaim count==2", vp);
1123 } else if (vp->v_usecount == 1) {
1124 vprint("reclaim count==1", vp);
1126 vprint("reclaim bad count", vp);
1134 struct vop_lock_args /* {
1138 register struct vnode *vp = ap->a_vp;
1139 register struct vcache *avc = (struct vcache *)vp;
1141 if (vp->v_tag == VT_NON)
1143 return (lockmgr(&avc->rwlock, ap->a_flags, &vp->v_interlock,
1149 struct vop_unlock_args /* {
1153 struct vnode *vp = ap->a_vp;
1154 struct vcache *avc = (struct vcache *)vp;
1155 return (lockmgr(&avc->rwlock, ap->a_flags | LK_RELEASE,
1156 &vp->v_interlock, ap->a_p));
1162 struct vop_bmap_args /* {
1165 struct vnode **a_vpp;
1174 *ap->a_bnp = ap->a_bn * (PAGE_SIZE / DEV_BSIZE);
1177 *ap->a_vpp = ap->a_vp;
1179 if (ap->a_runp != NULL)
1182 if (ap->a_runb != NULL)
1189 afs_vop_strategy(ap)
1190 struct vop_strategy_args /* {
1196 error= afs_ustrategy(ap->a_bp);
1202 struct vop_print_args /* {
1206 register struct vnode *vp = ap->a_vp;
1207 register struct vcache *vc = (struct vcache *)ap->a_vp;
1210 printf("tag %d, fid: %ld.%x.%x.%x, opens %d, writers %d", vp->v_tag, vc->fid.Cell,
1211 vc->fid.Fid.Volume, vc->fid.Fid.Vnode, vc->fid.Fid.Unique, vc->opens,
1212 vc->execsOrWriters);
1213 printf("\n states%s%s%s%s%s", (s&CStatd) ? " statd" : "", (s&CRO) ? " readonly" : "",(s&CDirty) ? " dirty" : "",(s&CMAPPED) ? " mapped" : "", (s&CVFlushed) ? " flush in progress" : "");
1215 printf("\n UBC: %s%s",
1216 UBCINFOEXISTS(vp) ? "exists, " : "does not exist",
1218 sprintf(buf, "holdcnt %d", vp->v_ubcinfo->ui_holdcnt),buf : "");
1224 afs_vop_islocked(ap)
1225 struct vop_islocked_args /* {
1229 struct vcache *vc = (struct vcache *)ap->a_vp;
1230 return lockstatus(&vc->rwlock);
1234 * Return POSIX pathconf information applicable to ufs filesystems.
1236 afs_vop_pathconf(ap)
1237 struct vop_pathconf_args /* {
1243 AFS_STATCNT(afs_cntl);
1244 switch (ap->a_name) {
1246 *ap->a_retval = LINK_MAX;
1249 *ap->a_retval = NAME_MAX;
1252 *ap->a_retval = PATH_MAX;
1254 case _PC_CHOWN_RESTRICTED:
1270 * Advisory record locking support (fcntl() POSIX style)
1274 struct vop_advlock_args /* {
1283 struct proc *p=current_proc();
1286 cr=*p->p_cred->pc_ucred;
1289 error= afs_lockctl((struct vcache *)ap->a_vp, ap->a_fl, ap->a_op, &cr,
1296 afs_vop_truncate(ap)
1297 struct vop_truncate_args /* {
1301 struct ucred *a_cred;
1305 printf("stray afs_vop_truncate\n");
1311 struct vop_update_args /* {
1313 struct timeval *a_access;
1314 struct timeval *a_modify;
1318 printf("stray afs_vop_update\n");
1322 int afs_vop_blktooff(ap)
1323 struct vop_blktooff_args /* {
1329 *ap->a_offset = (off_t)(ap->a_lblkno * DEV_BSIZE);
1333 int afs_vop_offtoblk(ap)
1334 struct vop_offtoblk_args /* {
1340 *ap->a_lblkno = (daddr_t)(ap->a_offset / DEV_BSIZE);
1345 int afs_vop_cmap(ap)
1346 struct vop_cmap_args /* {
1355 *ap->a_bpn = (daddr_t)(ap->a_foffset / DEV_BSIZE);
1356 *ap->a_run= MAX(ap->a_size, AFS_CHUNKSIZE(ap->a_foffset));