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.23 2004/11/18 20:04:24 dillon Exp $
43 #include <sys/param.h>
44 #include <sys/systm.h>
47 #include <sys/kernel.h>
49 #include <sys/malloc.h>
50 #include <sys/mount.h>
51 #include <sys/unistd.h>
52 #include <sys/vnode.h>
53 #include <sys/namei.h>
54 #include <sys/nlookup.h>
57 #include <machine/limits.h>
60 #include <vm/vm_object.h>
61 #include <vm/vm_page.h>
62 #include <vm/vm_pager.h>
63 #include <vm/vnode_pager.h>
65 static int vop_nolookup (struct vop_lookup_args *);
66 static int vop_nostrategy (struct vop_strategy_args *);
69 * This vnode table stores what we want to do if the filesystem doesn't
70 * implement a particular VOP.
72 * If there is no specific entry here, we will return EOPNOTSUPP.
74 struct vop_ops *default_vnode_vops;
75 static struct vnodeopv_entry_desc default_vnodeop_entries[] = {
76 { &vop_default_desc, vop_eopnotsupp },
77 { &vop_advlock_desc, vop_einval },
78 { &vop_bwrite_desc, (void *) vop_stdbwrite },
79 { &vop_close_desc, vop_null },
80 { &vop_createvobject_desc, (void *) vop_stdcreatevobject },
81 { &vop_destroyvobject_desc, (void *) vop_stddestroyvobject },
82 { &vop_fsync_desc, vop_null },
83 { &vop_getvobject_desc, (void *) vop_stdgetvobject },
84 { &vop_ioctl_desc, vop_enotty },
85 { &vop_islocked_desc, (void *) vop_stdislocked },
86 { &vop_lease_desc, vop_null },
87 { &vop_lock_desc, (void *) vop_stdlock },
88 { &vop_mmap_desc, vop_einval },
89 { &vop_lookup_desc, (void *) vop_nolookup },
90 { &vop_open_desc, vop_null },
91 { &vop_pathconf_desc, vop_einval },
92 { &vop_poll_desc, (void *) vop_nopoll },
93 { &vop_readlink_desc, vop_einval },
94 { &vop_reallocblks_desc, vop_eopnotsupp },
95 { &vop_revoke_desc, (void *) vop_stdrevoke },
96 { &vop_strategy_desc, (void *) vop_nostrategy },
97 { &vop_unlock_desc, (void *) vop_stdunlock },
98 { &vop_getacl_desc, vop_eopnotsupp },
99 { &vop_setacl_desc, vop_eopnotsupp },
100 { &vop_aclcheck_desc, vop_eopnotsupp },
101 { &vop_getextattr_desc, vop_eopnotsupp },
102 { &vop_setextattr_desc, vop_eopnotsupp },
103 { &vop_nresolve_desc, (void *) vop_compat_nresolve },
104 { &vop_nlookupdotdot_desc, (void *) vop_compat_nlookupdotdot },
105 { &vop_ncreate_desc, (void *) vop_compat_ncreate },
106 { &vop_nmkdir_desc, (void *) vop_compat_nmkdir },
107 { &vop_nmknod_desc, (void *) vop_compat_nmknod },
108 { &vop_nlink_desc, (void *) vop_compat_nlink },
109 { &vop_nsymlink_desc, (void *) vop_compat_nsymlink },
110 { &vop_nwhiteout_desc, (void *) vop_compat_nwhiteout },
111 { &vop_nremove_desc, (void *) vop_compat_nremove },
112 { &vop_nrmdir_desc, (void *) vop_compat_nrmdir },
113 { &vop_nrename_desc, (void *) vop_compat_nrename },
117 static struct vnodeopv_desc default_vnodeop_opv_desc =
118 { &default_vnode_vops, default_vnodeop_entries };
120 VNODEOP_SET(default_vnodeop_opv_desc);
123 vop_eopnotsupp(struct vop_generic_args *ap)
129 vop_ebadf(struct vop_generic_args *ap)
135 vop_enotty(struct vop_generic_args *ap)
141 vop_einval(struct vop_generic_args *ap)
147 vop_null(struct vop_generic_args *ap)
153 vop_defaultop(struct vop_generic_args *ap)
155 return (VOCALL(default_vnode_vops, ap));
159 vop_panic(struct vop_generic_args *ap)
162 panic("filesystem goof: vop_panic[%s]", ap->a_desc->vdesc_name);
166 * vop_compat_resolve { struct namecache *a_ncp } XXX STOPGAP FUNCTION
168 * XXX OLD API ROUTINE! WHEN ALL VFSs HAVE BEEN CLEANED UP THIS PROCEDURE
169 * WILL BE REMOVED. This procedure exists for all VFSs which have not
170 * yet implemented VOP_NRESOLVE(). It converts VOP_NRESOLVE() into a
171 * vop_lookup() and does appropriate translations.
173 * Resolve a ncp for VFSs which do not support the VOP. Eventually all
174 * VFSs will support this VOP and this routine can be removed, since
175 * VOP_NRESOLVE() is far less complex then the older LOOKUP/CACHEDLOOKUP
178 * A locked ncp is passed in to be resolved. The NCP is resolved by
179 * figuring out the vnode (if any) and calling cache_setvp() to attach the
180 * vnode to the entry. If the entry represents a non-existant node then
181 * cache_setvp() is called with a NULL vnode to resolve the entry into a
182 * negative cache entry. No vnode locks are retained and the
183 * ncp is left locked on return.
185 * The ncp will NEVER represent "", "." or "..", or contain any slashes.
187 * There is a potential directory and vnode interlock. The lock order
188 * requirement is: namecache, governing directory, resolved vnode.
191 vop_compat_nresolve(struct vop_nresolve_args *ap)
196 struct namecache *ncp;
197 struct componentname cnp;
199 ncp = ap->a_ncp; /* locked namecache node */
200 if (ncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
202 if (ncp->nc_parent == NULL)
204 if ((dvp = ncp->nc_parent->nc_vp) == NULL)
208 * UFS currently stores all sorts of side effects, including a loop
209 * variable, in the directory inode. That needs to be fixed and the
210 * other VFS's audited before we can switch to LK_SHARED.
212 if ((error = vget(dvp, LK_EXCLUSIVE, curthread)) != 0) {
213 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
218 bzero(&cnp, sizeof(cnp));
219 cnp.cn_nameiop = NAMEI_LOOKUP;
221 cnp.cn_nameptr = ncp->nc_name;
222 cnp.cn_namelen = ncp->nc_nlen;
223 cnp.cn_cred = ap->a_cred;
224 cnp.cn_td = curthread; /* XXX */
227 * vop_lookup() always returns vp locked. dvp may or may not be
228 * left locked depending on CNP_PDIRUNLOCK.
230 error = vop_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
232 VOP_UNLOCK(vp, 0, curthread);
233 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
234 VOP_UNLOCK(dvp, 0, curthread);
235 if ((ncp->nc_flag & NCF_UNRESOLVED) == 0) {
236 /* was resolved by another process while we were unlocked */
239 } else if (error == 0) {
240 KKASSERT(vp != NULL);
241 cache_setvp(ncp, vp);
243 } else if (error == ENOENT) {
244 KKASSERT(vp == NULL);
245 if (cnp.cn_flags & CNP_ISWHITEOUT)
246 ncp->nc_flag |= NCF_WHITEOUT;
247 cache_setvp(ncp, NULL);
254 * vop_compat_nlookupdotdot { struct vnode *a_dvp,
255 * struct vnode **a_vpp,
256 * struct ucred *a_cred }
258 * Lookup the vnode representing the parent directory of the specified
259 * directory vnode. a_dvp should not be locked. If no error occurs *a_vpp
260 * will contained the parent vnode, locked and refd, else *a_vpp will be NULL.
262 * This function is designed to aid NFS server-side operations and is
263 * used by cache_fromdvp() to create a consistent, connected namecache
266 * As part of the NEW API work, VFSs will first split their CNP_ISDOTDOT
267 * code out from their *_lookup() and create *_nlookupdotdot(). Then as time
268 * permits VFSs will implement the remaining *_n*() calls and finally get
269 * rid of their *_lookup() call.
272 vop_compat_nlookupdotdot(struct vop_nlookupdotdot_args *ap)
274 struct componentname cnp;
278 * UFS currently stores all sorts of side effects, including a loop
279 * variable, in the directory inode. That needs to be fixed and the
280 * other VFS's audited before we can switch to LK_SHARED.
283 if ((error = vget(ap->a_dvp, LK_EXCLUSIVE, curthread)) != 0)
285 if (ap->a_dvp->v_type != VDIR) {
290 bzero(&cnp, sizeof(cnp));
291 cnp.cn_nameiop = NAMEI_LOOKUP;
292 cnp.cn_flags = CNP_ISDOTDOT;
293 cnp.cn_nameptr = "..";
295 cnp.cn_cred = ap->a_cred;
296 cnp.cn_td = curthread; /* XXX */
299 * vop_lookup() always returns vp locked. dvp may or may not be
300 * left locked depending on CNP_PDIRUNLOCK.
302 error = vop_lookup(ap->a_head.a_ops, ap->a_dvp, ap->a_vpp, &cnp);
304 VOP_UNLOCK(*ap->a_vpp, 0, curthread);
305 if (cnp.cn_flags & CNP_PDIRUNLOCK)
313 * vop_compat_ncreate { struct namecache *a_ncp, XXX STOPGAP FUNCTION
314 * struct vnode *a_vpp,
315 * struct ucred *a_cred,
316 * struct vattr *a_vap }
318 * Create a file as specified by a_vap. Compatibility requires us to issue
319 * the appropriate VOP_OLD_LOOKUP before we issue VOP_OLD_CREATE in order
320 * to setup the directory inode's i_offset and i_count (e.g. in UFS).
323 vop_compat_ncreate(struct vop_ncreate_args *ap)
325 struct thread *td = curthread;
326 struct componentname cnp;
327 struct namecache *ncp;
332 * Sanity checks, get a locked directory vnode.
334 ncp = ap->a_ncp; /* locked namecache node */
335 if (ncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
337 if (ncp->nc_parent == NULL)
339 if ((dvp = ncp->nc_parent->nc_vp) == NULL)
342 if ((error = vget(dvp, LK_EXCLUSIVE, td)) != 0) {
343 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
349 * Setup the cnp for a traditional vop_lookup() call. The lookup
350 * caches all information required to create the entry in the
351 * directory inode. We expect a return code of EJUSTRETURN for
352 * the CREATE case. The cnp must simulated a saved-name situation.
354 bzero(&cnp, sizeof(cnp));
355 cnp.cn_nameiop = NAMEI_CREATE;
356 cnp.cn_flags = CNP_LOCKPARENT;
357 cnp.cn_nameptr = ncp->nc_name;
358 cnp.cn_namelen = ncp->nc_nlen;
359 cnp.cn_cred = ap->a_cred;
363 error = vop_lookup(ap->a_head.a_ops, dvp, ap->a_vpp, &cnp);
366 * EJUSTRETURN should be returned for this case, which means that
367 * the VFS has setup the directory inode for the create. The dvp we
368 * passed in is expected to remain in a locked state.
370 * If the VOP_OLD_CREATE is successful we are responsible for updating
371 * the cache state of the locked ncp that was passed to us.
373 if (error == EJUSTRETURN) {
374 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
375 VOP_LEASE(dvp, td, ap->a_cred, LEASE_WRITE);
376 error = VOP_OLD_CREATE(dvp, ap->a_vpp, &cnp, ap->a_vap);
378 cache_setunresolved(ncp);
379 cache_setvp(ncp, *ap->a_vpp);
387 KKASSERT(*ap->a_vpp == NULL);
389 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
390 VOP_UNLOCK(dvp, 0, td);
396 * vop_compat_nmkdir { struct namecache *a_ncp, XXX STOPGAP FUNCTION
397 * struct vnode *a_vpp,
398 * struct ucred *a_cred,
399 * struct vattr *a_vap }
401 * Create a directory as specified by a_vap. Compatibility requires us to
402 * issue the appropriate VOP_OLD_LOOKUP before we issue VOP_OLD_MKDIR in
403 * order to setup the directory inode's i_offset and i_count (e.g. in UFS).
406 vop_compat_nmkdir(struct vop_nmkdir_args *ap)
408 struct thread *td = curthread;
409 struct componentname cnp;
410 struct namecache *ncp;
415 * Sanity checks, get a locked directory vnode.
417 ncp = ap->a_ncp; /* locked namecache node */
418 if (ncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
420 if (ncp->nc_parent == NULL)
422 if ((dvp = ncp->nc_parent->nc_vp) == NULL)
425 if ((error = vget(dvp, LK_EXCLUSIVE, td)) != 0) {
426 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
432 * Setup the cnp for a traditional vop_lookup() call. The lookup
433 * caches all information required to create the entry in the
434 * directory inode. We expect a return code of EJUSTRETURN for
435 * the CREATE case. The cnp must simulated a saved-name situation.
437 bzero(&cnp, sizeof(cnp));
438 cnp.cn_nameiop = NAMEI_CREATE;
439 cnp.cn_flags = CNP_LOCKPARENT;
440 cnp.cn_nameptr = ncp->nc_name;
441 cnp.cn_namelen = ncp->nc_nlen;
442 cnp.cn_cred = ap->a_cred;
446 error = vop_lookup(ap->a_head.a_ops, dvp, ap->a_vpp, &cnp);
449 * EJUSTRETURN should be returned for this case, which means that
450 * the VFS has setup the directory inode for the create. The dvp we
451 * passed in is expected to remain in a locked state.
453 * If the VOP_OLD_MKDIR is successful we are responsible for updating
454 * the cache state of the locked ncp that was passed to us.
456 if (error == EJUSTRETURN) {
457 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
458 VOP_LEASE(dvp, td, ap->a_cred, LEASE_WRITE);
459 error = VOP_OLD_MKDIR(dvp, ap->a_vpp, &cnp, ap->a_vap);
461 cache_setunresolved(ncp);
462 cache_setvp(ncp, *ap->a_vpp);
470 KKASSERT(*ap->a_vpp == NULL);
472 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
473 VOP_UNLOCK(dvp, 0, td);
479 * vop_compat_nmknod { struct namecache *a_ncp, XXX STOPGAP FUNCTION
480 * struct vnode *a_vpp,
481 * struct ucred *a_cred,
482 * struct vattr *a_vap }
484 * Create a device or fifo node as specified by a_vap. Compatibility requires
485 * us to issue the appropriate VOP_OLD_LOOKUP before we issue VOP_OLD_MKNOD
486 * in order to setup the directory inode's i_offset and i_count (e.g. in UFS).
489 vop_compat_nmknod(struct vop_nmknod_args *ap)
491 struct thread *td = curthread;
492 struct componentname cnp;
493 struct namecache *ncp;
498 * Sanity checks, get a locked directory vnode.
500 ncp = ap->a_ncp; /* locked namecache node */
501 if (ncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
503 if (ncp->nc_parent == NULL)
505 if ((dvp = ncp->nc_parent->nc_vp) == NULL)
508 if ((error = vget(dvp, LK_EXCLUSIVE, td)) != 0) {
509 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
515 * Setup the cnp for a traditional vop_lookup() call. The lookup
516 * caches all information required to create the entry in the
517 * directory inode. We expect a return code of EJUSTRETURN for
518 * the CREATE case. The cnp must simulated a saved-name situation.
520 bzero(&cnp, sizeof(cnp));
521 cnp.cn_nameiop = NAMEI_CREATE;
522 cnp.cn_flags = CNP_LOCKPARENT;
523 cnp.cn_nameptr = ncp->nc_name;
524 cnp.cn_namelen = ncp->nc_nlen;
525 cnp.cn_cred = ap->a_cred;
529 error = vop_lookup(ap->a_head.a_ops, dvp, ap->a_vpp, &cnp);
532 * EJUSTRETURN should be returned for this case, which means that
533 * the VFS has setup the directory inode for the create. The dvp we
534 * passed in is expected to remain in a locked state.
536 * If the VOP_OLD_MKNOD is successful we are responsible for updating
537 * the cache state of the locked ncp that was passed to us.
539 if (error == EJUSTRETURN) {
540 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
541 VOP_LEASE(dvp, td, ap->a_cred, LEASE_WRITE);
542 error = VOP_OLD_MKNOD(dvp, ap->a_vpp, &cnp, ap->a_vap);
544 cache_setunresolved(ncp);
545 cache_setvp(ncp, *ap->a_vpp);
553 KKASSERT(*ap->a_vpp == NULL);
555 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
556 VOP_UNLOCK(dvp, 0, td);
562 * vop_compat_nlink { struct namecache *a_ncp, XXX STOPGAP FUNCTION
563 * struct vnode *a_vp,
564 * struct ucred *a_cred }
566 * The passed vp is locked and represents the source. The passed ncp is
567 * locked and represents the target to create.
570 vop_compat_nlink(struct vop_nlink_args *ap)
572 struct thread *td = curthread;
573 struct componentname cnp;
574 struct namecache *ncp;
580 * Sanity checks, get a locked directory vnode.
582 ncp = ap->a_ncp; /* locked namecache node */
583 if (ncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
585 if (ncp->nc_parent == NULL)
587 if ((dvp = ncp->nc_parent->nc_vp) == NULL)
590 if ((error = vget(dvp, LK_EXCLUSIVE, td)) != 0) {
591 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
597 * Setup the cnp for a traditional vop_lookup() call. The lookup
598 * caches all information required to create the entry in the
599 * directory inode. We expect a return code of EJUSTRETURN for
600 * the CREATE case. The cnp must simulated a saved-name situation.
602 bzero(&cnp, sizeof(cnp));
603 cnp.cn_nameiop = NAMEI_CREATE;
604 cnp.cn_flags = CNP_LOCKPARENT;
605 cnp.cn_nameptr = ncp->nc_name;
606 cnp.cn_namelen = ncp->nc_nlen;
607 cnp.cn_cred = ap->a_cred;
611 error = vop_lookup(ap->a_head.a_ops, dvp, &tvp, &cnp);
614 * EJUSTRETURN should be returned for this case, which means that
615 * the VFS has setup the directory inode for the create. The dvp we
616 * passed in is expected to remain in a locked state.
618 * If the VOP_OLD_LINK is successful we are responsible for updating
619 * the cache state of the locked ncp that was passed to us.
621 if (error == EJUSTRETURN) {
622 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
623 VOP_LEASE(dvp, td, ap->a_cred, LEASE_WRITE);
624 VOP_LEASE(ap->a_vp, td, ap->a_cred, LEASE_WRITE);
625 error = VOP_OLD_LINK(dvp, ap->a_vp, &cnp);
627 cache_setunresolved(ncp);
628 cache_setvp(ncp, ap->a_vp);
636 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
637 VOP_UNLOCK(dvp, 0, td);
643 vop_compat_nsymlink(struct vop_nsymlink_args *ap)
645 struct thread *td = curthread;
646 struct componentname cnp;
647 struct namecache *ncp;
653 * Sanity checks, get a locked directory vnode.
656 ncp = ap->a_ncp; /* locked namecache node */
657 if (ncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
659 if (ncp->nc_parent == NULL)
661 if ((dvp = ncp->nc_parent->nc_vp) == NULL)
664 if ((error = vget(dvp, LK_EXCLUSIVE, td)) != 0) {
665 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
671 * Setup the cnp for a traditional vop_lookup() call. The lookup
672 * caches all information required to create the entry in the
673 * directory inode. We expect a return code of EJUSTRETURN for
674 * the CREATE case. The cnp must simulated a saved-name situation.
676 bzero(&cnp, sizeof(cnp));
677 cnp.cn_nameiop = NAMEI_CREATE;
678 cnp.cn_flags = CNP_LOCKPARENT;
679 cnp.cn_nameptr = ncp->nc_name;
680 cnp.cn_namelen = ncp->nc_nlen;
681 cnp.cn_cred = ap->a_cred;
685 error = vop_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
688 * EJUSTRETURN should be returned for this case, which means that
689 * the VFS has setup the directory inode for the create. The dvp we
690 * passed in is expected to remain in a locked state.
692 * If the VOP_OLD_SYMLINK is successful we are responsible for updating
693 * the cache state of the locked ncp that was passed to us.
695 if (error == EJUSTRETURN) {
696 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
697 VOP_LEASE(dvp, td, ap->a_cred, LEASE_WRITE);
698 error = VOP_OLD_SYMLINK(dvp, &vp, &cnp, ap->a_vap, ap->a_target);
700 cache_setunresolved(ncp);
701 cache_setvp(ncp, vp);
710 KKASSERT(vp == NULL);
712 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
713 VOP_UNLOCK(dvp, 0, td);
719 * vop_compat_nwhiteout { struct namecache *a_ncp, XXX STOPGAP FUNCTION
720 * struct ucred *a_cred,
723 * Issie a whiteout operation (create, lookup, or delete). Compatibility
724 * requires us to issue the appropriate VOP_OLD_LOOKUP before we issue
725 * VOP_OLD_WHITEOUT in order to setup the directory inode's i_offset and i_count
726 * (e.g. in UFS) for the NAMEI_CREATE and NAMEI_DELETE ops. For NAMEI_LOOKUP
727 * no lookup is necessary.
730 vop_compat_nwhiteout(struct vop_nwhiteout_args *ap)
732 struct thread *td = curthread;
733 struct componentname cnp;
734 struct namecache *ncp;
740 * Sanity checks, get a locked directory vnode.
742 ncp = ap->a_ncp; /* locked namecache node */
743 if (ncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
745 if (ncp->nc_parent == NULL)
747 if ((dvp = ncp->nc_parent->nc_vp) == NULL)
750 if ((error = vget(dvp, LK_EXCLUSIVE, td)) != 0) {
751 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
757 * Setup the cnp for a traditional vop_lookup() call. The lookup
758 * caches all information required to create the entry in the
759 * directory inode. We expect a return code of EJUSTRETURN for
760 * the CREATE case. The cnp must simulated a saved-name situation.
762 bzero(&cnp, sizeof(cnp));
763 cnp.cn_nameiop = ap->a_flags;
764 cnp.cn_flags = CNP_LOCKPARENT;
765 cnp.cn_nameptr = ncp->nc_name;
766 cnp.cn_namelen = ncp->nc_nlen;
767 cnp.cn_cred = ap->a_cred;
773 * EJUSTRETURN should be returned for the CREATE or DELETE cases.
774 * The VFS has setup the directory inode for the create. The dvp we
775 * passed in is expected to remain in a locked state.
777 * If the VOP_OLD_WHITEOUT is successful we are responsible for updating
778 * the cache state of the locked ncp that was passed to us.
780 switch(ap->a_flags) {
782 cnp.cn_flags |= CNP_DOWHITEOUT;
785 error = vop_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
786 if (error == EJUSTRETURN) {
787 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
788 VOP_LEASE(dvp, td, ap->a_cred, LEASE_WRITE);
789 error = VOP_OLD_WHITEOUT(dvp, &cnp, ap->a_flags);
791 cache_setunresolved(ncp);
798 KKASSERT(vp == NULL);
802 error = VOP_OLD_WHITEOUT(dvp, NULL, ap->a_flags);
808 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
809 VOP_UNLOCK(dvp, 0, td);
816 * vop_compat_nremove { struct namecache *a_ncp, XXX STOPGAP FUNCTION
817 * struct ucred *a_cred }
820 vop_compat_nremove(struct vop_nremove_args *ap)
822 struct thread *td = curthread;
823 struct componentname cnp;
824 struct namecache *ncp;
830 * Sanity checks, get a locked directory vnode.
832 ncp = ap->a_ncp; /* locked namecache node */
833 if (ncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
835 if (ncp->nc_parent == NULL)
837 if ((dvp = ncp->nc_parent->nc_vp) == NULL)
840 if ((error = vget(dvp, LK_EXCLUSIVE, td)) != 0) {
841 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
847 * Setup the cnp for a traditional vop_lookup() call. The lookup
848 * caches all information required to delete the entry in the
849 * directory inode. We expect a return code of 0 for the DELETE
850 * case (meaning that a vp has been found). The cnp must simulated
851 * a saved-name situation.
853 bzero(&cnp, sizeof(cnp));
854 cnp.cn_nameiop = NAMEI_DELETE;
855 cnp.cn_flags = CNP_LOCKPARENT;
856 cnp.cn_nameptr = ncp->nc_name;
857 cnp.cn_namelen = ncp->nc_nlen;
858 cnp.cn_cred = ap->a_cred;
862 * The vnode must be a directory and must not represent the
866 error = vop_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
867 if (error == 0 && vp->v_type == VDIR)
870 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
871 VOP_LEASE(dvp, td, ap->a_cred, LEASE_WRITE);
872 VOP_LEASE(vp, td, ap->a_cred, LEASE_WRITE);
873 error = VOP_OLD_REMOVE(dvp, vp, &cnp);
875 cache_setunresolved(ncp);
876 cache_setvp(ncp, NULL);
885 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
886 VOP_UNLOCK(dvp, 0, td);
892 * vop_compat_nrmdir { struct namecache *a_ncp, XXX STOPGAP FUNCTION
893 * struct ucred *a_cred }
896 vop_compat_nrmdir(struct vop_nrmdir_args *ap)
898 struct thread *td = curthread;
899 struct componentname cnp;
900 struct namecache *ncp;
906 * Sanity checks, get a locked directory vnode.
908 ncp = ap->a_ncp; /* locked namecache node */
909 if (ncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
911 if (ncp->nc_parent == NULL)
913 if ((dvp = ncp->nc_parent->nc_vp) == NULL)
916 if ((error = vget(dvp, LK_EXCLUSIVE, td)) != 0) {
917 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
923 * Setup the cnp for a traditional vop_lookup() call. The lookup
924 * caches all information required to delete the entry in the
925 * directory inode. We expect a return code of 0 for the DELETE
926 * case (meaning that a vp has been found). The cnp must simulated
927 * a saved-name situation.
929 bzero(&cnp, sizeof(cnp));
930 cnp.cn_nameiop = NAMEI_DELETE;
931 cnp.cn_flags = CNP_LOCKPARENT;
932 cnp.cn_nameptr = ncp->nc_name;
933 cnp.cn_namelen = ncp->nc_nlen;
934 cnp.cn_cred = ap->a_cred;
938 * The vnode must be a directory and must not represent the
942 error = vop_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
943 if (error == 0 && vp->v_type != VDIR)
945 if (error == 0 && vp == dvp)
947 if (error == 0 && (vp->v_flag & VROOT))
950 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
951 VOP_LEASE(dvp, td, ap->a_cred, LEASE_WRITE);
952 VOP_LEASE(vp, td, ap->a_cred, LEASE_WRITE);
953 error = VOP_OLD_RMDIR(dvp, vp, &cnp);
956 * Note that this invalidation will cause any process
957 * currently CD'd into the directory being removed to be
958 * disconnected from the topology and not be able to ".."
962 cache_inval(ncp, CINV_DESTROY);
970 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
971 VOP_UNLOCK(dvp, 0, td);
977 * vop_compat_nrename { struct namecache *a_fncp, XXX STOPGAP FUNCTION
978 * struct namecache *a_tncp,
979 * struct ucred *a_cred }
981 * This is a fairly difficult procedure. The old VOP_OLD_RENAME requires that
982 * the source directory and vnode be unlocked and the target directory and
983 * vnode (if it exists) be locked. All arguments will be vrele'd and
984 * the targets will also be unlocked regardless of the return code.
987 vop_compat_nrename(struct vop_nrename_args *ap)
989 struct thread *td = curthread;
990 struct componentname fcnp;
991 struct componentname tcnp;
992 struct namecache *fncp;
993 struct namecache *tncp;
994 struct vnode *fdvp, *fvp;
995 struct vnode *tdvp, *tvp;
999 * Sanity checks, get referenced vnodes representing the source.
1001 fncp = ap->a_fncp; /* locked namecache node */
1002 if (fncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
1004 if (fncp->nc_parent == NULL)
1006 if ((fdvp = fncp->nc_parent->nc_vp) == NULL)
1010 * Temporarily lock the source directory and lookup in DELETE mode to
1011 * check permissions. XXX delete permissions should have been
1012 * checked by nlookup(), we need to add NLC_DELETE for delete
1013 * checking. It is unclear whether VFS's require the directory setup
1014 * info NAMEI_DELETE causes to be stored in the fdvp's inode, but
1015 * since it isn't locked and since UFS always does a relookup of
1016 * the source, it is believed that the only side effect that matters
1017 * is the permissions check.
1019 if ((error = vget(fdvp, LK_EXCLUSIVE, td)) != 0) {
1020 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
1021 fncp, fncp->nc_name);
1025 bzero(&fcnp, sizeof(fcnp));
1026 fcnp.cn_nameiop = NAMEI_DELETE;
1027 fcnp.cn_flags = CNP_LOCKPARENT;
1028 fcnp.cn_nameptr = fncp->nc_name;
1029 fcnp.cn_namelen = fncp->nc_nlen;
1030 fcnp.cn_cred = ap->a_cred;
1034 * note: vop_lookup (i.e. VOP_OLD_LOOKUP) always returns a locked
1038 error = vop_lookup(ap->a_head.a_ops, fdvp, &fvp, &fcnp);
1039 if (error == 0 && (fvp->v_flag & VROOT)) {
1040 vput(fvp); /* as if vop_lookup had failed */
1043 if ((fcnp.cn_flags & CNP_PDIRUNLOCK) == 0) {
1044 fcnp.cn_flags |= CNP_PDIRUNLOCK;
1045 VOP_UNLOCK(fdvp, 0, td);
1051 VOP_UNLOCK(fvp, 0, td);
1054 * fdvp and fvp are now referenced and unlocked.
1056 * Get a locked directory vnode for the target and lookup the target
1057 * in CREATE mode so it places the required information in the
1060 tncp = ap->a_tncp; /* locked namecache node */
1061 if (tncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
1063 if (tncp->nc_parent == NULL)
1065 if ((tdvp = tncp->nc_parent->nc_vp) == NULL)
1072 if ((error = vget(tdvp, LK_EXCLUSIVE, td)) != 0) {
1073 printf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
1074 tncp, tncp->nc_name);
1081 * Setup the cnp for a traditional vop_lookup() call. The lookup
1082 * caches all information required to create the entry in the
1083 * target directory inode.
1085 bzero(&tcnp, sizeof(tcnp));
1086 tcnp.cn_nameiop = NAMEI_RENAME;
1087 tcnp.cn_flags = CNP_LOCKPARENT;
1088 tcnp.cn_nameptr = tncp->nc_name;
1089 tcnp.cn_namelen = tncp->nc_nlen;
1090 tcnp.cn_cred = ap->a_cred;
1094 error = vop_lookup(ap->a_head.a_ops, tdvp, &tvp, &tcnp);
1096 if (error == EJUSTRETURN) {
1098 * Target does not exist. tvp should be NULL.
1100 KKASSERT(tvp == NULL);
1101 KKASSERT((tcnp.cn_flags & CNP_PDIRUNLOCK) == 0);
1102 error = VOP_OLD_RENAME(fdvp, fvp, &fcnp, tdvp, tvp, &tcnp);
1104 cache_rename(fncp, tncp);
1105 cache_setvp(tncp, fvp);
1107 } else if (error == 0) {
1109 * Target exists. VOP_OLD_RENAME should correctly delete the
1112 KKASSERT((tcnp.cn_flags & CNP_PDIRUNLOCK) == 0);
1113 error = VOP_OLD_RENAME(fdvp, fvp, &fcnp, tdvp, tvp, &tcnp);
1115 cache_rename(fncp, tncp);
1116 cache_setvp(tncp, fvp);
1121 if (tcnp.cn_flags & CNP_PDIRUNLOCK)
1131 struct vop_lookup_args /* {
1132 struct vnode *a_dvp;
1133 struct vnode **a_vpp;
1134 struct componentname *a_cnp;
1145 * Strategy routine for VFS devices that have none.
1147 * B_ERROR and B_INVAL must be cleared prior to calling any strategy
1148 * routine. Typically this is done for a B_READ strategy call. Typically
1149 * B_INVAL is assumed to already be clear prior to a write and should not
1150 * be cleared manually unless you just made the buffer invalid. B_ERROR
1151 * should be cleared either way.
1155 vop_nostrategy (struct vop_strategy_args *ap)
1157 printf("No strategy for buffer at %p\n", ap->a_bp);
1158 vprint("", ap->a_vp);
1159 vprint("", ap->a_bp->b_vp);
1160 ap->a_bp->b_flags |= B_ERROR;
1161 ap->a_bp->b_error = EOPNOTSUPP;
1163 return (EOPNOTSUPP);
1168 struct vop_pathconf_args /* {
1175 switch (ap->a_name) {
1177 *ap->a_retval = LINK_MAX;
1180 *ap->a_retval = MAX_CANON;
1183 *ap->a_retval = MAX_INPUT;
1186 *ap->a_retval = PIPE_BUF;
1188 case _PC_CHOWN_RESTRICTED:
1192 *ap->a_retval = _POSIX_VDISABLE;
1201 * Standard lock. The lock is recursive-capable only if the lock was
1202 * initialized with LK_CANRECURSE or that flag is passed in a_flags.
1206 struct vop_lock_args /* {
1215 error = lockmgr(&ap->a_vp->v_lock, ap->a_flags, NULL, ap->a_td);
1217 error = debuglockmgr(&ap->a_vp->v_lock, ap->a_flags,
1219 "vop_stdlock", ap->a_vp->filename, ap->a_vp->line);
1226 struct vop_unlock_args /* {
1229 struct thread *a_td;
1234 error = lockmgr(&ap->a_vp->v_lock, ap->a_flags | LK_RELEASE,
1241 struct vop_islocked_args /* {
1243 struct thread *a_td;
1246 return (lockstatus(&ap->a_vp->v_lock, ap->a_td));
1250 * Return true for select/poll.
1254 struct vop_poll_args /* {
1257 struct ucred *a_cred;
1262 * Return true for read/write. If the user asked for something
1263 * special, return POLLNVAL, so that clients have a way of
1264 * determining reliably whether or not the extended
1265 * functionality is present without hard-coding knowledge
1266 * of specific filesystem implementations.
1268 if (ap->a_events & ~POLLSTANDARD)
1271 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
1275 * Implement poll for local filesystems that support it.
1279 struct vop_poll_args /* {
1282 struct ucred *a_cred;
1283 struct thread *a_td;
1286 if (ap->a_events & ~POLLSTANDARD)
1287 return (vn_pollrecord(ap->a_vp, ap->a_td, ap->a_events));
1288 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
1293 struct vop_bwrite_args *ap;
1295 return (bwrite(ap->a_bp));
1299 vop_stdcreatevobject(ap)
1300 struct vop_createvobject_args /* {
1305 struct vnode *vp = ap->a_vp;
1306 struct thread *td = ap->a_td;
1311 if (!vn_isdisk(vp, NULL) && vn_canvmio(vp) == FALSE)
1315 if ((object = vp->v_object) == NULL) {
1316 if (vp->v_type == VREG || vp->v_type == VDIR) {
1317 if ((error = VOP_GETATTR(vp, &vat, td)) != 0)
1319 object = vnode_pager_alloc(vp, vat.va_size, 0, 0);
1320 } else if (vp->v_rdev && dev_is_good(vp->v_rdev)) {
1322 * XXX v_rdev uses NULL/non-NULL instead of NODEV
1324 * This simply allocates the biggest object possible
1325 * for a disk vnode. This should be fixed, but doesn't
1326 * cause any problems (yet).
1328 object = vnode_pager_alloc(vp, IDX_TO_OFF(INT_MAX), 0, 0);
1333 * Dereference the reference we just created. This assumes
1334 * that the object is associated with the vp.
1336 object->ref_count--;
1339 if (object->flags & OBJ_DEAD) {
1340 VOP_UNLOCK(vp, 0, td);
1341 tsleep(object, 0, "vodead", 0);
1342 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
1347 KASSERT(vp->v_object != NULL, ("vfs_object_create: NULL object"));
1348 vp->v_flag |= VOBJBUF;
1355 vop_stddestroyvobject(ap)
1356 struct vop_destroyvobject_args /* {
1360 struct vnode *vp = ap->a_vp;
1361 vm_object_t obj = vp->v_object;
1363 if (vp->v_object == NULL)
1366 if (obj->ref_count == 0) {
1368 * vclean() may be called twice. The first time
1369 * removes the primary reference to the object,
1370 * the second time goes one further and is a
1371 * special-case to terminate the object.
1373 * don't double-terminate the object.
1375 if ((obj->flags & OBJ_DEAD) == 0)
1376 vm_object_terminate(obj);
1379 * Woe to the process that tries to page now :-).
1381 vm_pager_deallocate(obj);
1387 * Return the underlying VM object. This routine may be called with or
1388 * without the vnode interlock held. If called without, the returned
1389 * object is not guarenteed to be valid. The syncer typically gets the
1390 * object without holding the interlock in order to quickly test whether
1391 * it might be dirty before going heavy-weight. vm_object's use zalloc
1392 * and thus stable-storage, so this is safe.
1395 vop_stdgetvobject(ap)
1396 struct vop_getvobject_args /* {
1398 struct vm_object **objpp;
1401 struct vnode *vp = ap->a_vp;
1402 struct vm_object **objpp = ap->a_objpp;
1405 *objpp = vp->v_object;
1406 return (vp->v_object ? 0 : EINVAL);
1411 * used to fill the vfs fucntion table to get reasonable default return values.
1414 vfs_stdmount(struct mount *mp, char *path, caddr_t data,
1415 struct nlookupdata *nd, struct thread *td)
1421 vfs_stdunmount(struct mount *mp, int mntflags, struct thread *td)
1427 vfs_stdroot(struct mount *mp, struct vnode **vpp)
1429 return (EOPNOTSUPP);
1433 vfs_stdstatfs(struct mount *mp, struct statfs *sbp, struct thread *td)
1435 return (EOPNOTSUPP);
1439 vfs_stdvptofh(struct vnode *vp, struct fid *fhp)
1441 return (EOPNOTSUPP);
1445 vfs_stdstart(struct mount *mp, int flags, struct thread *td)
1451 vfs_stdquotactl(struct mount *mp, int cmds, uid_t uid,
1452 caddr_t arg, struct thread *td)
1454 return (EOPNOTSUPP);
1458 vfs_stdsync(struct mount *mp, int waitfor, struct thread *td)
1464 vfs_stdvget(struct mount *mp, ino_t ino, struct vnode **vpp)
1466 return (EOPNOTSUPP);
1470 vfs_stdfhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
1472 return (EOPNOTSUPP);
1476 vfs_stdcheckexp(struct mount *mp, struct sockaddr *nam, int *extflagsp,
1477 struct ucred **credanonp)
1479 return (EOPNOTSUPP);
1483 vfs_stdinit(struct vfsconf *vfsp)
1489 vfs_stduninit(struct vfsconf *vfsp)
1495 vfs_stdextattrctl(struct mount *mp, int cmd, const char *attrname,
1496 caddr_t arg, struct thread *td)
1501 /* end of vfs default ops */