2 * Portions Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
10 #include <afs/sysincludes.h> /* Standard vendor system headers */
11 #include <afsincludes.h> /* Afs-based standard headers */
12 #include <afs/afs_stats.h> /* statistics */
13 #include <sys/malloc.h>
14 #include <sys/namei.h>
16 #if defined(AFS_DARWIN70_ENV)
17 #include <vfs/vfs_support.h>
18 #endif /* defined(AFS_DARWIN70_ENV) */
19 #ifdef AFS_DARWIN80_ENV
20 #include <sys/vnode_if.h>
21 #include <sys/kauth.h>
24 #ifdef AFS_DARWIN80_ENV
25 #define VOPPREF(x) &vnop_ ## x
26 #define VOPPROT(x) vnop_ ## x
27 #define OSI_UPL_ABORT_RANGE(pl, offset, size, flags) \
28 ubc_upl_abort_range((pl), (offset), (size), (flags))
29 #define OSI_UPL_COMMIT_RANGE(pl, offset, size, flags) \
30 ubc_upl_commit_range((pl), (offset), (size), (flags))
31 #define OSI_UPL_MAP(upl, offset) ubc_upl_map((upl), (offset))
32 #define OSI_UPL_UNMAP(upl) ubc_upl_unmap((upl))
33 #define VOP_ABORTOP(x, y)
35 #define VOPPREF(x) &vop_ ## x
36 #define VOPPROT(x) vop_ ## x
37 #define OSI_UPL_ABORT_RANGE(pl, offset, size, flags) \
38 kernel_upl_abort_range((pl), (offset), (size), (flags))
39 #define OSI_UPL_COMMIT_RANGE(pl, offset, size, flags) \
40 kernel_upl_commit_range((pl), (offset), (size), (flags), \
41 UPL_GET_INTERNAL_PAGE_LIST((pl)),\
43 #define OSI_UPL_MAP(upl, offset) kernel_upl_map(kernel_map, (upl), (offset))
44 #define OSI_UPL_UNMAP(upl) kernel_upl_unmap(kernel_map, (upl))
47 extern char afs_zeros[AFS_ZEROS];
49 int afs_vop_lookup(struct VOPPROT(lookup_args) *);
50 int afs_vop_create(struct VOPPROT(create_args) *);
51 int afs_vop_mknod(struct VOPPROT(mknod_args) *);
52 int afs_vop_open(struct VOPPROT(open_args) *);
53 int afs_vop_close(struct VOPPROT(close_args) *);
54 int afs_vop_access(struct VOPPROT(access_args) *);
55 int afs_vop_getattr(struct VOPPROT(getattr_args) *);
56 int afs_vop_setattr(struct VOPPROT(setattr_args) *);
57 int afs_vop_read(struct VOPPROT(read_args) *);
58 int afs_vop_write(struct VOPPROT(write_args) *);
59 int afs_vop_pagein(struct VOPPROT(pagein_args) *);
60 int afs_vop_pageout(struct VOPPROT(pageout_args) *);
61 int afs_vop_ioctl(struct VOPPROT(ioctl_args) *);
62 int afs_vop_select(struct VOPPROT(select_args) *);
63 int afs_vop_mmap(struct VOPPROT(mmap_args) *);
64 int afs_vop_fsync(struct VOPPROT(fsync_args) *);
65 int afs_vop_remove(struct VOPPROT(remove_args) *);
66 int afs_vop_link(struct VOPPROT(link_args) *);
67 int afs_vop_rename(struct VOPPROT(rename_args) *);
68 int afs_vop_mkdir(struct VOPPROT(mkdir_args) *);
69 int afs_vop_rmdir(struct VOPPROT(rmdir_args) *);
70 int afs_vop_symlink(struct VOPPROT(symlink_args) *);
71 int afs_vop_readdir(struct VOPPROT(readdir_args) *);
72 int afs_vop_readlink(struct VOPPROT(readlink_args) *);
73 #if !defined(AFS_DARWIN70_ENV)
74 extern int ufs_abortop(struct vop_abortop_args *);
75 #endif /* !defined(AFS_DARWIN70_ENV) */
76 int afs_vop_inactive(struct VOPPROT(inactive_args) *);
77 int afs_vop_reclaim(struct VOPPROT(reclaim_args) *);
78 int afs_vop_strategy(struct VOPPROT(strategy_args) *);
79 int afs_vop_pathconf(struct VOPPROT(pathconf_args) *);
80 int afs_vop_advlock(struct VOPPROT(advlock_args) *);
81 int afs_vop_blktooff __P((struct VOPPROT(blktooff_args) *));
82 int afs_vop_offtoblk __P((struct VOPPROT(offtoblk_args) *));
83 #ifndef AFS_DARWIN80_ENV
84 int afs_vop_truncate(struct VOPPROT(truncate_args) *);
85 int afs_vop_update(struct VOPPROT(update_args) *);
86 int afs_vop_lock(struct VOPPROT(lock_args) *);
87 int afs_vop_unlock(struct VOPPROT(unlock_args) *);
88 int afs_vop_bmap(struct VOPPROT(bmap_args) *);
89 int afs_vop_seek(struct VOPPROT(seek_args) *);
90 int afs_vop_cmap __P((struct VOPPROT(cmap_args) *));
91 int afs_vop_print(struct VOPPROT(print_args) *);
92 int afs_vop_islocked(struct VOPPROT(islocked_args) *);
95 #define afs_vop_opnotsupp \
96 ((int (*) __P((struct vop_reallocblks_args *)))eopnotsupp)
97 #define afs_vop_valloc afs_vop_opnotsupp
98 #define afs_vop_vfree afs_vop_opnotsupp
99 #define afs_vop_blkatoff afs_vop_opnotsupp
100 #define afs_vop_reallocblks afs_vop_opnotsupp
102 /* Global vfs data structures for AFS. */
103 int (**afs_vnodeop_p) ();
105 #define VOPFUNC int (*)(void *)
107 struct vnodeopv_entry_desc afs_vnodeop_entries[] = {
108 {VOPPREF(default_desc), (VOPFUNC)vn_default_error},
109 {VOPPREF(lookup_desc), (VOPFUNC)afs_vop_lookup}, /* lookup */
110 {VOPPREF(create_desc), (VOPFUNC)afs_vop_create}, /* create */
111 {VOPPREF(mknod_desc), (VOPFUNC)afs_vop_mknod}, /* mknod */
112 {VOPPREF(open_desc), (VOPFUNC)afs_vop_open}, /* open */
113 {VOPPREF(close_desc), (VOPFUNC)afs_vop_close}, /* close */
114 {VOPPREF(access_desc), (VOPFUNC)afs_vop_access}, /* access */
115 {VOPPREF(getattr_desc), (VOPFUNC)afs_vop_getattr}, /* getattr */
116 {VOPPREF(setattr_desc), (VOPFUNC)afs_vop_setattr}, /* setattr */
117 {VOPPREF(read_desc), (VOPFUNC)afs_vop_read}, /* read */
118 {VOPPREF(write_desc), (VOPFUNC)afs_vop_write}, /* write */
119 {VOPPREF(pagein_desc), (VOPFUNC)afs_vop_pagein}, /* read */
120 {VOPPREF(pageout_desc), (VOPFUNC)afs_vop_pageout}, /* write */
121 {VOPPREF(ioctl_desc), (VOPFUNC)afs_vop_ioctl}, /* XXX ioctl */
122 {VOPPREF(select_desc), (VOPFUNC)afs_vop_select}, /* select */
123 {VOPPREF(mmap_desc), (VOPFUNC)afs_vop_mmap}, /* mmap */
124 {VOPPREF(fsync_desc), (VOPFUNC)afs_vop_fsync}, /* fsync */
125 #ifndef AFS_DARWIN80_ENV
126 {VOPPREF(seek_desc), (VOPFUNC)afs_vop_seek}, /* seek */
128 {VOPPREF(remove_desc), (VOPFUNC)afs_vop_remove}, /* remove */
129 {VOPPREF(link_desc), (VOPFUNC)afs_vop_link}, /* link */
130 {VOPPREF(rename_desc), (VOPFUNC)afs_vop_rename}, /* rename */
131 {VOPPREF(mkdir_desc), (VOPFUNC)afs_vop_mkdir}, /* mkdir */
132 {VOPPREF(rmdir_desc), (VOPFUNC)afs_vop_rmdir}, /* rmdir */
133 {VOPPREF(symlink_desc), (VOPFUNC)afs_vop_symlink}, /* symlink */
134 {VOPPREF(readdir_desc), (VOPFUNC)afs_vop_readdir}, /* readdir */
135 {VOPPREF(readlink_desc), (VOPFUNC)afs_vop_readlink}, /* readlink */
136 #ifndef AFS_DARWIN80_ENV
137 #if defined(AFS_DARWIN70_ENV)
138 {VOPPREF(abortop_desc), (VOPFUNC)nop_abortop }, /* abortop */
139 #else /* ! defined(AFS_DARWIN70_ENV) */
140 /* Yes, we use the ufs_abortop call. It just releases the namei
142 {VOPPREF(abortop_desc), (VOPFUNC)ufs_abortop}, /* abortop */
143 #endif /* defined(AFS_DARWIN70_ENV) */
145 {VOPPREF(inactive_desc), (VOPFUNC)afs_vop_inactive}, /* inactive */
146 {VOPPREF(reclaim_desc), (VOPFUNC)afs_vop_reclaim}, /* reclaim */
147 #ifndef AFS_DARWIN80_ENV
148 {VOPPREF(lock_desc), (VOPFUNC)afs_vop_lock}, /* lock */
149 {VOPPREF(unlock_desc), (VOPFUNC)afs_vop_unlock}, /* unlock */
150 {VOPPREF(bmap_desc), (VOPFUNC)afs_vop_bmap}, /* bmap */
152 #ifdef AFS_DARWIN80_ENV
153 {VOPPREF(strategy_desc), (VOPFUNC)err_strategy}, /* strategy */
155 {VOPPREF(strategy_desc), (VOPFUNC)afs_vop_strategy}, /* strategy */
157 #ifndef AFS_DARWIN80_ENV
158 {VOPPREF(print_desc), (VOPFUNC)afs_vop_print}, /* print */
159 {VOPPREF(islocked_desc), (VOPFUNC)afs_vop_islocked}, /* islocked */
161 {VOPPREF(pathconf_desc), (VOPFUNC)afs_vop_pathconf}, /* pathconf */
162 {VOPPREF(advlock_desc), (VOPFUNC)afs_vop_advlock}, /* advlock */
163 #ifndef AFS_DARWIN80_ENV
164 {VOPPREF(blkatoff_desc), (VOPFUNC)afs_vop_blkatoff}, /* blkatoff */
165 {VOPPREF(valloc_desc), (VOPFUNC)afs_vop_valloc}, /* valloc */
166 {VOPPREF(reallocblks_desc), (VOPFUNC)afs_vop_reallocblks}, /* reallocblks */
167 {VOPPREF(vfree_desc), (VOPFUNC)afs_vop_vfree}, /* vfree */
168 {VOPPREF(update_desc), (VOPFUNC)afs_vop_update}, /* update */
169 {VOPPREF(cmap_desc), (VOPFUNC)afs_vop_cmap}, /* cmap */
170 {VOPPREF(truncate_desc), (VOPFUNC)afs_vop_truncate}, /* truncate */
172 {VOPPREF(blktooff_desc), (VOPFUNC)afs_vop_blktooff}, /* blktooff */
173 {VOPPREF(offtoblk_desc), (VOPFUNC)afs_vop_offtoblk}, /* offtoblk */
174 {VOPPREF(bwrite_desc), (VOPFUNC)vn_bwrite},
175 {(struct vnodeop_desc *)NULL, (void (*)())NULL}
177 struct vnodeopv_desc afs_vnodeop_opv_desc =
178 { &afs_vnodeop_p, afs_vnodeop_entries };
180 #ifdef AFS_DARWIN80_ENV
181 /* vfs structures for incompletely initialized vnodes */
182 int (**afs_dead_vnodeop_p) ();
184 struct vnodeopv_entry_desc afs_dead_vnodeop_entries[] = {
185 {VOPPREF(default_desc), (VOPFUNC)vn_default_error},
186 {VOPPREF(lookup_desc), (VOPFUNC)vn_default_error}, /* lookup */
187 {VOPPREF(create_desc), (VOPFUNC)err_create}, /* create */
188 {VOPPREF(mknod_desc), (VOPFUNC)err_mknod}, /* mknod */
189 {VOPPREF(open_desc), (VOPFUNC)err_open}, /* open */
190 {VOPPREF(close_desc), (VOPFUNC)err_close}, /* close */
191 {VOPPREF(access_desc), (VOPFUNC)err_access}, /* access */
192 {VOPPREF(getattr_desc), (VOPFUNC)err_getattr}, /* getattr */
193 {VOPPREF(setattr_desc), (VOPFUNC)err_setattr}, /* setattr */
194 {VOPPREF(read_desc), (VOPFUNC)err_read}, /* read */
195 {VOPPREF(write_desc), (VOPFUNC)err_write}, /* write */
196 {VOPPREF(pagein_desc), (VOPFUNC)err_pagein}, /* read */
197 {VOPPREF(pageout_desc), (VOPFUNC)err_pageout}, /* write */
198 {VOPPREF(ioctl_desc), (VOPFUNC)err_ioctl}, /* XXX ioctl */
199 {VOPPREF(select_desc), (VOPFUNC)nop_select}, /* select */
200 {VOPPREF(mmap_desc), (VOPFUNC)err_mmap}, /* mmap */
201 {VOPPREF(fsync_desc), (VOPFUNC)err_fsync}, /* fsync */
202 {VOPPREF(remove_desc), (VOPFUNC)err_remove}, /* remove */
203 {VOPPREF(link_desc), (VOPFUNC)err_link}, /* link */
204 {VOPPREF(rename_desc), (VOPFUNC)err_rename}, /* rename */
205 {VOPPREF(mkdir_desc), (VOPFUNC)err_mkdir}, /* mkdir */
206 {VOPPREF(rmdir_desc), (VOPFUNC)err_rmdir}, /* rmdir */
207 {VOPPREF(symlink_desc), (VOPFUNC)err_symlink}, /* symlink */
208 {VOPPREF(readdir_desc), (VOPFUNC)err_readdir}, /* readdir */
209 {VOPPREF(readlink_desc), (VOPFUNC)err_readlink}, /* readlink */
210 {VOPPREF(inactive_desc), (VOPFUNC)afs_vop_inactive}, /* inactive */
211 {VOPPREF(reclaim_desc), (VOPFUNC)afs_vop_reclaim}, /* reclaim */
212 {VOPPREF(strategy_desc), (VOPFUNC)err_strategy}, /* strategy */
213 {VOPPREF(pathconf_desc), (VOPFUNC)err_pathconf}, /* pathconf */
214 {VOPPREF(advlock_desc), (VOPFUNC)err_advlock}, /* advlock */
215 {VOPPREF(blktooff_desc), (VOPFUNC)err_blktooff}, /* blktooff */
216 {VOPPREF(offtoblk_desc), (VOPFUNC)err_offtoblk}, /* offtoblk */
217 {VOPPREF(bwrite_desc), (VOPFUNC)err_bwrite},
218 {(struct vnodeop_desc *)NULL, (void (*)())NULL}
220 struct vnodeopv_desc afs_dead_vnodeop_opv_desc =
221 { &afs_dead_vnodeop_p, afs_dead_vnodeop_entries };
225 struct componentname *cnp = ap->a_cnp; \
227 MALLOC(name, char *, cnp->cn_namelen+1, M_TEMP, M_WAITOK); \
228 memcpy(name, cnp->cn_nameptr, cnp->cn_namelen); \
229 name[cnp->cn_namelen] = '\0'
231 #define DROPNAME() FREE(name, M_TEMP)
234 darwin_vn_hold(struct vnode *vp)
236 int haveGlock=ISAFS_GLOCK();
237 struct vcache *tvc = VTOAFS(vp);
239 #ifndef AFS_DARWIN80_ENV
240 tvc->f.states |= CUBCinit;
242 #ifdef AFS_DARWIN80_ENV
243 osi_Assert((tvc->f.states & CVInit) == 0);
244 if (tvc->f.states & CDeadVnode)
245 osi_Assert(!vnode_isinuse(vp, 1));
247 if (haveGlock) AFS_GUNLOCK();
249 #ifdef AFS_DARWIN80_ENV
251 /* being terminated. kernel won't give us a ref. Now what? our
252 callers don't expect us to fail */
254 panic("vn_hold on terminating vnode");
256 if (haveGlock) AFS_GLOCK();
262 panic("vn_hold on terminating vnode");
265 if (haveGlock) AFS_GLOCK();
271 /* vget needed for 0 ref'd vnode in GetVCache to not panic in vref.
272 vref needed for multiref'd vnode in vnop_remove not to deadlock
273 ourselves during vop_inactive, except we also need to not reinst
274 the ubc... so we just call VREF there now anyway. */
276 if (VREFCOUNT_GT(tvc, 0))
277 VREF(((struct vnode *)(vp)));
279 afs_vget(afs_globalVFS, 0, (vp));
282 #ifndef AFS_DARWIN80_ENV
283 if (UBCINFOMISSING(vp) || UBCINFORECLAIMED(vp)) {
288 if (haveGlock) AFS_GLOCK();
289 #ifndef AFS_DARWIN80_ENV
290 tvc->f.states &= ~CUBCinit;
295 struct VOPPROT(lookup_args)/* {
296 * struct vnodeop_desc * a_desc;
297 * struct vnode *a_dvp;
298 * struct vnode **a_vpp;
299 * struct componentname *a_cnp;
304 struct vnode *vp, *dvp;
305 register int flags = ap->a_cnp->cn_flags;
306 int lockparent; /* 1 => lockparent flag is set */
307 int wantparent; /* 1 => wantparent or lockparent flag */
309 #ifdef AFS_DARWIN80_ENV
310 vcp = VTOAFS(ap->a_dvp);
311 if (vcp->mvstat != 1) {
312 error = cache_lookup(ap->a_dvp, ap->a_vpp, ap->a_cnp);
323 lockparent = flags & LOCKPARENT;
324 wantparent = flags & (LOCKPARENT | WANTPARENT);
326 if (!vnode_isdir(ap->a_dvp)) {
332 #ifndef AFS_DARWIN80_ENV
333 if (flags & ISDOTDOT)
334 VOP_UNLOCK(dvp, 0, p);
337 error = afs_lookup(VTOAFS(dvp), name, &vcp, vop_cn_cred);
340 #ifndef AFS_DARWIN80_ENV
341 if (flags & ISDOTDOT)
342 VOP_LOCK(dvp, LK_EXCLUSIVE | LK_RETRY, p);
344 if ((cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME)
345 && (flags & ISLASTCN) && error == ENOENT)
347 #ifndef AFS_DARWIN80_ENV
348 if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))
349 cnp->cn_flags |= SAVENAME;
355 #ifdef AFS_DARWIN80_ENV
356 if ((error=afs_darwin_finalizevnode(vcp, ap->a_dvp, ap->a_cnp, 0))) {
362 vp = AFSTOV(vcp); /* always get a node if no error */
363 #ifndef AFS_DARWIN80_ENV /* XXX needed for multi-mount thing, but can't have it yet */
364 vp->v_vfsp = dvp->v_vfsp;
366 if (UBCINFOMISSING(vp) ||
367 UBCINFORECLAIMED(vp)) {
372 #ifndef AFS_DARWIN80_ENV
373 /* The parent directory comes in locked. We unlock it on return
374 * unless the caller wants it left locked.
375 * we also always return the vnode locked. */
377 if (flags & ISDOTDOT) {
378 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
379 /* always return the child locked */
380 if (lockparent && (flags & ISLASTCN)
381 && (error = vn_lock(dvp, LK_EXCLUSIVE, p))) {
386 } else if (vp == dvp) {
387 /* they're the same; afs_lookup() already ref'ed the leaf.
388 * It came in locked, so we don't need to ref OR lock it */
390 if (!lockparent || !(flags & ISLASTCN))
391 VOP_UNLOCK(dvp, 0, p); /* done with parent. */
392 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
393 /* always return the child locked */
398 #ifndef AFS_DARWIN80_ENV
399 if ((cnp->cn_nameiop == RENAME && wantparent && (flags & ISLASTCN)
400 || (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))))
401 cnp->cn_flags |= SAVENAME;
410 struct VOPPROT(create_args) /* {
411 * struct vnode *a_dvp;
412 * struct vnode **a_vpp;
413 * struct componentname *a_cnp;
414 * struct vattr *a_vap;
419 register struct vnode *dvp = ap->a_dvp;
424 /* vnode layer handles excl/nonexcl */
427 afs_create(VTOAFS(dvp), name, ap->a_vap, NONEXCL, ap->a_vap->va_mode,
431 #ifndef AFS_DARWIN80_ENV
432 VOP_ABORTOP(dvp, cnp);
440 #ifdef AFS_DARWIN80_ENV
441 if ((error=afs_darwin_finalizevnode(vcp, ap->a_dvp, ap->a_cnp, 0))) {
447 *ap->a_vpp = AFSTOV(vcp);
448 #ifndef AFS_DARWIN80_ENV /* XXX needed for multi-mount thing, but can't have it yet */
449 (*ap->a_vpp)->v_vfsp = dvp->v_vfsp;
450 vn_lock(*ap->a_vpp, LK_EXCLUSIVE | LK_RETRY, p);
451 if (UBCINFOMISSING(*ap->a_vpp) || UBCINFORECLAIMED(*ap->a_vpp)) {
452 vcp->f.states |= CUBCinit;
453 ubc_info_init(*ap->a_vpp);
454 vcp->f.states &= ~CUBCinit;
460 #ifndef AFS_DARWIN80_ENV
461 if ((cnp->cn_flags & SAVESTART) == 0)
462 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
471 struct VOPPROT(mknod_args) /* {
472 * struct vnode *a_dvp;
473 * struct vnode **a_vpp;
474 * struct componentname *a_cnp;
475 * struct vattr *a_vap;
478 #ifndef AFS_DARWIN80_ENV
479 FREE_ZONE(ap->a_cnp->cn_pnbuf, ap->a_cnp->cn_pnlen, M_NAMEI);
487 struct VOPPROT(open_args) /* {
488 * struct vnode *a_vp;
490 * struct ucred *a_cred;
495 struct vnode *vp = ap->a_vp;
496 struct vcache *vc = VTOAFS(vp);
497 #if defined(AFS_DARWIN14_ENV) && !defined(AFS_DARWIN80_ENV)
499 /*----------------------------------------------------------------
500 * osi_VM_TryReclaim() removes the ubcinfo of a vnode, but that vnode
501 * can later be passed to vn_open(), which will skip the call to
502 * ubc_hold(), and when the ubcinfo is later added, the ui_refcount
503 * will be off. So we compensate by calling ubc_hold() ourselves
504 * when ui_refcount is less than 2. If an error occurs in afs_open()
505 * we must call ubc_rele(), which is what vn_open() would do if it
506 * was able to call ubc_hold() in the first place.
507 *----------------------------------------------------------------*/
508 if (vp->v_type == VREG && !(vp->v_flag & VSYSTEM)
509 && vp->v_ubcinfo->ui_refcount < 2)
510 didhold = ubc_hold(vp);
511 #endif /* AFS_DARWIN14_ENV */
513 error = afs_open(&vc, ap->a_mode, vop_cred);
515 if (AFSTOV(vc) != vp)
516 panic("AFS open changed vnode!");
518 osi_FlushPages(vc, vop_cred);
520 #if defined(AFS_DARWIN14_ENV) && !defined(AFS_DARWIN80_ENV)
521 if (error && didhold)
523 #endif /* AFS_DARWIN14_ENV */
529 struct VOPPROT(close_args) /* {
530 * struct vnode *a_vp;
532 * struct ucred *a_cred;
537 struct vnode *vp = ap->a_vp;
538 struct vcache *avc = VTOAFS(vp);
541 code = afs_close(avc, ap->a_fflag, vop_cred);
543 code = afs_close(avc, ap->a_fflag, &afs_osi_cred);
544 osi_FlushPages(avc, vop_cred); /* hold bozon lock, but not basic vnode lock */
545 /* This is legit; it just forces the fstrace event to happen */
546 code = afs_CheckCode(code, NULL, 60);
552 #ifdef AFS_DARWIN80_ENV
553 extern int afs_fakestat_enable;
557 struct VOPPROT(access_args) /* {
558 * struct vnode *a_vp;
560 * vfs_context_t a_context;
564 struct vrequest treq;
565 struct afs_fakestat_state fakestate;
566 struct vcache * tvc = VTOAFS(ap->a_vp);
568 int cmb = CHECK_MODE_BITS;
570 afs_InitFakeStat(&fakestate);
571 if ((code = afs_InitReq(&treq, vop_cred)))
574 code = afs_TryEvalFakeStat(&tvc, &fakestate, &treq);
576 code = afs_CheckCode(code, &treq, 55);
580 code = afs_VerifyVCache(tvc, &treq);
582 code = afs_CheckCode(code, &treq, 56);
585 if (afs_fakestat_enable && tvc->mvstat && !(tvc->f.states & CStatd)) {
589 if (vnode_isdir(ap->a_vp)) {
590 if (ap->a_action & KAUTH_VNODE_LIST_DIRECTORY)
591 bits |= PRSFS_LOOKUP;
592 if (ap->a_action & KAUTH_VNODE_ADD_FILE)
593 bits |= PRSFS_INSERT;
594 if (ap->a_action & KAUTH_VNODE_SEARCH)
595 bits |= PRSFS_LOOKUP;
596 if (ap->a_action & KAUTH_VNODE_DELETE)
597 bits |= PRSFS_DELETE;
598 if (ap->a_action & KAUTH_VNODE_ADD_SUBDIRECTORY)
599 bits |= PRSFS_INSERT;
600 if (ap->a_action & KAUTH_VNODE_DELETE_CHILD)
601 bits |= PRSFS_DELETE;
602 #if 0 /* I'd argue this should be enforced on the parent. But that's ugly */
603 if (ap->a_action & KAUTH_VNODE_READ_ATTRIBUTES)
604 bits |= PRSFS_LOOKUP;
605 if (ap->a_action & KAUTH_VNODE_READ_SECURITY) /* mode bits/gid, not afs acl */
606 bits |= PRSFS_LOOKUP;
609 if (ap->a_action & KAUTH_VNODE_READ_DATA)
611 if (ap->a_action & KAUTH_VNODE_WRITE_DATA)
613 if (ap->a_action & KAUTH_VNODE_EXECUTE)
614 bits |= PRSFS_READ; /* and mode bits.... */
615 if (ap->a_action & KAUTH_VNODE_READ_ATTRIBUTES)
616 bits |= PRSFS_LOOKUP;
617 if (ap->a_action & KAUTH_VNODE_READ_SECURITY) /* mode bits/gid, not afs acl */
618 bits |= PRSFS_LOOKUP;
619 if ((ap->a_action & ((1 << 25) - 1)) == KAUTH_VNODE_EXECUTE)
620 /* if only exec, don't check for read mode bit */
621 /* high bits of ap->a_action are not for 'generic rights bits', and
622 so should not be checked (KAUTH_VNODE_ACCESS is often present
623 and needs to be masked off) */
624 cmb |= CMB_ALLOW_EXEC_AS_READ;
626 if (ap->a_action & KAUTH_VNODE_WRITE_ATTRIBUTES)
628 #if 0 /* no extended attributes */
629 if (ap->a_action & KAUTH_VNODE_READ_EXTATTRIBUTES)
631 if (ap->a_action & KAUTH_VNODE_WRITE_EXTATTRIBUTES)
634 if (ap->a_action & KAUTH_VNODE_WRITE_SECURITY)
636 /* we can't check for KAUTH_VNODE_TAKE_OWNERSHIP, so we always permit it */
638 code = afs_AccessOK(tvc, bits, &treq, cmb);
639 #if defined(AFS_DARWIN80_ENV)
640 /* In a dropbox, cp on 10.4 behaves badly, looping on EACCES */
641 /* In a dropbox, Finder may reopen the file. Let it. */
642 if (code == 0 && ((bits &~(PRSFS_READ|PRSFS_WRITE)) == 0)) {
643 code = afs_AccessOK(tvc, PRSFS_ADMINISTER|PRSFS_INSERT|bits, &treq, cmb);
646 if (code == 1 && vnode_vtype(ap->a_vp) == VREG &&
647 ap->a_action & KAUTH_VNODE_EXECUTE &&
648 (tvc->f.m.Mode & 0100) != 0100) {
652 code= 0; /* if access is ok */
654 code = afs_CheckCode(EACCES, &treq, 57); /* failure code */
657 afs_PutFakeStat(&fakestate);
665 struct VOPPROT(access_args) /* {
666 * struct vnode *a_vp;
668 * struct ucred *a_cred;
674 code = afs_access(VTOAFS(ap->a_vp), ap->a_mode, vop_cred);
682 struct VOPPROT(getattr_args) /* {
683 * struct vnode *a_vp;
684 * struct vattr *a_vap;
685 * struct ucred *a_cred;
692 code = afs_getattr(VTOAFS(ap->a_vp), ap->a_vap, vop_cred);
693 /* This is legit; it just forces the fstrace event to happen */
694 code = afs_CheckCode(code, NULL, 58);
696 #ifdef AFS_DARWIN80_ENV
697 VATTR_SET_SUPPORTED(ap->a_vap, va_type);
698 VATTR_SET_SUPPORTED(ap->a_vap, va_mode);
699 VATTR_SET_SUPPORTED(ap->a_vap, va_uid);
700 VATTR_SET_SUPPORTED(ap->a_vap, va_gid);
701 VATTR_SET_SUPPORTED(ap->a_vap, va_fsid);
702 VATTR_SET_SUPPORTED(ap->a_vap, va_fileid);
703 VATTR_SET_SUPPORTED(ap->a_vap, va_nlink);
704 VATTR_SET_SUPPORTED(ap->a_vap, va_data_size);
705 VATTR_SET_SUPPORTED(ap->a_vap, va_access_time);
706 VATTR_SET_SUPPORTED(ap->a_vap, va_modify_time);
707 VATTR_SET_SUPPORTED(ap->a_vap, va_change_time);
708 VATTR_SET_SUPPORTED(ap->a_vap, va_gen);
709 VATTR_SET_SUPPORTED(ap->a_vap, va_flags);
710 VATTR_SET_SUPPORTED(ap->a_vap, va_iosize);
711 VATTR_SET_SUPPORTED(ap->a_vap, va_total_alloc);
718 struct VOPPROT(setattr_args) /* {
719 * struct vnode *a_vp;
720 * struct vattr *a_vap;
721 * struct ucred *a_cred;
727 code = afs_setattr(VTOAFS(ap->a_vp), ap->a_vap, vop_cred);
728 /* This is legit; it just forces the fstrace event to happen */
729 code = afs_CheckCode(code, NULL, 59);
736 struct VOPPROT(read_args) /* {
737 * struct vnode *a_vp;
740 * struct ucred *a_cred;
744 struct vnode *vp = ap->a_vp;
745 struct vcache *avc = VTOAFS(vp);
747 if (vnode_isdir(ap->a_vp))
749 #ifdef AFS_DARWIN80_ENV
750 ubc_sync_range(ap->a_vp, AFS_UIO_OFFSET(ap->a_uio), AFS_UIO_OFFSET(ap->a_uio) + AFS_UIO_RESID(ap->a_uio), UBC_PUSHDIRTY);
752 if (UBCINFOEXISTS(ap->a_vp)) {
753 ubc_clean(ap->a_vp, 0);
757 osi_FlushPages(avc, vop_cred); /* hold bozon lock, but not basic vnode lock */
758 code = afs_read(avc, ap->a_uio, vop_cred, 0, 0, 0);
765 struct VOPPROT(pagein_args) /* {
766 * struct vnode *a_vp;
768 * vm_offset_t a_pl_offset;
771 * struct ucred *a_cred;
775 register struct vnode *vp = ap->a_vp;
777 size_t size = ap->a_size;
778 off_t f_offset = ap->a_f_offset;
779 vm_offset_t pl_offset = ap->a_pl_offset;
780 int flags = ap->a_flags;
783 #ifdef AFS_DARWIN80_ENV
788 struct uio *uio = &auio;
790 int nocommit = flags & UPL_NOCOMMIT;
793 struct vcache *tvc = VTOAFS(vp);
794 #ifndef AFS_DARWIN80_ENV
795 if (UBCINVALID(vp)) {
797 panic("afs_vop_pagein: invalid vp");
798 #endif /* DIAGNOSTIC */
802 UBCINFOCHECK("afs_vop_pagein", vp);
804 if (pl == (upl_t) NULL) {
805 panic("afs_vop_pagein: no upl");
808 cred = ubc_getcred(vp);
814 OSI_UPL_ABORT_RANGE(pl, pl_offset, size,
815 UPL_ABORT_ERROR | UPL_ABORT_FREE_ON_EMPTY);
820 OSI_UPL_ABORT_RANGE(pl, pl_offset, size,
821 UPL_ABORT_ERROR | UPL_ABORT_FREE_ON_EMPTY);
824 if (f_offset & PAGE_MASK)
825 panic("afs_vop_pagein: offset not page aligned");
827 OSI_UPL_MAP(pl, &ioaddr);
829 #ifdef AFS_DARWIN80_ENV
830 uio = uio_create(1, f_offset, UIO_SYSSPACE32, UIO_READ);
831 uio_addiov(uio, CAST_USER_ADDR_T(ioaddr), size);
833 auio.uio_iov = &aiov;
835 auio.uio_offset = f_offset;
836 auio.uio_segflg = UIO_SYSSPACE;
837 auio.uio_rw = UIO_READ;
838 auio.uio_procp = NULL;
839 auio.uio_resid = aiov.iov_len = size;
840 aiov.iov_base = (caddr_t) ioaddr;
843 osi_FlushPages(tvc, vop_cred); /* hold bozon lock, but not basic vnode lock */
844 code = afs_read(tvc, uio, cred, 0, 0, 0);
846 ObtainWriteLock(&tvc->lock, 2);
847 tvc->f.states |= CMAPPED;
848 ReleaseWriteLock(&tvc->lock);
852 /* Zero out rest of last page if there wasn't enough data in the file */
853 if (code == 0 && AFS_UIO_RESID(uio) > 0) {
854 #ifdef AFS_DARWIN80_ENV
855 memset(((caddr_t)ioaddr) + (size - AFS_UIO_RESID(uio)), 0,
858 memset(aiov.iov_base, 0, auio.uio_resid);
865 OSI_UPL_ABORT_RANGE(pl, pl_offset, size,
866 UPL_ABORT_ERROR | UPL_ABORT_FREE_ON_EMPTY);
868 OSI_UPL_COMMIT_RANGE(pl, pl_offset, size,
869 UPL_COMMIT_CLEAR_DIRTY |
870 UPL_COMMIT_FREE_ON_EMPTY);
872 #ifdef AFS_DARWIN80_ENV
880 struct VOPPROT(write_args) /* {
881 * struct vnode *a_vp;
884 * struct ucred *a_cred;
888 struct vcache *avc = VTOAFS(ap->a_vp);
890 #ifdef AFS_DARWIN80_ENV
891 ubc_sync_range(ap->a_vp, AFS_UIO_OFFSET(ap->a_uio), AFS_UIO_OFFSET(ap->a_uio) + AFS_UIO_RESID(ap->a_uio), UBC_INVALIDATE);
893 if (UBCINFOEXISTS(ap->a_vp)) {
894 ubc_clean(ap->a_vp, 1);
896 if (UBCINFOEXISTS(ap->a_vp))
897 osi_VM_NukePages(ap->a_vp, AFS_UIO_OFFSET(ap->a_uio),
898 AFS_UIO_RESID(ap->a_uio));
901 osi_FlushPages(avc, vop_cred); /* hold bozon lock, but not basic vnode lock */
903 afs_write(VTOAFS(ap->a_vp), ap->a_uio, ap->a_ioflag, vop_cred, 0);
910 struct VOPPROT(pageout_args) /* {
911 * struct vnode *a_vp;
913 * vm_offset_t a_pl_offset,
916 * struct ucred *a_cred,
920 register struct vnode *vp = ap->a_vp;
922 size_t size = ap->a_size;
923 off_t f_offset = ap->a_f_offset;
924 vm_offset_t pl_offset = ap->a_pl_offset;
925 int flags = ap->a_flags;
928 #ifdef AFS_DARWIN80_ENV
933 struct uio *uio = &auio;
935 int nocommit = flags & UPL_NOCOMMIT;
939 struct vcache *tvc = VTOAFS(vp);
940 #ifndef AFS_DARWIN80_ENV
941 if (UBCINVALID(vp)) {
943 panic("afs_vop_pageout: invalid vp");
944 #endif /* DIAGNOSTIC */
948 UBCINFOCHECK("afs_vop_pageout", vp);
950 if (pl == (upl_t) NULL) {
951 panic("afs_vop_pageout: no upl");
953 #if !defined(AFS_DARWIN80_ENV) /* XXX nfs now uses it's own bufs (struct nfsbuf)
955 layer doesn't have them anymore? In any case,
956 we can't just copy code from nfs... */
960 int biosize = DEV_BSIZE;
962 lbn = f_offset / DEV_BSIZE;
964 for (iosize = size; iosize > 0; iosize -= biosize, lbn++) {
967 if (bp = incore(vp, lbn)) {
968 if (ISSET(bp->b_flags, B_BUSY))
969 panic("nfs_pageout: found BUSY buffer incore\n");
972 SET(bp->b_flags, (B_BUSY | B_INVAL));
979 cred = ubc_getcred(vp);
985 OSI_UPL_ABORT_RANGE(pl, pl_offset, size,
986 UPL_ABORT_FREE_ON_EMPTY);
989 if (flags & (IO_APPEND | IO_SYNC))
990 panic("nfs_pageout: (IO_APPEND | IO_SYNC)");
993 OSI_UPL_ABORT_RANGE(pl, pl_offset, size,
994 UPL_ABORT_FREE_ON_EMPTY);
997 if (f_offset >= tvc->f.m.Length) {
999 OSI_UPL_ABORT_RANGE(pl, pl_offset, size,
1000 UPL_ABORT_FREE_ON_EMPTY);
1004 if (f_offset & PAGE_MASK)
1005 panic("afs_vop_pageout: offset not page aligned");
1007 /* size will always be a multiple of PAGE_SIZE */
1008 /* pageout isn't supposed to extend files */
1009 if (f_offset + size > tvc->f.m.Length)
1010 iosize = tvc->f.m.Length - f_offset;
1014 if (size > (iosize + (PAGE_SIZE - 1)) & ~PAGE_MASK && !nocommit) {
1015 int iosize_rnd=(iosize + (PAGE_SIZE - 1)) & ~PAGE_MASK;
1016 OSI_UPL_ABORT_RANGE(pl, pl_offset + iosize_rnd,
1018 UPL_ABORT_FREE_ON_EMPTY);
1020 OSI_UPL_MAP(pl, &ioaddr);
1021 ioaddr += pl_offset;
1022 #ifdef AFS_DARWIN80_ENV
1023 uio = uio_create(1, f_offset, UIO_SYSSPACE32, UIO_READ);
1024 uio_addiov(uio, CAST_USER_ADDR_T(ioaddr), size);
1026 auio.uio_iov = &aiov;
1027 auio.uio_iovcnt = 1;
1028 auio.uio_offset = f_offset;
1029 auio.uio_segflg = UIO_SYSSPACE;
1030 auio.uio_rw = UIO_WRITE;
1031 auio.uio_procp = NULL;
1032 auio.uio_resid = aiov.iov_len = iosize;
1033 aiov.iov_base = (caddr_t) ioaddr;
1038 * check for partial page and clear the
1039 * contents past end of the file before
1040 * releasing it in the VM page cache
1042 if ((f_offset < tvc->f.m.Length) && (f_offset + size) > tvc->f.m.Length) {
1043 size_t io = tvc->f.m.Length - f_offset;
1045 memset((caddr_t) (ioaddr + pl_offset + io), 0, size - io);
1051 osi_FlushPages(tvc, vop_cred); /* hold bozon lock, but not basic vnode lock */
1052 ObtainWriteLock(&tvc->lock, 1);
1054 ReleaseWriteLock(&tvc->lock);
1056 code = afs_write(tvc, uio, flags, cred, 0);
1058 ObtainWriteLock(&tvc->lock, 1);
1059 afs_FakeClose(tvc, cred);
1060 ReleaseWriteLock(&tvc->lock);
1065 OSI_UPL_ABORT_RANGE(pl, pl_offset, size,
1066 UPL_ABORT_FREE_ON_EMPTY);
1068 OSI_UPL_COMMIT_RANGE(pl, pl_offset, size,
1069 UPL_COMMIT_CLEAR_DIRTY |
1070 UPL_COMMIT_FREE_ON_EMPTY);
1073 #ifdef AFS_DARWIN80_ENV
1081 struct VOPPROT(ioctl_args) /* {
1082 * struct vnode *a_vp;
1086 * struct ucred *a_cred;
1090 struct vcache *tvc = VTOAFS(ap->a_vp);
1091 struct afs_ioctl data;
1094 /* in case we ever get in here... */
1096 AFS_STATCNT(afs_ioctl);
1097 if (((ap->a_command >> 8) & 0xff) == 'V') {
1098 /* This is a VICEIOCTL call */
1100 error = HandleIoctl(tvc, ap->a_command, ap->a_data);
1104 /* No-op call; just return. */
1112 struct VOPPROT(select_args) /* {
1113 * struct vnode *a_vp;
1116 * struct ucred *a_cred;
1121 * We should really check to see if I/O is possible.
1129 * NB Currently unsupported.
1134 struct VOPPROT(mmap_args) /* {
1135 * struct vnode *a_vp;
1137 * struct ucred *a_cred;
1146 struct VOPPROT(fsync_args) /* {
1147 * struct vnode *a_vp;
1148 * struct ucred *a_cred;
1153 int wait = ap->a_waitfor == MNT_WAIT;
1155 register struct vnode *vp = ap->a_vp;
1156 int haveGlock = ISAFS_GLOCK();
1158 /* afs_vop_lookup glocks, can call us through vinvalbuf from GetVCache */
1159 if (!haveGlock) AFS_GLOCK();
1161 error = afs_fsync(VTOAFS(vp), vop_cred);
1163 error = afs_fsync(VTOAFS(vp), &afs_osi_cred);
1164 if (!haveGlock) AFS_GUNLOCK();
1168 #ifndef AFS_DARWIN80_ENV
1171 struct VOPPROT(seek_args) /* {
1172 * struct vnode *a_vp;
1175 * struct ucred *a_cred;
1178 if (ap->a_newoff > ULONG_MAX) /* AFS doesn't support 64-bit offsets */
1186 struct VOPPROT(remove_args) /* {
1187 * struct vnode *a_dvp;
1188 * struct vnode *a_vp;
1189 * struct componentname *a_cnp;
1193 register struct vnode *vp = ap->a_vp;
1194 register struct vnode *dvp = ap->a_dvp;
1196 #ifdef AFS_DARWIN80_ENV
1197 if (ap->a_flags & VNODE_REMOVE_NODELETEBUSY) {
1198 /* Caller requested Carbon delete semantics */
1199 if (vnode_isinuse(vp, 0)) {
1207 error = afs_remove(VTOAFS(dvp), name, vop_cn_cred);
1208 error = afs_CheckCode(error, NULL, 61);
1212 #ifdef AFS_DARWIN80_ENV
1213 struct vcache *tvc = VTOAFS(vp);
1215 if (!(tvc->f.states & CUnlinked)) {
1216 ubc_setsize(vp, (off_t)0);
1220 /* necessary so we don't deadlock ourselves in vclean */
1221 VOP_UNLOCK(vp, 0, cnp->cn_proc);
1223 /* If crashes continue in ubc_hold, comment this out */
1224 (void)ubc_uncache(vp);
1227 /* should check for PRSFS_INSERT and not PRSFS_DELETE, but the
1228 goal here is to deal with Finder's unhappiness with resource
1229 forks that have no resources in a dropbox setting */
1230 if (name[0] == '.' && name[1] == '_' && error == EACCES)
1234 #ifndef AFS_DARWIN80_ENV
1242 #ifndef AFS_DARWIN80_ENV
1243 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
1251 struct VOPPROT(link_args) /* {
1252 * struct vnode *a_vp;
1253 * struct vnode *a_tdvp;
1254 * struct componentname *a_cnp;
1258 register struct vnode *dvp = ap->a_tdvp;
1259 register struct vnode *vp = ap->a_vp;
1264 if (vnode_isdir(vp)) {
1265 VOP_ABORTOP(vp, cnp);
1269 #ifndef AFS_DARWIN80_ENV
1270 if (error = vn_lock(vp, LK_EXCLUSIVE, p)) {
1271 VOP_ABORTOP(dvp, cnp);
1276 error = afs_link(VTOAFS(vp), VTOAFS(dvp), name, vop_cn_cred);
1278 #ifndef AFS_DARWIN80_ENV
1279 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
1281 #ifndef AFS_DARWIN80_ENV
1283 VOP_UNLOCK(vp, 0, p);
1286 #ifndef AFS_DARWIN80_ENV
1295 struct VOPPROT(rename_args) /* {
1296 * struct vnode *a_fdvp;
1297 * struct vnode *a_fvp;
1298 * struct componentname *a_fcnp;
1299 * struct vnode *a_tdvp;
1300 * struct vnode *a_tvp;
1301 * struct componentname *a_tcnp;
1305 struct componentname *fcnp = ap->a_fcnp;
1307 struct componentname *tcnp = ap->a_tcnp;
1309 struct vnode *tvp = ap->a_tvp;
1310 register struct vnode *tdvp = ap->a_tdvp;
1311 struct vnode *fvp = ap->a_fvp;
1312 register struct vnode *fdvp = ap->a_fdvp;
1317 #ifdef AFS_DARWIN80_ENV
1318 /* generic code tests for v_mount equality, so we don't have to, but we don't
1319 get the multiple-mount "benefits" of the old behavior
1322 /* Check for cross-device rename.
1323 * For AFS, this means anything not in AFS-space
1325 if ((0 != strcmp(tdvp->v_mount->mnt_stat.f_fstypename, "afs")) ||
1326 (tvp && (0 != strcmp(tvp->v_mount->mnt_stat.f_fstypename, "afs")))) {
1332 #ifdef AFS_DARWIN80_ENV
1333 /* the generic code doesn't do this, so we really should, but all the
1334 vrele's are wrong... */
1337 * if fvp == tvp, we're just removing one name of a pair of
1338 * directory entries for the same element. convert call into rename.
1339 ( (pinched from NetBSD 1.0's ufs_rename())
1342 if (vnode_isdir(fvp)) {
1345 VOP_ABORTOP(tdvp, tcnp); /* XXX, why not in NFS? */
1352 VOP_ABORTOP(fdvp, fcnp); /* XXX, why not in NFS? */
1358 /* Release destination completely. */
1359 VOP_ABORTOP(tdvp, tcnp);
1362 /* Delete source. */
1363 #if defined(AFS_DARWIN80_ENV)
1365 MALLOC(fname, char *, fcnp->cn_namelen + 1, M_TEMP, M_WAITOK);
1366 memcpy(fname, fcnp->cn_nameptr, fcnp->cn_namelen);
1367 fname[fcnp->cn_namelen] = '\0';
1369 error = afs_remove(VTOAFS(fdvp), fname, vop_cn_cred);
1371 FREE(fname, M_TEMP);
1376 fcnp->cn_flags &= ~MODMASK;
1377 fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
1378 if ((fcnp->cn_flags & SAVESTART) == 0)
1379 panic("afs_rename: lost from startdir");
1380 fcnp->cn_nameiop = DELETE;
1383 error=relookup(fdvp, &fvp, fcnp);
1389 error=VOP_REMOVE(fdvp, fvp, fcnp);
1400 #if !defined(AFS_DARWIN80_ENV)
1401 if (error = vn_lock(fvp, LK_EXCLUSIVE, p))
1405 MALLOC(fname, char *, fcnp->cn_namelen + 1, M_TEMP, M_WAITOK);
1406 memcpy(fname, fcnp->cn_nameptr, fcnp->cn_namelen);
1407 fname[fcnp->cn_namelen] = '\0';
1408 MALLOC(tname, char *, tcnp->cn_namelen + 1, M_TEMP, M_WAITOK);
1409 memcpy(tname, tcnp->cn_nameptr, tcnp->cn_namelen);
1410 tname[tcnp->cn_namelen] = '\0';
1414 /* XXX use "from" or "to" creds? NFS uses "to" creds */
1416 afs_rename(VTOAFS(fdvp), fname, VTOAFS(tdvp), tname, cn_cred(tcnp));
1419 #if !defined(AFS_DARWIN80_ENV)
1420 VOP_UNLOCK(fvp, 0, p);
1423 if (error == EXDEV) {
1424 /* The idea would be to have a userspace handler like afsdb to
1425 * run mv as the user, thus:
1427 printf("su %d -c /bin/mv /afs/.:mount/%d:%d:%d:%d/%s /afs/.:mount/%d:%d:%d:%d/%s\n",
1428 (cn_cred(tcnp))->cr_uid, fvc->f.fid.Cell, fvc->f.fid.Fid.Volume,
1429 fvc->f.fid.Fid.Vnode, fvc->f.fid.Fid.Unique, fname,
1430 tvc->f.fid.Cell, tvc->f.fid.Fid.Volume, tvc->f.fid.Fid.Vnode,
1431 tvc->f.fid.Fid.Unique, tname);
1434 #ifdef AFS_DARWIN80_ENV
1445 cache_enter(tdvp, fvp, tcnp);
1448 goto abortit; /* XXX */
1458 FREE(fname, M_TEMP);
1459 FREE(tname, M_TEMP);
1465 struct VOPPROT(mkdir_args) /* {
1466 * struct vnode *a_dvp;
1467 * struct vnode **a_vpp;
1468 * struct componentname *a_cnp;
1469 * struct vattr *a_vap;
1472 register struct vnode *dvp = ap->a_dvp;
1473 register struct vattr *vap = ap->a_vap;
1480 #if defined(DIAGNOSTIC) && !defined(AFS_DARWIN80_ENV)
1481 if ((cnp->cn_flags & HASBUF) == 0)
1482 panic("afs_vop_mkdir: no name");
1485 error = afs_mkdir(VTOAFS(dvp), name, vap, &vcp, vop_cn_cred);
1488 #ifndef AFS_DARWIN80_ENV
1489 VOP_ABORTOP(dvp, cnp);
1496 #ifdef AFS_DARWIN80_ENV
1497 afs_darwin_finalizevnode(vcp, ap->a_dvp, ap->a_cnp, 0);
1499 *ap->a_vpp = AFSTOV(vcp);
1500 #ifndef AFS_DARWIN80_ENV /* XXX needed for multi-mount thing, but can't have it yet */
1501 (*ap->a_vpp)->v_vfsp = dvp->v_vfsp;
1502 vn_lock(*ap->a_vpp, LK_EXCLUSIVE | LK_RETRY, p);
1507 #ifndef AFS_DARWIN80_ENV
1508 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
1516 struct VOPPROT(rmdir_args) /* {
1517 * struct vnode *a_dvp;
1518 * struct vnode *a_vp;
1519 * struct componentname *a_cnp;
1523 register struct vnode *vp = ap->a_vp;
1524 register struct vnode *dvp = ap->a_dvp;
1528 #ifndef AFS_DARWIN80_ENV
1531 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
1538 error = afs_rmdir(VTOAFS(dvp), name, vop_cn_cred);
1543 #ifndef AFS_DARWIN80_ENV
1552 struct VOPPROT(symlink_args) /* {
1553 * struct vnode *a_dvp;
1554 * struct vnode **a_vpp;
1555 * struct componentname *a_cnp;
1556 * struct vattr *a_vap;
1560 register struct vnode *dvp = ap->a_dvp;
1562 /* NFS ignores a_vpp; so do we. */
1567 afs_symlink(VTOAFS(dvp), name, ap->a_vap, ap->a_target, vop_cn_cred);
1570 #ifndef AFS_DARWIN80_ENV
1571 FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
1579 struct VOPPROT(readdir_args) /* {
1580 * struct vnode *a_vp;
1581 * struct uio *a_uio;
1582 * struct ucred *a_cred;
1584 * u_long *a_cookies;
1590 /* printf("readdir %x cookies %x ncookies %d\n", ap->a_vp, ap->a_cookies,
1592 #ifdef AFS_DARWIN80_ENV
1593 /* too much work for now */
1594 /* should only break nfs exports */
1595 if (ap->a_flags & (VNODE_READDIR_EXTENDED | VNODE_READDIR_REQSEEKOFF))
1598 off = AFS_UIO_OFFSET(ap->a_uio);
1601 afs_readdir(VTOAFS(ap->a_vp), ap->a_uio, vop_cred, ap->a_eofflag);
1603 #ifndef AFS_DARWIN80_ENV
1604 if (!error && ap->a_ncookies != NULL) {
1605 struct uio *uio = ap->a_uio;
1606 const struct dirent *dp, *dp_start, *dp_end;
1608 u_long *cookies, *cookiep;
1610 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
1611 panic("afs_readdir: burned cookies");
1612 dp = (const struct dirent *)
1613 ((const char *)uio->uio_iov->iov_base - (uio->uio_offset - off));
1615 dp_end = (const struct dirent *)uio->uio_iov->iov_base;
1616 for (dp_start = dp, ncookies = 0; dp < dp_end;
1617 dp = (const struct dirent *)((const char *)dp + dp->d_reclen))
1620 MALLOC(cookies, u_long *, ncookies * sizeof(u_long), M_TEMP,
1622 for (dp = dp_start, cookiep = cookies; dp < dp_end;
1623 dp = (const struct dirent *)((const char *)dp + dp->d_reclen)) {
1624 off += dp->d_reclen;
1627 *ap->a_cookies = cookies;
1628 *ap->a_ncookies = ncookies;
1636 afs_vop_readlink(ap)
1637 struct VOPPROT(readlink_args) /* {
1638 * struct vnode *a_vp;
1639 * struct uio *a_uio;
1640 * struct ucred *a_cred;
1644 /* printf("readlink %x\n", ap->a_vp);*/
1646 error = afs_readlink(VTOAFS(ap->a_vp), ap->a_uio, vop_cred);
1651 extern int prtactive;
1654 afs_vop_inactive(ap)
1655 struct VOPPROT(inactive_args) /* {
1656 * struct vnode *a_vp;
1660 register struct vnode *vp = ap->a_vp;
1661 struct vcache *tvc = VTOAFS(vp);
1662 #ifndef AFS_DARWIN80_ENV
1663 if (prtactive && vp->v_usecount != 0)
1664 vprint("afs_vop_inactive(): pushing active", vp);
1667 #ifdef AFS_DARWIN80_ENV
1668 int unlinked = tvc->f.states & CUnlinked;
1671 afs_InactiveVCache(tvc, 0); /* decrs ref counts */
1673 #ifdef AFS_DARWIN80_ENV
1680 #ifndef AFS_DARWIN80_ENV
1681 VOP_UNLOCK(vp, 0, ap->a_p);
1688 struct VOPPROT(reclaim_args) /* {
1689 * struct vnode *a_vp;
1693 int sl, writelocked;
1694 register struct vnode *vp = ap->a_vp;
1695 struct vcache *tvc = VTOAFS(vp);
1697 osi_Assert(!ISAFS_GLOCK());
1698 cache_purge(vp); /* just in case... */
1701 writelocked = (0 == NBObtainWriteLock(&afs_xvcache, 335));
1703 ObtainWriteLock(&afs_xvreclaim, 176);
1704 #ifdef AFS_DARWIN80_ENV
1705 vnode_clearfsnode(AFSTOV(tvc));
1706 vnode_removefsref(AFSTOV(tvc));
1708 tvc->v->v_data = NULL; /* remove from vnode */
1710 AFSTOV(tvc) = NULL; /* also drop the ptr to vnode */
1711 tvc->f.states |= CVInit; /* also CDeadVnode? */
1712 tvc->nextfree = ReclaimedVCList;
1713 ReclaimedVCList = tvc;
1714 ReleaseWriteLock(&afs_xvreclaim);
1716 error = afs_FlushVCache(tvc, &sl); /* toss our stuff from vnode */
1717 if (tvc->f.states & (CVInit
1718 #ifdef AFS_DARWIN80_ENV
1722 tvc->f.states &= ~(CVInit
1723 #ifdef AFS_DARWIN80_ENV
1727 afs_osi_Wakeup(&tvc->f.states);
1729 if (!error && vnode_fsnode(vp))
1730 panic("afs_reclaim: vnode not cleaned");
1731 if (!error && (tvc->v != NULL))
1732 panic("afs_reclaim: vcache not cleaned");
1733 ReleaseWriteLock(&afs_xvcache);
1741 * Return POSIX pathconf information applicable to ufs filesystems.
1743 afs_vop_pathconf(ap)
1744 struct VOPPROT(pathconf_args) /* {
1745 * struct vnode *a_vp;
1750 AFS_STATCNT(afs_cntl);
1751 switch (ap->a_name) {
1753 *ap->a_retval = LINK_MAX;
1756 *ap->a_retval = NAME_MAX;
1759 *ap->a_retval = PATH_MAX;
1761 case _PC_CHOWN_RESTRICTED:
1770 #if defined(AFS_DARWIN70_ENV)
1771 case _PC_NAME_CHARS_MAX:
1772 *ap->a_retval = NAME_MAX;
1774 case _PC_CASE_SENSITIVE:
1777 case _PC_CASE_PRESERVING:
1780 #endif /* defined(AFS_DARWIN70_ENV) */
1788 * Advisory record locking support (fcntl() POSIX style)
1792 struct VOPPROT(advlock_args) /* {
1793 * struct vnode *a_vp;
1796 * struct flock *a_fl;
1804 #ifdef AFS_DARWIN80_ENV
1808 struct proc *p = current_proc();
1811 cr = *p->p_cred->pc_ucred;
1815 if (ap->a_flags & F_POSIX) {
1816 #ifdef AFS_DARWIN80_ENV
1817 p = (proc_t) ap->a_id;
1820 p = (struct proc *) ap->a_id;
1824 clid = (int)ap->a_id;
1826 if (ap->a_op == F_UNLCK) {
1828 } else if (ap->a_op == F_SETLK && ap->a_flags & F_WAIT) {
1834 error = afs_lockctl(VTOAFS(ap->a_vp), ap->a_fl, op, tcr, clid);
1840 afs_vop_blktooff(ap)
1841 struct VOPPROT(blktooff_args) /* {
1842 * struct vnode *a_vp;
1847 *ap->a_offset = (off_t) (ap->a_lblkno * DEV_BSIZE);
1852 afs_vop_offtoblk(ap)
1853 struct VOPPROT(offtoblk_args) /* {
1854 * struct vnode *a_vp;
1856 * daddr_t *a_lblkno;
1859 *ap->a_lblkno = (daddr_t) (ap->a_offset / DEV_BSIZE);
1864 #ifndef AFS_DARWIN80_ENV
1867 struct VOPPROT(lock_args) /* {
1868 * struct vnode *a_vp;
1871 register struct vnode *vp = ap->a_vp;
1872 register struct vcache *avc = VTOAFS(vp);
1874 if (vp->v_tag == VT_NON)
1877 return (lockmgr(&avc->rwlock, ap->a_flags, &vp->v_interlock, ap->a_p));
1882 struct VOPPROT(unlock_args) /* {
1883 * struct vnode *a_vp;
1886 struct vnode *vp = ap->a_vp;
1887 struct vcache *avc = VTOAFS(vp);
1890 (&avc->rwlock, ap->a_flags | LK_RELEASE, &vp->v_interlock,
1896 afs_vop_truncate(ap)
1897 struct VOPPROT(truncate_args) /* {
1898 * struct vnode *a_vp;
1901 * struct ucred *a_cred;
1905 printf("stray afs_vop_truncate\n");
1911 struct VOPPROT(update_args) /* {
1912 * struct vnode *a_vp;
1913 * struct timeval *a_access;
1914 * struct timeval *a_modify;
1918 printf("stray afs_vop_update\n");
1924 struct VOPPROT(bmap_args) /* {
1925 * struct vnode *a_vp;
1927 * struct vnode **a_vpp;
1935 *ap->a_bnp = ap->a_bn * (PAGE_SIZE / DEV_BSIZE);
1938 *ap->a_vpp = ap->a_vp;
1940 if (ap->a_runp != NULL)
1943 if (ap->a_runb != NULL)
1951 afs_vop_strategy(ap)
1952 struct VOPPROT(strategy_args) /* {
1958 error = afs_ustrategy(ap->a_bp);
1965 struct VOPPROT(print_args) /* {
1966 * struct vnode *a_vp;
1969 register struct vnode *vp = ap->a_vp;
1970 register struct vcache *vc = VTOAFS(ap->a_vp);
1971 int s = vc->f.states;
1972 printf("tag %d, fid: %ld.%x.%x.%x, opens %d, writers %d", vp->v_tag,
1973 vc->f.fid.Cell, vc->f.fid.Fid.Volume, vc->f.fid.Fid.Vnode,
1974 vc->f.fid.Fid.Unique, vc->opens, vc->execsOrWriters);
1975 printf("\n states%s%s%s%s%s", (s & CStatd) ? " statd" : "",
1976 (s & CRO) ? " readonly" : "", (s & CDirty) ? " dirty" : "",
1977 (s & CMAPPED) ? " mapped" : "",
1978 (s & CVFlushed) ? " flush in progress" : "");
1979 if (UBCISVALID(vp)) {
1981 if (UBCINFOEXISTS(vp)) {
1983 #ifdef AFS_DARWIN14_ENV
1984 printf("refs %d%s%s", vp->v_ubcinfo->ui_refcount,
1985 ubc_issetflags(vp, UI_HASOBJREF) ? " HASOBJREF" : "",
1986 ubc_issetflags(vp, UI_WASMAPPED) ? " WASMAPPED" : "");
1988 printf("holdcnt %d", vp->v_ubcinfo->ui_holdcnt);
1991 printf("does not exist");
1998 afs_vop_islocked(ap)
1999 struct VOPPROT(islocked_args) /* {
2000 * struct vnode *a_vp;
2003 struct vcache *vc = VTOAFS(ap->a_vp);
2004 return lockstatus(&vc->rwlock);
2009 struct VOPPROT(cmap_args) /* {
2010 * struct vnode *a_vp;
2018 *ap->a_bpn = (daddr_t) (ap->a_foffset / DEV_BSIZE);
2019 *ap->a_run = MAX(ap->a_size, AFS_CHUNKSIZE(ap->a_foffset));
2025 afs_darwin_getnewvnode(struct vcache *avc)
2027 #ifdef AFS_DARWIN80_ENV
2030 struct vnode_fsparam par;
2032 memset(&par, 0, sizeof(struct vnode_fsparam));
2035 ObtainWriteLock(&avc->lock,342);
2036 if (avc->f.states & CStatd) {
2037 par.vnfs_vtype = avc->f.m.Type;
2038 par.vnfs_vops = afs_vnodeop_p;
2039 par.vnfs_filesize = avc->f.m.Length;
2041 par.vnfs_flags = VNFS_NOCACHE;
2044 par.vnfs_vtype = VNON;
2045 par.vnfs_vops = afs_dead_vnodeop_p;
2046 par.vnfs_flags = VNFS_NOCACHE|VNFS_CANTCACHE;
2049 ReleaseWriteLock(&avc->lock);
2051 par.vnfs_dvp = ac->dvp;
2052 par.vnfs_cnp = ac->cnp;
2053 par.vnfs_markroot = ac->markroot;
2055 par.vnfs_vtype = VNON;
2056 par.vnfs_vops = afs_dead_vnodeop_p;
2057 par.vnfs_flags = VNFS_NOCACHE|VNFS_CANTCACHE;
2059 par.vnfs_mp = afs_globalVFS;
2060 par.vnfs_fsnode = avc;
2062 error = vnode_create(VNCREATE_FLAVOR, VCREATESIZE, &par, &vp);
2069 vnode_recycle(vp); /* terminate as soon as iocount drops */
2070 avc->f.states |= CDeadVnode;
2071 } else if (!ac->markroot && !ac->cnp) {
2072 /* the caller doesn't know anything about this vnode. if markroot
2073 should have been set and wasn't, bad things may happen, so encourage
2078 vnode_recycle(vp); /* terminate as soon as iocount drops */
2079 avc->f.states |= CDeadVnode;
2084 while (getnewvnode(VT_AFS, afs_globalVFS, afs_vnodeop_p, &avc->v)) {
2085 /* no vnodes available, force an alloc (limits be damned)! */
2086 printf("failed to get vnode\n");
2088 avc->v->v_data = (void *)avc;
2092 #ifdef AFS_DARWIN80_ENV
2093 /* if this fails, then tvc has been unrefed and may have been freed.
2096 afs_darwin_finalizevnode(struct vcache *avc, struct vnode *dvp, struct componentname *cnp, int isroot) {
2100 struct vnode_fsparam par;
2102 ObtainWriteLock(&avc->lock,325);
2104 if (!(avc->f.states & CDeadVnode) && vnode_vtype(ovp) != VNON) {
2106 #if 0 /* unsupported */
2108 vnode_update_identity(ovp, dvp, cnp->cn_nameptr, cnp->cn_namelen,
2110 VNODE_UPDATE_PARENT|VNODE_UPDATE_NAME);
2112 /* Can end up in reclaim... drop GLOCK */
2115 ReleaseWriteLock(&avc->lock);
2119 if ((avc->f.states & CDeadVnode) && vnode_vtype(ovp) != VNON)
2120 panic("vcache %p should not be CDeadVnode", avc);
2122 memset(&par, 0, sizeof(struct vnode_fsparam));
2123 par.vnfs_mp = afs_globalVFS;
2124 par.vnfs_vtype = avc->f.m.Type;
2125 par.vnfs_vops = afs_vnodeop_p;
2126 par.vnfs_filesize = avc->f.m.Length;
2127 par.vnfs_fsnode = avc;
2129 if (cnp && (cnp->cn_flags & ISDOTDOT) == 0)
2131 if (!dvp || !cnp || (cnp->cn_flags & MAKEENTRY) == 0)
2132 par.vnfs_flags = VNFS_NOCACHE;
2134 par.vnfs_markroot = 1;
2135 error = vnode_create(VNCREATE_FLAVOR, VCREATESIZE, &par, &nvp);
2137 vnode_addfsref(nvp);
2138 if ((avc->f.states & CDeadVnode) && vnode_vtype(ovp) != VNON)
2139 printf("vcache %p should not be CDeadVnode", avc);
2140 if (avc->v == ovp) {
2141 if (!(avc->f.states & CVInit)) {
2142 vnode_clearfsnode(ovp);
2143 vnode_removefsref(ovp);
2147 avc->f.states &=~ CDeadVnode;
2152 ReleaseWriteLock(&avc->lock);
2154 afs_osi_Wakeup(&avc->f.states);