6 #include <afs/sysincludes.h> /* Standard vendor system headers */
7 #include <afs/afsincludes.h> /* Afs-based standard headers */
8 #include <afs/afs_stats.h> /* statistics */
9 #include <sys/malloc.h>
10 #include <sys/namei.h>
13 int afs_vop_lookup(struct vop_lookup_args *);
14 int afs_vop_create(struct vop_create_args *);
15 int afs_vop_mknod(struct vop_mknod_args *);
16 int afs_vop_open(struct vop_open_args *);
17 int afs_vop_close(struct vop_close_args *);
18 int afs_vop_access(struct vop_access_args *);
19 int afs_vop_getattr(struct vop_getattr_args *);
20 int afs_vop_setattr(struct vop_setattr_args *);
21 int afs_vop_read(struct vop_read_args *);
22 int afs_vop_write(struct vop_write_args *);
23 int afs_vop_pagein(struct vop_pagein_args *);
24 int afs_vop_pageout(struct vop_pageout_args *);
25 int afs_vop_ioctl(struct vop_ioctl_args *);
26 int afs_vop_select(struct vop_select_args *);
27 int afs_vop_mmap(struct vop_mmap_args *);
28 int afs_vop_fsync(struct vop_fsync_args *);
29 int afs_vop_seek(struct vop_seek_args *);
30 int afs_vop_remove(struct vop_remove_args *);
31 int afs_vop_link(struct vop_link_args *);
32 int afs_vop_rename(struct vop_rename_args *);
33 int afs_vop_mkdir(struct vop_mkdir_args *);
34 int afs_vop_rmdir(struct vop_rmdir_args *);
35 int afs_vop_symlink(struct vop_symlink_args *);
36 int afs_vop_readdir(struct vop_readdir_args *);
37 int afs_vop_readlink(struct vop_readlink_args *);
38 extern int ufs_abortop(struct vop_abortop_args *);
39 int afs_vop_inactive(struct vop_inactive_args *);
40 int afs_vop_reclaim(struct vop_reclaim_args *);
41 int afs_vop_lock(struct vop_lock_args *);
42 int afs_vop_unlock(struct vop_unlock_args *);
43 int afs_vop_bmap(struct vop_bmap_args *);
44 int afs_vop_strategy(struct vop_strategy_args *);
45 int afs_vop_print(struct vop_print_args *);
46 int afs_vop_islocked(struct vop_islocked_args *);
47 int afs_vop_pathconf(struct vop_pathconf_args *);
48 int afs_vop_advlock(struct vop_advlock_args *);
49 int afs_vop_truncate(struct vop_truncate_args *);
50 int afs_vop_update(struct vop_update_args *);
51 int afs_vop_blktooff __P((struct vop_blktooff_args *));
52 int afs_vop_offtoblk __P((struct vop_offtoblk_args *));
53 int afs_vop_cmap __P((struct vop_cmap_args *));
56 #define afs_vop_opnotsupp \
57 ((int (*) __P((struct vop_reallocblks_args *)))eopnotsupp)
58 #define afs_vop_valloc afs_vop_opnotsupp
59 #define afs_vop_vfree afs_vop_opnotsupp
60 #define afs_vop_blkatoff afs_vop_opnotsupp
61 #define afs_vop_reallocblks afs_vop_opnotsupp
63 /* Global vfs data structures for AFS. */
64 int (**afs_vnodeop_p)();
65 struct vnodeopv_entry_desc afs_vnodeop_entries[] = {
66 { &vop_default_desc, vn_default_error },
67 { &vop_lookup_desc, afs_vop_lookup }, /* lookup */
68 { &vop_create_desc, afs_vop_create }, /* create */
69 { &vop_mknod_desc, afs_vop_mknod }, /* mknod */
70 { &vop_open_desc, afs_vop_open }, /* open */
71 { &vop_close_desc, afs_vop_close }, /* close */
72 { &vop_access_desc, afs_vop_access }, /* access */
73 { &vop_getattr_desc, afs_vop_getattr }, /* getattr */
74 { &vop_setattr_desc, afs_vop_setattr }, /* setattr */
75 { &vop_read_desc, afs_vop_read }, /* read */
76 { &vop_write_desc, afs_vop_write }, /* write */
77 { &vop_pagein_desc, afs_vop_pagein }, /* read */
78 { &vop_pageout_desc, afs_vop_pageout }, /* write */
79 { &vop_ioctl_desc, afs_vop_ioctl }, /* XXX ioctl */
80 { &vop_select_desc, afs_vop_select }, /* select */
81 { &vop_mmap_desc, afs_vop_mmap }, /* mmap */
82 { &vop_fsync_desc, afs_vop_fsync }, /* fsync */
83 { &vop_seek_desc, afs_vop_seek }, /* seek */
84 { &vop_remove_desc, afs_vop_remove }, /* remove */
85 { &vop_link_desc, afs_vop_link }, /* link */
86 { &vop_rename_desc, afs_vop_rename }, /* rename */
87 { &vop_mkdir_desc, afs_vop_mkdir }, /* mkdir */
88 { &vop_rmdir_desc, afs_vop_rmdir }, /* rmdir */
89 { &vop_symlink_desc, afs_vop_symlink }, /* symlink */
90 { &vop_readdir_desc, afs_vop_readdir }, /* readdir */
91 { &vop_readlink_desc, afs_vop_readlink }, /* readlink */
92 /* Yes, we use the ufs_abortop call. It just releases the namei
94 { &vop_abortop_desc, ufs_abortop }, /* abortop */
95 { &vop_inactive_desc, afs_vop_inactive }, /* inactive */
96 { &vop_reclaim_desc, afs_vop_reclaim }, /* reclaim */
97 { &vop_lock_desc, afs_vop_lock }, /* lock */
98 { &vop_unlock_desc, afs_vop_unlock }, /* unlock */
99 { &vop_bmap_desc, afs_vop_bmap }, /* bmap */
100 { &vop_strategy_desc, afs_vop_strategy }, /* strategy */
101 { &vop_print_desc, afs_vop_print }, /* print */
102 { &vop_islocked_desc, afs_vop_islocked }, /* islocked */
103 { &vop_pathconf_desc, afs_vop_pathconf }, /* pathconf */
104 { &vop_advlock_desc, afs_vop_advlock }, /* advlock */
105 { &vop_blkatoff_desc, afs_vop_blkatoff }, /* blkatoff */
106 { &vop_valloc_desc, afs_vop_valloc }, /* valloc */
107 { &vop_reallocblks_desc, afs_vop_reallocblks }, /* reallocblks */
108 { &vop_vfree_desc, afs_vop_vfree }, /* vfree */
109 { &vop_truncate_desc, afs_vop_truncate }, /* truncate */
110 { &vop_update_desc, afs_vop_update }, /* update */
111 { &vop_blktooff_desc, afs_vop_blktooff }, /* blktooff */
112 { &vop_offtoblk_desc, afs_vop_offtoblk }, /* offtoblk */
113 { &vop_cmap_desc, afs_vop_cmap }, /* cmap */
114 { &vop_bwrite_desc, vn_bwrite },
115 { (struct vnodeop_desc*)NULL, (int(*)())NULL }
117 struct vnodeopv_desc afs_vnodeop_opv_desc =
118 { &afs_vnodeop_p, afs_vnodeop_entries };
121 struct componentname *cnp = ap->a_cnp; \
123 MALLOC(name, char *, cnp->cn_namelen+1, M_TEMP, M_WAITOK); \
124 bcopy(cnp->cn_nameptr, name, cnp->cn_namelen); \
125 name[cnp->cn_namelen] = '\0'
127 #define DROPNAME() FREE(name, M_TEMP)
133 struct vop_lookup_args /* {
134 struct vnodeop_desc * a_desc;
136 struct vnode **a_vpp;
137 struct componentname *a_cnp;
142 struct vnode *vp, *dvp;
143 register int flags = ap->a_cnp->cn_flags;
144 int lockparent; /* 1 => lockparent flag is set */
145 int wantparent; /* 1 => wantparent or lockparent flag */
149 lockparent = flags & LOCKPARENT;
150 wantparent = flags & (LOCKPARENT|WANTPARENT);
152 if (ap->a_dvp->v_type != VDIR) {
158 if (flags & ISDOTDOT)
159 VOP_UNLOCK(dvp, 0, p);
161 error = afs_lookup((struct vcache *)dvp, name, &vcp, cnp->cn_cred);
164 if (flags & ISDOTDOT)
165 VOP_LOCK(dvp, LK_EXCLUSIVE | LK_RETRY, p);
166 if ((cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME) &&
167 (flags & ISLASTCN) && error == ENOENT)
169 if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))
170 cnp->cn_flags |= SAVENAME;
175 vp = (struct vnode *)vcp; /* always get a node if no error */
177 /* The parent directory comes in locked. We unlock it on return
178 unless the caller wants it left locked.
179 we also always return the vnode locked. */
181 if (flags & ISDOTDOT) {
182 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
183 /* always return the child locked */
184 if (lockparent && (flags & ISLASTCN) &&
185 (error = vn_lock(dvp, LK_EXCLUSIVE, p))) {
190 } else if (vp == dvp) {
191 /* they're the same; afs_lookup() already ref'ed the leaf.
192 It came in locked, so we don't need to ref OR lock it */
194 if (!lockparent || !(flags & ISLASTCN))
195 VOP_UNLOCK(dvp, 0, p); /* done with parent. */
196 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
197 /* always return the child locked */
201 if ((cnp->cn_nameiop == RENAME && wantparent && (flags & ISLASTCN) ||
202 (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))))
203 cnp->cn_flags |= SAVENAME;
211 struct vop_create_args /* {
213 struct vnode **a_vpp;
214 struct componentname *a_cnp;
220 register struct vnode *dvp = ap->a_dvp;
225 /* vnode layer handles excl/nonexcl */
227 error = afs_create((struct vcache *)dvp, name, ap->a_vap, NONEXCL,
228 ap->a_vap->va_mode, &vcp,
232 VOP_ABORTOP(dvp, cnp);
239 *ap->a_vpp = (struct vnode *)vcp;
240 vn_lock((struct vnode *)vcp, LK_EXCLUSIVE| LK_RETRY, p);
241 if (UBCINFOMISSING((struct vnode *)vcp) ||
242 UBCINFORECLAIMED((struct vnode *)vcp))
243 ubc_info_init((struct vnode *)vcp);
247 if ((cnp->cn_flags & SAVESTART) == 0)
248 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
256 struct vop_mknod_args /* {
258 struct vnode **a_vpp;
259 struct componentname *a_cnp;
263 FREE_ZONE(ap->a_cnp->cn_pnbuf, ap->a_cnp->cn_pnlen, M_NAMEI);
270 struct vop_open_args /* {
273 struct ucred *a_cred;
278 struct vcache *vc = (struct vcache *)ap->a_vp;
280 error = afs_open(&vc, ap->a_mode, ap->a_cred);
282 if ((struct vnode *)vc != ap->a_vp)
283 panic("AFS open changed vnode!");
285 afs_BozonLock(&vc->pvnLock, vc);
287 afs_BozonUnlock(&vc->pvnLock, vc);
294 struct vop_close_args /* {
297 struct ucred *a_cred;
302 struct vcache *avc=ap->a_vp;
305 code=afs_close(avc, ap->a_fflag, ap->a_cred, ap->a_p);
307 code=afs_close(avc, ap->a_fflag, &afs_osi_cred, ap->a_p);
308 afs_BozonLock(&avc->pvnLock, avc);
309 osi_FlushPages(avc); /* hold bozon lock, but not basic vnode lock */
310 afs_BozonUnlock(&avc->pvnLock, avc);
317 struct vop_access_args /* {
320 struct ucred *a_cred;
326 code=afs_access((struct vcache *)ap->a_vp, ap->a_mode, ap->a_cred);
332 struct vop_getattr_args /* {
335 struct ucred *a_cred;
341 code=afs_getattr((struct vcache *)ap->a_vp, ap->a_vap, ap->a_cred);
347 struct vop_setattr_args /* {
350 struct ucred *a_cred;
356 code=afs_setattr((struct vcache *)ap->a_vp, ap->a_vap, ap->a_cred);
362 struct vop_read_args /* {
366 struct ucred *a_cred;
370 struct vcache *avc=(struct vcache *)ap->a_vp;
372 afs_BozonLock(&avc->pvnLock, avc);
373 osi_FlushPages(avc); /* hold bozon lock, but not basic vnode lock */
374 code=afs_read(avc, ap->a_uio, ap->a_cred, 0, 0, 0);
375 afs_BozonUnlock(&avc->pvnLock, avc);
381 struct vop_pagein_args /* {
384 vm_offset_t a_pl_offset;
387 struct ucred *a_cred;
391 register struct vnode *vp = ap->a_vp;
393 size_t size= ap->a_size;
394 off_t f_offset = ap->a_f_offset;
395 vm_offset_t pl_offset = ap->a_pl_offset;
396 int flags = ap->a_flags;
401 struct uio * uio = &auio;
402 int nocommit = flags & UPL_NOCOMMIT;
405 struct vcache *tvc=(struct vcache *)vp;
407 if (UBCINVALID(vp)) {
409 panic("afs_vop_pagein: invalid vp");
410 #endif /* DIAGNOSTIC */
414 UBCINFOCHECK("afs_vop_pagein", vp);
415 if(pl == (upl_t)NULL) {
416 panic("afs_vop_pagein: no upl");
419 cred = ubc_getcred(vp);
425 kernel_upl_abort_range(pl, pl_offset, size,
426 UPL_ABORT_ERROR | UPL_ABORT_FREE_ON_EMPTY);
431 kernel_upl_abort_range(pl, pl_offset, size,
432 UPL_ABORT_ERROR | UPL_ABORT_FREE_ON_EMPTY);
435 if (f_offset & PAGE_MASK)
436 panic("afs_vop_pagein: offset not page aligned");
438 auio.uio_iov = &aiov;
440 auio.uio_offset = f_offset;
441 auio.uio_segflg = UIO_SYSSPACE;
442 auio.uio_rw = UIO_READ;
443 auio.uio_procp = NULL;
444 kernel_upl_map(kernel_map, pl, &ioaddr);
446 auio.uio_resid = aiov.iov_len = size;
447 aiov.iov_base = (caddr_t)ioaddr;
449 afs_BozonLock(&tvc->pvnLock, tvc);
450 osi_FlushPages(tvc); /* hold bozon lock, but not basic vnode lock */
451 code=afs_read(tvc, uio, cred, 0, 0, 0);
453 ObtainWriteLock(&tvc->lock, 2);
454 tvc->states |= CMAPPED;
455 ReleaseWriteLock(&tvc->lock);
457 afs_BozonUnlock(&tvc->pvnLock, tvc);
459 kernel_upl_unmap(kernel_map, pl);
462 kernel_upl_abort_range(pl, pl_offset, size,
463 UPL_ABORT_ERROR | UPL_ABORT_FREE_ON_EMPTY);
465 kernel_upl_commit_range(pl, pl_offset, size,
466 UPL_COMMIT_CLEAR_DIRTY | UPL_COMMIT_FREE_ON_EMPTY,
467 UPL_GET_INTERNAL_PAGE_LIST(pl), MAX_UPL_TRANSFER);
474 struct vop_write_args /* {
478 struct ucred *a_cred;
482 struct vcache *avc=(struct vcache *)ap->a_vp;
485 afs_BozonLock(&avc->pvnLock, avc);
486 osi_FlushPages(avc); /* hold bozon lock, but not basic vnode lock */
487 if (UBCINFOEXISTS(ap->a_vp))
488 ubc_clean(ap->a_vp, 1);
489 if (UBCINFOEXISTS(ap->a_vp))
490 osi_VM_NukePages(ap->a_vp, ap->a_uio->uio_offset, ap->a_uio->uio_resid);
491 code=afs_write((struct vcache *)ap->a_vp, ap->a_uio, ap->a_ioflag, ap->a_cred, 0);
492 afs_BozonUnlock(&avc->pvnLock, avc);
499 struct vop_pageout_args /* {
502 vm_offset_t a_pl_offset,
505 struct ucred *a_cred,
509 register struct vnode *vp = ap->a_vp;
511 size_t size= ap->a_size;
512 off_t f_offset = ap->a_f_offset;
513 vm_offset_t pl_offset = ap->a_pl_offset;
514 int flags = ap->a_flags;
519 struct uio * uio = &auio;
520 int nocommit = flags & UPL_NOCOMMIT;
523 struct vcache *tvc=(struct vcache *)vp;
525 if (UBCINVALID(vp)) {
527 panic("afs_vop_pageout: invalid vp");
528 #endif /* DIAGNOSTIC */
532 UBCINFOCHECK("afs_vop_pageout", vp);
533 if(pl == (upl_t)NULL) {
534 panic("afs_vop_pageout: no upl");
537 { int lbn, iosize, s;
539 int biosize = DEV_BSIZE;
541 lbn = f_offset / DEV_BSIZE;
543 for (iosize = size; iosize > 0; iosize -= biosize, lbn++) {
546 if (bp = incore(vp, lbn)) {
547 if (ISSET(bp->b_flags, B_BUSY))
548 panic("nfs_pageout: found BUSY buffer incore\n")
552 SET(bp->b_flags, (B_BUSY | B_INVAL));
559 cred = ubc_getcred(vp);
565 kernel_upl_abort_range(pl, pl_offset, size,
566 UPL_ABORT_FREE_ON_EMPTY);
569 if (flags & (IO_APPEND | IO_SYNC))
570 panic("nfs_pageout: (IO_APPEND | IO_SYNC)");
573 kernel_upl_abort_range(pl, pl_offset, size,
574 UPL_ABORT_FREE_ON_EMPTY);
577 if (f_offset >= tvc->m.Length) {
579 kernel_upl_abort_range(pl, pl_offset, size,
580 UPL_ABORT_FREE_ON_EMPTY);
584 if (f_offset & PAGE_MASK)
585 panic("afs_vop_pageout: offset not page aligned");
587 auio.uio_iov = &aiov;
589 auio.uio_offset = f_offset;
590 auio.uio_segflg = UIO_SYSSPACE;
591 auio.uio_rw = UIO_WRITE;
592 auio.uio_procp = NULL;
593 kernel_upl_map(kernel_map, pl, &ioaddr);
595 auio.uio_resid = aiov.iov_len = size;
596 aiov.iov_base = (caddr_t)ioaddr;
600 * check for partial page and clear the
601 * contents past end of the file before
602 * releasing it in the VM page cache
604 if ((f_offset < tvc->m.Length) && (f_offset + size) > tvc->m.Length) {
605 size_t io = tvc->m.Length - f_offset;
607 bzero((caddr_t)(ioaddr + pl_offset + io), size - io);
613 afs_BozonLock(&tvc->pvnLock, tvc);
614 osi_FlushPages(tvc); /* hold bozon lock, but not basic vnode lock */
615 ObtainWriteLock(&tvc->lock, 1);
617 ReleaseWriteLock(&tvc->lock);
619 code=afs_write(tvc, uio, flags, cred, 0);
621 ObtainWriteLock(&tvc->lock, 1);
622 afs_FakeClose(tvc, cred);
623 ReleaseWriteLock(&tvc->lock);
624 afs_BozonUnlock(&tvc->pvnLock, tvc);
626 kernel_upl_unmap(kernel_map, pl);
629 kernel_upl_abort_range(pl, pl_offset, size,
630 UPL_ABORT_FREE_ON_EMPTY);
632 kernel_upl_commit_range(pl, pl_offset, size,
633 UPL_COMMIT_CLEAR_DIRTY | UPL_COMMIT_FREE_ON_EMPTY,
634 UPL_GET_INTERNAL_PAGE_LIST(pl), MAX_UPL_TRANSFER);
641 struct vop_ioctl_args /* {
646 struct ucred *a_cred;
650 struct vcache *tvc = (struct vcache *)ap->a_vp;
651 struct afs_ioctl data;
654 /* in case we ever get in here... */
656 AFS_STATCNT(afs_ioctl);
657 if (((ap->a_command >> 8) & 0xff) == 'V') {
658 /* This is a VICEIOCTL call */
660 error = HandleIoctl(tvc, (struct file *)0/*Not used*/,
661 ap->a_command, ap->a_data);
665 /* No-op call; just return. */
673 struct vop_select_args /* {
677 struct ucred *a_cred;
682 * We should really check to see if I/O is possible.
689 * NB Currently unsupported.
694 struct vop_mmap_args /* {
697 struct ucred *a_cred;
706 struct vop_fsync_args /* {
708 struct ucred *a_cred;
713 int wait = ap->a_waitfor == MNT_WAIT;
715 register struct vnode *vp = ap->a_vp;
718 /*vflushbuf(vp, wait);*/
720 error=afs_fsync((struct vcache *)vp, ap->a_cred);
722 error=afs_fsync((struct vcache *)vp, &afs_osi_cred);
729 struct vop_seek_args /* {
733 struct ucred *a_cred;
736 if (ap->a_newoff > ULONG_MAX) /* AFS doesn't support 64-bit offsets */
743 struct vop_remove_args /* {
746 struct componentname *a_cnp;
750 register struct vnode *vp = ap->a_vp;
751 register struct vnode *dvp = ap->a_dvp;
755 error = afs_remove((struct vcache *)dvp, name, cnp->cn_cred);
763 if (UBCINFOEXISTS(vp)) {
764 int wasmapped=ubc_issetflags(vp, UI_WASMAPPED);
765 int hasobjref=ubc_issetflags(vp, UI_HASOBJREF);
767 (void) ubc_uncache(vp);
770 /* WARNING vp may not be valid after this */
773 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
780 struct vop_link_args /* {
782 struct vnode *a_tdvp;
783 struct componentname *a_cnp;
787 register struct vnode *dvp = ap->a_tdvp;
788 register struct vnode *vp = ap->a_vp;
793 if (dvp->v_mount != vp->v_mount) {
794 VOP_ABORTOP(vp, cnp);
798 if (vp->v_type == VDIR) {
799 VOP_ABORTOP(vp, cnp);
803 if (error = vn_lock(vp, LK_EXCLUSIVE, p)) {
804 VOP_ABORTOP(dvp, cnp);
808 error = afs_link((struct vcache *)vp, (struct vcache *)dvp, name, cnp->cn_cred);
810 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
821 struct vop_rename_args /* {
822 struct vnode *a_fdvp;
824 struct componentname *a_fcnp;
825 struct vnode *a_tdvp;
827 struct componentname *a_tcnp;
831 struct componentname *fcnp = ap->a_fcnp;
833 struct componentname *tcnp = ap->a_tcnp;
835 struct vnode *tvp = ap->a_tvp;
836 register struct vnode *tdvp = ap->a_tdvp;
837 struct vnode *fvp = ap->a_fvp;
838 register struct vnode *fdvp = ap->a_fdvp;
839 struct proc *p=fcnp->cn_proc;
842 * Check for cross-device rename.
844 if ((fvp->v_mount != tdvp->v_mount) ||
845 (tvp && (fvp->v_mount != tvp->v_mount))) {
848 VOP_ABORTOP(tdvp, tcnp); /* XXX, why not in NFS? */
855 VOP_ABORTOP(fdvp, fcnp); /* XXX, why not in NFS? */
861 * if fvp == tvp, we're just removing one name of a pair of
862 * directory entries for the same element. convert call into rename.
863 ( (pinched from NetBSD 1.0's ufs_rename())
866 if (fvp->v_type == VDIR) {
871 /* Release destination completely. */
872 VOP_ABORTOP(tdvp, tcnp);
879 fcnp->cn_flags &= ~MODMASK;
880 fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
881 if ((fcnp->cn_flags & SAVESTART) == 0)
882 panic("afs_rename: lost from startdir");
883 fcnp->cn_nameiop = DELETE;
884 (void) relookup(fdvp, &fvp, fcnp);
885 return (VOP_REMOVE(fdvp, fvp, fcnp));
887 if (error = vn_lock(fvp, LK_EXCLUSIVE, p))
890 MALLOC(fname, char *, fcnp->cn_namelen+1, M_TEMP, M_WAITOK);
891 bcopy(fcnp->cn_nameptr, fname, fcnp->cn_namelen);
892 fname[fcnp->cn_namelen] = '\0';
893 MALLOC(tname, char *, tcnp->cn_namelen+1, M_TEMP, M_WAITOK);
894 bcopy(tcnp->cn_nameptr, tname, tcnp->cn_namelen);
895 tname[tcnp->cn_namelen] = '\0';
899 /* XXX use "from" or "to" creds? NFS uses "to" creds */
900 error = afs_rename((struct vcache *)fdvp, fname, (struct vcache *)tdvp, tname, tcnp->cn_cred);
903 VOP_UNLOCK(fvp, 0, p);
907 goto abortit; /* XXX */
921 struct vop_mkdir_args /* {
923 struct vnode **a_vpp;
924 struct componentname *a_cnp;
928 register struct vnode *dvp = ap->a_dvp;
929 register struct vattr *vap = ap->a_vap;
937 if ((cnp->cn_flags & HASBUF) == 0)
938 panic("afs_vop_mkdir: no name");
941 error = afs_mkdir((struct vcache *)dvp, name, vap, &vcp, cnp->cn_cred);
944 VOP_ABORTOP(dvp, cnp);
950 *ap->a_vpp = (struct vnode *)vcp;
951 vn_lock((struct vnode *)vcp, LK_EXCLUSIVE|LK_RETRY, p);
955 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
962 struct vop_rmdir_args /* {
965 struct componentname *a_cnp;
969 register struct vnode *vp = ap->a_vp;
970 register struct vnode *dvp = ap->a_dvp;
976 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
982 error = afs_rmdir((struct vcache *)dvp, name, cnp->cn_cred);
992 struct vop_symlink_args /* {
994 struct vnode **a_vpp;
995 struct componentname *a_cnp;
1000 register struct vnode *dvp = ap->a_dvp;
1002 /* NFS ignores a_vpp; so do we. */
1006 error = afs_symlink((struct vcache *)dvp, name, ap->a_vap, ap->a_target,
1010 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
1017 struct vop_readdir_args /* {
1020 struct ucred *a_cred;
1028 /* printf("readdir %x cookies %x ncookies %d\n", ap->a_vp, ap->a_cookies,
1030 off=ap->a_uio->uio_offset;
1032 error= afs_readdir((struct vcache *)ap->a_vp, ap->a_uio, ap->a_cred,
1035 if (!error && ap->a_ncookies != NULL) {
1036 struct uio *uio = ap->a_uio;
1037 const struct dirent *dp, *dp_start, *dp_end;
1039 u_long *cookies, *cookiep;
1041 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
1042 panic("afs_readdir: burned cookies");
1043 dp = (const struct dirent *)
1044 ((const char *)uio->uio_iov->iov_base - (uio->uio_offset - off));
1046 dp_end = (const struct dirent *) uio->uio_iov->iov_base;
1047 for (dp_start = dp, ncookies = 0;
1049 dp = (const struct dirent *)((const char *) dp + dp->d_reclen))
1052 MALLOC(cookies, u_long *, ncookies * sizeof(u_long),
1054 for (dp = dp_start, cookiep = cookies;
1056 dp = (const struct dirent *)((const char *) dp + dp->d_reclen)) {
1057 off += dp->d_reclen;
1060 *ap->a_cookies = cookies;
1061 *ap->a_ncookies = ncookies;
1068 afs_vop_readlink(ap)
1069 struct vop_readlink_args /* {
1072 struct ucred *a_cred;
1076 /* printf("readlink %x\n", ap->a_vp);*/
1078 error= afs_readlink((struct vcache *)ap->a_vp, ap->a_uio, ap->a_cred);
1083 extern int prtactive;
1086 afs_vop_inactive(ap)
1087 struct vop_inactive_args /* {
1092 register struct vnode *vp = ap->a_vp;
1094 if (prtactive && vp->v_usecount != 0)
1095 vprint("afs_vop_inactive(): pushing active", vp);
1098 afs_InactiveVCache((struct vcache *)vp, 0); /* decrs ref counts */
1100 VOP_UNLOCK(vp, 0, ap->a_p);
1106 struct vop_reclaim_args /* {
1112 register struct vnode *vp = ap->a_vp;
1114 cache_purge(vp); /* just in case... */
1118 error = afs_FlushVCache((struct vcache *)vp, &sl); /* tosses our stuff from vnode */
1121 if (!error && vp->v_data)
1122 panic("afs_reclaim: vnode not cleaned");
1125 if (vp->v_usecount == 2) {
1126 vprint("reclaim count==2", vp);
1127 } else if (vp->v_usecount == 1) {
1128 vprint("reclaim count==1", vp);
1130 vprint("reclaim bad count", vp);
1138 struct vop_lock_args /* {
1142 register struct vnode *vp = ap->a_vp;
1143 register struct vcache *avc = (struct vcache *)vp;
1145 if (vp->v_tag == VT_NON)
1147 return (lockmgr(&avc->rwlock, ap->a_flags, &vp->v_interlock,
1153 struct vop_unlock_args /* {
1157 struct vnode *vp = ap->a_vp;
1158 struct vcache *avc = (struct vcache *)vp;
1159 return (lockmgr(&avc->rwlock, ap->a_flags | LK_RELEASE,
1160 &vp->v_interlock, ap->a_p));
1166 struct vop_bmap_args /* {
1169 struct vnode **a_vpp;
1178 *ap->a_bnp = ap->a_bn * (PAGE_SIZE / DEV_BSIZE);
1181 *ap->a_vpp = ap->a_vp;
1183 if (ap->a_runp != NULL)
1186 if (ap->a_runb != NULL)
1193 afs_vop_strategy(ap)
1194 struct vop_strategy_args /* {
1200 error= afs_ustrategy(ap->a_bp);
1206 struct vop_print_args /* {
1210 register struct vnode *vp = ap->a_vp;
1211 register struct vcache *vc = (struct vcache *)ap->a_vp;
1214 printf("tag %d, fid: %ld.%x.%x.%x, opens %d, writers %d", vp->v_tag, vc->fid.Cell,
1215 vc->fid.Fid.Volume, vc->fid.Fid.Vnode, vc->fid.Fid.Unique, vc->opens,
1216 vc->execsOrWriters);
1217 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" : "");
1219 printf("\n UBC: %s%s",
1220 UBCINFOEXISTS(vp) ? "exists, " : "does not exist",
1222 sprintf(buf, "holdcnt %d", vp->v_ubcinfo->ui_holdcnt),buf : "");
1228 afs_vop_islocked(ap)
1229 struct vop_islocked_args /* {
1233 struct vcache *vc = (struct vcache *)ap->a_vp;
1234 return lockstatus(&vc->rwlock);
1238 * Return POSIX pathconf information applicable to ufs filesystems.
1240 afs_vop_pathconf(ap)
1241 struct vop_pathconf_args /* {
1247 AFS_STATCNT(afs_cntl);
1248 switch (ap->a_name) {
1250 *ap->a_retval = LINK_MAX;
1253 *ap->a_retval = NAME_MAX;
1256 *ap->a_retval = PATH_MAX;
1258 case _PC_CHOWN_RESTRICTED:
1274 * Advisory record locking support (fcntl() POSIX style)
1278 struct vop_advlock_args /* {
1287 struct proc *p=current_proc();
1290 cr=*p->p_cred->pc_ucred;
1293 error= afs_lockctl((struct vcache *)ap->a_vp, ap->a_fl, ap->a_op, &cr,
1300 afs_vop_truncate(ap)
1301 struct vop_truncate_args /* {
1305 struct ucred *a_cred;
1309 printf("stray afs_vop_truncate\n");
1315 struct vop_update_args /* {
1317 struct timeval *a_access;
1318 struct timeval *a_modify;
1322 printf("stray afs_vop_update\n");
1326 int afs_vop_blktooff(ap)
1327 struct vop_blktooff_args /* {
1333 *ap->a_offset = (off_t)(ap->a_lblkno * DEV_BSIZE);
1337 int afs_vop_offtoblk(ap)
1338 struct vop_offtoblk_args /* {
1344 *ap->a_lblkno = (daddr_t)(ap->a_offset / DEV_BSIZE);
1349 int afs_vop_cmap(ap)
1350 struct vop_cmap_args /* {
1359 *ap->a_bpn = (daddr_t)(ap->a_foffset / DEV_BSIZE);
1360 *ap->a_run= MAX(ap->a_size, AFS_CHUNKSIZE(ap->a_foffset));