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>
59 #include <sys/vfs_quota.h>
61 #include <machine/limits.h>
64 #include <vm/vm_object.h>
65 #include <vm/vm_page.h>
66 #include <vm/vm_pager.h>
67 #include <vm/vnode_pager.h>
69 static int vop_nolookup (struct vop_old_lookup_args *);
70 static int vop_nostrategy (struct vop_strategy_args *);
73 * This vnode table stores what we want to do if the filesystem doesn't
74 * implement a particular VOP.
76 * If there is no specific entry here, we will return EOPNOTSUPP.
78 struct vop_ops default_vnode_vops = {
79 .vop_default = vop_eopnotsupp,
80 .vop_advlock = (void *)vop_einval,
81 .vop_fsync = (void *)vop_null,
82 .vop_ioctl = (void *)vop_enotty,
83 .vop_mmap = (void *)vop_einval,
84 .vop_old_lookup = vop_nolookup,
85 .vop_open = vop_stdopen,
86 .vop_close = vop_stdclose,
87 .vop_pathconf = vop_stdpathconf,
88 .vop_readlink = (void *)vop_einval,
89 .vop_reallocblks = (void *)vop_eopnotsupp,
90 .vop_strategy = vop_nostrategy,
91 .vop_getacl = (void *)vop_eopnotsupp,
92 .vop_setacl = (void *)vop_eopnotsupp,
93 .vop_aclcheck = (void *)vop_eopnotsupp,
94 .vop_getextattr = (void *)vop_eopnotsupp,
95 .vop_setextattr = (void *)vop_eopnotsupp,
96 .vop_markatime = vop_stdmarkatime,
97 .vop_nresolve = vop_compat_nresolve,
98 .vop_nlookupdotdot = vop_compat_nlookupdotdot,
99 .vop_ncreate = vop_compat_ncreate,
100 .vop_nmkdir = vop_compat_nmkdir,
101 .vop_nmknod = vop_compat_nmknod,
102 .vop_nlink = vop_compat_nlink,
103 .vop_nsymlink = vop_compat_nsymlink,
104 .vop_nwhiteout = vop_compat_nwhiteout,
105 .vop_nremove = vop_compat_nremove,
106 .vop_nrmdir = vop_compat_nrmdir,
107 .vop_nrename = vop_compat_nrename,
108 .vop_mountctl = vop_stdmountctl
111 VNODEOP_SET(default_vnode_vops);
114 vop_eopnotsupp(struct vop_generic_args *ap)
120 vop_ebadf(struct vop_generic_args *ap)
126 vop_enotty(struct vop_generic_args *ap)
132 vop_einval(struct vop_generic_args *ap)
138 vop_stdmarkatime(struct vop_markatime_args *ap)
144 vop_null(struct vop_generic_args *ap)
150 vop_defaultop(struct vop_generic_args *ap)
152 return (VOCALL(&default_vnode_vops, ap));
156 vop_panic(struct vop_generic_args *ap)
158 panic("filesystem goof: vop_panic[%s]", ap->a_desc->sd_name);
162 * vop_compat_resolve { struct nchandle *a_nch, struct vnode *dvp }
163 * XXX STOPGAP FUNCTION
165 * XXX OLD API ROUTINE! WHEN ALL VFSs HAVE BEEN CLEANED UP THIS PROCEDURE
166 * WILL BE REMOVED. This procedure exists for all VFSs which have not
167 * yet implemented VOP_NRESOLVE(). It converts VOP_NRESOLVE() into a
168 * vop_old_lookup() and does appropriate translations.
170 * Resolve a ncp for VFSs which do not support the VOP. Eventually all
171 * VFSs will support this VOP and this routine can be removed, since
172 * VOP_NRESOLVE() is far less complex then the older LOOKUP/CACHEDLOOKUP
175 * A locked ncp is passed in to be resolved. The NCP is resolved by
176 * figuring out the vnode (if any) and calling cache_setvp() to attach the
177 * vnode to the entry. If the entry represents a non-existant node then
178 * cache_setvp() is called with a NULL vnode to resolve the entry into a
179 * negative cache entry. No vnode locks are retained and the
180 * ncp is left locked on return.
182 * The ncp will NEVER represent "", "." or "..", or contain any slashes.
184 * There is a potential directory and vnode interlock. The lock order
185 * requirement is: namecache, governing directory, resolved vnode.
188 vop_compat_nresolve(struct vop_nresolve_args *ap)
193 struct nchandle *nch;
194 struct namecache *ncp;
195 struct componentname cnp;
197 nch = ap->a_nch; /* locked namecache node */
202 * UFS currently stores all sorts of side effects, including a loop
203 * variable, in the directory inode. That needs to be fixed and the
204 * other VFS's audited before we can switch to LK_SHARED.
206 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
207 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
212 bzero(&cnp, sizeof(cnp));
213 cnp.cn_nameiop = NAMEI_LOOKUP;
215 cnp.cn_nameptr = ncp->nc_name;
216 cnp.cn_namelen = ncp->nc_nlen;
217 cnp.cn_cred = ap->a_cred;
218 cnp.cn_td = curthread; /* XXX */
221 * vop_old_lookup() always returns vp locked. dvp may or may not be
222 * left locked depending on CNP_PDIRUNLOCK.
224 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
227 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
229 if ((ncp->nc_flag & NCF_UNRESOLVED) == 0) {
230 /* was resolved by another process while we were unlocked */
233 } else if (error == 0) {
234 KKASSERT(vp != NULL);
235 cache_setvp(nch, vp);
237 } else if (error == ENOENT) {
238 KKASSERT(vp == NULL);
239 if (cnp.cn_flags & CNP_ISWHITEOUT)
240 ncp->nc_flag |= NCF_WHITEOUT;
241 cache_setvp(nch, NULL);
248 * vop_compat_nlookupdotdot { struct vnode *a_dvp,
249 * struct vnode **a_vpp,
250 * struct ucred *a_cred }
252 * Lookup the vnode representing the parent directory of the specified
253 * directory vnode. a_dvp should not be locked. If no error occurs *a_vpp
254 * will contained the parent vnode, locked and refd, else *a_vpp will be NULL.
256 * This function is designed to aid NFS server-side operations and is
257 * used by cache_fromdvp() to create a consistent, connected namecache
260 * As part of the NEW API work, VFSs will first split their CNP_ISDOTDOT
261 * code out from their *_lookup() and create *_nlookupdotdot(). Then as time
262 * permits VFSs will implement the remaining *_n*() calls and finally get
263 * rid of their *_lookup() call.
266 vop_compat_nlookupdotdot(struct vop_nlookupdotdot_args *ap)
268 struct componentname cnp;
272 * UFS currently stores all sorts of side effects, including a loop
273 * variable, in the directory inode. That needs to be fixed and the
274 * other VFS's audited before we can switch to LK_SHARED.
277 if ((error = vget(ap->a_dvp, LK_EXCLUSIVE)) != 0)
279 if (ap->a_dvp->v_type != VDIR) {
284 bzero(&cnp, sizeof(cnp));
285 cnp.cn_nameiop = NAMEI_LOOKUP;
286 cnp.cn_flags = CNP_ISDOTDOT;
287 cnp.cn_nameptr = "..";
289 cnp.cn_cred = ap->a_cred;
290 cnp.cn_td = curthread; /* XXX */
293 * vop_old_lookup() always returns vp locked. dvp may or may not be
294 * left locked depending on CNP_PDIRUNLOCK.
296 * (*vpp) will be returned locked if no error occured, which is the
299 error = vop_old_lookup(ap->a_head.a_ops, ap->a_dvp, ap->a_vpp, &cnp);
300 if (cnp.cn_flags & CNP_PDIRUNLOCK)
308 * vop_compat_ncreate { struct nchandle *a_nch, XXX STOPGAP FUNCTION
309 * struct vnode *a_dvp,
310 * struct vnode **a_vpp,
311 * struct ucred *a_cred,
312 * struct vattr *a_vap }
314 * Create a file as specified by a_vap. Compatibility requires us to issue
315 * the appropriate VOP_OLD_LOOKUP before we issue VOP_OLD_CREATE in order
316 * to setup the directory inode's i_offset and i_count (e.g. in UFS).
319 vop_compat_ncreate(struct vop_ncreate_args *ap)
321 struct thread *td = curthread;
322 struct componentname cnp;
323 struct nchandle *nch;
324 struct namecache *ncp;
329 * Sanity checks, get a locked directory vnode.
331 nch = ap->a_nch; /* locked namecache node */
335 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
336 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
342 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
343 * caches all information required to create the entry in the
344 * directory inode. We expect a return code of EJUSTRETURN for
345 * the CREATE case. The cnp must simulated a saved-name situation.
347 bzero(&cnp, sizeof(cnp));
348 cnp.cn_nameiop = NAMEI_CREATE;
349 cnp.cn_flags = CNP_LOCKPARENT;
350 cnp.cn_nameptr = ncp->nc_name;
351 cnp.cn_namelen = ncp->nc_nlen;
352 cnp.cn_cred = ap->a_cred;
356 error = vop_old_lookup(ap->a_head.a_ops, dvp, ap->a_vpp, &cnp);
359 * EJUSTRETURN should be returned for this case, which means that
360 * the VFS has setup the directory inode for the create. The dvp we
361 * passed in is expected to remain in a locked state.
363 * If the VOP_OLD_CREATE is successful we are responsible for updating
364 * the cache state of the locked ncp that was passed to us.
366 if (error == EJUSTRETURN) {
367 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
368 error = VOP_OLD_CREATE(dvp, ap->a_vpp, &cnp, ap->a_vap);
370 cache_setunresolved(nch);
371 cache_setvp(nch, *ap->a_vpp);
379 KKASSERT(*ap->a_vpp == NULL);
381 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
388 * vop_compat_nmkdir { struct nchandle *a_nch, XXX STOPGAP FUNCTION
389 * struct vnode *a_dvp,
390 * struct vnode **a_vpp,
391 * struct ucred *a_cred,
392 * struct vattr *a_vap }
394 * Create a directory as specified by a_vap. Compatibility requires us to
395 * issue the appropriate VOP_OLD_LOOKUP before we issue VOP_OLD_MKDIR in
396 * order to setup the directory inode's i_offset and i_count (e.g. in UFS).
399 vop_compat_nmkdir(struct vop_nmkdir_args *ap)
401 struct thread *td = curthread;
402 struct componentname cnp;
403 struct nchandle *nch;
404 struct namecache *ncp;
409 * Sanity checks, get a locked directory vnode.
411 nch = ap->a_nch; /* locked namecache node */
414 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
415 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
421 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
422 * caches all information required to create the entry in the
423 * directory inode. We expect a return code of EJUSTRETURN for
424 * the CREATE case. The cnp must simulated a saved-name situation.
426 bzero(&cnp, sizeof(cnp));
427 cnp.cn_nameiop = NAMEI_CREATE;
428 cnp.cn_flags = CNP_LOCKPARENT;
429 cnp.cn_nameptr = ncp->nc_name;
430 cnp.cn_namelen = ncp->nc_nlen;
431 cnp.cn_cred = ap->a_cred;
435 error = vop_old_lookup(ap->a_head.a_ops, dvp, ap->a_vpp, &cnp);
438 * EJUSTRETURN should be returned for this case, which means that
439 * the VFS has setup the directory inode for the create. The dvp we
440 * passed in is expected to remain in a locked state.
442 * If the VOP_OLD_MKDIR is successful we are responsible for updating
443 * the cache state of the locked ncp that was passed to us.
445 if (error == EJUSTRETURN) {
446 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
447 error = VOP_OLD_MKDIR(dvp, ap->a_vpp, &cnp, ap->a_vap);
449 cache_setunresolved(nch);
450 cache_setvp(nch, *ap->a_vpp);
458 KKASSERT(*ap->a_vpp == NULL);
460 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
467 * vop_compat_nmknod { struct nchandle *a_nch, XXX STOPGAP FUNCTION
468 * struct vnode *a_dvp,
469 * struct vnode **a_vpp,
470 * struct ucred *a_cred,
471 * struct vattr *a_vap }
473 * Create a device or fifo node as specified by a_vap. Compatibility requires
474 * us to issue the appropriate VOP_OLD_LOOKUP before we issue VOP_OLD_MKNOD
475 * in order to setup the directory inode's i_offset and i_count (e.g. in UFS).
478 vop_compat_nmknod(struct vop_nmknod_args *ap)
480 struct thread *td = curthread;
481 struct componentname cnp;
482 struct nchandle *nch;
483 struct namecache *ncp;
488 * Sanity checks, get a locked directory vnode.
490 nch = ap->a_nch; /* locked namecache node */
494 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
495 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
501 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
502 * caches all information required to create the entry in the
503 * directory inode. We expect a return code of EJUSTRETURN for
504 * the CREATE case. The cnp must simulated a saved-name situation.
506 bzero(&cnp, sizeof(cnp));
507 cnp.cn_nameiop = NAMEI_CREATE;
508 cnp.cn_flags = CNP_LOCKPARENT;
509 cnp.cn_nameptr = ncp->nc_name;
510 cnp.cn_namelen = ncp->nc_nlen;
511 cnp.cn_cred = ap->a_cred;
515 error = vop_old_lookup(ap->a_head.a_ops, dvp, ap->a_vpp, &cnp);
518 * EJUSTRETURN should be returned for this case, which means that
519 * the VFS has setup the directory inode for the create. The dvp we
520 * passed in is expected to remain in a locked state.
522 * If the VOP_OLD_MKNOD is successful we are responsible for updating
523 * the cache state of the locked ncp that was passed to us.
525 if (error == EJUSTRETURN) {
526 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
527 error = VOP_OLD_MKNOD(dvp, ap->a_vpp, &cnp, ap->a_vap);
529 cache_setunresolved(nch);
530 cache_setvp(nch, *ap->a_vpp);
538 KKASSERT(*ap->a_vpp == NULL);
540 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
547 * vop_compat_nlink { struct nchandle *a_nch, XXX STOPGAP FUNCTION
548 * struct vnode *a_dvp,
549 * struct vnode *a_vp,
550 * struct ucred *a_cred }
552 * The passed vp is locked and represents the source. The passed ncp is
553 * locked and represents the target to create.
556 vop_compat_nlink(struct vop_nlink_args *ap)
558 struct thread *td = curthread;
559 struct componentname cnp;
560 struct nchandle *nch;
561 struct namecache *ncp;
567 * Sanity checks, get a locked directory vnode.
569 nch = ap->a_nch; /* locked namecache node */
573 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
574 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
580 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
581 * caches all information required to create the entry in the
582 * directory inode. We expect a return code of EJUSTRETURN for
583 * the CREATE case. The cnp must simulated a saved-name situation.
585 bzero(&cnp, sizeof(cnp));
586 cnp.cn_nameiop = NAMEI_CREATE;
587 cnp.cn_flags = CNP_LOCKPARENT;
588 cnp.cn_nameptr = ncp->nc_name;
589 cnp.cn_namelen = ncp->nc_nlen;
590 cnp.cn_cred = ap->a_cred;
594 error = vop_old_lookup(ap->a_head.a_ops, dvp, &tvp, &cnp);
597 * EJUSTRETURN should be returned for this case, which means that
598 * the VFS has setup the directory inode for the create. The dvp we
599 * passed in is expected to remain in a locked state.
601 * If the VOP_OLD_LINK is successful we are responsible for updating
602 * the cache state of the locked ncp that was passed to us.
604 if (error == EJUSTRETURN) {
605 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
606 error = VOP_OLD_LINK(dvp, ap->a_vp, &cnp);
608 cache_setunresolved(nch);
609 cache_setvp(nch, ap->a_vp);
617 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
624 vop_compat_nsymlink(struct vop_nsymlink_args *ap)
626 struct thread *td = curthread;
627 struct componentname cnp;
628 struct nchandle *nch;
629 struct namecache *ncp;
635 * Sanity checks, get a locked directory vnode.
638 nch = ap->a_nch; /* locked namecache node */
642 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
643 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
649 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
650 * caches all information required to create the entry in the
651 * directory inode. We expect a return code of EJUSTRETURN for
652 * the CREATE case. The cnp must simulated a saved-name situation.
654 bzero(&cnp, sizeof(cnp));
655 cnp.cn_nameiop = NAMEI_CREATE;
656 cnp.cn_flags = CNP_LOCKPARENT;
657 cnp.cn_nameptr = ncp->nc_name;
658 cnp.cn_namelen = ncp->nc_nlen;
659 cnp.cn_cred = ap->a_cred;
663 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
666 * EJUSTRETURN should be returned for this case, which means that
667 * the VFS has setup the directory inode for the create. The dvp we
668 * passed in is expected to remain in a locked state.
670 * If the VOP_OLD_SYMLINK is successful we are responsible for updating
671 * the cache state of the locked ncp that was passed to us.
673 if (error == EJUSTRETURN) {
674 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
675 error = VOP_OLD_SYMLINK(dvp, &vp, &cnp, ap->a_vap, ap->a_target);
677 cache_setunresolved(nch);
678 cache_setvp(nch, vp);
687 KKASSERT(vp == NULL);
689 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
696 * vop_compat_nwhiteout { struct nchandle *a_nch, XXX STOPGAP FUNCTION
697 * struct vnode *a_dvp,
698 * struct ucred *a_cred,
701 * Issie a whiteout operation (create, lookup, or delete). Compatibility
702 * requires us to issue the appropriate VOP_OLD_LOOKUP before we issue
703 * VOP_OLD_WHITEOUT in order to setup the directory inode's i_offset and i_count
704 * (e.g. in UFS) for the NAMEI_CREATE and NAMEI_DELETE ops. For NAMEI_LOOKUP
705 * no lookup is necessary.
708 vop_compat_nwhiteout(struct vop_nwhiteout_args *ap)
710 struct thread *td = curthread;
711 struct componentname cnp;
712 struct nchandle *nch;
713 struct namecache *ncp;
719 * Sanity checks, get a locked directory vnode.
721 nch = ap->a_nch; /* locked namecache node */
725 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
726 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
732 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
733 * caches all information required to create the entry in the
734 * directory inode. We expect a return code of EJUSTRETURN for
735 * the CREATE case. The cnp must simulated a saved-name situation.
737 bzero(&cnp, sizeof(cnp));
738 cnp.cn_nameiop = ap->a_flags;
739 cnp.cn_flags = CNP_LOCKPARENT;
740 cnp.cn_nameptr = ncp->nc_name;
741 cnp.cn_namelen = ncp->nc_nlen;
742 cnp.cn_cred = ap->a_cred;
748 * EJUSTRETURN should be returned for the CREATE or DELETE cases.
749 * The VFS has setup the directory inode for the create. The dvp we
750 * passed in is expected to remain in a locked state.
752 * If the VOP_OLD_WHITEOUT is successful we are responsible for updating
753 * the cache state of the locked ncp that was passed to us.
755 switch(ap->a_flags) {
757 cnp.cn_flags |= CNP_DOWHITEOUT;
760 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
761 if (error == EJUSTRETURN) {
762 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
763 error = VOP_OLD_WHITEOUT(dvp, &cnp, ap->a_flags);
765 cache_setunresolved(nch);
772 KKASSERT(vp == NULL);
776 error = VOP_OLD_WHITEOUT(dvp, NULL, ap->a_flags);
782 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
790 * vop_compat_nremove { struct nchandle *a_nch, XXX STOPGAP FUNCTION
791 * struct vnode *a_dvp,
792 * struct ucred *a_cred }
795 vop_compat_nremove(struct vop_nremove_args *ap)
797 struct thread *td = curthread;
798 struct componentname cnp;
799 struct nchandle *nch;
800 struct namecache *ncp;
806 * Sanity checks, get a locked directory vnode.
808 nch = ap->a_nch; /* locked namecache node */
812 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
813 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
819 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
820 * caches all information required to delete the entry in the
821 * directory inode. We expect a return code of 0 for the DELETE
822 * case (meaning that a vp has been found). The cnp must simulated
823 * a saved-name situation.
825 bzero(&cnp, sizeof(cnp));
826 cnp.cn_nameiop = NAMEI_DELETE;
827 cnp.cn_flags = CNP_LOCKPARENT;
828 cnp.cn_nameptr = ncp->nc_name;
829 cnp.cn_namelen = ncp->nc_nlen;
830 cnp.cn_cred = ap->a_cred;
834 * The vnode must be a directory and must not represent the
838 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
839 if (error == 0 && vp->v_type == VDIR)
842 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
843 error = VOP_OLD_REMOVE(dvp, vp, &cnp);
845 cache_setunresolved(nch);
846 cache_setvp(nch, NULL);
847 cache_inval_vp(vp, CINV_DESTROY);
856 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
863 * vop_compat_nrmdir { struct nchandle *a_nch, XXX STOPGAP FUNCTION
865 * struct ucred *a_cred }
868 vop_compat_nrmdir(struct vop_nrmdir_args *ap)
870 struct thread *td = curthread;
871 struct componentname cnp;
872 struct nchandle *nch;
873 struct namecache *ncp;
879 * Sanity checks, get a locked directory vnode.
881 nch = ap->a_nch; /* locked namecache node */
885 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
886 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
892 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
893 * caches all information required to delete the entry in the
894 * directory inode. We expect a return code of 0 for the DELETE
895 * case (meaning that a vp has been found). The cnp must simulated
896 * a saved-name situation.
898 bzero(&cnp, sizeof(cnp));
899 cnp.cn_nameiop = NAMEI_DELETE;
900 cnp.cn_flags = CNP_LOCKPARENT;
901 cnp.cn_nameptr = ncp->nc_name;
902 cnp.cn_namelen = ncp->nc_nlen;
903 cnp.cn_cred = ap->a_cred;
907 * The vnode must be a directory and must not represent the
911 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
912 if (error == 0 && vp->v_type != VDIR)
914 if (error == 0 && vp == dvp)
916 if (error == 0 && (vp->v_flag & VROOT))
919 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
920 error = VOP_OLD_RMDIR(dvp, vp, &cnp);
923 * Note that this invalidation will cause any process
924 * currently CD'd into the directory being removed to be
925 * disconnected from the topology and not be able to ".."
929 cache_inval(nch, CINV_DESTROY);
930 cache_inval_vp(vp, CINV_DESTROY);
939 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
946 * vop_compat_nrename { struct nchandle *a_fnch, XXX STOPGAP FUNCTION
947 * struct nchandle *a_tnch,
948 * struct ucred *a_cred }
950 * This is a fairly difficult procedure. The old VOP_OLD_RENAME requires that
951 * the source directory and vnode be unlocked and the target directory and
952 * vnode (if it exists) be locked. All arguments will be vrele'd and
953 * the targets will also be unlocked regardless of the return code.
956 vop_compat_nrename(struct vop_nrename_args *ap)
958 struct thread *td = curthread;
959 struct componentname fcnp;
960 struct componentname tcnp;
961 struct nchandle *fnch;
962 struct nchandle *tnch;
963 struct namecache *fncp;
964 struct namecache *tncp;
965 struct vnode *fdvp, *fvp;
966 struct vnode *tdvp, *tvp;
970 * Sanity checks, get referenced vnodes representing the source.
972 fnch = ap->a_fnch; /* locked namecache node */
977 * Temporarily lock the source directory and lookup in DELETE mode to
978 * check permissions. XXX delete permissions should have been
979 * checked by nlookup(), we need to add NLC_DELETE for delete
980 * checking. It is unclear whether VFS's require the directory setup
981 * info NAMEI_DELETE causes to be stored in the fdvp's inode, but
982 * since it isn't locked and since UFS always does a relookup of
983 * the source, it is believed that the only side effect that matters
984 * is the permissions check.
986 if ((error = vget(fdvp, LK_EXCLUSIVE)) != 0) {
987 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
988 fncp, fncp->nc_name);
992 bzero(&fcnp, sizeof(fcnp));
993 fcnp.cn_nameiop = NAMEI_DELETE;
994 fcnp.cn_flags = CNP_LOCKPARENT;
995 fcnp.cn_nameptr = fncp->nc_name;
996 fcnp.cn_namelen = fncp->nc_nlen;
997 fcnp.cn_cred = ap->a_cred;
1001 * note: vop_old_lookup (i.e. VOP_OLD_LOOKUP) always returns a locked
1005 error = vop_old_lookup(ap->a_head.a_ops, fdvp, &fvp, &fcnp);
1006 if (error == 0 && (fvp->v_flag & VROOT)) {
1007 vput(fvp); /* as if vop_old_lookup had failed */
1010 if ((fcnp.cn_flags & CNP_PDIRUNLOCK) == 0) {
1011 fcnp.cn_flags |= CNP_PDIRUNLOCK;
1021 * fdvp and fvp are now referenced and unlocked.
1023 * Get a locked directory vnode for the target and lookup the target
1024 * in CREATE mode so it places the required information in the
1027 tnch = ap->a_tnch; /* locked namecache node */
1035 if ((error = vget(tdvp, LK_EXCLUSIVE)) != 0) {
1036 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
1037 tncp, tncp->nc_name);
1044 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
1045 * caches all information required to create the entry in the
1046 * target directory inode.
1048 bzero(&tcnp, sizeof(tcnp));
1049 tcnp.cn_nameiop = NAMEI_RENAME;
1050 tcnp.cn_flags = CNP_LOCKPARENT;
1051 tcnp.cn_nameptr = tncp->nc_name;
1052 tcnp.cn_namelen = tncp->nc_nlen;
1053 tcnp.cn_cred = ap->a_cred;
1057 error = vop_old_lookup(ap->a_head.a_ops, tdvp, &tvp, &tcnp);
1059 if (error == EJUSTRETURN) {
1061 * Target does not exist. tvp should be NULL.
1063 KKASSERT(tvp == NULL);
1064 KKASSERT((tcnp.cn_flags & CNP_PDIRUNLOCK) == 0);
1065 error = VOP_OLD_RENAME(fdvp, fvp, &fcnp, tdvp, tvp, &tcnp);
1067 cache_rename(fnch, tnch);
1068 } else if (error == 0) {
1070 * Target exists. VOP_OLD_RENAME should correctly delete the
1073 KKASSERT((tcnp.cn_flags & CNP_PDIRUNLOCK) == 0);
1074 error = VOP_OLD_RENAME(fdvp, fvp, &fcnp, tdvp, tvp, &tcnp);
1076 cache_rename(fnch, tnch);
1080 if (tcnp.cn_flags & CNP_PDIRUNLOCK)
1089 vop_nolookup(struct vop_old_lookup_args *ap)
1099 * Strategy routine for VFS devices that have none.
1101 * B_ERROR and B_INVAL must be cleared prior to calling any strategy
1102 * routine. Typically this is done for a BUF_CMD_READ strategy call.
1103 * Typically B_INVAL is assumed to already be clear prior to a write
1104 * and should not be cleared manually unless you just made the buffer
1105 * invalid. B_ERROR should be cleared either way.
1109 vop_nostrategy (struct vop_strategy_args *ap)
1111 kprintf("No strategy for buffer at %p\n", ap->a_bio->bio_buf);
1112 vprint("", ap->a_vp);
1113 ap->a_bio->bio_buf->b_flags |= B_ERROR;
1114 ap->a_bio->bio_buf->b_error = EOPNOTSUPP;
1116 return (EOPNOTSUPP);
1120 vop_stdpathconf(struct vop_pathconf_args *ap)
1124 switch (ap->a_name) {
1126 *ap->a_retval = LINK_MAX;
1129 *ap->a_retval = NAME_MAX;
1132 *ap->a_retval = PATH_MAX;
1135 *ap->a_retval = MAX_CANON;
1138 *ap->a_retval = MAX_INPUT;
1141 *ap->a_retval = PIPE_BUF;
1143 case _PC_CHOWN_RESTRICTED:
1150 *ap->a_retval = _POSIX_VDISABLE;
1162 * (struct vnode *a_vp, int a_mode, struct ucred *a_ucred, struct file *a_fp)
1164 * a_mode: note, 'F' modes, e.g. FREAD, FWRITE
1167 vop_stdopen(struct vop_open_args *ap)
1169 struct vnode *vp = ap->a_vp;
1172 if ((fp = ap->a_fp) != NULL) {
1173 switch(vp->v_type) {
1175 fp->f_type = DTYPE_FIFO;
1178 fp->f_type = DTYPE_VNODE;
1181 fp->f_flag = ap->a_mode & FMASK;
1182 fp->f_ops = &vnode_fileops;
1186 if (ap->a_mode & FWRITE)
1188 KKASSERT(vp->v_opencount >= 0 && vp->v_opencount != INT_MAX);
1196 * (struct vnode *a_vp, int a_fflag)
1198 * a_fflag: note, 'F' modes, e.g. FREAD, FWRITE. same as a_mode in stdopen?
1201 vop_stdclose(struct vop_close_args *ap)
1203 struct vnode *vp = ap->a_vp;
1205 KASSERT(vp->v_opencount > 0,
1206 ("VOP_STDCLOSE: BAD OPENCOUNT %p %d type=%d ops=%p flgs=%08x\n",
1207 vp, vp->v_opencount, vp->v_type, *vp->v_ops, vp->v_flag));
1208 if (ap->a_fflag & FWRITE) {
1209 KASSERT(vp->v_writecount > 0,
1210 ("VOP_STDCLOSE: BAD WRITECOUNT %p %d\n",
1211 vp, vp->v_writecount));
1219 * Implement standard getpages and putpages. All filesystems must use
1220 * the buffer cache to back regular files.
1223 vop_stdgetpages(struct vop_getpages_args *ap)
1228 if ((mp = ap->a_vp->v_mount) != NULL) {
1229 error = vnode_pager_generic_getpages(
1230 ap->a_vp, ap->a_m, ap->a_count,
1231 ap->a_reqpage, ap->a_seqaccess);
1233 error = VM_PAGER_BAD;
1239 vop_stdputpages(struct vop_putpages_args *ap)
1244 if ((mp = ap->a_vp->v_mount) != NULL) {
1245 error = vnode_pager_generic_putpages(
1246 ap->a_vp, ap->a_m, ap->a_count,
1247 ap->a_sync, ap->a_rtvals);
1249 error = VM_PAGER_BAD;
1255 vop_stdnoread(struct vop_read_args *ap)
1261 vop_stdnowrite(struct vop_write_args *ap)
1268 * used to fill the vfs fucntion table to get reasonable default return values.
1271 vfs_stdmount(struct mount *mp, char *path, caddr_t data, struct ucred *cred)
1277 vfs_stdunmount(struct mount *mp, int mntflags)
1283 vop_stdmountctl(struct vop_mountctl_args *ap)
1289 mp = ap->a_head.a_ops->head.vv_mount;
1292 case MOUNTCTL_MOUNTFLAGS:
1294 * Get a string buffer with all the mount flags
1295 * names comman separated.
1296 * mount(2) will use this information.
1298 *ap->a_res = vfs_flagstostr(mp->mnt_flag & MNT_VISFLAGMASK, NULL,
1299 ap->a_buf, ap->a_buflen, &error);
1301 case MOUNTCTL_INSTALL_VFS_JOURNAL:
1302 case MOUNTCTL_RESTART_VFS_JOURNAL:
1303 case MOUNTCTL_REMOVE_VFS_JOURNAL:
1304 case MOUNTCTL_RESYNC_VFS_JOURNAL:
1305 case MOUNTCTL_STATUS_VFS_JOURNAL:
1306 error = journal_mountctl(ap);
1316 vfs_stdroot(struct mount *mp, struct vnode **vpp)
1318 return (EOPNOTSUPP);
1322 vfs_stdstatfs(struct mount *mp, struct statfs *sbp, struct ucred *cred)
1324 return (EOPNOTSUPP);
1328 * If the VFS does not implement statvfs, then call statfs and convert
1329 * the values. This code was taken from libc's __cvtstatvfs() function,
1330 * contributed by Joerg Sonnenberger.
1333 vfs_stdstatvfs(struct mount *mp, struct statvfs *sbp, struct ucred *cred)
1339 error = VFS_STATFS(mp, in, cred);
1341 bzero(sbp, sizeof(*sbp));
1343 sbp->f_bsize = in->f_bsize;
1344 sbp->f_frsize = in->f_bsize;
1345 sbp->f_blocks = in->f_blocks;
1346 sbp->f_bfree = in->f_bfree;
1347 sbp->f_bavail = in->f_bavail;
1348 sbp->f_files = in->f_files;
1349 sbp->f_ffree = in->f_ffree;
1353 * This field counts the number of available inodes to non-root
1354 * users, but this information is not available via statfs.
1355 * Just ignore this issue by returning the total number
1358 sbp->f_favail = in->f_ffree;
1362 * This field has a different meaning for statfs and statvfs.
1363 * For the former it is the cookie exported for NFS and not
1364 * intended for normal userland use.
1369 if (in->f_flags & MNT_RDONLY)
1370 sbp->f_flag |= ST_RDONLY;
1371 if (in->f_flags & MNT_NOSUID)
1372 sbp->f_flag |= ST_NOSUID;
1374 sbp->f_owner = in->f_owner;
1377 * statfs contains the type as string, statvfs expects it as
1382 sbp->f_syncreads = in->f_syncreads;
1383 sbp->f_syncwrites = in->f_syncwrites;
1384 sbp->f_asyncreads = in->f_asyncreads;
1385 sbp->f_asyncwrites = in->f_asyncwrites;
1391 vfs_stdvptofh(struct vnode *vp, struct fid *fhp)
1393 return (EOPNOTSUPP);
1397 vfs_stdstart(struct mount *mp, int flags)
1403 vfs_stdquotactl(struct mount *mp, int cmds, uid_t uid,
1404 caddr_t arg, struct ucred *cred)
1406 return (EOPNOTSUPP);
1410 vfs_stdsync(struct mount *mp, int waitfor)
1416 vfs_stdnosync(struct mount *mp, int waitfor)
1418 return (EOPNOTSUPP);
1422 vfs_stdvget(struct mount *mp, struct vnode *dvp, ino_t ino, struct vnode **vpp)
1424 return (EOPNOTSUPP);
1428 vfs_stdfhtovp(struct mount *mp, struct vnode *rootvp,
1429 struct fid *fhp, struct vnode **vpp)
1431 return (EOPNOTSUPP);
1435 vfs_stdcheckexp(struct mount *mp, struct sockaddr *nam, int *extflagsp,
1436 struct ucred **credanonp)
1438 return (EOPNOTSUPP);
1442 vfs_stdinit(struct vfsconf *vfsp)
1448 vfs_stduninit(struct vfsconf *vfsp)
1454 vfs_stdextattrctl(struct mount *mp, int cmd, struct vnode *vp,
1455 int attrnamespace, const char *attrname,
1461 #define ACCOUNTING_NB_FSTYPES 8
1463 static const char *accounting_fstypes[ACCOUNTING_NB_FSTYPES] = {
1464 "ext2fs", "hammer", "hpfs", "mfs", "ntfs", "null", "tmpfs", "ufs" };
1467 vfs_stdac_init(struct mount *mp)
1469 const char* fs_type;
1470 int i, fstype_ok = 0;
1472 /* is mounted fs type one we want to do some accounting for ? */
1473 for (i=0; i<ACCOUNTING_NB_FSTYPES; i++) {
1474 fs_type = accounting_fstypes[i];
1475 if (strncmp(mp->mnt_stat.f_fstypename, fs_type,
1476 sizeof(mp->mnt_stat)) == 0) {
1489 vfs_stdac_done(struct mount *mp)
1491 const char* fs_type;
1492 int i, fstype_ok = 0;
1494 /* is mounted fs type one we want to do some accounting for ? */
1495 for (i=0; i<ACCOUNTING_NB_FSTYPES; i++) {
1496 fs_type = accounting_fstypes[i];
1497 if (strncmp(mp->mnt_stat.f_fstypename, fs_type,
1498 sizeof(mp->mnt_stat)) == 0) {
1511 vfs_stdncpgen_set(struct mount *mp, struct namecache *ncp)
1516 vfs_stdncpgen_test(struct mount *mp, struct namecache *ncp)
1520 /* end of vfs default ops */