2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed
6 * to Berkeley by John Heidemann of the UCLA Ficus project.
8 * Source: * @(#)i405_init.c 2.10 92/04/27 UCLA Ficus project
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * $FreeBSD: src/sys/kern/vfs_default.c,v 1.28.2.7 2003/01/10 18:23:26 bde Exp $
40 * $DragonFly: src/sys/kern/vfs_default.c,v 1.40 2006/05/06 18:48:52 dillon Exp $
43 #include <sys/param.h>
44 #include <sys/systm.h>
47 #include <sys/fcntl.h>
49 #include <sys/kernel.h>
51 #include <sys/malloc.h>
52 #include <sys/mount.h>
53 #include <sys/unistd.h>
54 #include <sys/vnode.h>
55 #include <sys/namei.h>
56 #include <sys/nlookup.h>
58 #include <sys/mountctl.h>
60 #include <machine/limits.h>
63 #include <vm/vm_object.h>
64 #include <vm/vm_page.h>
65 #include <vm/vm_pager.h>
66 #include <vm/vnode_pager.h>
68 static int vop_nolookup (struct vop_old_lookup_args *);
69 static int vop_nostrategy (struct vop_strategy_args *);
72 * This vnode table stores what we want to do if the filesystem doesn't
73 * implement a particular VOP.
75 * If there is no specific entry here, we will return EOPNOTSUPP.
77 struct vop_ops *default_vnode_vops;
78 static struct vnodeopv_entry_desc default_vnodeop_entries[] = {
79 { &vop_default_desc, vop_eopnotsupp },
80 { &vop_advlock_desc, vop_einval },
81 { &vop_fsync_desc, vop_null },
82 { &vop_ioctl_desc, vop_enotty },
83 { &vop_islocked_desc, (void *) vop_stdislocked },
84 { &vop_lock_desc, (void *) vop_stdlock },
85 { &vop_mmap_desc, vop_einval },
86 { &vop_old_lookup_desc, (void *) vop_nolookup },
87 { &vop_open_desc, (void *) vop_stdopen },
88 { &vop_close_desc, (void *) vop_stdclose },
89 { &vop_pathconf_desc, vop_einval },
90 { &vop_poll_desc, (void *) vop_nopoll },
91 { &vop_readlink_desc, vop_einval },
92 { &vop_reallocblks_desc, vop_eopnotsupp },
93 { &vop_revoke_desc, (void *) vop_stdrevoke },
94 { &vop_strategy_desc, (void *) vop_nostrategy },
95 { &vop_unlock_desc, (void *) vop_stdunlock },
96 { &vop_getacl_desc, vop_eopnotsupp },
97 { &vop_setacl_desc, vop_eopnotsupp },
98 { &vop_aclcheck_desc, vop_eopnotsupp },
99 { &vop_getextattr_desc, vop_eopnotsupp },
100 { &vop_setextattr_desc, vop_eopnotsupp },
101 { &vop_nresolve_desc, (void *) vop_compat_nresolve },
102 { &vop_nlookupdotdot_desc, (void *) vop_compat_nlookupdotdot },
103 { &vop_ncreate_desc, (void *) vop_compat_ncreate },
104 { &vop_nmkdir_desc, (void *) vop_compat_nmkdir },
105 { &vop_nmknod_desc, (void *) vop_compat_nmknod },
106 { &vop_nlink_desc, (void *) vop_compat_nlink },
107 { &vop_nsymlink_desc, (void *) vop_compat_nsymlink },
108 { &vop_nwhiteout_desc, (void *) vop_compat_nwhiteout },
109 { &vop_nremove_desc, (void *) vop_compat_nremove },
110 { &vop_nrmdir_desc, (void *) vop_compat_nrmdir },
111 { &vop_nrename_desc, (void *) vop_compat_nrename },
112 { &vop_mountctl_desc, (void *) journal_mountctl },
116 static struct vnodeopv_desc default_vnodeop_opv_desc =
117 { &default_vnode_vops, default_vnodeop_entries, 0 };
119 VNODEOP_SET(default_vnodeop_opv_desc);
122 vop_eopnotsupp(struct vop_generic_args *ap)
128 vop_ebadf(struct vop_generic_args *ap)
134 vop_enotty(struct vop_generic_args *ap)
140 vop_einval(struct vop_generic_args *ap)
146 vop_null(struct vop_generic_args *ap)
152 vop_defaultop(struct vop_generic_args *ap)
154 return (VOCALL(default_vnode_vops, ap));
158 vop_panic(struct vop_generic_args *ap)
161 panic("filesystem goof: vop_panic[%s]", ap->a_desc->vdesc_name);
165 * vop_compat_resolve { struct namecache *a_ncp } XXX STOPGAP FUNCTION
167 * XXX OLD API ROUTINE! WHEN ALL VFSs HAVE BEEN CLEANED UP THIS PROCEDURE
168 * WILL BE REMOVED. This procedure exists for all VFSs which have not
169 * yet implemented VOP_NRESOLVE(). It converts VOP_NRESOLVE() into a
170 * vop_old_lookup() and does appropriate translations.
172 * Resolve a ncp for VFSs which do not support the VOP. Eventually all
173 * VFSs will support this VOP and this routine can be removed, since
174 * VOP_NRESOLVE() is far less complex then the older LOOKUP/CACHEDLOOKUP
177 * A locked ncp is passed in to be resolved. The NCP is resolved by
178 * figuring out the vnode (if any) and calling cache_setvp() to attach the
179 * vnode to the entry. If the entry represents a non-existant node then
180 * cache_setvp() is called with a NULL vnode to resolve the entry into a
181 * negative cache entry. No vnode locks are retained and the
182 * ncp is left locked on return.
184 * The ncp will NEVER represent "", "." or "..", or contain any slashes.
186 * There is a potential directory and vnode interlock. The lock order
187 * requirement is: namecache, governing directory, resolved vnode.
190 vop_compat_nresolve(struct vop_nresolve_args *ap)
195 struct namecache *ncp;
196 struct componentname cnp;
198 ncp = ap->a_ncp; /* locked namecache node */
199 if (ncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
201 if (ncp->nc_parent == NULL)
203 if ((dvp = ncp->nc_parent->nc_vp) == NULL)
207 * UFS currently stores all sorts of side effects, including a loop
208 * variable, in the directory inode. That needs to be fixed and the
209 * other VFS's audited before we can switch to LK_SHARED.
211 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
212 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
217 bzero(&cnp, sizeof(cnp));
218 cnp.cn_nameiop = NAMEI_LOOKUP;
220 cnp.cn_nameptr = ncp->nc_name;
221 cnp.cn_namelen = ncp->nc_nlen;
222 cnp.cn_cred = ap->a_cred;
223 cnp.cn_td = curthread; /* XXX */
226 * vop_old_lookup() always returns vp locked. dvp may or may not be
227 * left locked depending on CNP_PDIRUNLOCK.
229 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
232 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
234 if ((ncp->nc_flag & NCF_UNRESOLVED) == 0) {
235 /* was resolved by another process while we were unlocked */
238 } else if (error == 0) {
239 KKASSERT(vp != NULL);
240 cache_setvp(ncp, vp);
242 } else if (error == ENOENT) {
243 KKASSERT(vp == NULL);
244 if (cnp.cn_flags & CNP_ISWHITEOUT)
245 ncp->nc_flag |= NCF_WHITEOUT;
246 cache_setvp(ncp, NULL);
253 * vop_compat_nlookupdotdot { struct vnode *a_dvp,
254 * struct vnode **a_vpp,
255 * struct ucred *a_cred }
257 * Lookup the vnode representing the parent directory of the specified
258 * directory vnode. a_dvp should not be locked. If no error occurs *a_vpp
259 * will contained the parent vnode, locked and refd, else *a_vpp will be NULL.
261 * This function is designed to aid NFS server-side operations and is
262 * used by cache_fromdvp() to create a consistent, connected namecache
265 * As part of the NEW API work, VFSs will first split their CNP_ISDOTDOT
266 * code out from their *_lookup() and create *_nlookupdotdot(). Then as time
267 * permits VFSs will implement the remaining *_n*() calls and finally get
268 * rid of their *_lookup() call.
271 vop_compat_nlookupdotdot(struct vop_nlookupdotdot_args *ap)
273 struct componentname cnp;
277 * UFS currently stores all sorts of side effects, including a loop
278 * variable, in the directory inode. That needs to be fixed and the
279 * other VFS's audited before we can switch to LK_SHARED.
282 if ((error = vget(ap->a_dvp, LK_EXCLUSIVE)) != 0)
284 if (ap->a_dvp->v_type != VDIR) {
289 bzero(&cnp, sizeof(cnp));
290 cnp.cn_nameiop = NAMEI_LOOKUP;
291 cnp.cn_flags = CNP_ISDOTDOT;
292 cnp.cn_nameptr = "..";
294 cnp.cn_cred = ap->a_cred;
295 cnp.cn_td = curthread; /* XXX */
298 * vop_old_lookup() always returns vp locked. dvp may or may not be
299 * left locked depending on CNP_PDIRUNLOCK.
301 error = vop_old_lookup(ap->a_head.a_ops, ap->a_dvp, ap->a_vpp, &cnp);
303 VOP_UNLOCK(*ap->a_vpp, 0);
304 if (cnp.cn_flags & CNP_PDIRUNLOCK)
312 * vop_compat_ncreate { struct namecache *a_ncp, XXX STOPGAP FUNCTION
313 * struct vnode *a_vpp,
314 * struct ucred *a_cred,
315 * struct vattr *a_vap }
317 * Create a file as specified by a_vap. Compatibility requires us to issue
318 * the appropriate VOP_OLD_LOOKUP before we issue VOP_OLD_CREATE in order
319 * to setup the directory inode's i_offset and i_count (e.g. in UFS).
322 vop_compat_ncreate(struct vop_ncreate_args *ap)
324 struct thread *td = curthread;
325 struct componentname cnp;
326 struct namecache *ncp;
331 * Sanity checks, get a locked directory vnode.
333 ncp = ap->a_ncp; /* locked namecache node */
334 if (ncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
336 if (ncp->nc_parent == NULL)
338 if ((dvp = ncp->nc_parent->nc_vp) == NULL)
341 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
342 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
348 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
349 * caches all information required to create the entry in the
350 * directory inode. We expect a return code of EJUSTRETURN for
351 * the CREATE case. The cnp must simulated a saved-name situation.
353 bzero(&cnp, sizeof(cnp));
354 cnp.cn_nameiop = NAMEI_CREATE;
355 cnp.cn_flags = CNP_LOCKPARENT;
356 cnp.cn_nameptr = ncp->nc_name;
357 cnp.cn_namelen = ncp->nc_nlen;
358 cnp.cn_cred = ap->a_cred;
362 error = vop_old_lookup(ap->a_head.a_ops, dvp, ap->a_vpp, &cnp);
365 * EJUSTRETURN should be returned for this case, which means that
366 * the VFS has setup the directory inode for the create. The dvp we
367 * passed in is expected to remain in a locked state.
369 * If the VOP_OLD_CREATE is successful we are responsible for updating
370 * the cache state of the locked ncp that was passed to us.
372 if (error == EJUSTRETURN) {
373 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
374 error = VOP_OLD_CREATE(dvp, ap->a_vpp, &cnp, ap->a_vap);
376 cache_setunresolved(ncp);
377 cache_setvp(ncp, *ap->a_vpp);
385 KKASSERT(*ap->a_vpp == NULL);
387 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
394 * vop_compat_nmkdir { struct namecache *a_ncp, XXX STOPGAP FUNCTION
395 * struct vnode *a_vpp,
396 * struct ucred *a_cred,
397 * struct vattr *a_vap }
399 * Create a directory as specified by a_vap. Compatibility requires us to
400 * issue the appropriate VOP_OLD_LOOKUP before we issue VOP_OLD_MKDIR in
401 * order to setup the directory inode's i_offset and i_count (e.g. in UFS).
404 vop_compat_nmkdir(struct vop_nmkdir_args *ap)
406 struct thread *td = curthread;
407 struct componentname cnp;
408 struct namecache *ncp;
413 * Sanity checks, get a locked directory vnode.
415 ncp = ap->a_ncp; /* locked namecache node */
416 if (ncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
418 if (ncp->nc_parent == NULL)
420 if ((dvp = ncp->nc_parent->nc_vp) == NULL)
423 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
424 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
430 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
431 * caches all information required to create the entry in the
432 * directory inode. We expect a return code of EJUSTRETURN for
433 * the CREATE case. The cnp must simulated a saved-name situation.
435 bzero(&cnp, sizeof(cnp));
436 cnp.cn_nameiop = NAMEI_CREATE;
437 cnp.cn_flags = CNP_LOCKPARENT;
438 cnp.cn_nameptr = ncp->nc_name;
439 cnp.cn_namelen = ncp->nc_nlen;
440 cnp.cn_cred = ap->a_cred;
444 error = vop_old_lookup(ap->a_head.a_ops, dvp, ap->a_vpp, &cnp);
447 * EJUSTRETURN should be returned for this case, which means that
448 * the VFS has setup the directory inode for the create. The dvp we
449 * passed in is expected to remain in a locked state.
451 * If the VOP_OLD_MKDIR is successful we are responsible for updating
452 * the cache state of the locked ncp that was passed to us.
454 if (error == EJUSTRETURN) {
455 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
456 error = VOP_OLD_MKDIR(dvp, ap->a_vpp, &cnp, ap->a_vap);
458 cache_setunresolved(ncp);
459 cache_setvp(ncp, *ap->a_vpp);
467 KKASSERT(*ap->a_vpp == NULL);
469 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
476 * vop_compat_nmknod { struct namecache *a_ncp, XXX STOPGAP FUNCTION
477 * struct vnode *a_vpp,
478 * struct ucred *a_cred,
479 * struct vattr *a_vap }
481 * Create a device or fifo node as specified by a_vap. Compatibility requires
482 * us to issue the appropriate VOP_OLD_LOOKUP before we issue VOP_OLD_MKNOD
483 * in order to setup the directory inode's i_offset and i_count (e.g. in UFS).
486 vop_compat_nmknod(struct vop_nmknod_args *ap)
488 struct thread *td = curthread;
489 struct componentname cnp;
490 struct namecache *ncp;
495 * Sanity checks, get a locked directory vnode.
497 ncp = ap->a_ncp; /* locked namecache node */
498 if (ncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
500 if (ncp->nc_parent == NULL)
502 if ((dvp = ncp->nc_parent->nc_vp) == NULL)
505 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
506 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
512 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
513 * caches all information required to create the entry in the
514 * directory inode. We expect a return code of EJUSTRETURN for
515 * the CREATE case. The cnp must simulated a saved-name situation.
517 bzero(&cnp, sizeof(cnp));
518 cnp.cn_nameiop = NAMEI_CREATE;
519 cnp.cn_flags = CNP_LOCKPARENT;
520 cnp.cn_nameptr = ncp->nc_name;
521 cnp.cn_namelen = ncp->nc_nlen;
522 cnp.cn_cred = ap->a_cred;
526 error = vop_old_lookup(ap->a_head.a_ops, dvp, ap->a_vpp, &cnp);
529 * EJUSTRETURN should be returned for this case, which means that
530 * the VFS has setup the directory inode for the create. The dvp we
531 * passed in is expected to remain in a locked state.
533 * If the VOP_OLD_MKNOD is successful we are responsible for updating
534 * the cache state of the locked ncp that was passed to us.
536 if (error == EJUSTRETURN) {
537 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
538 error = VOP_OLD_MKNOD(dvp, ap->a_vpp, &cnp, ap->a_vap);
540 cache_setunresolved(ncp);
541 cache_setvp(ncp, *ap->a_vpp);
549 KKASSERT(*ap->a_vpp == NULL);
551 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
558 * vop_compat_nlink { struct namecache *a_ncp, XXX STOPGAP FUNCTION
559 * struct vnode *a_vp,
560 * struct ucred *a_cred }
562 * The passed vp is locked and represents the source. The passed ncp is
563 * locked and represents the target to create.
566 vop_compat_nlink(struct vop_nlink_args *ap)
568 struct thread *td = curthread;
569 struct componentname cnp;
570 struct namecache *ncp;
576 * Sanity checks, get a locked directory vnode.
578 ncp = ap->a_ncp; /* locked namecache node */
579 if (ncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
581 if (ncp->nc_parent == NULL)
583 if ((dvp = ncp->nc_parent->nc_vp) == NULL)
586 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
587 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
593 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
594 * caches all information required to create the entry in the
595 * directory inode. We expect a return code of EJUSTRETURN for
596 * the CREATE case. The cnp must simulated a saved-name situation.
598 bzero(&cnp, sizeof(cnp));
599 cnp.cn_nameiop = NAMEI_CREATE;
600 cnp.cn_flags = CNP_LOCKPARENT;
601 cnp.cn_nameptr = ncp->nc_name;
602 cnp.cn_namelen = ncp->nc_nlen;
603 cnp.cn_cred = ap->a_cred;
607 error = vop_old_lookup(ap->a_head.a_ops, dvp, &tvp, &cnp);
610 * EJUSTRETURN should be returned for this case, which means that
611 * the VFS has setup the directory inode for the create. The dvp we
612 * passed in is expected to remain in a locked state.
614 * If the VOP_OLD_LINK is successful we are responsible for updating
615 * the cache state of the locked ncp that was passed to us.
617 if (error == EJUSTRETURN) {
618 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
619 error = VOP_OLD_LINK(dvp, ap->a_vp, &cnp);
621 cache_setunresolved(ncp);
622 cache_setvp(ncp, ap->a_vp);
630 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
637 vop_compat_nsymlink(struct vop_nsymlink_args *ap)
639 struct thread *td = curthread;
640 struct componentname cnp;
641 struct namecache *ncp;
647 * Sanity checks, get a locked directory vnode.
650 ncp = ap->a_ncp; /* locked namecache node */
651 if (ncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
653 if (ncp->nc_parent == NULL)
655 if ((dvp = ncp->nc_parent->nc_vp) == NULL)
658 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
659 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
665 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
666 * caches all information required to create the entry in the
667 * directory inode. We expect a return code of EJUSTRETURN for
668 * the CREATE case. The cnp must simulated a saved-name situation.
670 bzero(&cnp, sizeof(cnp));
671 cnp.cn_nameiop = NAMEI_CREATE;
672 cnp.cn_flags = CNP_LOCKPARENT;
673 cnp.cn_nameptr = ncp->nc_name;
674 cnp.cn_namelen = ncp->nc_nlen;
675 cnp.cn_cred = ap->a_cred;
679 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
682 * EJUSTRETURN should be returned for this case, which means that
683 * the VFS has setup the directory inode for the create. The dvp we
684 * passed in is expected to remain in a locked state.
686 * If the VOP_OLD_SYMLINK is successful we are responsible for updating
687 * the cache state of the locked ncp that was passed to us.
689 if (error == EJUSTRETURN) {
690 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
691 error = VOP_OLD_SYMLINK(dvp, &vp, &cnp, ap->a_vap, ap->a_target);
693 cache_setunresolved(ncp);
694 cache_setvp(ncp, vp);
703 KKASSERT(vp == NULL);
705 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
712 * vop_compat_nwhiteout { struct namecache *a_ncp, XXX STOPGAP FUNCTION
713 * struct ucred *a_cred,
716 * Issie a whiteout operation (create, lookup, or delete). Compatibility
717 * requires us to issue the appropriate VOP_OLD_LOOKUP before we issue
718 * VOP_OLD_WHITEOUT in order to setup the directory inode's i_offset and i_count
719 * (e.g. in UFS) for the NAMEI_CREATE and NAMEI_DELETE ops. For NAMEI_LOOKUP
720 * no lookup is necessary.
723 vop_compat_nwhiteout(struct vop_nwhiteout_args *ap)
725 struct thread *td = curthread;
726 struct componentname cnp;
727 struct namecache *ncp;
733 * Sanity checks, get a locked directory vnode.
735 ncp = ap->a_ncp; /* locked namecache node */
736 if (ncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
738 if (ncp->nc_parent == NULL)
740 if ((dvp = ncp->nc_parent->nc_vp) == NULL)
743 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
744 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
750 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
751 * caches all information required to create the entry in the
752 * directory inode. We expect a return code of EJUSTRETURN for
753 * the CREATE case. The cnp must simulated a saved-name situation.
755 bzero(&cnp, sizeof(cnp));
756 cnp.cn_nameiop = ap->a_flags;
757 cnp.cn_flags = CNP_LOCKPARENT;
758 cnp.cn_nameptr = ncp->nc_name;
759 cnp.cn_namelen = ncp->nc_nlen;
760 cnp.cn_cred = ap->a_cred;
766 * EJUSTRETURN should be returned for the CREATE or DELETE cases.
767 * The VFS has setup the directory inode for the create. The dvp we
768 * passed in is expected to remain in a locked state.
770 * If the VOP_OLD_WHITEOUT is successful we are responsible for updating
771 * the cache state of the locked ncp that was passed to us.
773 switch(ap->a_flags) {
775 cnp.cn_flags |= CNP_DOWHITEOUT;
778 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
779 if (error == EJUSTRETURN) {
780 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
781 error = VOP_OLD_WHITEOUT(dvp, &cnp, ap->a_flags);
783 cache_setunresolved(ncp);
790 KKASSERT(vp == NULL);
794 error = VOP_OLD_WHITEOUT(dvp, NULL, ap->a_flags);
800 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
808 * vop_compat_nremove { struct namecache *a_ncp, XXX STOPGAP FUNCTION
809 * struct ucred *a_cred }
812 vop_compat_nremove(struct vop_nremove_args *ap)
814 struct thread *td = curthread;
815 struct componentname cnp;
816 struct namecache *ncp;
822 * Sanity checks, get a locked directory vnode.
824 ncp = ap->a_ncp; /* locked namecache node */
825 if (ncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
827 if (ncp->nc_parent == NULL)
829 if ((dvp = ncp->nc_parent->nc_vp) == NULL)
832 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
833 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
839 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
840 * caches all information required to delete the entry in the
841 * directory inode. We expect a return code of 0 for the DELETE
842 * case (meaning that a vp has been found). The cnp must simulated
843 * a saved-name situation.
845 bzero(&cnp, sizeof(cnp));
846 cnp.cn_nameiop = NAMEI_DELETE;
847 cnp.cn_flags = CNP_LOCKPARENT;
848 cnp.cn_nameptr = ncp->nc_name;
849 cnp.cn_namelen = ncp->nc_nlen;
850 cnp.cn_cred = ap->a_cred;
854 * The vnode must be a directory and must not represent the
858 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
859 if (error == 0 && vp->v_type == VDIR)
862 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
863 error = VOP_OLD_REMOVE(dvp, vp, &cnp);
865 cache_setunresolved(ncp);
866 cache_setvp(ncp, NULL);
875 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
882 * vop_compat_nrmdir { struct namecache *a_ncp, XXX STOPGAP FUNCTION
883 * struct ucred *a_cred }
886 vop_compat_nrmdir(struct vop_nrmdir_args *ap)
888 struct thread *td = curthread;
889 struct componentname cnp;
890 struct namecache *ncp;
896 * Sanity checks, get a locked directory vnode.
898 ncp = ap->a_ncp; /* locked namecache node */
899 if (ncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
901 if (ncp->nc_parent == NULL)
903 if ((dvp = ncp->nc_parent->nc_vp) == NULL)
906 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
907 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
913 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
914 * caches all information required to delete the entry in the
915 * directory inode. We expect a return code of 0 for the DELETE
916 * case (meaning that a vp has been found). The cnp must simulated
917 * a saved-name situation.
919 bzero(&cnp, sizeof(cnp));
920 cnp.cn_nameiop = NAMEI_DELETE;
921 cnp.cn_flags = CNP_LOCKPARENT;
922 cnp.cn_nameptr = ncp->nc_name;
923 cnp.cn_namelen = ncp->nc_nlen;
924 cnp.cn_cred = ap->a_cred;
928 * The vnode must be a directory and must not represent the
932 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
933 if (error == 0 && vp->v_type != VDIR)
935 if (error == 0 && vp == dvp)
937 if (error == 0 && (vp->v_flag & VROOT))
940 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
941 error = VOP_OLD_RMDIR(dvp, vp, &cnp);
944 * Note that this invalidation will cause any process
945 * currently CD'd into the directory being removed to be
946 * disconnected from the topology and not be able to ".."
950 cache_inval(ncp, CINV_DESTROY);
958 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
965 * vop_compat_nrename { struct namecache *a_fncp, XXX STOPGAP FUNCTION
966 * struct namecache *a_tncp,
967 * struct ucred *a_cred }
969 * This is a fairly difficult procedure. The old VOP_OLD_RENAME requires that
970 * the source directory and vnode be unlocked and the target directory and
971 * vnode (if it exists) be locked. All arguments will be vrele'd and
972 * the targets will also be unlocked regardless of the return code.
975 vop_compat_nrename(struct vop_nrename_args *ap)
977 struct thread *td = curthread;
978 struct componentname fcnp;
979 struct componentname tcnp;
980 struct namecache *fncp;
981 struct namecache *tncp;
982 struct vnode *fdvp, *fvp;
983 struct vnode *tdvp, *tvp;
987 * Sanity checks, get referenced vnodes representing the source.
989 fncp = ap->a_fncp; /* locked namecache node */
990 if (fncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
992 if (fncp->nc_parent == NULL)
994 if ((fdvp = fncp->nc_parent->nc_vp) == NULL)
998 * Temporarily lock the source directory and lookup in DELETE mode to
999 * check permissions. XXX delete permissions should have been
1000 * checked by nlookup(), we need to add NLC_DELETE for delete
1001 * checking. It is unclear whether VFS's require the directory setup
1002 * info NAMEI_DELETE causes to be stored in the fdvp's inode, but
1003 * since it isn't locked and since UFS always does a relookup of
1004 * the source, it is believed that the only side effect that matters
1005 * is the permissions check.
1007 if ((error = vget(fdvp, LK_EXCLUSIVE)) != 0) {
1008 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
1009 fncp, fncp->nc_name);
1013 bzero(&fcnp, sizeof(fcnp));
1014 fcnp.cn_nameiop = NAMEI_DELETE;
1015 fcnp.cn_flags = CNP_LOCKPARENT;
1016 fcnp.cn_nameptr = fncp->nc_name;
1017 fcnp.cn_namelen = fncp->nc_nlen;
1018 fcnp.cn_cred = ap->a_cred;
1022 * note: vop_old_lookup (i.e. VOP_OLD_LOOKUP) always returns a locked
1026 error = vop_old_lookup(ap->a_head.a_ops, fdvp, &fvp, &fcnp);
1027 if (error == 0 && (fvp->v_flag & VROOT)) {
1028 vput(fvp); /* as if vop_old_lookup had failed */
1031 if ((fcnp.cn_flags & CNP_PDIRUNLOCK) == 0) {
1032 fcnp.cn_flags |= CNP_PDIRUNLOCK;
1033 VOP_UNLOCK(fdvp, 0);
1042 * fdvp and fvp are now referenced and unlocked.
1044 * Get a locked directory vnode for the target and lookup the target
1045 * in CREATE mode so it places the required information in the
1048 tncp = ap->a_tncp; /* locked namecache node */
1049 if (tncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
1051 if (tncp->nc_parent == NULL)
1053 if ((tdvp = tncp->nc_parent->nc_vp) == NULL)
1060 if ((error = vget(tdvp, LK_EXCLUSIVE)) != 0) {
1061 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
1062 tncp, tncp->nc_name);
1069 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
1070 * caches all information required to create the entry in the
1071 * target directory inode.
1073 bzero(&tcnp, sizeof(tcnp));
1074 tcnp.cn_nameiop = NAMEI_RENAME;
1075 tcnp.cn_flags = CNP_LOCKPARENT;
1076 tcnp.cn_nameptr = tncp->nc_name;
1077 tcnp.cn_namelen = tncp->nc_nlen;
1078 tcnp.cn_cred = ap->a_cred;
1082 error = vop_old_lookup(ap->a_head.a_ops, tdvp, &tvp, &tcnp);
1084 if (error == EJUSTRETURN) {
1086 * Target does not exist. tvp should be NULL.
1088 KKASSERT(tvp == NULL);
1089 KKASSERT((tcnp.cn_flags & CNP_PDIRUNLOCK) == 0);
1090 error = VOP_OLD_RENAME(fdvp, fvp, &fcnp, tdvp, tvp, &tcnp);
1092 cache_rename(fncp, tncp);
1093 cache_setvp(tncp, fvp);
1095 } else if (error == 0) {
1097 * Target exists. VOP_OLD_RENAME should correctly delete the
1100 KKASSERT((tcnp.cn_flags & CNP_PDIRUNLOCK) == 0);
1101 error = VOP_OLD_RENAME(fdvp, fvp, &fcnp, tdvp, tvp, &tcnp);
1103 cache_rename(fncp, tncp);
1104 cache_setvp(tncp, fvp);
1109 if (tcnp.cn_flags & CNP_PDIRUNLOCK)
1119 struct vop_old_lookup_args /* {
1120 struct vnode *a_dvp;
1121 struct vnode **a_vpp;
1122 struct componentname *a_cnp;
1133 * Strategy routine for VFS devices that have none.
1135 * B_ERROR and B_INVAL must be cleared prior to calling any strategy
1136 * routine. Typically this is done for a BUF_CMD_READ strategy call.
1137 * Typically B_INVAL is assumed to already be clear prior to a write
1138 * and should not be cleared manually unless you just made the buffer
1139 * invalid. B_ERROR should be cleared either way.
1143 vop_nostrategy (struct vop_strategy_args *ap)
1145 printf("No strategy for buffer at %p\n", ap->a_bio->bio_buf);
1146 vprint("", ap->a_vp);
1147 ap->a_bio->bio_buf->b_flags |= B_ERROR;
1148 ap->a_bio->bio_buf->b_error = EOPNOTSUPP;
1150 return (EOPNOTSUPP);
1155 struct vop_pathconf_args /* {
1162 switch (ap->a_name) {
1164 *ap->a_retval = LINK_MAX;
1167 *ap->a_retval = MAX_CANON;
1170 *ap->a_retval = MAX_INPUT;
1173 *ap->a_retval = PIPE_BUF;
1175 case _PC_CHOWN_RESTRICTED:
1179 *ap->a_retval = _POSIX_VDISABLE;
1190 * (struct vnode *a_vp, int a_mode, struct ucred *a_ucred, struct file *a_fp,
1191 * struct thread *a_td)
1193 * a_mode: note, 'F' modes, e.g. FREAD, FWRITE
1196 vop_stdopen(struct vop_open_args *ap)
1198 struct vnode *vp = ap->a_vp;
1201 if ((fp = ap->a_fp) != NULL) {
1202 switch(vp->v_type) {
1204 fp->f_type = DTYPE_FIFO;
1207 fp->f_type = DTYPE_VNODE;
1210 fp->f_flag = ap->a_mode & FMASK;
1211 fp->f_ops = &vnode_fileops;
1215 if (ap->a_mode & FWRITE)
1217 KKASSERT(vp->v_opencount >= 0 && vp->v_opencount != INT_MAX);
1225 * (struct vnode *a_vp, int a_fflag, struct thread *a_td)
1227 * a_fflag: note, 'F' modes, e.g. FREAD, FWRITE. same as a_mode in stdopen?
1230 vop_stdclose(struct vop_close_args *ap)
1232 struct vnode *vp = ap->a_vp;
1234 KASSERT(vp->v_opencount > 0,
1235 ("VOP_STDCLOSE: BAD OPENCOUNT %p %d\n", vp, vp->v_opencount));
1236 if (ap->a_fflag & FWRITE) {
1237 KASSERT(vp->v_writecount > 0,
1238 ("VOP_STDCLOSE: BAD WRITECOUNT %p %d\n",
1239 vp, vp->v_writecount));
1247 * Standard lock. The lock is recursive-capable only if the lock was
1248 * initialized with LK_CANRECURSE or that flag is passed in a_flags.
1252 struct vop_lock_args /* {
1260 error = lockmgr(&ap->a_vp->v_lock, ap->a_flags);
1262 error = debuglockmgr(&ap->a_vp->v_lock, ap->a_flags,
1263 "vop_stdlock", ap->a_vp->filename, ap->a_vp->line);
1270 struct vop_unlock_args /* {
1277 error = lockmgr(&ap->a_vp->v_lock, ap->a_flags | LK_RELEASE);
1283 struct vop_islocked_args /* {
1285 struct thread *a_td;
1288 return (lockstatus(&ap->a_vp->v_lock, ap->a_td));
1292 * Return true for select/poll.
1296 struct vop_poll_args /* {
1299 struct ucred *a_cred;
1304 * Return true for read/write. If the user asked for something
1305 * special, return POLLNVAL, so that clients have a way of
1306 * determining reliably whether or not the extended
1307 * functionality is present without hard-coding knowledge
1308 * of specific filesystem implementations.
1310 if (ap->a_events & ~POLLSTANDARD)
1313 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
1317 * Implement poll for local filesystems that support it.
1321 struct vop_poll_args /* {
1324 struct ucred *a_cred;
1327 if (ap->a_events & ~POLLSTANDARD)
1328 return (vn_pollrecord(ap->a_vp, ap->a_events));
1329 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
1334 * used to fill the vfs fucntion table to get reasonable default return values.
1337 vfs_stdmount(struct mount *mp, char *path, caddr_t data, struct ucred *cred)
1343 vfs_stdunmount(struct mount *mp, int mntflags)
1349 vfs_stdroot(struct mount *mp, struct vnode **vpp)
1351 return (EOPNOTSUPP);
1355 vfs_stdstatfs(struct mount *mp, struct statfs *sbp, struct ucred *cred)
1357 return (EOPNOTSUPP);
1361 vfs_stdvptofh(struct vnode *vp, struct fid *fhp)
1363 return (EOPNOTSUPP);
1367 vfs_stdstart(struct mount *mp, int flags)
1373 vfs_stdquotactl(struct mount *mp, int cmds, uid_t uid,
1374 caddr_t arg, struct ucred *cred)
1376 return (EOPNOTSUPP);
1380 vfs_stdsync(struct mount *mp, int waitfor)
1386 vfs_stdnosync(struct mount *mp, int waitfor)
1388 return (EOPNOTSUPP);
1392 vfs_stdvget(struct mount *mp, ino_t ino, struct vnode **vpp)
1394 return (EOPNOTSUPP);
1398 vfs_stdfhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
1400 return (EOPNOTSUPP);
1404 vfs_stdcheckexp(struct mount *mp, struct sockaddr *nam, int *extflagsp,
1405 struct ucred **credanonp)
1407 return (EOPNOTSUPP);
1411 vfs_stdinit(struct vfsconf *vfsp)
1417 vfs_stduninit(struct vfsconf *vfsp)
1423 vfs_stdextattrctl(struct mount *mp, int cmd, const char *attrname,
1424 caddr_t arg, struct ucred *cred)
1429 /* end of vfs default ops */