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 * The statvfs->statfs conversion code was contributed to the DragonFly
9 * Project by Joerg Sonnenberger <joerg@bec.de>.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * Source: * @(#)i405_init.c 2.10 92/04/27 UCLA Ficus project
40 * $FreeBSD: src/sys/kern/vfs_default.c,v 1.28.2.7 2003/01/10 18:23:26 bde Exp $
41 * $DragonFly: src/sys/kern/vfs_default.c,v 1.55 2008/09/28 04:31:50 dillon Exp $
44 #include <sys/param.h>
45 #include <sys/systm.h>
48 #include <sys/fcntl.h>
50 #include <sys/kernel.h>
52 #include <sys/malloc.h>
53 #include <sys/mount.h>
54 #include <sys/unistd.h>
55 #include <sys/vnode.h>
56 #include <sys/namei.h>
57 #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 .vop_default = vop_eopnotsupp,
79 .vop_advlock = (void *)vop_einval,
80 .vop_fsync = (void *)vop_null,
81 .vop_ioctl = (void *)vop_enotty,
82 .vop_mmap = (void *)vop_einval,
83 .vop_old_lookup = vop_nolookup,
84 .vop_open = vop_stdopen,
85 .vop_close = vop_stdclose,
86 .vop_pathconf = vop_stdpathconf,
87 .vop_readlink = (void *)vop_einval,
88 .vop_reallocblks = (void *)vop_eopnotsupp,
89 .vop_strategy = vop_nostrategy,
90 .vop_getacl = (void *)vop_eopnotsupp,
91 .vop_setacl = (void *)vop_eopnotsupp,
92 .vop_aclcheck = (void *)vop_eopnotsupp,
93 .vop_getextattr = (void *)vop_eopnotsupp,
94 .vop_setextattr = (void *)vop_eopnotsupp,
95 .vop_markatime = vop_stdmarkatime,
96 .vop_nresolve = vop_compat_nresolve,
97 .vop_nlookupdotdot = vop_compat_nlookupdotdot,
98 .vop_ncreate = vop_compat_ncreate,
99 .vop_nmkdir = vop_compat_nmkdir,
100 .vop_nmknod = vop_compat_nmknod,
101 .vop_nlink = vop_compat_nlink,
102 .vop_nsymlink = vop_compat_nsymlink,
103 .vop_nwhiteout = vop_compat_nwhiteout,
104 .vop_nremove = vop_compat_nremove,
105 .vop_nrmdir = vop_compat_nrmdir,
106 .vop_nrename = vop_compat_nrename,
107 .vop_mountctl = vop_stdmountctl
110 VNODEOP_SET(default_vnode_vops);
113 vop_eopnotsupp(struct vop_generic_args *ap)
119 vop_ebadf(struct vop_generic_args *ap)
125 vop_enotty(struct vop_generic_args *ap)
131 vop_einval(struct vop_generic_args *ap)
137 vop_stdmarkatime(struct vop_markatime_args *ap)
143 vop_null(struct vop_generic_args *ap)
149 vop_defaultop(struct vop_generic_args *ap)
151 return (VOCALL(&default_vnode_vops, ap));
155 vop_panic(struct vop_generic_args *ap)
157 panic("filesystem goof: vop_panic[%s]", ap->a_desc->sd_name);
161 * vop_compat_resolve { struct nchandle *a_nch, struct vnode *dvp }
162 * XXX STOPGAP FUNCTION
164 * XXX OLD API ROUTINE! WHEN ALL VFSs HAVE BEEN CLEANED UP THIS PROCEDURE
165 * WILL BE REMOVED. This procedure exists for all VFSs which have not
166 * yet implemented VOP_NRESOLVE(). It converts VOP_NRESOLVE() into a
167 * vop_old_lookup() and does appropriate translations.
169 * Resolve a ncp for VFSs which do not support the VOP. Eventually all
170 * VFSs will support this VOP and this routine can be removed, since
171 * VOP_NRESOLVE() is far less complex then the older LOOKUP/CACHEDLOOKUP
174 * A locked ncp is passed in to be resolved. The NCP is resolved by
175 * figuring out the vnode (if any) and calling cache_setvp() to attach the
176 * vnode to the entry. If the entry represents a non-existant node then
177 * cache_setvp() is called with a NULL vnode to resolve the entry into a
178 * negative cache entry. No vnode locks are retained and the
179 * ncp is left locked on return.
181 * The ncp will NEVER represent "", "." or "..", or contain any slashes.
183 * There is a potential directory and vnode interlock. The lock order
184 * requirement is: namecache, governing directory, resolved vnode.
187 vop_compat_nresolve(struct vop_nresolve_args *ap)
192 struct nchandle *nch;
193 struct namecache *ncp;
194 struct componentname cnp;
196 nch = ap->a_nch; /* locked namecache node */
201 * UFS currently stores all sorts of side effects, including a loop
202 * variable, in the directory inode. That needs to be fixed and the
203 * other VFS's audited before we can switch to LK_SHARED.
205 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
206 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
211 bzero(&cnp, sizeof(cnp));
212 cnp.cn_nameiop = NAMEI_LOOKUP;
214 cnp.cn_nameptr = ncp->nc_name;
215 cnp.cn_namelen = ncp->nc_nlen;
216 cnp.cn_cred = ap->a_cred;
217 cnp.cn_td = curthread; /* XXX */
220 * vop_old_lookup() always returns vp locked. dvp may or may not be
221 * left locked depending on CNP_PDIRUNLOCK.
223 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
226 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
228 if ((ncp->nc_flag & NCF_UNRESOLVED) == 0) {
229 /* was resolved by another process while we were unlocked */
232 } else if (error == 0) {
233 KKASSERT(vp != NULL);
234 cache_setvp(nch, vp);
236 } else if (error == ENOENT) {
237 KKASSERT(vp == NULL);
238 if (cnp.cn_flags & CNP_ISWHITEOUT)
239 ncp->nc_flag |= NCF_WHITEOUT;
240 cache_setvp(nch, NULL);
247 * vop_compat_nlookupdotdot { struct vnode *a_dvp,
248 * struct vnode **a_vpp,
249 * struct ucred *a_cred }
251 * Lookup the vnode representing the parent directory of the specified
252 * directory vnode. a_dvp should not be locked. If no error occurs *a_vpp
253 * will contained the parent vnode, locked and refd, else *a_vpp will be NULL.
255 * This function is designed to aid NFS server-side operations and is
256 * used by cache_fromdvp() to create a consistent, connected namecache
259 * As part of the NEW API work, VFSs will first split their CNP_ISDOTDOT
260 * code out from their *_lookup() and create *_nlookupdotdot(). Then as time
261 * permits VFSs will implement the remaining *_n*() calls and finally get
262 * rid of their *_lookup() call.
265 vop_compat_nlookupdotdot(struct vop_nlookupdotdot_args *ap)
267 struct componentname cnp;
271 * UFS currently stores all sorts of side effects, including a loop
272 * variable, in the directory inode. That needs to be fixed and the
273 * other VFS's audited before we can switch to LK_SHARED.
276 if ((error = vget(ap->a_dvp, LK_EXCLUSIVE)) != 0)
278 if (ap->a_dvp->v_type != VDIR) {
283 bzero(&cnp, sizeof(cnp));
284 cnp.cn_nameiop = NAMEI_LOOKUP;
285 cnp.cn_flags = CNP_ISDOTDOT;
286 cnp.cn_nameptr = "..";
288 cnp.cn_cred = ap->a_cred;
289 cnp.cn_td = curthread; /* XXX */
292 * vop_old_lookup() always returns vp locked. dvp may or may not be
293 * left locked depending on CNP_PDIRUNLOCK.
295 error = vop_old_lookup(ap->a_head.a_ops, ap->a_dvp, ap->a_vpp, &cnp);
297 vn_unlock(*ap->a_vpp);
298 if (cnp.cn_flags & CNP_PDIRUNLOCK)
306 * vop_compat_ncreate { struct nchandle *a_nch, XXX STOPGAP FUNCTION
307 * struct vnode *a_dvp,
308 * struct vnode **a_vpp,
309 * struct ucred *a_cred,
310 * struct vattr *a_vap }
312 * Create a file as specified by a_vap. Compatibility requires us to issue
313 * the appropriate VOP_OLD_LOOKUP before we issue VOP_OLD_CREATE in order
314 * to setup the directory inode's i_offset and i_count (e.g. in UFS).
317 vop_compat_ncreate(struct vop_ncreate_args *ap)
319 struct thread *td = curthread;
320 struct componentname cnp;
321 struct nchandle *nch;
322 struct namecache *ncp;
327 * Sanity checks, get a locked directory vnode.
329 nch = ap->a_nch; /* locked namecache node */
333 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
334 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
340 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
341 * caches all information required to create the entry in the
342 * directory inode. We expect a return code of EJUSTRETURN for
343 * the CREATE case. The cnp must simulated a saved-name situation.
345 bzero(&cnp, sizeof(cnp));
346 cnp.cn_nameiop = NAMEI_CREATE;
347 cnp.cn_flags = CNP_LOCKPARENT;
348 cnp.cn_nameptr = ncp->nc_name;
349 cnp.cn_namelen = ncp->nc_nlen;
350 cnp.cn_cred = ap->a_cred;
354 error = vop_old_lookup(ap->a_head.a_ops, dvp, ap->a_vpp, &cnp);
357 * EJUSTRETURN should be returned for this case, which means that
358 * the VFS has setup the directory inode for the create. The dvp we
359 * passed in is expected to remain in a locked state.
361 * If the VOP_OLD_CREATE is successful we are responsible for updating
362 * the cache state of the locked ncp that was passed to us.
364 if (error == EJUSTRETURN) {
365 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
366 error = VOP_OLD_CREATE(dvp, ap->a_vpp, &cnp, ap->a_vap);
368 cache_setunresolved(nch);
369 cache_setvp(nch, *ap->a_vpp);
377 KKASSERT(*ap->a_vpp == NULL);
379 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
386 * vop_compat_nmkdir { struct nchandle *a_nch, XXX STOPGAP FUNCTION
387 * struct vnode *a_dvp,
388 * struct vnode **a_vpp,
389 * struct ucred *a_cred,
390 * struct vattr *a_vap }
392 * Create a directory as specified by a_vap. Compatibility requires us to
393 * issue the appropriate VOP_OLD_LOOKUP before we issue VOP_OLD_MKDIR in
394 * order to setup the directory inode's i_offset and i_count (e.g. in UFS).
397 vop_compat_nmkdir(struct vop_nmkdir_args *ap)
399 struct thread *td = curthread;
400 struct componentname cnp;
401 struct nchandle *nch;
402 struct namecache *ncp;
407 * Sanity checks, get a locked directory vnode.
409 nch = ap->a_nch; /* locked namecache node */
412 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
413 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
419 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
420 * caches all information required to create the entry in the
421 * directory inode. We expect a return code of EJUSTRETURN for
422 * the CREATE case. The cnp must simulated a saved-name situation.
424 bzero(&cnp, sizeof(cnp));
425 cnp.cn_nameiop = NAMEI_CREATE;
426 cnp.cn_flags = CNP_LOCKPARENT;
427 cnp.cn_nameptr = ncp->nc_name;
428 cnp.cn_namelen = ncp->nc_nlen;
429 cnp.cn_cred = ap->a_cred;
433 error = vop_old_lookup(ap->a_head.a_ops, dvp, ap->a_vpp, &cnp);
436 * EJUSTRETURN should be returned for this case, which means that
437 * the VFS has setup the directory inode for the create. The dvp we
438 * passed in is expected to remain in a locked state.
440 * If the VOP_OLD_MKDIR is successful we are responsible for updating
441 * the cache state of the locked ncp that was passed to us.
443 if (error == EJUSTRETURN) {
444 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
445 error = VOP_OLD_MKDIR(dvp, ap->a_vpp, &cnp, ap->a_vap);
447 cache_setunresolved(nch);
448 cache_setvp(nch, *ap->a_vpp);
456 KKASSERT(*ap->a_vpp == NULL);
458 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
465 * vop_compat_nmknod { struct nchandle *a_nch, XXX STOPGAP FUNCTION
466 * struct vnode *a_dvp,
467 * struct vnode **a_vpp,
468 * struct ucred *a_cred,
469 * struct vattr *a_vap }
471 * Create a device or fifo node as specified by a_vap. Compatibility requires
472 * us to issue the appropriate VOP_OLD_LOOKUP before we issue VOP_OLD_MKNOD
473 * in order to setup the directory inode's i_offset and i_count (e.g. in UFS).
476 vop_compat_nmknod(struct vop_nmknod_args *ap)
478 struct thread *td = curthread;
479 struct componentname cnp;
480 struct nchandle *nch;
481 struct namecache *ncp;
486 * Sanity checks, get a locked directory vnode.
488 nch = ap->a_nch; /* locked namecache node */
492 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
493 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
499 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
500 * caches all information required to create the entry in the
501 * directory inode. We expect a return code of EJUSTRETURN for
502 * the CREATE case. The cnp must simulated a saved-name situation.
504 bzero(&cnp, sizeof(cnp));
505 cnp.cn_nameiop = NAMEI_CREATE;
506 cnp.cn_flags = CNP_LOCKPARENT;
507 cnp.cn_nameptr = ncp->nc_name;
508 cnp.cn_namelen = ncp->nc_nlen;
509 cnp.cn_cred = ap->a_cred;
513 error = vop_old_lookup(ap->a_head.a_ops, dvp, ap->a_vpp, &cnp);
516 * EJUSTRETURN should be returned for this case, which means that
517 * the VFS has setup the directory inode for the create. The dvp we
518 * passed in is expected to remain in a locked state.
520 * If the VOP_OLD_MKNOD is successful we are responsible for updating
521 * the cache state of the locked ncp that was passed to us.
523 if (error == EJUSTRETURN) {
524 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
525 error = VOP_OLD_MKNOD(dvp, ap->a_vpp, &cnp, ap->a_vap);
527 cache_setunresolved(nch);
528 cache_setvp(nch, *ap->a_vpp);
536 KKASSERT(*ap->a_vpp == NULL);
538 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
545 * vop_compat_nlink { struct nchandle *a_nch, XXX STOPGAP FUNCTION
546 * struct vnode *a_dvp,
547 * struct vnode *a_vp,
548 * struct ucred *a_cred }
550 * The passed vp is locked and represents the source. The passed ncp is
551 * locked and represents the target to create.
554 vop_compat_nlink(struct vop_nlink_args *ap)
556 struct thread *td = curthread;
557 struct componentname cnp;
558 struct nchandle *nch;
559 struct namecache *ncp;
565 * Sanity checks, get a locked directory vnode.
567 nch = ap->a_nch; /* locked namecache node */
571 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
572 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
578 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
579 * caches all information required to create the entry in the
580 * directory inode. We expect a return code of EJUSTRETURN for
581 * the CREATE case. The cnp must simulated a saved-name situation.
583 bzero(&cnp, sizeof(cnp));
584 cnp.cn_nameiop = NAMEI_CREATE;
585 cnp.cn_flags = CNP_LOCKPARENT;
586 cnp.cn_nameptr = ncp->nc_name;
587 cnp.cn_namelen = ncp->nc_nlen;
588 cnp.cn_cred = ap->a_cred;
592 error = vop_old_lookup(ap->a_head.a_ops, dvp, &tvp, &cnp);
595 * EJUSTRETURN should be returned for this case, which means that
596 * the VFS has setup the directory inode for the create. The dvp we
597 * passed in is expected to remain in a locked state.
599 * If the VOP_OLD_LINK is successful we are responsible for updating
600 * the cache state of the locked ncp that was passed to us.
602 if (error == EJUSTRETURN) {
603 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
604 error = VOP_OLD_LINK(dvp, ap->a_vp, &cnp);
606 cache_setunresolved(nch);
607 cache_setvp(nch, ap->a_vp);
615 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
622 vop_compat_nsymlink(struct vop_nsymlink_args *ap)
624 struct thread *td = curthread;
625 struct componentname cnp;
626 struct nchandle *nch;
627 struct namecache *ncp;
633 * Sanity checks, get a locked directory vnode.
636 nch = ap->a_nch; /* locked namecache node */
640 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
641 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
647 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
648 * caches all information required to create the entry in the
649 * directory inode. We expect a return code of EJUSTRETURN for
650 * the CREATE case. The cnp must simulated a saved-name situation.
652 bzero(&cnp, sizeof(cnp));
653 cnp.cn_nameiop = NAMEI_CREATE;
654 cnp.cn_flags = CNP_LOCKPARENT;
655 cnp.cn_nameptr = ncp->nc_name;
656 cnp.cn_namelen = ncp->nc_nlen;
657 cnp.cn_cred = ap->a_cred;
661 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
664 * EJUSTRETURN should be returned for this case, which means that
665 * the VFS has setup the directory inode for the create. The dvp we
666 * passed in is expected to remain in a locked state.
668 * If the VOP_OLD_SYMLINK is successful we are responsible for updating
669 * the cache state of the locked ncp that was passed to us.
671 if (error == EJUSTRETURN) {
672 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
673 error = VOP_OLD_SYMLINK(dvp, &vp, &cnp, ap->a_vap, ap->a_target);
675 cache_setunresolved(nch);
676 cache_setvp(nch, vp);
685 KKASSERT(vp == NULL);
687 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
694 * vop_compat_nwhiteout { struct nchandle *a_nch, XXX STOPGAP FUNCTION
695 * struct vnode *a_dvp,
696 * struct ucred *a_cred,
699 * Issie a whiteout operation (create, lookup, or delete). Compatibility
700 * requires us to issue the appropriate VOP_OLD_LOOKUP before we issue
701 * VOP_OLD_WHITEOUT in order to setup the directory inode's i_offset and i_count
702 * (e.g. in UFS) for the NAMEI_CREATE and NAMEI_DELETE ops. For NAMEI_LOOKUP
703 * no lookup is necessary.
706 vop_compat_nwhiteout(struct vop_nwhiteout_args *ap)
708 struct thread *td = curthread;
709 struct componentname cnp;
710 struct nchandle *nch;
711 struct namecache *ncp;
717 * Sanity checks, get a locked directory vnode.
719 nch = ap->a_nch; /* locked namecache node */
723 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
724 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
730 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
731 * caches all information required to create the entry in the
732 * directory inode. We expect a return code of EJUSTRETURN for
733 * the CREATE case. The cnp must simulated a saved-name situation.
735 bzero(&cnp, sizeof(cnp));
736 cnp.cn_nameiop = ap->a_flags;
737 cnp.cn_flags = CNP_LOCKPARENT;
738 cnp.cn_nameptr = ncp->nc_name;
739 cnp.cn_namelen = ncp->nc_nlen;
740 cnp.cn_cred = ap->a_cred;
746 * EJUSTRETURN should be returned for the CREATE or DELETE cases.
747 * The VFS has setup the directory inode for the create. The dvp we
748 * passed in is expected to remain in a locked state.
750 * If the VOP_OLD_WHITEOUT is successful we are responsible for updating
751 * the cache state of the locked ncp that was passed to us.
753 switch(ap->a_flags) {
755 cnp.cn_flags |= CNP_DOWHITEOUT;
758 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
759 if (error == EJUSTRETURN) {
760 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
761 error = VOP_OLD_WHITEOUT(dvp, &cnp, ap->a_flags);
763 cache_setunresolved(nch);
770 KKASSERT(vp == NULL);
774 error = VOP_OLD_WHITEOUT(dvp, NULL, ap->a_flags);
780 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
788 * vop_compat_nremove { struct nchandle *a_nch, XXX STOPGAP FUNCTION
789 * struct vnode *a_dvp,
790 * struct ucred *a_cred }
793 vop_compat_nremove(struct vop_nremove_args *ap)
795 struct thread *td = curthread;
796 struct componentname cnp;
797 struct nchandle *nch;
798 struct namecache *ncp;
804 * Sanity checks, get a locked directory vnode.
806 nch = ap->a_nch; /* locked namecache node */
810 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
811 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
817 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
818 * caches all information required to delete the entry in the
819 * directory inode. We expect a return code of 0 for the DELETE
820 * case (meaning that a vp has been found). The cnp must simulated
821 * a saved-name situation.
823 bzero(&cnp, sizeof(cnp));
824 cnp.cn_nameiop = NAMEI_DELETE;
825 cnp.cn_flags = CNP_LOCKPARENT;
826 cnp.cn_nameptr = ncp->nc_name;
827 cnp.cn_namelen = ncp->nc_nlen;
828 cnp.cn_cred = ap->a_cred;
832 * The vnode must be a directory and must not represent the
836 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
837 if (error == 0 && vp->v_type == VDIR)
840 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
841 error = VOP_OLD_REMOVE(dvp, vp, &cnp);
843 cache_setunresolved(nch);
844 cache_setvp(nch, NULL);
845 cache_inval_vp(vp, CINV_DESTROY);
854 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
861 * vop_compat_nrmdir { struct nchandle *a_nch, XXX STOPGAP FUNCTION
863 * struct ucred *a_cred }
866 vop_compat_nrmdir(struct vop_nrmdir_args *ap)
868 struct thread *td = curthread;
869 struct componentname cnp;
870 struct nchandle *nch;
871 struct namecache *ncp;
877 * Sanity checks, get a locked directory vnode.
879 nch = ap->a_nch; /* locked namecache node */
883 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
884 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
890 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
891 * caches all information required to delete the entry in the
892 * directory inode. We expect a return code of 0 for the DELETE
893 * case (meaning that a vp has been found). The cnp must simulated
894 * a saved-name situation.
896 bzero(&cnp, sizeof(cnp));
897 cnp.cn_nameiop = NAMEI_DELETE;
898 cnp.cn_flags = CNP_LOCKPARENT;
899 cnp.cn_nameptr = ncp->nc_name;
900 cnp.cn_namelen = ncp->nc_nlen;
901 cnp.cn_cred = ap->a_cred;
905 * The vnode must be a directory and must not represent the
909 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
910 if (error == 0 && vp->v_type != VDIR)
912 if (error == 0 && vp == dvp)
914 if (error == 0 && (vp->v_flag & VROOT))
917 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
918 error = VOP_OLD_RMDIR(dvp, vp, &cnp);
921 * Note that this invalidation will cause any process
922 * currently CD'd into the directory being removed to be
923 * disconnected from the topology and not be able to ".."
927 cache_inval(nch, CINV_DESTROY);
928 cache_inval_vp(vp, CINV_DESTROY);
937 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
944 * vop_compat_nrename { struct nchandle *a_fnch, XXX STOPGAP FUNCTION
945 * struct nchandle *a_tnch,
946 * struct ucred *a_cred }
948 * This is a fairly difficult procedure. The old VOP_OLD_RENAME requires that
949 * the source directory and vnode be unlocked and the target directory and
950 * vnode (if it exists) be locked. All arguments will be vrele'd and
951 * the targets will also be unlocked regardless of the return code.
954 vop_compat_nrename(struct vop_nrename_args *ap)
956 struct thread *td = curthread;
957 struct componentname fcnp;
958 struct componentname tcnp;
959 struct nchandle *fnch;
960 struct nchandle *tnch;
961 struct namecache *fncp;
962 struct namecache *tncp;
963 struct vnode *fdvp, *fvp;
964 struct vnode *tdvp, *tvp;
968 * Sanity checks, get referenced vnodes representing the source.
970 fnch = ap->a_fnch; /* locked namecache node */
975 * Temporarily lock the source directory and lookup in DELETE mode to
976 * check permissions. XXX delete permissions should have been
977 * checked by nlookup(), we need to add NLC_DELETE for delete
978 * checking. It is unclear whether VFS's require the directory setup
979 * info NAMEI_DELETE causes to be stored in the fdvp's inode, but
980 * since it isn't locked and since UFS always does a relookup of
981 * the source, it is believed that the only side effect that matters
982 * is the permissions check.
984 if ((error = vget(fdvp, LK_EXCLUSIVE)) != 0) {
985 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
986 fncp, fncp->nc_name);
990 bzero(&fcnp, sizeof(fcnp));
991 fcnp.cn_nameiop = NAMEI_DELETE;
992 fcnp.cn_flags = CNP_LOCKPARENT;
993 fcnp.cn_nameptr = fncp->nc_name;
994 fcnp.cn_namelen = fncp->nc_nlen;
995 fcnp.cn_cred = ap->a_cred;
999 * note: vop_old_lookup (i.e. VOP_OLD_LOOKUP) always returns a locked
1003 error = vop_old_lookup(ap->a_head.a_ops, fdvp, &fvp, &fcnp);
1004 if (error == 0 && (fvp->v_flag & VROOT)) {
1005 vput(fvp); /* as if vop_old_lookup had failed */
1008 if ((fcnp.cn_flags & CNP_PDIRUNLOCK) == 0) {
1009 fcnp.cn_flags |= CNP_PDIRUNLOCK;
1019 * fdvp and fvp are now referenced and unlocked.
1021 * Get a locked directory vnode for the target and lookup the target
1022 * in CREATE mode so it places the required information in the
1025 tnch = ap->a_tnch; /* locked namecache node */
1033 if ((error = vget(tdvp, LK_EXCLUSIVE)) != 0) {
1034 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
1035 tncp, tncp->nc_name);
1042 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
1043 * caches all information required to create the entry in the
1044 * target directory inode.
1046 bzero(&tcnp, sizeof(tcnp));
1047 tcnp.cn_nameiop = NAMEI_RENAME;
1048 tcnp.cn_flags = CNP_LOCKPARENT;
1049 tcnp.cn_nameptr = tncp->nc_name;
1050 tcnp.cn_namelen = tncp->nc_nlen;
1051 tcnp.cn_cred = ap->a_cred;
1055 error = vop_old_lookup(ap->a_head.a_ops, tdvp, &tvp, &tcnp);
1057 if (error == EJUSTRETURN) {
1059 * Target does not exist. tvp should be NULL.
1061 KKASSERT(tvp == NULL);
1062 KKASSERT((tcnp.cn_flags & CNP_PDIRUNLOCK) == 0);
1063 error = VOP_OLD_RENAME(fdvp, fvp, &fcnp, tdvp, tvp, &tcnp);
1065 cache_rename(fnch, tnch);
1066 } else if (error == 0) {
1068 * Target exists. VOP_OLD_RENAME should correctly delete the
1071 KKASSERT((tcnp.cn_flags & CNP_PDIRUNLOCK) == 0);
1072 error = VOP_OLD_RENAME(fdvp, fvp, &fcnp, tdvp, tvp, &tcnp);
1074 cache_rename(fnch, tnch);
1078 if (tcnp.cn_flags & CNP_PDIRUNLOCK)
1087 vop_nolookup(struct vop_old_lookup_args *ap)
1097 * Strategy routine for VFS devices that have none.
1099 * B_ERROR and B_INVAL must be cleared prior to calling any strategy
1100 * routine. Typically this is done for a BUF_CMD_READ strategy call.
1101 * Typically B_INVAL is assumed to already be clear prior to a write
1102 * and should not be cleared manually unless you just made the buffer
1103 * invalid. B_ERROR should be cleared either way.
1107 vop_nostrategy (struct vop_strategy_args *ap)
1109 kprintf("No strategy for buffer at %p\n", ap->a_bio->bio_buf);
1110 vprint("", ap->a_vp);
1111 ap->a_bio->bio_buf->b_flags |= B_ERROR;
1112 ap->a_bio->bio_buf->b_error = EOPNOTSUPP;
1114 return (EOPNOTSUPP);
1118 vop_stdpathconf(struct vop_pathconf_args *ap)
1122 switch (ap->a_name) {
1124 *ap->a_retval = LINK_MAX;
1127 *ap->a_retval = NAME_MAX;
1130 *ap->a_retval = PATH_MAX;
1133 *ap->a_retval = MAX_CANON;
1136 *ap->a_retval = MAX_INPUT;
1139 *ap->a_retval = PIPE_BUF;
1141 case _PC_CHOWN_RESTRICTED:
1148 *ap->a_retval = _POSIX_VDISABLE;
1160 * (struct vnode *a_vp, int a_mode, struct ucred *a_ucred, struct file *a_fp)
1162 * a_mode: note, 'F' modes, e.g. FREAD, FWRITE
1165 vop_stdopen(struct vop_open_args *ap)
1167 struct vnode *vp = ap->a_vp;
1170 if ((fp = ap->a_fp) != NULL) {
1171 switch(vp->v_type) {
1173 fp->f_type = DTYPE_FIFO;
1176 fp->f_type = DTYPE_VNODE;
1179 fp->f_flag = ap->a_mode & FMASK;
1180 fp->f_ops = &vnode_fileops;
1184 if (ap->a_mode & FWRITE)
1186 KKASSERT(vp->v_opencount >= 0 && vp->v_opencount != INT_MAX);
1194 * (struct vnode *a_vp, int a_fflag)
1196 * a_fflag: note, 'F' modes, e.g. FREAD, FWRITE. same as a_mode in stdopen?
1199 vop_stdclose(struct vop_close_args *ap)
1201 struct vnode *vp = ap->a_vp;
1203 KASSERT(vp->v_opencount > 0,
1204 ("VOP_STDCLOSE: BAD OPENCOUNT %p %d type=%d ops=%p flgs=%08x\n",
1205 vp, vp->v_opencount, vp->v_type, *vp->v_ops, vp->v_flag));
1206 if (ap->a_fflag & FWRITE) {
1207 KASSERT(vp->v_writecount > 0,
1208 ("VOP_STDCLOSE: BAD WRITECOUNT %p %d\n",
1209 vp, vp->v_writecount));
1217 * Implement standard getpages and putpages. All filesystems must use
1218 * the buffer cache to back regular files.
1221 vop_stdgetpages(struct vop_getpages_args *ap)
1226 if ((mp = ap->a_vp->v_mount) != NULL) {
1227 error = vnode_pager_generic_getpages(
1228 ap->a_vp, ap->a_m, ap->a_count,
1229 ap->a_reqpage, ap->a_seqaccess);
1231 error = VM_PAGER_BAD;
1237 vop_stdputpages(struct vop_putpages_args *ap)
1242 if ((mp = ap->a_vp->v_mount) != NULL) {
1243 error = vnode_pager_generic_putpages(
1244 ap->a_vp, ap->a_m, ap->a_count,
1245 ap->a_sync, ap->a_rtvals);
1247 error = VM_PAGER_BAD;
1253 vop_stdnoread(struct vop_read_args *ap)
1259 vop_stdnowrite(struct vop_write_args *ap)
1266 * used to fill the vfs fucntion table to get reasonable default return values.
1269 vfs_stdmount(struct mount *mp, char *path, caddr_t data, struct ucred *cred)
1275 vfs_stdunmount(struct mount *mp, int mntflags)
1281 vop_stdmountctl(struct vop_mountctl_args *ap)
1287 mp = ap->a_head.a_ops->head.vv_mount;
1290 case MOUNTCTL_MOUNTFLAGS:
1292 * Get a string buffer with all the mount flags
1293 * names comman separated.
1294 * mount(2) will use this information.
1296 *ap->a_res = vfs_flagstostr(mp->mnt_flag & MNT_VISFLAGMASK, NULL,
1297 ap->a_buf, ap->a_buflen, &error);
1299 case MOUNTCTL_INSTALL_VFS_JOURNAL:
1300 case MOUNTCTL_RESTART_VFS_JOURNAL:
1301 case MOUNTCTL_REMOVE_VFS_JOURNAL:
1302 case MOUNTCTL_RESYNC_VFS_JOURNAL:
1303 case MOUNTCTL_STATUS_VFS_JOURNAL:
1304 error = journal_mountctl(ap);
1314 vfs_stdroot(struct mount *mp, struct vnode **vpp)
1316 return (EOPNOTSUPP);
1320 vfs_stdstatfs(struct mount *mp, struct statfs *sbp, struct ucred *cred)
1322 return (EOPNOTSUPP);
1326 * If the VFS does not implement statvfs, then call statfs and convert
1327 * the values. This code was taken from libc's __cvtstatvfs() function,
1328 * contributed by Joerg Sonnenberger.
1331 vfs_stdstatvfs(struct mount *mp, struct statvfs *sbp, struct ucred *cred)
1337 error = VFS_STATFS(mp, in, cred);
1339 bzero(sbp, sizeof(*sbp));
1341 sbp->f_bsize = in->f_bsize;
1342 sbp->f_frsize = in->f_bsize;
1343 sbp->f_blocks = in->f_blocks;
1344 sbp->f_bfree = in->f_bfree;
1345 sbp->f_bavail = in->f_bavail;
1346 sbp->f_files = in->f_files;
1347 sbp->f_ffree = in->f_ffree;
1351 * This field counts the number of available inodes to non-root
1352 * users, but this information is not available via statfs.
1353 * Just ignore this issue by returning the total number
1356 sbp->f_favail = in->f_ffree;
1360 * This field has a different meaning for statfs and statvfs.
1361 * For the former it is the cookie exported for NFS and not
1362 * intended for normal userland use.
1367 if (in->f_flags & MNT_RDONLY)
1368 sbp->f_flag |= ST_RDONLY;
1369 if (in->f_flags & MNT_NOSUID)
1370 sbp->f_flag |= ST_NOSUID;
1372 sbp->f_owner = in->f_owner;
1375 * statfs contains the type as string, statvfs expects it as
1380 sbp->f_syncreads = in->f_syncreads;
1381 sbp->f_syncwrites = in->f_syncwrites;
1382 sbp->f_asyncreads = in->f_asyncreads;
1383 sbp->f_asyncwrites = in->f_asyncwrites;
1389 vfs_stdvptofh(struct vnode *vp, struct fid *fhp)
1391 return (EOPNOTSUPP);
1395 vfs_stdstart(struct mount *mp, int flags)
1401 vfs_stdquotactl(struct mount *mp, int cmds, uid_t uid,
1402 caddr_t arg, struct ucred *cred)
1404 return (EOPNOTSUPP);
1408 vfs_stdsync(struct mount *mp, int waitfor)
1414 vfs_stdnosync(struct mount *mp, int waitfor)
1416 return (EOPNOTSUPP);
1420 vfs_stdvget(struct mount *mp, struct vnode *dvp, ino_t ino, struct vnode **vpp)
1422 return (EOPNOTSUPP);
1426 vfs_stdfhtovp(struct mount *mp, struct vnode *rootvp,
1427 struct fid *fhp, struct vnode **vpp)
1429 return (EOPNOTSUPP);
1433 vfs_stdcheckexp(struct mount *mp, struct sockaddr *nam, int *extflagsp,
1434 struct ucred **credanonp)
1436 return (EOPNOTSUPP);
1440 vfs_stdinit(struct vfsconf *vfsp)
1446 vfs_stduninit(struct vfsconf *vfsp)
1452 vfs_stdextattrctl(struct mount *mp, int cmd, struct vnode *vp,
1453 int attrnamespace, const char *attrname,
1459 /* end of vfs default ops */