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. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * Source: * @(#)i405_init.c 2.10 92/04/27 UCLA Ficus project
36 * $FreeBSD: src/sys/kern/vfs_default.c,v 1.28.2.7 2003/01/10 18:23:26 bde Exp $
39 #include <sys/param.h>
40 #include <sys/systm.h>
43 #include <sys/fcntl.h>
45 #include <sys/kernel.h>
47 #include <sys/malloc.h>
48 #include <sys/mount.h>
49 #include <sys/unistd.h>
50 #include <sys/vnode.h>
51 #include <sys/namei.h>
52 #include <sys/mountctl.h>
53 #include <sys/vfs_quota.h>
55 #include <machine/limits.h>
58 #include <vm/vm_object.h>
59 #include <vm/vm_page.h>
60 #include <vm/vm_pager.h>
61 #include <vm/vnode_pager.h>
63 static int vop_nolookup (struct vop_old_lookup_args *);
64 static int vop_nostrategy (struct vop_strategy_args *);
67 * This vnode table stores what we want to do if the filesystem doesn't
68 * implement a particular VOP.
70 * If there is no specific entry here, we will return EOPNOTSUPP.
72 struct vop_ops default_vnode_vops = {
73 .vop_default = vop_eopnotsupp,
74 .vop_advlock = (void *)vop_einval,
75 .vop_fsync = (void *)vop_null,
76 .vop_ioctl = (void *)vop_enotty,
77 .vop_mmap = (void *)vop_einval,
78 .vop_old_lookup = vop_nolookup,
79 .vop_open = vop_stdopen,
80 .vop_close = vop_stdclose,
81 .vop_getattr_quick = vop_stdgetattr_quick,
82 .vop_pathconf = vop_stdpathconf,
83 .vop_readlink = (void *)vop_einval,
84 .vop_reallocblks = (void *)vop_eopnotsupp,
85 .vop_strategy = vop_nostrategy,
86 .vop_getacl = (void *)vop_eopnotsupp,
87 .vop_setacl = (void *)vop_eopnotsupp,
88 .vop_aclcheck = (void *)vop_eopnotsupp,
89 .vop_getextattr = (void *)vop_eopnotsupp,
90 .vop_setextattr = (void *)vop_eopnotsupp,
91 .vop_markatime = vop_stdmarkatime,
92 .vop_nresolve = vop_compat_nresolve,
93 .vop_nlookupdotdot = vop_compat_nlookupdotdot,
94 .vop_ncreate = vop_compat_ncreate,
95 .vop_nmkdir = vop_compat_nmkdir,
96 .vop_nmknod = vop_compat_nmknod,
97 .vop_nlink = vop_compat_nlink,
98 .vop_nsymlink = vop_compat_nsymlink,
99 .vop_nwhiteout = vop_compat_nwhiteout,
100 .vop_nremove = vop_compat_nremove,
101 .vop_nrmdir = vop_compat_nrmdir,
102 .vop_nrename = vop_compat_nrename,
103 .vop_mountctl = vop_stdmountctl
106 VNODEOP_SET(default_vnode_vops);
109 vop_eopnotsupp(struct vop_generic_args *ap)
115 vop_ebadf(struct vop_generic_args *ap)
121 vop_enotty(struct vop_generic_args *ap)
127 vop_einval(struct vop_generic_args *ap)
133 vop_stdmarkatime(struct vop_markatime_args *ap)
139 vop_null(struct vop_generic_args *ap)
145 vop_defaultop(struct vop_generic_args *ap)
147 return (VOCALL(&default_vnode_vops, ap));
151 * vop_compat_resolve { struct nchandle *a_nch, struct vnode *dvp }
152 * XXX STOPGAP FUNCTION
154 * XXX OLD API ROUTINE! WHEN ALL VFSs HAVE BEEN CLEANED UP THIS PROCEDURE
155 * WILL BE REMOVED. This procedure exists for all VFSs which have not
156 * yet implemented VOP_NRESOLVE(). It converts VOP_NRESOLVE() into a
157 * vop_old_lookup() and does appropriate translations.
159 * Resolve a ncp for VFSs which do not support the VOP. Eventually all
160 * VFSs will support this VOP and this routine can be removed, since
161 * VOP_NRESOLVE() is far less complex then the older LOOKUP/CACHEDLOOKUP
164 * A locked ncp is passed in to be resolved. The NCP is resolved by
165 * figuring out the vnode (if any) and calling cache_setvp() to attach the
166 * vnode to the entry. If the entry represents a non-existant node then
167 * cache_setvp() is called with a NULL vnode to resolve the entry into a
168 * negative cache entry. No vnode locks are retained and the
169 * ncp is left locked on return.
171 * The ncp will NEVER represent "", "." or "..", or contain any slashes.
173 * There is a potential directory and vnode interlock. The lock order
174 * requirement is: namecache, governing directory, resolved vnode.
177 vop_compat_nresolve(struct vop_nresolve_args *ap)
182 struct nchandle *nch;
183 struct namecache *ncp;
184 struct componentname cnp;
186 nch = ap->a_nch; /* locked namecache node */
191 * UFS currently stores all sorts of side effects, including a loop
192 * variable, in the directory inode. That needs to be fixed and the
193 * other VFS's audited before we can switch to LK_SHARED.
195 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
196 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
201 bzero(&cnp, sizeof(cnp));
202 cnp.cn_nameiop = NAMEI_LOOKUP;
204 cnp.cn_nameptr = ncp->nc_name;
205 cnp.cn_namelen = ncp->nc_nlen;
206 cnp.cn_cred = ap->a_cred;
207 cnp.cn_td = curthread; /* XXX */
210 * vop_old_lookup() always returns vp locked. dvp may or may not be
211 * left locked depending on CNP_PDIRUNLOCK.
213 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
216 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
218 if ((ncp->nc_flag & NCF_UNRESOLVED) == 0) {
219 /* was resolved by another process while we were unlocked */
222 } else if (error == 0) {
223 KKASSERT(vp != NULL);
224 cache_setvp(nch, vp);
226 } else if (error == ENOENT) {
227 KKASSERT(vp == NULL);
228 if (cnp.cn_flags & CNP_ISWHITEOUT)
229 ncp->nc_flag |= NCF_WHITEOUT;
230 cache_setvp(nch, NULL);
237 * vop_compat_nlookupdotdot { struct vnode *a_dvp,
238 * struct vnode **a_vpp,
239 * struct ucred *a_cred }
241 * Lookup the vnode representing the parent directory of the specified
242 * directory vnode. a_dvp should not be locked. If no error occurs *a_vpp
243 * will contained the parent vnode, locked and refd, else *a_vpp will be NULL.
245 * This function is designed to aid NFS server-side operations and is
246 * used by cache_fromdvp() to create a consistent, connected namecache
249 * As part of the NEW API work, VFSs will first split their CNP_ISDOTDOT
250 * code out from their *_lookup() and create *_nlookupdotdot(). Then as time
251 * permits VFSs will implement the remaining *_n*() calls and finally get
252 * rid of their *_lookup() call.
255 vop_compat_nlookupdotdot(struct vop_nlookupdotdot_args *ap)
257 struct componentname cnp;
261 * UFS currently stores all sorts of side effects, including a loop
262 * variable, in the directory inode. That needs to be fixed and the
263 * other VFS's audited before we can switch to LK_SHARED.
266 if ((error = vget(ap->a_dvp, LK_EXCLUSIVE)) != 0)
268 if (ap->a_dvp->v_type != VDIR) {
273 bzero(&cnp, sizeof(cnp));
274 cnp.cn_nameiop = NAMEI_LOOKUP;
275 cnp.cn_flags = CNP_ISDOTDOT;
276 cnp.cn_nameptr = "..";
278 cnp.cn_cred = ap->a_cred;
279 cnp.cn_td = curthread; /* XXX */
282 * vop_old_lookup() always returns vp locked. dvp may or may not be
283 * left locked depending on CNP_PDIRUNLOCK.
285 * (*vpp) will be returned locked if no error occured, which is the
288 error = vop_old_lookup(ap->a_head.a_ops, ap->a_dvp, ap->a_vpp, &cnp);
289 if (cnp.cn_flags & CNP_PDIRUNLOCK)
297 * vop_compat_ncreate { struct nchandle *a_nch, XXX STOPGAP FUNCTION
298 * struct vnode *a_dvp,
299 * struct vnode **a_vpp,
300 * struct ucred *a_cred,
301 * struct vattr *a_vap }
303 * Create a file as specified by a_vap. Compatibility requires us to issue
304 * the appropriate VOP_OLD_LOOKUP before we issue VOP_OLD_CREATE in order
305 * to setup the directory inode's i_offset and i_count (e.g. in UFS).
308 vop_compat_ncreate(struct vop_ncreate_args *ap)
310 struct thread *td = curthread;
311 struct componentname cnp;
312 struct nchandle *nch;
313 struct namecache *ncp;
318 * Sanity checks, get a locked directory vnode.
320 nch = ap->a_nch; /* locked namecache node */
324 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
325 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
331 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
332 * caches all information required to create the entry in the
333 * directory inode. We expect a return code of EJUSTRETURN for
334 * the CREATE case. The cnp must simulated a saved-name situation.
336 bzero(&cnp, sizeof(cnp));
337 cnp.cn_nameiop = NAMEI_CREATE;
338 cnp.cn_flags = CNP_LOCKPARENT;
339 cnp.cn_nameptr = ncp->nc_name;
340 cnp.cn_namelen = ncp->nc_nlen;
341 cnp.cn_cred = ap->a_cred;
345 error = vop_old_lookup(ap->a_head.a_ops, dvp, ap->a_vpp, &cnp);
348 * EJUSTRETURN should be returned for this case, which means that
349 * the VFS has setup the directory inode for the create. The dvp we
350 * passed in is expected to remain in a locked state.
352 * If the VOP_OLD_CREATE is successful we are responsible for updating
353 * the cache state of the locked ncp that was passed to us.
355 if (error == EJUSTRETURN) {
356 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
357 error = VOP_OLD_CREATE(dvp, ap->a_vpp, &cnp, ap->a_vap);
359 cache_setunresolved(nch);
360 cache_setvp(nch, *ap->a_vpp);
368 KKASSERT(*ap->a_vpp == NULL);
370 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
377 * vop_compat_nmkdir { struct nchandle *a_nch, XXX STOPGAP FUNCTION
378 * struct vnode *a_dvp,
379 * struct vnode **a_vpp,
380 * struct ucred *a_cred,
381 * struct vattr *a_vap }
383 * Create a directory as specified by a_vap. Compatibility requires us to
384 * issue the appropriate VOP_OLD_LOOKUP before we issue VOP_OLD_MKDIR in
385 * order to setup the directory inode's i_offset and i_count (e.g. in UFS).
388 vop_compat_nmkdir(struct vop_nmkdir_args *ap)
390 struct thread *td = curthread;
391 struct componentname cnp;
392 struct nchandle *nch;
393 struct namecache *ncp;
398 * Sanity checks, get a locked directory vnode.
400 nch = ap->a_nch; /* locked namecache node */
403 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
404 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
410 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
411 * caches all information required to create the entry in the
412 * directory inode. We expect a return code of EJUSTRETURN for
413 * the CREATE case. The cnp must simulated a saved-name situation.
415 bzero(&cnp, sizeof(cnp));
416 cnp.cn_nameiop = NAMEI_CREATE;
417 cnp.cn_flags = CNP_LOCKPARENT;
418 cnp.cn_nameptr = ncp->nc_name;
419 cnp.cn_namelen = ncp->nc_nlen;
420 cnp.cn_cred = ap->a_cred;
424 error = vop_old_lookup(ap->a_head.a_ops, dvp, ap->a_vpp, &cnp);
427 * EJUSTRETURN should be returned for this case, which means that
428 * the VFS has setup the directory inode for the create. The dvp we
429 * passed in is expected to remain in a locked state.
431 * If the VOP_OLD_MKDIR is successful we are responsible for updating
432 * the cache state of the locked ncp that was passed to us.
434 if (error == EJUSTRETURN) {
435 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
436 error = VOP_OLD_MKDIR(dvp, ap->a_vpp, &cnp, ap->a_vap);
438 cache_setunresolved(nch);
439 cache_setvp(nch, *ap->a_vpp);
447 KKASSERT(*ap->a_vpp == NULL);
449 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
456 * vop_compat_nmknod { struct nchandle *a_nch, XXX STOPGAP FUNCTION
457 * struct vnode *a_dvp,
458 * struct vnode **a_vpp,
459 * struct ucred *a_cred,
460 * struct vattr *a_vap }
462 * Create a device or fifo node as specified by a_vap. Compatibility requires
463 * us to issue the appropriate VOP_OLD_LOOKUP before we issue VOP_OLD_MKNOD
464 * in order to setup the directory inode's i_offset and i_count (e.g. in UFS).
467 vop_compat_nmknod(struct vop_nmknod_args *ap)
469 struct thread *td = curthread;
470 struct componentname cnp;
471 struct nchandle *nch;
472 struct namecache *ncp;
477 * Sanity checks, get a locked directory vnode.
479 nch = ap->a_nch; /* locked namecache node */
483 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
484 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
490 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
491 * caches all information required to create the entry in the
492 * directory inode. We expect a return code of EJUSTRETURN for
493 * the CREATE case. The cnp must simulated a saved-name situation.
495 bzero(&cnp, sizeof(cnp));
496 cnp.cn_nameiop = NAMEI_CREATE;
497 cnp.cn_flags = CNP_LOCKPARENT;
498 cnp.cn_nameptr = ncp->nc_name;
499 cnp.cn_namelen = ncp->nc_nlen;
500 cnp.cn_cred = ap->a_cred;
504 error = vop_old_lookup(ap->a_head.a_ops, dvp, ap->a_vpp, &cnp);
507 * EJUSTRETURN should be returned for this case, which means that
508 * the VFS has setup the directory inode for the create. The dvp we
509 * passed in is expected to remain in a locked state.
511 * If the VOP_OLD_MKNOD is successful we are responsible for updating
512 * the cache state of the locked ncp that was passed to us.
514 if (error == EJUSTRETURN) {
515 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
516 error = VOP_OLD_MKNOD(dvp, ap->a_vpp, &cnp, ap->a_vap);
518 cache_setunresolved(nch);
519 cache_setvp(nch, *ap->a_vpp);
527 KKASSERT(*ap->a_vpp == NULL);
529 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
536 * vop_compat_nlink { struct nchandle *a_nch, XXX STOPGAP FUNCTION
537 * struct vnode *a_dvp,
538 * struct vnode *a_vp,
539 * struct ucred *a_cred }
541 * The passed vp is locked and represents the source. The passed ncp is
542 * locked and represents the target to create.
545 vop_compat_nlink(struct vop_nlink_args *ap)
547 struct thread *td = curthread;
548 struct componentname cnp;
549 struct nchandle *nch;
550 struct namecache *ncp;
556 * Sanity checks, get a locked directory vnode.
558 nch = ap->a_nch; /* locked namecache node */
562 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
563 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
569 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
570 * caches all information required to create the entry in the
571 * directory inode. We expect a return code of EJUSTRETURN for
572 * the CREATE case. The cnp must simulated a saved-name situation.
574 * It should not be possible for there to be a vnode collision
575 * between the source vp and target (name lookup). However NFS
576 * clients racing each other can cause NFS to alias the same vnode
577 * across several names without the rest of the system knowing it.
578 * Use CNP_NOTVP to avoid a panic in this situation.
580 bzero(&cnp, sizeof(cnp));
581 cnp.cn_nameiop = NAMEI_CREATE;
582 cnp.cn_flags = CNP_LOCKPARENT | CNP_NOTVP;
583 cnp.cn_nameptr = ncp->nc_name;
584 cnp.cn_namelen = ncp->nc_nlen;
585 cnp.cn_cred = ap->a_cred;
587 cnp.cn_notvp = ap->a_vp;
590 error = vop_old_lookup(ap->a_head.a_ops, dvp, &tvp, &cnp);
593 * EJUSTRETURN should be returned for this case, which means that
594 * the VFS has setup the directory inode for the create. The dvp we
595 * passed in is expected to remain in a locked state.
597 * If the VOP_OLD_LINK is successful we are responsible for updating
598 * the cache state of the locked ncp that was passed to us.
600 if (error == EJUSTRETURN) {
601 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
602 error = VOP_OLD_LINK(dvp, ap->a_vp, &cnp);
604 cache_setunresolved(nch);
605 cache_setvp(nch, ap->a_vp);
613 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
620 vop_compat_nsymlink(struct vop_nsymlink_args *ap)
622 struct thread *td = curthread;
623 struct componentname cnp;
624 struct nchandle *nch;
625 struct namecache *ncp;
631 * Sanity checks, get a locked directory vnode.
634 nch = ap->a_nch; /* locked namecache node */
638 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
639 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
645 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
646 * caches all information required to create the entry in the
647 * directory inode. We expect a return code of EJUSTRETURN for
648 * the CREATE case. The cnp must simulated a saved-name situation.
650 bzero(&cnp, sizeof(cnp));
651 cnp.cn_nameiop = NAMEI_CREATE;
652 cnp.cn_flags = CNP_LOCKPARENT;
653 cnp.cn_nameptr = ncp->nc_name;
654 cnp.cn_namelen = ncp->nc_nlen;
655 cnp.cn_cred = ap->a_cred;
659 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
662 * EJUSTRETURN should be returned for this case, which means that
663 * the VFS has setup the directory inode for the create. The dvp we
664 * passed in is expected to remain in a locked state.
666 * If the VOP_OLD_SYMLINK is successful we are responsible for updating
667 * the cache state of the locked ncp that was passed to us.
669 if (error == EJUSTRETURN) {
670 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
671 error = VOP_OLD_SYMLINK(dvp, &vp, &cnp, ap->a_vap, ap->a_target);
673 cache_setunresolved(nch);
674 cache_setvp(nch, vp);
683 KKASSERT(vp == NULL);
685 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
692 * vop_compat_nwhiteout { struct nchandle *a_nch, XXX STOPGAP FUNCTION
693 * struct vnode *a_dvp,
694 * struct ucred *a_cred,
697 * Issie a whiteout operation (create, lookup, or delete). Compatibility
698 * requires us to issue the appropriate VOP_OLD_LOOKUP before we issue
699 * VOP_OLD_WHITEOUT in order to setup the directory inode's i_offset and i_count
700 * (e.g. in UFS) for the NAMEI_CREATE and NAMEI_DELETE ops. For NAMEI_LOOKUP
701 * no lookup is necessary.
704 vop_compat_nwhiteout(struct vop_nwhiteout_args *ap)
706 struct thread *td = curthread;
707 struct componentname cnp;
708 struct nchandle *nch;
709 struct namecache *ncp;
715 * Sanity checks, get a locked directory vnode.
717 nch = ap->a_nch; /* locked namecache node */
721 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
722 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
728 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
729 * caches all information required to create the entry in the
730 * directory inode. We expect a return code of EJUSTRETURN for
731 * the CREATE case. The cnp must simulated a saved-name situation.
733 bzero(&cnp, sizeof(cnp));
734 cnp.cn_nameiop = ap->a_flags;
735 cnp.cn_flags = CNP_LOCKPARENT;
736 cnp.cn_nameptr = ncp->nc_name;
737 cnp.cn_namelen = ncp->nc_nlen;
738 cnp.cn_cred = ap->a_cred;
744 * EJUSTRETURN should be returned for the CREATE or DELETE cases.
745 * The VFS has setup the directory inode for the create. The dvp we
746 * passed in is expected to remain in a locked state.
748 * If the VOP_OLD_WHITEOUT is successful we are responsible for updating
749 * the cache state of the locked ncp that was passed to us.
751 switch(ap->a_flags) {
753 cnp.cn_flags |= CNP_DOWHITEOUT;
756 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
757 if (error == EJUSTRETURN) {
758 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
759 error = VOP_OLD_WHITEOUT(dvp, &cnp, ap->a_flags);
761 cache_setunresolved(nch);
768 KKASSERT(vp == NULL);
772 error = VOP_OLD_WHITEOUT(dvp, NULL, ap->a_flags);
778 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
786 * vop_compat_nremove { struct nchandle *a_nch, XXX STOPGAP FUNCTION
787 * struct vnode *a_dvp,
788 * struct ucred *a_cred }
791 vop_compat_nremove(struct vop_nremove_args *ap)
793 struct thread *td = curthread;
794 struct componentname cnp;
795 struct nchandle *nch;
796 struct namecache *ncp;
802 * Sanity checks, get a locked directory vnode.
804 nch = ap->a_nch; /* locked namecache node */
808 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
809 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
815 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
816 * caches all information required to delete the entry in the
817 * directory inode. We expect a return code of 0 for the DELETE
818 * case (meaning that a vp has been found). The cnp must simulated
819 * a saved-name situation.
821 bzero(&cnp, sizeof(cnp));
822 cnp.cn_nameiop = NAMEI_DELETE;
823 cnp.cn_flags = CNP_LOCKPARENT;
824 cnp.cn_nameptr = ncp->nc_name;
825 cnp.cn_namelen = ncp->nc_nlen;
826 cnp.cn_cred = ap->a_cred;
830 * The vnode must be a directory and must not represent the
834 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
835 if (error == 0 && vp->v_type == VDIR)
838 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
839 error = VOP_OLD_REMOVE(dvp, vp, &cnp);
849 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
856 * vop_compat_nrmdir { struct nchandle *a_nch, XXX STOPGAP FUNCTION
858 * struct ucred *a_cred }
861 vop_compat_nrmdir(struct vop_nrmdir_args *ap)
863 struct thread *td = curthread;
864 struct componentname cnp;
865 struct nchandle *nch;
866 struct namecache *ncp;
872 * Sanity checks, get a locked directory vnode.
874 nch = ap->a_nch; /* locked namecache node */
878 if ((error = vget(dvp, LK_EXCLUSIVE)) != 0) {
879 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
885 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
886 * caches all information required to delete the entry in the
887 * directory inode. We expect a return code of 0 for the DELETE
888 * case (meaning that a vp has been found). The cnp must simulated
889 * a saved-name situation.
891 bzero(&cnp, sizeof(cnp));
892 cnp.cn_nameiop = NAMEI_DELETE;
893 cnp.cn_flags = CNP_LOCKPARENT;
894 cnp.cn_nameptr = ncp->nc_name;
895 cnp.cn_namelen = ncp->nc_nlen;
896 cnp.cn_cred = ap->a_cred;
900 * The vnode must be a directory and must not represent the
904 error = vop_old_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
905 if (error == 0 && vp->v_type != VDIR)
907 if (error == 0 && vp == dvp)
909 if (error == 0 && (vp->v_flag & VROOT))
912 KKASSERT((cnp.cn_flags & CNP_PDIRUNLOCK) == 0);
913 error = VOP_OLD_RMDIR(dvp, vp, &cnp);
916 * Note that this invalidation will cause any process
917 * currently CD'd into the directory being removed to be
918 * disconnected from the topology and not be able to ".."
922 cache_inval(nch, CINV_DESTROY);
923 cache_inval_vp(vp, CINV_DESTROY);
932 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
939 * vop_compat_nrename { struct nchandle *a_fnch, XXX STOPGAP FUNCTION
940 * struct nchandle *a_tnch,
941 * struct ucred *a_cred }
943 * This is a fairly difficult procedure. The old VOP_OLD_RENAME requires that
944 * the source directory and vnode be unlocked and the target directory and
945 * vnode (if it exists) be locked. All arguments will be vrele'd and
946 * the targets will also be unlocked regardless of the return code.
949 vop_compat_nrename(struct vop_nrename_args *ap)
951 struct thread *td = curthread;
952 struct componentname fcnp;
953 struct componentname tcnp;
954 struct nchandle *fnch;
955 struct nchandle *tnch;
956 struct namecache *fncp;
957 struct namecache *tncp;
958 struct vnode *fdvp, *fvp;
959 struct vnode *tdvp, *tvp;
963 * Sanity checks, get referenced vnodes representing the source.
965 fnch = ap->a_fnch; /* locked namecache node */
970 * Temporarily lock the source directory and lookup in DELETE mode to
971 * check permissions. XXX delete permissions should have been
972 * checked by nlookup(), we need to add NLC_DELETE for delete
973 * checking. It is unclear whether VFS's require the directory setup
974 * info NAMEI_DELETE causes to be stored in the fdvp's inode, but
975 * since it isn't locked and since UFS always does a relookup of
976 * the source, it is believed that the only side effect that matters
977 * is the permissions check.
979 if ((error = vget(fdvp, LK_EXCLUSIVE)) != 0) {
980 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
981 fncp, fncp->nc_name);
985 bzero(&fcnp, sizeof(fcnp));
986 fcnp.cn_nameiop = NAMEI_DELETE;
987 fcnp.cn_flags = CNP_LOCKPARENT;
988 fcnp.cn_nameptr = fncp->nc_name;
989 fcnp.cn_namelen = fncp->nc_nlen;
990 fcnp.cn_cred = ap->a_cred;
994 * note: vop_old_lookup (i.e. VOP_OLD_LOOKUP) always returns a locked
998 error = vop_old_lookup(ap->a_head.a_ops, fdvp, &fvp, &fcnp);
999 if (error == 0 && (fvp->v_flag & VROOT)) {
1000 vput(fvp); /* as if vop_old_lookup had failed */
1003 if ((fcnp.cn_flags & CNP_PDIRUNLOCK) == 0) {
1004 fcnp.cn_flags |= CNP_PDIRUNLOCK;
1014 * fdvp and fvp are now referenced and unlocked.
1016 * Get a locked directory vnode for the target and lookup the target
1017 * in CREATE mode so it places the required information in the
1020 tnch = ap->a_tnch; /* locked namecache node */
1028 if ((error = vget(tdvp, LK_EXCLUSIVE)) != 0) {
1029 kprintf("[diagnostic] vop_compat_resolve: EAGAIN on ncp %p %s\n",
1030 tncp, tncp->nc_name);
1037 * Setup the cnp for a traditional vop_old_lookup() call. The lookup
1038 * caches all information required to create the entry in the
1039 * target directory inode.
1041 bzero(&tcnp, sizeof(tcnp));
1042 tcnp.cn_nameiop = NAMEI_RENAME;
1043 tcnp.cn_flags = CNP_LOCKPARENT;
1044 tcnp.cn_nameptr = tncp->nc_name;
1045 tcnp.cn_namelen = tncp->nc_nlen;
1046 tcnp.cn_cred = ap->a_cred;
1050 error = vop_old_lookup(ap->a_head.a_ops, tdvp, &tvp, &tcnp);
1052 if (error == EJUSTRETURN) {
1054 * Target does not exist. tvp should be NULL.
1056 KKASSERT(tvp == NULL);
1057 KKASSERT((tcnp.cn_flags & CNP_PDIRUNLOCK) == 0);
1058 error = VOP_OLD_RENAME(fdvp, fvp, &fcnp, tdvp, tvp, &tcnp);
1060 cache_rename(fnch, tnch);
1061 } else if (error == 0) {
1063 * Target exists. VOP_OLD_RENAME should correctly delete the
1066 KKASSERT((tcnp.cn_flags & CNP_PDIRUNLOCK) == 0);
1067 error = VOP_OLD_RENAME(fdvp, fvp, &fcnp, tdvp, tvp, &tcnp);
1069 cache_rename(fnch, tnch);
1073 if (tcnp.cn_flags & CNP_PDIRUNLOCK)
1082 vop_nolookup(struct vop_old_lookup_args *ap)
1092 * Strategy routine for VFS devices that have none.
1094 * B_ERROR and B_INVAL must be cleared prior to calling any strategy
1095 * routine. Typically this is done for a BUF_CMD_READ strategy call.
1096 * Typically B_INVAL is assumed to already be clear prior to a write
1097 * and should not be cleared manually unless you just made the buffer
1098 * invalid. B_ERROR should be cleared either way.
1102 vop_nostrategy (struct vop_strategy_args *ap)
1104 kprintf("No strategy for buffer at %p\n", ap->a_bio->bio_buf);
1105 vprint("", ap->a_vp);
1106 ap->a_bio->bio_buf->b_flags |= B_ERROR;
1107 ap->a_bio->bio_buf->b_error = EOPNOTSUPP;
1109 return (EOPNOTSUPP);
1113 vop_stdpathconf(struct vop_pathconf_args *ap)
1117 switch (ap->a_name) {
1118 case _PC_CHOWN_RESTRICTED:
1119 *ap->a_retval = _POSIX_CHOWN_RESTRICTED;
1122 *ap->a_retval = LINK_MAX;
1125 *ap->a_retval = MAX_CANON;
1128 *ap->a_retval = MAX_INPUT;
1131 *ap->a_retval = NAME_MAX;
1134 *ap->a_retval = _POSIX_NO_TRUNC;
1137 *ap->a_retval = PATH_MAX;
1140 *ap->a_retval = PIPE_BUF;
1143 *ap->a_retval = _POSIX_VDISABLE;
1155 * (struct vnode *a_vp, int a_mode, struct ucred *a_ucred, struct file *a_fp)
1157 * a_mode: note, 'F' modes, e.g. FREAD, FWRITE
1160 vop_stdopen(struct vop_open_args *ap)
1162 struct vnode *vp = ap->a_vp;
1165 if ((fp = ap->a_fp) != NULL) {
1166 switch(vp->v_type) {
1168 fp->f_type = DTYPE_FIFO;
1171 fp->f_type = DTYPE_VNODE;
1174 /* retain flags not to be copied */
1175 fp->f_flag = (fp->f_flag & ~FMASK) | (ap->a_mode & FMASK);
1176 fp->f_ops = &vnode_fileops;
1180 if (ap->a_mode & FWRITE)
1181 atomic_add_int(&vp->v_writecount, 1);
1182 KKASSERT(vp->v_opencount >= 0 && vp->v_opencount != INT_MAX);
1183 atomic_add_int(&vp->v_opencount, 1);
1190 * (struct vnode *a_vp, int a_fflag)
1192 * a_fflag: note, 'F' modes, e.g. FREAD, FWRITE. same as a_mode in stdopen?
1194 * v_lastwrite_ts is used to record the timestamp that should be used to
1195 * set the file mtime for any asynchronously flushed pages modified via
1196 * mmap(), which can occur after the last close().
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",
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",
1209 vp, vp->v_writecount));
1210 atomic_add_int(&vp->v_writecount, -1);
1212 atomic_add_int(&vp->v_opencount, -1);
1217 * Standard getattr_quick
1219 * Just calls getattr
1222 vop_stdgetattr_quick(struct vop_getattr_args *ap)
1224 return VOP_GETATTR(ap->a_vp, ap->a_vap);
1228 * Implement standard getpages and putpages. All filesystems must use
1229 * the buffer cache to back regular files.
1232 vop_stdgetpages(struct vop_getpages_args *ap)
1237 if ((mp = ap->a_vp->v_mount) != NULL) {
1238 error = vnode_pager_generic_getpages(
1239 ap->a_vp, ap->a_m, ap->a_count,
1240 ap->a_reqpage, ap->a_seqaccess);
1242 error = VM_PAGER_BAD;
1248 vop_stdputpages(struct vop_putpages_args *ap)
1253 if ((mp = ap->a_vp->v_mount) != NULL) {
1254 error = vnode_pager_generic_putpages(
1255 ap->a_vp, ap->a_m, ap->a_count,
1256 ap->a_flags, ap->a_rtvals);
1258 error = VM_PAGER_BAD;
1264 vop_stdnoread(struct vop_read_args *ap)
1270 vop_stdnowrite(struct vop_write_args *ap)
1277 * used to fill the vfs fucntion table to get reasonable default return values.
1280 vop_stdmountctl(struct vop_mountctl_args *ap)
1286 mp = ap->a_head.a_ops->head.vv_mount;
1289 case MOUNTCTL_MOUNTFLAGS:
1291 * Get a string buffer with all the mount flags
1292 * names comman separated.
1293 * mount(2) will use this information.
1295 *ap->a_res = vfs_flagstostr(mp->mnt_flag & MNT_VISFLAGMASK, NULL,
1296 ap->a_buf, ap->a_buflen, &error);
1298 case MOUNTCTL_INSTALL_VFS_JOURNAL:
1299 case MOUNTCTL_RESTART_VFS_JOURNAL:
1300 case MOUNTCTL_REMOVE_VFS_JOURNAL:
1301 case MOUNTCTL_RESYNC_VFS_JOURNAL:
1302 case MOUNTCTL_STATUS_VFS_JOURNAL:
1303 error = journal_mountctl(ap);
1313 vfs_stdroot(struct mount *mp, struct vnode **vpp)
1315 return (EOPNOTSUPP);
1319 vfs_stdstatfs(struct mount *mp, struct statfs *sbp, struct ucred *cred)
1321 return (EOPNOTSUPP);
1325 * If the VFS does not implement statvfs, then call statfs and convert
1326 * the values. This code was taken from libc's __cvtstatvfs() function,
1327 * contributed by Joerg Sonnenberger.
1330 vfs_stdstatvfs(struct mount *mp, struct statvfs *sbp, struct ucred *cred)
1336 error = VFS_STATFS(mp, in, cred);
1338 bzero(sbp, sizeof(*sbp));
1340 sbp->f_bsize = in->f_bsize;
1341 sbp->f_frsize = in->f_bsize;
1342 sbp->f_blocks = in->f_blocks;
1343 sbp->f_bfree = in->f_bfree;
1344 sbp->f_bavail = in->f_bavail;
1345 sbp->f_files = in->f_files;
1346 sbp->f_ffree = in->f_ffree;
1350 * This field counts the number of available inodes to non-root
1351 * users, but this information is not available via statfs.
1352 * Just ignore this issue by returning the total number
1355 sbp->f_favail = in->f_ffree;
1359 * This field has a different meaning for statfs and statvfs.
1360 * For the former it is the cookie exported for NFS and not
1361 * intended for normal userland use.
1366 if (in->f_flags & MNT_RDONLY)
1367 sbp->f_flag |= ST_RDONLY;
1368 if (in->f_flags & MNT_NOSUID)
1369 sbp->f_flag |= ST_NOSUID;
1371 sbp->f_owner = in->f_owner;
1374 * statfs contains the type as string, statvfs expects it as
1379 sbp->f_syncreads = in->f_syncreads;
1380 sbp->f_syncwrites = in->f_syncwrites;
1381 sbp->f_asyncreads = in->f_asyncreads;
1382 sbp->f_asyncwrites = in->f_asyncwrites;
1388 vfs_stdvptofh(struct vnode *vp, struct fid *fhp)
1390 return (EOPNOTSUPP);
1394 vfs_stdstart(struct mount *mp, int flags)
1400 vfs_stdquotactl(struct mount *mp, int cmds, uid_t uid,
1401 caddr_t arg, struct ucred *cred)
1403 return (EOPNOTSUPP);
1407 vfs_stdsync(struct mount *mp, int waitfor)
1413 vfs_stdnosync(struct mount *mp, int waitfor)
1415 return (EOPNOTSUPP);
1419 vfs_stdvget(struct mount *mp, struct vnode *dvp, ino_t ino, struct vnode **vpp)
1421 return (EOPNOTSUPP);
1425 vfs_stdfhtovp(struct mount *mp, struct vnode *rootvp,
1426 struct fid *fhp, struct vnode **vpp)
1428 return (EOPNOTSUPP);
1432 vfs_stdcheckexp(struct mount *mp, struct sockaddr *nam, int *extflagsp,
1433 struct ucred **credanonp)
1435 return (EOPNOTSUPP);
1439 vfs_stdinit(struct vfsconf *vfsp)
1445 vfs_stduninit(struct vfsconf *vfsp)
1451 vfs_stdextattrctl(struct mount *mp, int cmd, struct vnode *vp,
1452 int attrnamespace, const char *attrname,
1458 #define ACCOUNTING_NB_FSTYPES 7
1460 static const char *accounting_fstypes[ACCOUNTING_NB_FSTYPES] = {
1461 "ext2fs", "hammer", "mfs", "ntfs", "null", "tmpfs", "ufs" };
1464 vfs_stdac_init(struct mount *mp)
1466 const char* fs_type;
1467 int i, fstype_ok = 0;
1469 /* is mounted fs type one we want to do some accounting for ? */
1470 for (i=0; i<ACCOUNTING_NB_FSTYPES; i++) {
1471 fs_type = accounting_fstypes[i];
1472 if (strncmp(mp->mnt_stat.f_fstypename, fs_type,
1473 sizeof(mp->mnt_stat)) == 0) {
1486 vfs_stdac_done(struct mount *mp)
1492 vfs_stdncpgen_set(struct mount *mp, struct namecache *ncp)
1497 vfs_stdncpgen_test(struct mount *mp, struct namecache *ncp)
1503 vfs_stdmodifying(struct mount *mp)
1505 if (mp->mnt_flag & MNT_RDONLY)
1509 /* end of vfs default ops */