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 $
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>
57 #include <sys/mountctl.h>
58 #include <sys/vfs_quota.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 * (*vpp) will be returned locked if no error occured, which is the
298 error = vop_old_lookup(ap->a_head.a_ops, ap->a_dvp, ap->a_vpp, &cnp);
299 if (cnp.cn_flags & CNP_PDIRUNLOCK)
307 * vop_compat_ncreate { struct nchandle *a_nch, XXX STOPGAP FUNCTION
308 * struct vnode *a_dvp,
309 * struct vnode **a_vpp,
310 * struct ucred *a_cred,
311 * struct vattr *a_vap }
313 * Create a file as specified by a_vap. Compatibility requires us to issue
314 * the appropriate VOP_OLD_LOOKUP before we issue VOP_OLD_CREATE in order
315 * to setup the directory inode's i_offset and i_count (e.g. in UFS).
318 vop_compat_ncreate(struct vop_ncreate_args *ap)
320 struct thread *td = curthread;
321 struct componentname cnp;
322 struct nchandle *nch;
323 struct namecache *ncp;
328 * Sanity checks, get a locked directory vnode.
330 nch = ap->a_nch; /* locked namecache node */
334 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
335 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
341 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
342 * caches all information required to create the entry in the
343 * directory inode. We expect a return code of EJUSTRETURN for
344 * the CREATE case. The cnp must simulated a saved-name situation.
346 bzero(&cnp, sizeof(cnp));
347 cnp.cn_nameiop = NAMEI_CREATE;
348 cnp.cn_flags = CNP_LOCKPARENT;
349 cnp.cn_nameptr = ncp->nc_name;
350 cnp.cn_namelen = ncp->nc_nlen;
351 cnp.cn_cred = ap->a_cred;
355 error = vop_old_lookup(ap->a_head.a_ops, dvp, ap->a_vpp, &cnp);
358 * EJUSTRETURN should be returned for this case, which means that
359 * the VFS has setup the directory inode for the create. The dvp we
360 * passed in is expected to remain in a locked state.
362 * If the VOP_OLD_CREATE is successful we are responsible for updating
363 * the cache state of the locked ncp that was passed to us.
365 if (error == EJUSTRETURN) {
366 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
367 error = VOP_OLD_CREATE(dvp, ap->a_vpp, &cnp, ap->a_vap);
369 cache_setunresolved(nch);
370 cache_setvp(nch, *ap->a_vpp);
378 KKASSERT(*ap->a_vpp == NULL);
380 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
387 * vop_compat_nmkdir { struct nchandle *a_nch, XXX STOPGAP FUNCTION
388 * struct vnode *a_dvp,
389 * struct vnode **a_vpp,
390 * struct ucred *a_cred,
391 * struct vattr *a_vap }
393 * Create a directory as specified by a_vap. Compatibility requires us to
394 * issue the appropriate VOP_OLD_LOOKUP before we issue VOP_OLD_MKDIR in
395 * order to setup the directory inode's i_offset and i_count (e.g. in UFS).
398 vop_compat_nmkdir(struct vop_nmkdir_args *ap)
400 struct thread *td = curthread;
401 struct componentname cnp;
402 struct nchandle *nch;
403 struct namecache *ncp;
408 * Sanity checks, get a locked directory vnode.
410 nch = ap->a_nch; /* locked namecache node */
413 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
414 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
420 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
421 * caches all information required to create the entry in the
422 * directory inode. We expect a return code of EJUSTRETURN for
423 * the CREATE case. The cnp must simulated a saved-name situation.
425 bzero(&cnp, sizeof(cnp));
426 cnp.cn_nameiop = NAMEI_CREATE;
427 cnp.cn_flags = CNP_LOCKPARENT;
428 cnp.cn_nameptr = ncp->nc_name;
429 cnp.cn_namelen = ncp->nc_nlen;
430 cnp.cn_cred = ap->a_cred;
434 error = vop_old_lookup(ap->a_head.a_ops, dvp, ap->a_vpp, &cnp);
437 * EJUSTRETURN should be returned for this case, which means that
438 * the VFS has setup the directory inode for the create. The dvp we
439 * passed in is expected to remain in a locked state.
441 * If the VOP_OLD_MKDIR is successful we are responsible for updating
442 * the cache state of the locked ncp that was passed to us.
444 if (error == EJUSTRETURN) {
445 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
446 error = VOP_OLD_MKDIR(dvp, ap->a_vpp, &cnp, ap->a_vap);
448 cache_setunresolved(nch);
449 cache_setvp(nch, *ap->a_vpp);
457 KKASSERT(*ap->a_vpp == NULL);
459 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
466 * vop_compat_nmknod { struct nchandle *a_nch, XXX STOPGAP FUNCTION
467 * struct vnode *a_dvp,
468 * struct vnode **a_vpp,
469 * struct ucred *a_cred,
470 * struct vattr *a_vap }
472 * Create a device or fifo node as specified by a_vap. Compatibility requires
473 * us to issue the appropriate VOP_OLD_LOOKUP before we issue VOP_OLD_MKNOD
474 * in order to setup the directory inode's i_offset and i_count (e.g. in UFS).
477 vop_compat_nmknod(struct vop_nmknod_args *ap)
479 struct thread *td = curthread;
480 struct componentname cnp;
481 struct nchandle *nch;
482 struct namecache *ncp;
487 * Sanity checks, get a locked directory vnode.
489 nch = ap->a_nch; /* locked namecache node */
493 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
494 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
500 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
501 * caches all information required to create the entry in the
502 * directory inode. We expect a return code of EJUSTRETURN for
503 * the CREATE case. The cnp must simulated a saved-name situation.
505 bzero(&cnp, sizeof(cnp));
506 cnp.cn_nameiop = NAMEI_CREATE;
507 cnp.cn_flags = CNP_LOCKPARENT;
508 cnp.cn_nameptr = ncp->nc_name;
509 cnp.cn_namelen = ncp->nc_nlen;
510 cnp.cn_cred = ap->a_cred;
514 error = vop_old_lookup(ap->a_head.a_ops, dvp, ap->a_vpp, &cnp);
517 * EJUSTRETURN should be returned for this case, which means that
518 * the VFS has setup the directory inode for the create. The dvp we
519 * passed in is expected to remain in a locked state.
521 * If the VOP_OLD_MKNOD is successful we are responsible for updating
522 * the cache state of the locked ncp that was passed to us.
524 if (error == EJUSTRETURN) {
525 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
526 error = VOP_OLD_MKNOD(dvp, ap->a_vpp, &cnp, ap->a_vap);
528 cache_setunresolved(nch);
529 cache_setvp(nch, *ap->a_vpp);
537 KKASSERT(*ap->a_vpp == NULL);
539 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
546 * vop_compat_nlink { struct nchandle *a_nch, XXX STOPGAP FUNCTION
547 * struct vnode *a_dvp,
548 * struct vnode *a_vp,
549 * struct ucred *a_cred }
551 * The passed vp is locked and represents the source. The passed ncp is
552 * locked and represents the target to create.
555 vop_compat_nlink(struct vop_nlink_args *ap)
557 struct thread *td = curthread;
558 struct componentname cnp;
559 struct nchandle *nch;
560 struct namecache *ncp;
566 * Sanity checks, get a locked directory vnode.
568 nch = ap->a_nch; /* locked namecache node */
572 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
573 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
579 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
580 * caches all information required to create the entry in the
581 * directory inode. We expect a return code of EJUSTRETURN for
582 * the CREATE case. The cnp must simulated a saved-name situation.
584 bzero(&cnp, sizeof(cnp));
585 cnp.cn_nameiop = NAMEI_CREATE;
586 cnp.cn_flags = CNP_LOCKPARENT;
587 cnp.cn_nameptr = ncp->nc_name;
588 cnp.cn_namelen = ncp->nc_nlen;
589 cnp.cn_cred = ap->a_cred;
593 error = vop_old_lookup(ap->a_head.a_ops, dvp, &tvp, &cnp);
596 * EJUSTRETURN should be returned for this case, which means that
597 * the VFS has setup the directory inode for the create. The dvp we
598 * passed in is expected to remain in a locked state.
600 * If the VOP_OLD_LINK is successful we are responsible for updating
601 * the cache state of the locked ncp that was passed to us.
603 if (error == EJUSTRETURN) {
604 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
605 error = VOP_OLD_LINK(dvp, ap->a_vp, &cnp);
607 cache_setunresolved(nch);
608 cache_setvp(nch, ap->a_vp);
616 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
623 vop_compat_nsymlink(struct vop_nsymlink_args *ap)
625 struct thread *td = curthread;
626 struct componentname cnp;
627 struct nchandle *nch;
628 struct namecache *ncp;
634 * Sanity checks, get a locked directory vnode.
637 nch = ap->a_nch; /* locked namecache node */
641 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
642 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
648 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
649 * caches all information required to create the entry in the
650 * directory inode. We expect a return code of EJUSTRETURN for
651 * the CREATE case. The cnp must simulated a saved-name situation.
653 bzero(&cnp, sizeof(cnp));
654 cnp.cn_nameiop = NAMEI_CREATE;
655 cnp.cn_flags = CNP_LOCKPARENT;
656 cnp.cn_nameptr = ncp->nc_name;
657 cnp.cn_namelen = ncp->nc_nlen;
658 cnp.cn_cred = ap->a_cred;
662 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
665 * EJUSTRETURN should be returned for this case, which means that
666 * the VFS has setup the directory inode for the create. The dvp we
667 * passed in is expected to remain in a locked state.
669 * If the VOP_OLD_SYMLINK is successful we are responsible for updating
670 * the cache state of the locked ncp that was passed to us.
672 if (error == EJUSTRETURN) {
673 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
674 error = VOP_OLD_SYMLINK(dvp, &vp, &cnp, ap->a_vap, ap->a_target);
676 cache_setunresolved(nch);
677 cache_setvp(nch, vp);
686 KKASSERT(vp == NULL);
688 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
695 * vop_compat_nwhiteout { struct nchandle *a_nch, XXX STOPGAP FUNCTION
696 * struct vnode *a_dvp,
697 * struct ucred *a_cred,
700 * Issie a whiteout operation (create, lookup, or delete). Compatibility
701 * requires us to issue the appropriate VOP_OLD_LOOKUP before we issue
702 * VOP_OLD_WHITEOUT in order to setup the directory inode's i_offset and i_count
703 * (e.g. in UFS) for the NAMEI_CREATE and NAMEI_DELETE ops. For NAMEI_LOOKUP
704 * no lookup is necessary.
707 vop_compat_nwhiteout(struct vop_nwhiteout_args *ap)
709 struct thread *td = curthread;
710 struct componentname cnp;
711 struct nchandle *nch;
712 struct namecache *ncp;
718 * Sanity checks, get a locked directory vnode.
720 nch = ap->a_nch; /* locked namecache node */
724 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
725 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
731 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
732 * caches all information required to create the entry in the
733 * directory inode. We expect a return code of EJUSTRETURN for
734 * the CREATE case. The cnp must simulated a saved-name situation.
736 bzero(&cnp, sizeof(cnp));
737 cnp.cn_nameiop = ap->a_flags;
738 cnp.cn_flags = CNP_LOCKPARENT;
739 cnp.cn_nameptr = ncp->nc_name;
740 cnp.cn_namelen = ncp->nc_nlen;
741 cnp.cn_cred = ap->a_cred;
747 * EJUSTRETURN should be returned for the CREATE or DELETE cases.
748 * The VFS has setup the directory inode for the create. The dvp we
749 * passed in is expected to remain in a locked state.
751 * If the VOP_OLD_WHITEOUT is successful we are responsible for updating
752 * the cache state of the locked ncp that was passed to us.
754 switch(ap->a_flags) {
756 cnp.cn_flags |= CNP_DOWHITEOUT;
759 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
760 if (error == EJUSTRETURN) {
761 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
762 error = VOP_OLD_WHITEOUT(dvp, &cnp, ap->a_flags);
764 cache_setunresolved(nch);
771 KKASSERT(vp == NULL);
775 error = VOP_OLD_WHITEOUT(dvp, NULL, ap->a_flags);
781 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
789 * vop_compat_nremove { struct nchandle *a_nch, XXX STOPGAP FUNCTION
790 * struct vnode *a_dvp,
791 * struct ucred *a_cred }
794 vop_compat_nremove(struct vop_nremove_args *ap)
796 struct thread *td = curthread;
797 struct componentname cnp;
798 struct nchandle *nch;
799 struct namecache *ncp;
805 * Sanity checks, get a locked directory vnode.
807 nch = ap->a_nch; /* locked namecache node */
811 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
812 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
818 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
819 * caches all information required to delete the entry in the
820 * directory inode. We expect a return code of 0 for the DELETE
821 * case (meaning that a vp has been found). The cnp must simulated
822 * a saved-name situation.
824 bzero(&cnp, sizeof(cnp));
825 cnp.cn_nameiop = NAMEI_DELETE;
826 cnp.cn_flags = CNP_LOCKPARENT;
827 cnp.cn_nameptr = ncp->nc_name;
828 cnp.cn_namelen = ncp->nc_nlen;
829 cnp.cn_cred = ap->a_cred;
833 * The vnode must be a directory and must not represent the
837 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
838 if (error == 0 && vp->v_type == VDIR)
841 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
842 error = VOP_OLD_REMOVE(dvp, vp, &cnp);
844 cache_setunresolved(nch);
845 cache_setvp(nch, NULL);
846 cache_inval_vp(vp, CINV_DESTROY);
855 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
862 * vop_compat_nrmdir { struct nchandle *a_nch, XXX STOPGAP FUNCTION
864 * struct ucred *a_cred }
867 vop_compat_nrmdir(struct vop_nrmdir_args *ap)
869 struct thread *td = curthread;
870 struct componentname cnp;
871 struct nchandle *nch;
872 struct namecache *ncp;
878 * Sanity checks, get a locked directory vnode.
880 nch = ap->a_nch; /* locked namecache node */
884 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
885 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
891 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
892 * caches all information required to delete the entry in the
893 * directory inode. We expect a return code of 0 for the DELETE
894 * case (meaning that a vp has been found). The cnp must simulated
895 * a saved-name situation.
897 bzero(&cnp, sizeof(cnp));
898 cnp.cn_nameiop = NAMEI_DELETE;
899 cnp.cn_flags = CNP_LOCKPARENT;
900 cnp.cn_nameptr = ncp->nc_name;
901 cnp.cn_namelen = ncp->nc_nlen;
902 cnp.cn_cred = ap->a_cred;
906 * The vnode must be a directory and must not represent the
910 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
911 if (error == 0 && vp->v_type != VDIR)
913 if (error == 0 && vp == dvp)
915 if (error == 0 && (vp->v_flag & VROOT))
918 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
919 error = VOP_OLD_RMDIR(dvp, vp, &cnp);
922 * Note that this invalidation will cause any process
923 * currently CD'd into the directory being removed to be
924 * disconnected from the topology and not be able to ".."
928 cache_inval(nch, CINV_DESTROY);
929 cache_inval_vp(vp, CINV_DESTROY);
938 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
945 * vop_compat_nrename { struct nchandle *a_fnch, XXX STOPGAP FUNCTION
946 * struct nchandle *a_tnch,
947 * struct ucred *a_cred }
949 * This is a fairly difficult procedure. The old VOP_OLD_RENAME requires that
950 * the source directory and vnode be unlocked and the target directory and
951 * vnode (if it exists) be locked. All arguments will be vrele'd and
952 * the targets will also be unlocked regardless of the return code.
955 vop_compat_nrename(struct vop_nrename_args *ap)
957 struct thread *td = curthread;
958 struct componentname fcnp;
959 struct componentname tcnp;
960 struct nchandle *fnch;
961 struct nchandle *tnch;
962 struct namecache *fncp;
963 struct namecache *tncp;
964 struct vnode *fdvp, *fvp;
965 struct vnode *tdvp, *tvp;
969 * Sanity checks, get referenced vnodes representing the source.
971 fnch = ap->a_fnch; /* locked namecache node */
976 * Temporarily lock the source directory and lookup in DELETE mode to
977 * check permissions. XXX delete permissions should have been
978 * checked by nlookup(), we need to add NLC_DELETE for delete
979 * checking. It is unclear whether VFS's require the directory setup
980 * info NAMEI_DELETE causes to be stored in the fdvp's inode, but
981 * since it isn't locked and since UFS always does a relookup of
982 * the source, it is believed that the only side effect that matters
983 * is the permissions check.
985 if ((error = vget(fdvp, LK_EXCLUSIVE)) != 0) {
986 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
987 fncp, fncp->nc_name);
991 bzero(&fcnp, sizeof(fcnp));
992 fcnp.cn_nameiop = NAMEI_DELETE;
993 fcnp.cn_flags = CNP_LOCKPARENT;
994 fcnp.cn_nameptr = fncp->nc_name;
995 fcnp.cn_namelen = fncp->nc_nlen;
996 fcnp.cn_cred = ap->a_cred;
1000 * note: vop_old_lookup (i.e. VOP_OLD_LOOKUP) always returns a locked
1004 error = vop_old_lookup(ap->a_head.a_ops, fdvp, &fvp, &fcnp);
1005 if (error == 0 && (fvp->v_flag & VROOT)) {
1006 vput(fvp); /* as if vop_old_lookup had failed */
1009 if ((fcnp.cn_flags & CNP_PDIRUNLOCK) == 0) {
1010 fcnp.cn_flags |= CNP_PDIRUNLOCK;
1020 * fdvp and fvp are now referenced and unlocked.
1022 * Get a locked directory vnode for the target and lookup the target
1023 * in CREATE mode so it places the required information in the
1026 tnch = ap->a_tnch; /* locked namecache node */
1034 if ((error = vget(tdvp, LK_EXCLUSIVE)) != 0) {
1035 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
1036 tncp, tncp->nc_name);
1043 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
1044 * caches all information required to create the entry in the
1045 * target directory inode.
1047 bzero(&tcnp, sizeof(tcnp));
1048 tcnp.cn_nameiop = NAMEI_RENAME;
1049 tcnp.cn_flags = CNP_LOCKPARENT;
1050 tcnp.cn_nameptr = tncp->nc_name;
1051 tcnp.cn_namelen = tncp->nc_nlen;
1052 tcnp.cn_cred = ap->a_cred;
1056 error = vop_old_lookup(ap->a_head.a_ops, tdvp, &tvp, &tcnp);
1058 if (error == EJUSTRETURN) {
1060 * Target does not exist. tvp should be NULL.
1062 KKASSERT(tvp == NULL);
1063 KKASSERT((tcnp.cn_flags & CNP_PDIRUNLOCK) == 0);
1064 error = VOP_OLD_RENAME(fdvp, fvp, &fcnp, tdvp, tvp, &tcnp);
1066 cache_rename(fnch, tnch);
1067 } else if (error == 0) {
1069 * Target exists. VOP_OLD_RENAME should correctly delete the
1072 KKASSERT((tcnp.cn_flags & CNP_PDIRUNLOCK) == 0);
1073 error = VOP_OLD_RENAME(fdvp, fvp, &fcnp, tdvp, tvp, &tcnp);
1075 cache_rename(fnch, tnch);
1079 if (tcnp.cn_flags & CNP_PDIRUNLOCK)
1088 vop_nolookup(struct vop_old_lookup_args *ap)
1098 * Strategy routine for VFS devices that have none.
1100 * B_ERROR and B_INVAL must be cleared prior to calling any strategy
1101 * routine. Typically this is done for a BUF_CMD_READ strategy call.
1102 * Typically B_INVAL is assumed to already be clear prior to a write
1103 * and should not be cleared manually unless you just made the buffer
1104 * invalid. B_ERROR should be cleared either way.
1108 vop_nostrategy (struct vop_strategy_args *ap)
1110 kprintf("No strategy for buffer at %p\n", ap->a_bio->bio_buf);
1111 vprint("", ap->a_vp);
1112 ap->a_bio->bio_buf->b_flags |= B_ERROR;
1113 ap->a_bio->bio_buf->b_error = EOPNOTSUPP;
1115 return (EOPNOTSUPP);
1119 vop_stdpathconf(struct vop_pathconf_args *ap)
1123 switch (ap->a_name) {
1125 *ap->a_retval = LINK_MAX;
1128 *ap->a_retval = NAME_MAX;
1131 *ap->a_retval = PATH_MAX;
1134 *ap->a_retval = MAX_CANON;
1137 *ap->a_retval = MAX_INPUT;
1140 *ap->a_retval = PIPE_BUF;
1142 case _PC_CHOWN_RESTRICTED:
1149 *ap->a_retval = _POSIX_VDISABLE;
1161 * (struct vnode *a_vp, int a_mode, struct ucred *a_ucred, struct file *a_fp)
1163 * a_mode: note, 'F' modes, e.g. FREAD, FWRITE
1166 vop_stdopen(struct vop_open_args *ap)
1168 struct vnode *vp = ap->a_vp;
1171 if ((fp = ap->a_fp) != NULL) {
1172 switch(vp->v_type) {
1174 fp->f_type = DTYPE_FIFO;
1177 fp->f_type = DTYPE_VNODE;
1180 fp->f_flag = ap->a_mode & FMASK;
1181 fp->f_ops = &vnode_fileops;
1185 if (ap->a_mode & FWRITE)
1187 KKASSERT(vp->v_opencount >= 0 && vp->v_opencount != INT_MAX);
1195 * (struct vnode *a_vp, int a_fflag)
1197 * a_fflag: note, 'F' modes, e.g. FREAD, FWRITE. same as a_mode in stdopen?
1200 vop_stdclose(struct vop_close_args *ap)
1202 struct vnode *vp = ap->a_vp;
1204 KASSERT(vp->v_opencount > 0,
1205 ("VOP_STDCLOSE: BAD OPENCOUNT %p %d type=%d ops=%p flgs=%08x",
1206 vp, vp->v_opencount, vp->v_type, *vp->v_ops, vp->v_flag));
1207 if (ap->a_fflag & FWRITE) {
1208 KASSERT(vp->v_writecount > 0,
1209 ("VOP_STDCLOSE: BAD WRITECOUNT %p %d",
1210 vp, vp->v_writecount));
1218 * Implement standard getpages and putpages. All filesystems must use
1219 * the buffer cache to back regular files.
1222 vop_stdgetpages(struct vop_getpages_args *ap)
1227 if ((mp = ap->a_vp->v_mount) != NULL) {
1228 error = vnode_pager_generic_getpages(
1229 ap->a_vp, ap->a_m, ap->a_count,
1230 ap->a_reqpage, ap->a_seqaccess);
1232 error = VM_PAGER_BAD;
1238 vop_stdputpages(struct vop_putpages_args *ap)
1243 if ((mp = ap->a_vp->v_mount) != NULL) {
1244 error = vnode_pager_generic_putpages(
1245 ap->a_vp, ap->a_m, ap->a_count,
1246 ap->a_sync, ap->a_rtvals);
1248 error = VM_PAGER_BAD;
1254 vop_stdnoread(struct vop_read_args *ap)
1260 vop_stdnowrite(struct vop_write_args *ap)
1267 * used to fill the vfs fucntion table to get reasonable default return values.
1270 vfs_stdmount(struct mount *mp, char *path, caddr_t data, struct ucred *cred)
1276 vfs_stdunmount(struct mount *mp, int mntflags)
1282 vop_stdmountctl(struct vop_mountctl_args *ap)
1288 mp = ap->a_head.a_ops->head.vv_mount;
1291 case MOUNTCTL_MOUNTFLAGS:
1293 * Get a string buffer with all the mount flags
1294 * names comman separated.
1295 * mount(2) will use this information.
1297 *ap->a_res = vfs_flagstostr(mp->mnt_flag & MNT_VISFLAGMASK, NULL,
1298 ap->a_buf, ap->a_buflen, &error);
1300 case MOUNTCTL_INSTALL_VFS_JOURNAL:
1301 case MOUNTCTL_RESTART_VFS_JOURNAL:
1302 case MOUNTCTL_REMOVE_VFS_JOURNAL:
1303 case MOUNTCTL_RESYNC_VFS_JOURNAL:
1304 case MOUNTCTL_STATUS_VFS_JOURNAL:
1305 error = journal_mountctl(ap);
1315 vfs_stdroot(struct mount *mp, struct vnode **vpp)
1317 return (EOPNOTSUPP);
1321 vfs_stdstatfs(struct mount *mp, struct statfs *sbp, struct ucred *cred)
1323 return (EOPNOTSUPP);
1327 * If the VFS does not implement statvfs, then call statfs and convert
1328 * the values. This code was taken from libc's __cvtstatvfs() function,
1329 * contributed by Joerg Sonnenberger.
1332 vfs_stdstatvfs(struct mount *mp, struct statvfs *sbp, struct ucred *cred)
1338 error = VFS_STATFS(mp, in, cred);
1340 bzero(sbp, sizeof(*sbp));
1342 sbp->f_bsize = in->f_bsize;
1343 sbp->f_frsize = in->f_bsize;
1344 sbp->f_blocks = in->f_blocks;
1345 sbp->f_bfree = in->f_bfree;
1346 sbp->f_bavail = in->f_bavail;
1347 sbp->f_files = in->f_files;
1348 sbp->f_ffree = in->f_ffree;
1352 * This field counts the number of available inodes to non-root
1353 * users, but this information is not available via statfs.
1354 * Just ignore this issue by returning the total number
1357 sbp->f_favail = in->f_ffree;
1361 * This field has a different meaning for statfs and statvfs.
1362 * For the former it is the cookie exported for NFS and not
1363 * intended for normal userland use.
1368 if (in->f_flags & MNT_RDONLY)
1369 sbp->f_flag |= ST_RDONLY;
1370 if (in->f_flags & MNT_NOSUID)
1371 sbp->f_flag |= ST_NOSUID;
1373 sbp->f_owner = in->f_owner;
1376 * statfs contains the type as string, statvfs expects it as
1381 sbp->f_syncreads = in->f_syncreads;
1382 sbp->f_syncwrites = in->f_syncwrites;
1383 sbp->f_asyncreads = in->f_asyncreads;
1384 sbp->f_asyncwrites = in->f_asyncwrites;
1390 vfs_stdvptofh(struct vnode *vp, struct fid *fhp)
1392 return (EOPNOTSUPP);
1396 vfs_stdstart(struct mount *mp, int flags)
1402 vfs_stdquotactl(struct mount *mp, int cmds, uid_t uid,
1403 caddr_t arg, struct ucred *cred)
1405 return (EOPNOTSUPP);
1409 vfs_stdsync(struct mount *mp, int waitfor)
1415 vfs_stdnosync(struct mount *mp, int waitfor)
1417 return (EOPNOTSUPP);
1421 vfs_stdvget(struct mount *mp, struct vnode *dvp, ino_t ino, struct vnode **vpp)
1423 return (EOPNOTSUPP);
1427 vfs_stdfhtovp(struct mount *mp, struct vnode *rootvp,
1428 struct fid *fhp, struct vnode **vpp)
1430 return (EOPNOTSUPP);
1434 vfs_stdcheckexp(struct mount *mp, struct sockaddr *nam, int *extflagsp,
1435 struct ucred **credanonp)
1437 return (EOPNOTSUPP);
1441 vfs_stdinit(struct vfsconf *vfsp)
1447 vfs_stduninit(struct vfsconf *vfsp)
1453 vfs_stdextattrctl(struct mount *mp, int cmd, struct vnode *vp,
1454 int attrnamespace, const char *attrname,
1460 #define ACCOUNTING_NB_FSTYPES 8
1462 static const char *accounting_fstypes[ACCOUNTING_NB_FSTYPES] = {
1463 "ext2fs", "hammer", "hpfs", "mfs", "ntfs", "null", "tmpfs", "ufs" };
1466 vfs_stdac_init(struct mount *mp)
1468 const char* fs_type;
1469 int i, fstype_ok = 0;
1471 /* is mounted fs type one we want to do some accounting for ? */
1472 for (i=0; i<ACCOUNTING_NB_FSTYPES; i++) {
1473 fs_type = accounting_fstypes[i];
1474 if (strncmp(mp->mnt_stat.f_fstypename, fs_type,
1475 sizeof(mp->mnt_stat)) == 0) {
1488 vfs_stdac_done(struct mount *mp)
1494 vfs_stdncpgen_set(struct mount *mp, struct namecache *ncp)
1499 vfs_stdncpgen_test(struct mount *mp, struct namecache *ncp)
1503 /* end of vfs default ops */