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.13 2004/08/28 19:02:05 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>
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_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 static struct vnodeopv_entry_desc default_vnodeop_entries[] = {
74 { &vop_default_desc, vop_eopnotsupp },
75 { &vop_advlock_desc, vop_einval },
76 { &vop_bwrite_desc, (void *) vop_stdbwrite },
77 { &vop_close_desc, vop_null },
78 { &vop_createvobject_desc, (void *) vop_stdcreatevobject },
79 { &vop_destroyvobject_desc, (void *) vop_stddestroyvobject },
80 { &vop_fsync_desc, vop_null },
81 { &vop_getvobject_desc, (void *) vop_stdgetvobject },
82 { &vop_ioctl_desc, vop_enotty },
83 { &vop_islocked_desc, (void *) vop_stdislocked },
84 { &vop_lease_desc, vop_null },
85 { &vop_lock_desc, (void *) vop_stdlock },
86 { &vop_mmap_desc, vop_einval },
87 { &vop_lookup_desc, (void *) vop_nolookup },
88 { &vop_open_desc, vop_null },
89 { &vop_pathconf_desc, vop_einval },
90 { &vop_poll_desc, (void *) vop_nopoll },
91 { &vop_readlink_desc, vop_einval },
92 { &vop_reallocblks_desc, vop_eopnotsupp },
93 { &vop_revoke_desc, (void *) vop_stdrevoke },
94 { &vop_strategy_desc, (void *) vop_nostrategy },
95 { &vop_unlock_desc, (void *) vop_stdunlock },
96 { &vop_getacl_desc, vop_eopnotsupp },
97 { &vop_setacl_desc, vop_eopnotsupp },
98 { &vop_aclcheck_desc, vop_eopnotsupp },
99 { &vop_getextattr_desc, vop_eopnotsupp },
100 { &vop_setextattr_desc, vop_eopnotsupp },
104 static struct vnodeopv_desc default_vnodeop_opv_desc =
105 { &default_vnode_vops, default_vnodeop_entries };
107 VNODEOP_SET(default_vnodeop_opv_desc);
110 vop_eopnotsupp(struct vop_generic_args *ap)
113 printf("vop_notsupp[%s]\n", ap->a_desc->vdesc_name);
119 vop_ebadf(struct vop_generic_args *ap)
125 vop_enotty(struct vop_generic_args *ap)
131 vop_einval(struct vop_generic_args *ap)
137 vop_null(struct vop_generic_args *ap)
143 vop_defaultop(struct vop_generic_args *ap)
145 return (VOCALL(default_vnode_vops, ap));
149 vop_panic(struct vop_generic_args *ap)
152 panic("filesystem goof: vop_panic[%s]", ap->a_desc->vdesc_name);
157 struct vop_lookup_args /* {
159 struct vnode **a_vpp;
160 struct componentname *a_cnp;
171 * Strategy routine for VFS devices that have none.
173 * B_ERROR and B_INVAL must be cleared prior to calling any strategy
174 * routine. Typically this is done for a B_READ strategy call. Typically
175 * B_INVAL is assumed to already be clear prior to a write and should not
176 * be cleared manually unless you just made the buffer invalid. B_ERROR
177 * should be cleared either way.
181 vop_nostrategy (struct vop_strategy_args *ap)
183 printf("No strategy for buffer at %p\n", ap->a_bp);
184 vprint("", ap->a_vp);
185 vprint("", ap->a_bp->b_vp);
186 ap->a_bp->b_flags |= B_ERROR;
187 ap->a_bp->b_error = EOPNOTSUPP;
194 struct vop_pathconf_args /* {
201 switch (ap->a_name) {
203 *ap->a_retval = LINK_MAX;
206 *ap->a_retval = MAX_CANON;
209 *ap->a_retval = MAX_INPUT;
212 *ap->a_retval = PIPE_BUF;
214 case _PC_CHOWN_RESTRICTED:
218 *ap->a_retval = _POSIX_VDISABLE;
227 * Standard lock. The lock is recursive-capable only if the lock was
228 * initialized with LK_CANRECURSE or that flag is passed in a_flags.
232 struct vop_lock_args /* {
234 lwkt_tokref_t a_vlock;
242 error = lockmgr(&ap->a_vp->v_lock, ap->a_flags,
243 ap->a_vlock, ap->a_td);
245 error = debuglockmgr(&ap->a_vp->v_lock, ap->a_flags,
246 ap->a_vlock, ap->a_td,
247 "vop_stdlock", ap->a_vp->filename, ap->a_vp->line);
254 struct vop_unlock_args /* {
256 lwkt_tokref_t a_vlock;
263 error = lockmgr(&ap->a_vp->v_lock, ap->a_flags | LK_RELEASE,
264 ap->a_vlock, ap->a_td);
270 struct vop_islocked_args /* {
275 return (lockstatus(&ap->a_vp->v_lock, ap->a_td));
279 * Return true for select/poll.
283 struct vop_poll_args /* {
286 struct ucred *a_cred;
291 * Return true for read/write. If the user asked for something
292 * special, return POLLNVAL, so that clients have a way of
293 * determining reliably whether or not the extended
294 * functionality is present without hard-coding knowledge
295 * of specific filesystem implementations.
297 if (ap->a_events & ~POLLSTANDARD)
300 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
304 * Implement poll for local filesystems that support it.
308 struct vop_poll_args /* {
311 struct ucred *a_cred;
315 if (ap->a_events & ~POLLSTANDARD)
316 return (vn_pollrecord(ap->a_vp, ap->a_td, ap->a_events));
317 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
322 struct vop_bwrite_args *ap;
324 return (bwrite(ap->a_bp));
328 vop_stdcreatevobject(ap)
329 struct vop_createvobject_args /* {
334 struct vnode *vp = ap->a_vp;
335 struct thread *td = ap->a_td;
340 if (!vn_isdisk(vp, NULL) && vn_canvmio(vp) == FALSE)
344 if ((object = vp->v_object) == NULL) {
345 if (vp->v_type == VREG || vp->v_type == VDIR) {
346 if ((error = VOP_GETATTR(vp, &vat, td)) != 0)
348 object = vnode_pager_alloc(vp, vat.va_size, 0, 0);
349 } else if (vp->v_rdev && dev_is_good(vp->v_rdev)) {
351 * XXX v_rdev uses NULL/non-NULL instead of NODEV
353 * This simply allocates the biggest object possible
354 * for a disk vnode. This should be fixed, but doesn't
355 * cause any problems (yet).
357 object = vnode_pager_alloc(vp, IDX_TO_OFF(INT_MAX), 0, 0);
362 * Dereference the reference we just created. This assumes
363 * that the object is associated with the vp.
368 if (object->flags & OBJ_DEAD) {
369 VOP_UNLOCK(vp, NULL, 0, td);
370 tsleep(object, 0, "vodead", 0);
371 vn_lock(vp, NULL, LK_EXCLUSIVE | LK_RETRY, td);
376 KASSERT(vp->v_object != NULL, ("vfs_object_create: NULL object"));
377 vp->v_flag |= VOBJBUF;
384 vop_stddestroyvobject(ap)
385 struct vop_destroyvobject_args /* {
389 struct vnode *vp = ap->a_vp;
390 vm_object_t obj = vp->v_object;
392 if (vp->v_object == NULL)
395 if (obj->ref_count == 0) {
397 * vclean() may be called twice. The first time
398 * removes the primary reference to the object,
399 * the second time goes one further and is a
400 * special-case to terminate the object.
402 * don't double-terminate the object.
404 if ((obj->flags & OBJ_DEAD) == 0)
405 vm_object_terminate(obj);
408 * Woe to the process that tries to page now :-).
410 vm_pager_deallocate(obj);
416 * Return the underlying VM object. This routine may be called with or
417 * without the vnode interlock held. If called without, the returned
418 * object is not guarenteed to be valid. The syncer typically gets the
419 * object without holding the interlock in order to quickly test whether
420 * it might be dirty before going heavy-weight. vm_object's use zalloc
421 * and thus stable-storage, so this is safe.
424 vop_stdgetvobject(ap)
425 struct vop_getvobject_args /* {
427 struct vm_object **objpp;
430 struct vnode *vp = ap->a_vp;
431 struct vm_object **objpp = ap->a_objpp;
434 *objpp = vp->v_object;
435 return (vp->v_object ? 0 : EINVAL);
440 * used to fill the vfs fucntion table to get reasonable default return values.
443 vfs_stdmount(struct mount *mp, char *path, caddr_t data,
444 struct nameidata *ndp, struct thread *td)
450 vfs_stdunmount(struct mount *mp, int mntflags, struct thread *td)
456 vfs_stdroot(struct mount *mp, struct vnode **vpp)
462 vfs_stdstatfs(struct mount *mp, struct statfs *sbp, struct thread *td)
468 vfs_stdvptofh(struct vnode *vp, struct fid *fhp)
474 vfs_stdstart(struct mount *mp, int flags, struct thread *td)
480 vfs_stdquotactl(struct mount *mp, int cmds, uid_t uid,
481 caddr_t arg, struct thread *td)
487 vfs_stdsync(struct mount *mp, int waitfor, struct thread *td)
493 vfs_stdvget(struct mount *mp, ino_t ino, struct vnode **vpp)
499 vfs_stdfhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
505 vfs_stdcheckexp(struct mount *mp, struct sockaddr *nam, int *extflagsp,
506 struct ucred **credanonp)
512 vfs_stdinit(struct vfsconf *vfsp)
518 vfs_stduninit(struct vfsconf *vfsp)
524 vfs_stdextattrctl(struct mount *mp, int cmd, const char *attrname,
525 caddr_t arg, struct thread *td)
530 /* end of vfs default ops */