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 memcpy(name, cnp->cn_nameptr, 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 memset((caddr_t)(ioaddr + pl_offset + io), 0, 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);
758 if (!error && UBCINFOEXISTS(vp)) {
759 #ifdef AFS_DARWIN14_ENV
760 (void) ubc_uncache(vp);
762 int wasmapped=ubc_issetflags(vp, UI_WASMAPPED);
763 int hasobjref=ubc_issetflags(vp, UI_HASOBJREF);
765 (void) ubc_uncache(vp);
768 /* WARNING vp may not be valid after this */
777 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
784 struct vop_link_args /* {
786 struct vnode *a_tdvp;
787 struct componentname *a_cnp;
791 register struct vnode *dvp = ap->a_tdvp;
792 register struct vnode *vp = ap->a_vp;
797 if (dvp->v_mount != vp->v_mount) {
798 VOP_ABORTOP(vp, cnp);
802 if (vp->v_type == VDIR) {
803 VOP_ABORTOP(vp, cnp);
807 if (error = vn_lock(vp, LK_EXCLUSIVE, p)) {
808 VOP_ABORTOP(dvp, cnp);
812 error = afs_link((struct vcache *)vp, (struct vcache *)dvp, name, cnp->cn_cred);
814 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
825 struct vop_rename_args /* {
826 struct vnode *a_fdvp;
828 struct componentname *a_fcnp;
829 struct vnode *a_tdvp;
831 struct componentname *a_tcnp;
835 struct componentname *fcnp = ap->a_fcnp;
837 struct componentname *tcnp = ap->a_tcnp;
839 struct vnode *tvp = ap->a_tvp;
840 register struct vnode *tdvp = ap->a_tdvp;
841 struct vnode *fvp = ap->a_fvp;
842 register struct vnode *fdvp = ap->a_fdvp;
843 struct proc *p=fcnp->cn_proc;
846 * Check for cross-device rename.
848 if ((fvp->v_mount != tdvp->v_mount) ||
849 (tvp && (fvp->v_mount != tvp->v_mount))) {
852 VOP_ABORTOP(tdvp, tcnp); /* XXX, why not in NFS? */
859 VOP_ABORTOP(fdvp, fcnp); /* XXX, why not in NFS? */
865 * if fvp == tvp, we're just removing one name of a pair of
866 * directory entries for the same element. convert call into rename.
867 ( (pinched from NetBSD 1.0's ufs_rename())
870 if (fvp->v_type == VDIR) {
875 /* Release destination completely. */
876 VOP_ABORTOP(tdvp, tcnp);
883 fcnp->cn_flags &= ~MODMASK;
884 fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
885 if ((fcnp->cn_flags & SAVESTART) == 0)
886 panic("afs_rename: lost from startdir");
887 fcnp->cn_nameiop = DELETE;
888 (void) relookup(fdvp, &fvp, fcnp);
889 return (VOP_REMOVE(fdvp, fvp, fcnp));
891 if (error = vn_lock(fvp, LK_EXCLUSIVE, p))
894 MALLOC(fname, char *, fcnp->cn_namelen+1, M_TEMP, M_WAITOK);
895 memcpy(fname, fcnp->cn_nameptr, fcnp->cn_namelen);
896 fname[fcnp->cn_namelen] = '\0';
897 MALLOC(tname, char *, tcnp->cn_namelen+1, M_TEMP, M_WAITOK);
898 memcpy(tname, tcnp->cn_nameptr, tcnp->cn_namelen);
899 tname[tcnp->cn_namelen] = '\0';
903 /* XXX use "from" or "to" creds? NFS uses "to" creds */
904 error = afs_rename((struct vcache *)fdvp, fname, (struct vcache *)tdvp, tname, tcnp->cn_cred);
907 VOP_UNLOCK(fvp, 0, p);
911 goto abortit; /* XXX */
925 struct vop_mkdir_args /* {
927 struct vnode **a_vpp;
928 struct componentname *a_cnp;
932 register struct vnode *dvp = ap->a_dvp;
933 register struct vattr *vap = ap->a_vap;
941 if ((cnp->cn_flags & HASBUF) == 0)
942 panic("afs_vop_mkdir: no name");
945 error = afs_mkdir((struct vcache *)dvp, name, vap, &vcp, cnp->cn_cred);
948 VOP_ABORTOP(dvp, cnp);
954 *ap->a_vpp = (struct vnode *)vcp;
955 vn_lock((struct vnode *)vcp, LK_EXCLUSIVE|LK_RETRY, p);
959 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
966 struct vop_rmdir_args /* {
969 struct componentname *a_cnp;
973 register struct vnode *vp = ap->a_vp;
974 register struct vnode *dvp = ap->a_dvp;
980 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
986 error = afs_rmdir((struct vcache *)dvp, name, cnp->cn_cred);
996 struct vop_symlink_args /* {
998 struct vnode **a_vpp;
999 struct componentname *a_cnp;
1000 struct vattr *a_vap;
1004 register struct vnode *dvp = ap->a_dvp;
1006 /* NFS ignores a_vpp; so do we. */
1010 error = afs_symlink((struct vcache *)dvp, name, ap->a_vap, ap->a_target,
1014 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
1021 struct vop_readdir_args /* {
1024 struct ucred *a_cred;
1032 /* printf("readdir %x cookies %x ncookies %d\n", ap->a_vp, ap->a_cookies,
1034 off=ap->a_uio->uio_offset;
1036 error= afs_readdir((struct vcache *)ap->a_vp, ap->a_uio, ap->a_cred,
1039 if (!error && ap->a_ncookies != NULL) {
1040 struct uio *uio = ap->a_uio;
1041 const struct dirent *dp, *dp_start, *dp_end;
1043 u_long *cookies, *cookiep;
1045 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
1046 panic("afs_readdir: burned cookies");
1047 dp = (const struct dirent *)
1048 ((const char *)uio->uio_iov->iov_base - (uio->uio_offset - off));
1050 dp_end = (const struct dirent *) uio->uio_iov->iov_base;
1051 for (dp_start = dp, ncookies = 0;
1053 dp = (const struct dirent *)((const char *) dp + dp->d_reclen))
1056 MALLOC(cookies, u_long *, ncookies * sizeof(u_long),
1058 for (dp = dp_start, cookiep = cookies;
1060 dp = (const struct dirent *)((const char *) dp + dp->d_reclen)) {
1061 off += dp->d_reclen;
1064 *ap->a_cookies = cookies;
1065 *ap->a_ncookies = ncookies;
1072 afs_vop_readlink(ap)
1073 struct vop_readlink_args /* {
1076 struct ucred *a_cred;
1080 /* printf("readlink %x\n", ap->a_vp);*/
1082 error= afs_readlink((struct vcache *)ap->a_vp, ap->a_uio, ap->a_cred);
1087 extern int prtactive;
1090 afs_vop_inactive(ap)
1091 struct vop_inactive_args /* {
1096 register struct vnode *vp = ap->a_vp;
1098 if (prtactive && vp->v_usecount != 0)
1099 vprint("afs_vop_inactive(): pushing active", vp);
1102 afs_InactiveVCache((struct vcache *)vp, 0); /* decrs ref counts */
1104 VOP_UNLOCK(vp, 0, ap->a_p);
1110 struct vop_reclaim_args /* {
1116 register struct vnode *vp = ap->a_vp;
1118 cache_purge(vp); /* just in case... */
1122 error = afs_FlushVCache((struct vcache *)vp, &sl); /* tosses our stuff from vnode */
1125 if (!error && vp->v_data)
1126 panic("afs_reclaim: vnode not cleaned");
1129 if (vp->v_usecount == 2) {
1130 vprint("reclaim count==2", vp);
1131 } else if (vp->v_usecount == 1) {
1132 vprint("reclaim count==1", vp);
1134 vprint("reclaim bad count", vp);
1142 struct vop_lock_args /* {
1146 register struct vnode *vp = ap->a_vp;
1147 register struct vcache *avc = (struct vcache *)vp;
1149 if (vp->v_tag == VT_NON)
1151 return (lockmgr(&avc->rwlock, ap->a_flags, &vp->v_interlock,
1157 struct vop_unlock_args /* {
1161 struct vnode *vp = ap->a_vp;
1162 struct vcache *avc = (struct vcache *)vp;
1163 return (lockmgr(&avc->rwlock, ap->a_flags | LK_RELEASE,
1164 &vp->v_interlock, ap->a_p));
1170 struct vop_bmap_args /* {
1173 struct vnode **a_vpp;
1182 *ap->a_bnp = ap->a_bn * (PAGE_SIZE / DEV_BSIZE);
1185 *ap->a_vpp = ap->a_vp;
1187 if (ap->a_runp != NULL)
1190 if (ap->a_runb != NULL)
1197 afs_vop_strategy(ap)
1198 struct vop_strategy_args /* {
1204 error= afs_ustrategy(ap->a_bp);
1210 struct vop_print_args /* {
1214 register struct vnode *vp = ap->a_vp;
1215 register struct vcache *vc = (struct vcache *)ap->a_vp;
1218 printf("tag %d, fid: %ld.%x.%x.%x, opens %d, writers %d", vp->v_tag, vc->fid.Cell,
1219 vc->fid.Fid.Volume, vc->fid.Fid.Vnode, vc->fid.Fid.Unique, vc->opens,
1220 vc->execsOrWriters);
1221 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" : "");
1223 printf("\n UBC: %s%s",
1224 UBCINFOEXISTS(vp) ? "exists, " : "does not exist",
1225 #ifdef AFS_DARWIN14_ENV
1227 sprintf(buf, "refs %d", vp->v_ubcinfo->ui_refcount),buf : "");
1230 sprintf(buf, "holdcnt %d", vp->v_ubcinfo->ui_holdcnt),buf : "");
1237 afs_vop_islocked(ap)
1238 struct vop_islocked_args /* {
1242 struct vcache *vc = (struct vcache *)ap->a_vp;
1243 return lockstatus(&vc->rwlock);
1247 * Return POSIX pathconf information applicable to ufs filesystems.
1249 afs_vop_pathconf(ap)
1250 struct vop_pathconf_args /* {
1256 AFS_STATCNT(afs_cntl);
1257 switch (ap->a_name) {
1259 *ap->a_retval = LINK_MAX;
1262 *ap->a_retval = NAME_MAX;
1265 *ap->a_retval = PATH_MAX;
1267 case _PC_CHOWN_RESTRICTED:
1283 * Advisory record locking support (fcntl() POSIX style)
1287 struct vop_advlock_args /* {
1296 struct proc *p=current_proc();
1299 cr=*p->p_cred->pc_ucred;
1302 error= afs_lockctl((struct vcache *)ap->a_vp, ap->a_fl, ap->a_op, &cr,
1309 afs_vop_truncate(ap)
1310 struct vop_truncate_args /* {
1314 struct ucred *a_cred;
1318 printf("stray afs_vop_truncate\n");
1324 struct vop_update_args /* {
1326 struct timeval *a_access;
1327 struct timeval *a_modify;
1331 printf("stray afs_vop_update\n");
1335 int afs_vop_blktooff(ap)
1336 struct vop_blktooff_args /* {
1342 *ap->a_offset = (off_t)(ap->a_lblkno * DEV_BSIZE);
1346 int afs_vop_offtoblk(ap)
1347 struct vop_offtoblk_args /* {
1353 *ap->a_lblkno = (daddr_t)(ap->a_offset / DEV_BSIZE);
1358 int afs_vop_cmap(ap)
1359 struct vop_cmap_args /* {
1368 *ap->a_bpn = (daddr_t)(ap->a_foffset / DEV_BSIZE);
1369 *ap->a_run= MAX(ap->a_size, AFS_CHUNKSIZE(ap->a_foffset));