2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed
6 * to Berkeley by John Heidemann of the UCLA Ficus project.
8 * Source: * @(#)i405_init.c 2.10 92/04/27 UCLA Ficus project
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * $FreeBSD: src/sys/kern/vfs_default.c,v 1.28.2.7 2003/01/10 18:23:26 bde Exp $
40 * $DragonFly: src/sys/kern/vfs_default.c,v 1.21 2004/10/12 19:20:46 dillon Exp $
43 #include <sys/param.h>
44 #include <sys/systm.h>
47 #include <sys/kernel.h>
49 #include <sys/malloc.h>
50 #include <sys/mount.h>
51 #include <sys/unistd.h>
52 #include <sys/vnode.h>
53 #include <sys/namei.h>
56 #include <machine/limits.h>
59 #include <vm/vm_object.h>
60 #include <vm/vm_page.h>
61 #include <vm/vm_pager.h>
62 #include <vm/vnode_pager.h>
64 static int vop_nolookup (struct vop_lookup_args *);
65 static int vop_nostrategy (struct vop_strategy_args *);
68 * This vnode table stores what we want to do if the filesystem doesn't
69 * implement a particular VOP.
71 * If there is no specific entry here, we will return EOPNOTSUPP.
73 struct vop_ops *default_vnode_vops;
74 static struct vnodeopv_entry_desc default_vnodeop_entries[] = {
75 { &vop_default_desc, vop_eopnotsupp },
76 { &vop_advlock_desc, vop_einval },
77 { &vop_bwrite_desc, (void *) vop_stdbwrite },
78 { &vop_close_desc, vop_null },
79 { &vop_createvobject_desc, (void *) vop_stdcreatevobject },
80 { &vop_destroyvobject_desc, (void *) vop_stddestroyvobject },
81 { &vop_fsync_desc, vop_null },
82 { &vop_getvobject_desc, (void *) vop_stdgetvobject },
83 { &vop_ioctl_desc, vop_enotty },
84 { &vop_islocked_desc, (void *) vop_stdislocked },
85 { &vop_lease_desc, vop_null },
86 { &vop_lock_desc, (void *) vop_stdlock },
87 { &vop_mmap_desc, vop_einval },
88 { &vop_resolve_desc, (void *) vop_noresolve },
89 { &vop_lookup_desc, (void *) vop_nolookup },
90 { &vop_open_desc, vop_null },
91 { &vop_pathconf_desc, vop_einval },
92 { &vop_poll_desc, (void *) vop_nopoll },
93 { &vop_readlink_desc, vop_einval },
94 { &vop_reallocblks_desc, vop_eopnotsupp },
95 { &vop_revoke_desc, (void *) vop_stdrevoke },
96 { &vop_strategy_desc, (void *) vop_nostrategy },
97 { &vop_unlock_desc, (void *) vop_stdunlock },
98 { &vop_getacl_desc, vop_eopnotsupp },
99 { &vop_setacl_desc, vop_eopnotsupp },
100 { &vop_aclcheck_desc, vop_eopnotsupp },
101 { &vop_getextattr_desc, vop_eopnotsupp },
102 { &vop_setextattr_desc, vop_eopnotsupp },
106 static struct vnodeopv_desc default_vnodeop_opv_desc =
107 { &default_vnode_vops, default_vnodeop_entries };
109 VNODEOP_SET(default_vnodeop_opv_desc);
112 vop_eopnotsupp(struct vop_generic_args *ap)
118 vop_ebadf(struct vop_generic_args *ap)
124 vop_enotty(struct vop_generic_args *ap)
130 vop_einval(struct vop_generic_args *ap)
136 vop_null(struct vop_generic_args *ap)
142 vop_defaultop(struct vop_generic_args *ap)
144 return (VOCALL(default_vnode_vops, ap));
148 vop_panic(struct vop_generic_args *ap)
151 panic("filesystem goof: vop_panic[%s]", ap->a_desc->vdesc_name);
155 * vop_noresolve { struct namecache *a_ncp } XXX STOPGAP FUNCTION
157 * XXX OLD API ROUTINE! WHEN ALL VFSs HAVE BEEN CLEANED UP THIS PROCEDURE
158 * WILL BE REMOVED. This procedure exists for all VFSs which have not
159 * yet implemented vop_resolve(). It converts vop_resolve() into a
160 * vop_lookup() and does appropriate translations.
162 * Resolve a ncp for VFSs which do not support the VOP. Eventually all
163 * VFSs will support this VOP and this routine can be removed, since
164 * vop_resolve() is far less complex then the older LOOKUP/CACHEDLOOKUP
167 * A locked ncp is passed in to be resolved. The NCP is resolved by
168 * figuring out the vnode (if any) and calling cache_setvp() to attach the
169 * vnode to the entry. If the entry represents a non-existant node then
170 * cache_setvp() is called with a NULL vnode to resolve the entry into a
171 * negative cache entry. No vnode locks are retained and the
172 * ncp is left locked on return.
174 * There is a potential directory and vnode interlock. The lock order
175 * requirement is: namecache, governing directory, resolved vnode.
178 vop_noresolve(struct vop_resolve_args *ap)
183 struct namecache *ncp;
184 struct componentname cnp;
186 ncp = ap->a_ncp; /* locked namecache node */
187 if (ncp->nc_flag & NCF_MOUNTPT) /* can't cross a mount point! */
189 if (ncp->nc_parent == NULL)
191 if ((dvp = ncp->nc_parent->nc_vp) == NULL)
194 if ((error = vget(dvp, LK_EXCLUSIVE, curthread)) != 0) {
195 printf("[diagnostic] vop_noresolve: EAGAIN on ncp %p %*.*s\n",
196 ncp, ncp->nc_nlen, ncp->nc_nlen, ncp->nc_name);
200 bzero(&cnp, sizeof(cnp));
201 cnp.cn_nameiop = NAMEI_LOOKUP;
202 cnp.cn_flags = CNP_ISLASTCN;
203 cnp.cn_nameptr = ncp->nc_name;
204 cnp.cn_namelen = ncp->nc_nlen;
205 cnp.cn_cred = ap->a_cred;
206 cnp.cn_td = curthread; /* XXX */
209 * vop_lookup() always returns vp locked. dvp may or may not be
210 * left locked depending on CNP_PDIRUNLOCK.
212 error = vop_lookup(ap->a_head.a_ops, dvp, &vp, &cnp);
214 VOP_UNLOCK(vp, 0, curthread);
215 if ((cnp.cn_flags & CNP_PDIRUNLOCK) == 0)
216 VOP_UNLOCK(dvp, 0, curthread);
217 if ((ncp->nc_flag & NCF_UNRESOLVED) == 0) {
218 /* was resolved by another process while we were unlocked */
221 } else if (error == 0) {
222 KKASSERT(vp != NULL);
223 cache_setvp(ncp, vp);
225 } else if (error == ENOENT) {
226 KKASSERT(vp == NULL);
227 if (cnp.cn_flags & CNP_ISWHITEOUT)
228 ncp->nc_flag |= NCF_WHITEOUT;
229 cache_setvp(ncp, NULL);
238 * vop_noremove { struct namecache *a_ncp } XXX STOPGAP FUNCTION
240 * Remove the file/dir represented by a_ncp.
242 * XXX ultra difficult. A number of existing filesystems, including UFS,
243 * assume that the directory will remain locked and the lookup will
244 * store the directory offset and other things in the directory inode
245 * for the later VOP_REMOVE to use. We have to move all that
246 * functionality into e.g. UFS's VOP_REMOVE itself.
249 vop_nonremove(struct vop_nremove_args *ap)
251 struct namecache *ncfile;
252 struct namecache *ncdir;
253 struct componentname cnd;
261 ncdir = ncfile->nc_parent;
263 if ((error = cache_vget(ncdir, ap->a_cred, LK_EXCLUSIVE, &vpd)) != 0)
265 if ((error = cache_vget(ncfile, ap->a_cred, LK_EXCLUSIVE, &vp)) != 0) {
269 bzero(&cnd, sizeof(cnd));
270 cnd.cn_nameiop = NAMEI_DELETE;
272 cnd.cn_cred = ap->a_cred;
273 cnd.cn_nameptr = ncfile->nc_name;
274 cnd.cn_namelen = ncfile->nc_nlen;
275 error = VOP_REMOVE(vpd, NCPNULL, vp, &cnd);
282 * Re-resolve the ncp to match the fact that the file has been
283 * deleted from the namespace. If an error occured leave the ncp
284 * unresolved (meaning that we have no idea what the correct state
288 cache_setunresolved(ncfile);
289 cache_setvp(ncfile, NULL);
299 struct vop_lookup_args /* {
301 struct vnode **a_vpp;
302 struct componentname *a_cnp;
313 * Strategy routine for VFS devices that have none.
315 * B_ERROR and B_INVAL must be cleared prior to calling any strategy
316 * routine. Typically this is done for a B_READ strategy call. Typically
317 * B_INVAL is assumed to already be clear prior to a write and should not
318 * be cleared manually unless you just made the buffer invalid. B_ERROR
319 * should be cleared either way.
323 vop_nostrategy (struct vop_strategy_args *ap)
325 printf("No strategy for buffer at %p\n", ap->a_bp);
326 vprint("", ap->a_vp);
327 vprint("", ap->a_bp->b_vp);
328 ap->a_bp->b_flags |= B_ERROR;
329 ap->a_bp->b_error = EOPNOTSUPP;
336 struct vop_pathconf_args /* {
343 switch (ap->a_name) {
345 *ap->a_retval = LINK_MAX;
348 *ap->a_retval = MAX_CANON;
351 *ap->a_retval = MAX_INPUT;
354 *ap->a_retval = PIPE_BUF;
356 case _PC_CHOWN_RESTRICTED:
360 *ap->a_retval = _POSIX_VDISABLE;
369 * Standard lock. The lock is recursive-capable only if the lock was
370 * initialized with LK_CANRECURSE or that flag is passed in a_flags.
374 struct vop_lock_args /* {
383 error = lockmgr(&ap->a_vp->v_lock, ap->a_flags, NULL, ap->a_td);
385 error = debuglockmgr(&ap->a_vp->v_lock, ap->a_flags,
387 "vop_stdlock", ap->a_vp->filename, ap->a_vp->line);
394 struct vop_unlock_args /* {
402 error = lockmgr(&ap->a_vp->v_lock, ap->a_flags | LK_RELEASE,
409 struct vop_islocked_args /* {
414 return (lockstatus(&ap->a_vp->v_lock, ap->a_td));
418 * Return true for select/poll.
422 struct vop_poll_args /* {
425 struct ucred *a_cred;
430 * Return true for read/write. If the user asked for something
431 * special, return POLLNVAL, so that clients have a way of
432 * determining reliably whether or not the extended
433 * functionality is present without hard-coding knowledge
434 * of specific filesystem implementations.
436 if (ap->a_events & ~POLLSTANDARD)
439 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
443 * Implement poll for local filesystems that support it.
447 struct vop_poll_args /* {
450 struct ucred *a_cred;
454 if (ap->a_events & ~POLLSTANDARD)
455 return (vn_pollrecord(ap->a_vp, ap->a_td, ap->a_events));
456 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
461 struct vop_bwrite_args *ap;
463 return (bwrite(ap->a_bp));
467 vop_stdcreatevobject(ap)
468 struct vop_createvobject_args /* {
473 struct vnode *vp = ap->a_vp;
474 struct thread *td = ap->a_td;
479 if (!vn_isdisk(vp, NULL) && vn_canvmio(vp) == FALSE)
483 if ((object = vp->v_object) == NULL) {
484 if (vp->v_type == VREG || vp->v_type == VDIR) {
485 if ((error = VOP_GETATTR(vp, &vat, td)) != 0)
487 object = vnode_pager_alloc(vp, vat.va_size, 0, 0);
488 } else if (vp->v_rdev && dev_is_good(vp->v_rdev)) {
490 * XXX v_rdev uses NULL/non-NULL instead of NODEV
492 * This simply allocates the biggest object possible
493 * for a disk vnode. This should be fixed, but doesn't
494 * cause any problems (yet).
496 object = vnode_pager_alloc(vp, IDX_TO_OFF(INT_MAX), 0, 0);
501 * Dereference the reference we just created. This assumes
502 * that the object is associated with the vp.
507 if (object->flags & OBJ_DEAD) {
508 VOP_UNLOCK(vp, 0, td);
509 tsleep(object, 0, "vodead", 0);
510 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
515 KASSERT(vp->v_object != NULL, ("vfs_object_create: NULL object"));
516 vp->v_flag |= VOBJBUF;
523 vop_stddestroyvobject(ap)
524 struct vop_destroyvobject_args /* {
528 struct vnode *vp = ap->a_vp;
529 vm_object_t obj = vp->v_object;
531 if (vp->v_object == NULL)
534 if (obj->ref_count == 0) {
536 * vclean() may be called twice. The first time
537 * removes the primary reference to the object,
538 * the second time goes one further and is a
539 * special-case to terminate the object.
541 * don't double-terminate the object.
543 if ((obj->flags & OBJ_DEAD) == 0)
544 vm_object_terminate(obj);
547 * Woe to the process that tries to page now :-).
549 vm_pager_deallocate(obj);
555 * Return the underlying VM object. This routine may be called with or
556 * without the vnode interlock held. If called without, the returned
557 * object is not guarenteed to be valid. The syncer typically gets the
558 * object without holding the interlock in order to quickly test whether
559 * it might be dirty before going heavy-weight. vm_object's use zalloc
560 * and thus stable-storage, so this is safe.
563 vop_stdgetvobject(ap)
564 struct vop_getvobject_args /* {
566 struct vm_object **objpp;
569 struct vnode *vp = ap->a_vp;
570 struct vm_object **objpp = ap->a_objpp;
573 *objpp = vp->v_object;
574 return (vp->v_object ? 0 : EINVAL);
579 * used to fill the vfs fucntion table to get reasonable default return values.
582 vfs_stdmount(struct mount *mp, char *path, caddr_t data,
583 struct nameidata *ndp, struct thread *td)
589 vfs_stdunmount(struct mount *mp, int mntflags, struct thread *td)
595 vfs_stdroot(struct mount *mp, struct vnode **vpp)
601 vfs_stdstatfs(struct mount *mp, struct statfs *sbp, struct thread *td)
607 vfs_stdvptofh(struct vnode *vp, struct fid *fhp)
613 vfs_stdstart(struct mount *mp, int flags, struct thread *td)
619 vfs_stdquotactl(struct mount *mp, int cmds, uid_t uid,
620 caddr_t arg, struct thread *td)
626 vfs_stdsync(struct mount *mp, int waitfor, struct thread *td)
632 vfs_stdvget(struct mount *mp, ino_t ino, struct vnode **vpp)
638 vfs_stdfhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
644 vfs_stdcheckexp(struct mount *mp, struct sockaddr *nam, int *extflagsp,
645 struct ucred **credanonp)
651 vfs_stdinit(struct vfsconf *vfsp)
657 vfs_stduninit(struct vfsconf *vfsp)
663 vfs_stdextattrctl(struct mount *mp, int cmd, const char *attrname,
664 caddr_t arg, struct thread *td)
669 /* end of vfs default ops */