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 $
42 #include <sys/param.h>
43 #include <sys/systm.h>
46 #include <sys/kernel.h>
48 #include <sys/malloc.h>
49 #include <sys/mount.h>
50 #include <sys/unistd.h>
51 #include <sys/vnode.h>
54 #include <machine/limits.h>
57 #include <vm/vm_object.h>
58 #include <vm/vm_page.h>
59 #include <vm/vm_pager.h>
60 #include <vm/vnode_pager.h>
62 static int vop_nolookup __P((struct vop_lookup_args *));
63 static int vop_nostrategy __P((struct vop_strategy_args *));
66 * This vnode table stores what we want to do if the filesystem doesn't
67 * implement a particular VOP.
69 * If there is no specific entry here, we will return EOPNOTSUPP.
73 vop_t **default_vnodeop_p;
74 static struct vnodeopv_entry_desc default_vnodeop_entries[] = {
75 { &vop_default_desc, (vop_t *) vop_eopnotsupp },
76 { &vop_advlock_desc, (vop_t *) vop_einval },
77 { &vop_bwrite_desc, (vop_t *) vop_stdbwrite },
78 { &vop_close_desc, (vop_t *) vop_null },
79 { &vop_createvobject_desc, (vop_t *) vop_stdcreatevobject },
80 { &vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject },
81 { &vop_fsync_desc, (vop_t *) vop_null },
82 { &vop_getvobject_desc, (vop_t *) vop_stdgetvobject },
83 { &vop_ioctl_desc, (vop_t *) vop_enotty },
84 { &vop_islocked_desc, (vop_t *) vop_noislocked },
85 { &vop_lease_desc, (vop_t *) vop_null },
86 { &vop_lock_desc, (vop_t *) vop_nolock },
87 { &vop_mmap_desc, (vop_t *) vop_einval },
88 { &vop_lookup_desc, (vop_t *) vop_nolookup },
89 { &vop_open_desc, (vop_t *) vop_null },
90 { &vop_pathconf_desc, (vop_t *) vop_einval },
91 { &vop_poll_desc, (vop_t *) vop_nopoll },
92 { &vop_readlink_desc, (vop_t *) vop_einval },
93 { &vop_reallocblks_desc, (vop_t *) vop_eopnotsupp },
94 { &vop_revoke_desc, (vop_t *) vop_revoke },
95 { &vop_strategy_desc, (vop_t *) vop_nostrategy },
96 { &vop_unlock_desc, (vop_t *) vop_nounlock },
97 { &vop_getacl_desc, (vop_t *) vop_eopnotsupp },
98 { &vop_setacl_desc, (vop_t *) vop_eopnotsupp },
99 { &vop_aclcheck_desc, (vop_t *) vop_eopnotsupp },
100 { &vop_getextattr_desc, (vop_t *) vop_eopnotsupp },
101 { &vop_setextattr_desc, (vop_t *) vop_eopnotsupp },
105 static struct vnodeopv_desc default_vnodeop_opv_desc =
106 { &default_vnodeop_p, default_vnodeop_entries };
108 VNODEOP_SET(default_vnodeop_opv_desc);
111 vop_eopnotsupp(struct vop_generic_args *ap)
114 printf("vop_notsupp[%s]\n", ap->a_desc->vdesc_name);
121 vop_ebadf(struct vop_generic_args *ap)
128 vop_enotty(struct vop_generic_args *ap)
135 vop_einval(struct vop_generic_args *ap)
142 vop_null(struct vop_generic_args *ap)
149 vop_defaultop(struct vop_generic_args *ap)
152 return (VOCALL(default_vnodeop_p, ap->a_desc->vdesc_offset, ap));
156 vop_panic(struct vop_generic_args *ap)
159 panic("filesystem goof: vop_panic[%s]", ap->a_desc->vdesc_name);
164 struct vop_lookup_args /* {
166 struct vnode **a_vpp;
167 struct componentname *a_cnp;
178 * Strategy routine for VFS devices that have none.
180 * B_ERROR and B_INVAL must be cleared prior to calling any strategy
181 * routine. Typically this is done for a B_READ strategy call. Typically
182 * B_INVAL is assumed to already be clear prior to a write and should not
183 * be cleared manually unless you just made the buffer invalid. B_ERROR
184 * should be cleared either way.
188 vop_nostrategy (struct vop_strategy_args *ap)
190 printf("No strategy for buffer at %p\n", ap->a_bp);
191 vprint("", ap->a_vp);
192 vprint("", ap->a_bp->b_vp);
193 ap->a_bp->b_flags |= B_ERROR;
194 ap->a_bp->b_error = EOPNOTSUPP;
201 struct vop_pathconf_args /* {
208 switch (ap->a_name) {
210 *ap->a_retval = LINK_MAX;
213 *ap->a_retval = MAX_CANON;
216 *ap->a_retval = MAX_INPUT;
219 *ap->a_retval = PIPE_BUF;
221 case _PC_CHOWN_RESTRICTED:
225 *ap->a_retval = _POSIX_VDISABLE;
234 * Standard lock, unlock and islocked functions.
236 * These depend on the lock structure being the first element in the
237 * inode, ie: vp->v_data points to the the lock!
241 struct vop_lock_args /* {
249 if ((l = (struct lock *)ap->a_vp->v_data) == NULL) {
250 if (ap->a_flags & LK_INTERLOCK)
251 simple_unlock(&ap->a_vp->v_interlock);
256 return (lockmgr(l, ap->a_flags, &ap->a_vp->v_interlock, ap->a_p));
258 return (debuglockmgr(l, ap->a_flags, &ap->a_vp->v_interlock, ap->a_p,
259 "vop_stdlock", ap->a_vp->filename, ap->a_vp->line));
265 struct vop_unlock_args /* {
273 if ((l = (struct lock *)ap->a_vp->v_data) == NULL) {
274 if (ap->a_flags & LK_INTERLOCK)
275 simple_unlock(&ap->a_vp->v_interlock);
279 return (lockmgr(l, ap->a_flags | LK_RELEASE, &ap->a_vp->v_interlock,
285 struct vop_islocked_args /* {
292 if ((l = (struct lock *)ap->a_vp->v_data) == NULL)
295 return (lockstatus(l, ap->a_p));
299 * Return true for select/poll.
303 struct vop_poll_args /* {
306 struct ucred *a_cred;
311 * Return true for read/write. If the user asked for something
312 * special, return POLLNVAL, so that clients have a way of
313 * determining reliably whether or not the extended
314 * functionality is present without hard-coding knowledge
315 * of specific filesystem implementations.
317 if (ap->a_events & ~POLLSTANDARD)
320 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
324 * Implement poll for local filesystems that support it.
328 struct vop_poll_args /* {
331 struct ucred *a_cred;
335 if (ap->a_events & ~POLLSTANDARD)
336 return (vn_pollrecord(ap->a_vp, ap->a_p, ap->a_events));
337 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
342 struct vop_bwrite_args *ap;
344 return (bwrite(ap->a_bp));
348 * Stubs to use when there is no locking to be done on the underlying object.
349 * A minimal shared lock is necessary to ensure that the underlying object
350 * is not revoked while an operation is in progress. So, an active shared
351 * count is maintained in an auxillary vnode lock structure.
355 struct vop_lock_args /* {
362 * This code cannot be used until all the non-locking filesystems
363 * (notably NFS) are converted to properly lock and release nodes.
364 * Also, certain vnode operations change the locking state within
365 * the operation (create, mknod, remove, link, rename, mkdir, rmdir,
366 * and symlink). Ideally these operations should not change the
367 * lock state, but should be changed to let the caller of the
368 * function unlock them. Otherwise all intermediate vnode layers
369 * (such as union, umapfs, etc) must catch these functions to do
370 * the necessary locking at their layer. Note that the inactive
371 * and lookup operations also change their lock state, but this
372 * cannot be avoided, so these two operations will always need
373 * to be handled in intermediate layers.
375 struct vnode *vp = ap->a_vp;
376 struct lock *l = (struct lock *)vp->v_data;
377 int vnflags, flags = ap->a_flags;
380 if (ap->a_flags & LK_INTERLOCK)
381 simple_unlock(&ap->a_vp->v_interlock);
384 switch (flags & LK_TYPE_MASK) {
389 #ifdef DEBUG_VFS_LOCKS
391 * Normally, we use shared locks here, but that confuses
392 * the locking assertions.
394 vnflags = LK_EXCLUSIVE;
406 panic("vop_sharedlock: bad operation %d", flags & LK_TYPE_MASK);
408 if (flags & LK_INTERLOCK)
409 vnflags |= LK_INTERLOCK;
411 return (lockmgr(l, vnflags, &vp->v_interlock, ap->a_p));
413 return (debuglockmgr(l, vnflags, &vp->v_interlock, ap->a_p,
414 "vop_sharedlock", vp->filename, vp->line));
419 * Stubs to use when there is no locking to be done on the underlying object.
420 * A minimal shared lock is necessary to ensure that the underlying object
421 * is not revoked while an operation is in progress. So, an active shared
422 * count is maintained in an auxillary vnode lock structure.
426 struct vop_lock_args /* {
434 * This code cannot be used until all the non-locking filesystems
435 * (notably NFS) are converted to properly lock and release nodes.
436 * Also, certain vnode operations change the locking state within
437 * the operation (create, mknod, remove, link, rename, mkdir, rmdir,
438 * and symlink). Ideally these operations should not change the
439 * lock state, but should be changed to let the caller of the
440 * function unlock them. Otherwise all intermediate vnode layers
441 * (such as union, umapfs, etc) must catch these functions to do
442 * the necessary locking at their layer. Note that the inactive
443 * and lookup operations also change their lock state, but this
444 * cannot be avoided, so these two operations will always need
445 * to be handled in intermediate layers.
447 struct vnode *vp = ap->a_vp;
448 int vnflags, flags = ap->a_flags;
450 switch (flags & LK_TYPE_MASK) {
464 panic("vop_nolock: bad operation %d", flags & LK_TYPE_MASK);
466 if (flags & LK_INTERLOCK)
467 vnflags |= LK_INTERLOCK;
468 return(lockmgr(vp->v_vnlock, vnflags, &vp->v_interlock, ap->a_p));
471 * Since we are not using the lock manager, we must clear
472 * the interlock here.
474 if (ap->a_flags & LK_INTERLOCK)
475 simple_unlock(&ap->a_vp->v_interlock);
481 * Do the inverse of vop_nolock, handling the interlock in a compatible way.
485 struct vop_unlock_args /* {
491 if (ap->a_flags & LK_INTERLOCK)
492 simple_unlock(&ap->a_vp->v_interlock);
497 * Return whether or not the node is in use.
501 struct vop_islocked_args /* {
510 vop_stdcreatevobject(ap)
511 struct vop_createvobject_args /* {
517 struct vnode *vp = ap->a_vp;
518 struct ucred *cred = ap->a_cred;
519 struct proc *p = ap->a_p;
524 if (!vn_isdisk(vp, NULL) && vn_canvmio(vp) == FALSE)
528 if ((object = vp->v_object) == NULL) {
529 if (vp->v_type == VREG || vp->v_type == VDIR) {
530 if ((error = VOP_GETATTR(vp, &vat, cred, p)) != 0)
532 object = vnode_pager_alloc(vp, vat.va_size, 0, 0);
533 } else if (devsw(vp->v_rdev) != NULL) {
535 * This simply allocates the biggest object possible
536 * for a disk vnode. This should be fixed, but doesn't
537 * cause any problems (yet).
539 object = vnode_pager_alloc(vp, IDX_TO_OFF(INT_MAX), 0, 0);
544 * Dereference the reference we just created. This assumes
545 * that the object is associated with the vp.
550 if (object->flags & OBJ_DEAD) {
551 VOP_UNLOCK(vp, 0, p);
552 tsleep(object, PVM, "vodead", 0);
553 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
558 KASSERT(vp->v_object != NULL, ("vfs_object_create: NULL object"));
559 vp->v_flag |= VOBJBUF;
566 vop_stddestroyvobject(ap)
567 struct vop_destroyvobject_args /* {
571 struct vnode *vp = ap->a_vp;
572 vm_object_t obj = vp->v_object;
574 if (vp->v_object == NULL)
577 if (obj->ref_count == 0) {
579 * vclean() may be called twice. The first time
580 * removes the primary reference to the object,
581 * the second time goes one further and is a
582 * special-case to terminate the object.
584 * don't double-terminate the object.
586 if ((obj->flags & OBJ_DEAD) == 0)
587 vm_object_terminate(obj);
590 * Woe to the process that tries to page now :-).
592 vm_pager_deallocate(obj);
598 * Return the underlying VM object. This routine may be called with or
599 * without the vnode interlock held. If called without, the returned
600 * object is not guarenteed to be valid. The syncer typically gets the
601 * object without holding the interlock in order to quickly test whether
602 * it might be dirty before going heavy-weight. vm_object's use zalloc
603 * and thus stable-storage, so this is safe.
606 vop_stdgetvobject(ap)
607 struct vop_getvobject_args /* {
609 struct vm_object **objpp;
612 struct vnode *vp = ap->a_vp;
613 struct vm_object **objpp = ap->a_objpp;
616 *objpp = vp->v_object;
617 return (vp->v_object ? 0 : EINVAL);
622 * used to fill the vfs fucntion table to get reasonable default return values.
625 vfs_stdmount (mp, path, data, ndp, p)
629 struct nameidata *ndp;
636 vfs_stdunmount (mp, mntflags, p)
645 vfs_stdroot (mp, vpp)
653 vfs_stdstatfs (mp, sbp, p)
662 vfs_stdvptofh (vp, fhp)
670 vfs_stdstart (mp, flags, p)
679 vfs_stdquotactl (mp, cmds, uid, arg, p)
690 vfs_stdsync (mp, waitfor, cred, p)
700 vfs_stdvget (mp, ino, vpp)
709 vfs_stdfhtovp (mp, fhp, vpp)
718 vfs_stdcheckexp (mp, nam, extflagsp, credanonp)
720 struct sockaddr *nam;
722 struct ucred **credanonp;
729 struct vfsconf *vfsp;
736 struct vfsconf *vfsp;
742 vfs_stdextattrctl(mp, cmd, attrname, arg, p)
745 const char *attrname;
752 /* end of vfs default ops */