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
42 #include <sys/param.h>
43 #include <sys/systm.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>
53 static int vop_nostrategy __P((struct vop_strategy_args *));
56 * This vnode table stores what we want to do if the filesystem doesn't
57 * implement a particular VOP.
59 * If there is no specific entry here, we will return EOPNOTSUPP.
63 vop_t **default_vnodeop_p;
64 static struct vnodeopv_entry_desc default_vnodeop_entries[] = {
65 { &vop_default_desc, (vop_t *) vop_eopnotsupp },
66 { &vop_advlock_desc, (vop_t *) vop_einval },
67 { &vop_bwrite_desc, (vop_t *) vop_stdbwrite },
68 { &vop_close_desc, (vop_t *) vop_null },
69 { &vop_fsync_desc, (vop_t *) vop_null },
70 { &vop_ioctl_desc, (vop_t *) vop_enotty },
71 { &vop_islocked_desc, (vop_t *) vop_noislocked },
72 { &vop_lease_desc, (vop_t *) vop_null },
73 { &vop_lock_desc, (vop_t *) vop_nolock },
74 { &vop_mmap_desc, (vop_t *) vop_einval },
75 { &vop_open_desc, (vop_t *) vop_null },
76 { &vop_pathconf_desc, (vop_t *) vop_einval },
77 { &vop_poll_desc, (vop_t *) vop_nopoll },
78 { &vop_readlink_desc, (vop_t *) vop_einval },
79 { &vop_reallocblks_desc, (vop_t *) vop_eopnotsupp },
80 { &vop_revoke_desc, (vop_t *) vop_revoke },
81 { &vop_strategy_desc, (vop_t *) vop_nostrategy },
82 { &vop_unlock_desc, (vop_t *) vop_nounlock },
83 { &vop_getacl_desc, (vop_t *) vop_eopnotsupp },
84 { &vop_setacl_desc, (vop_t *) vop_eopnotsupp },
85 { &vop_aclcheck_desc, (vop_t *) vop_eopnotsupp },
86 { &vop_getextattr_desc, (vop_t *) vop_eopnotsupp },
87 { &vop_setextattr_desc, (vop_t *) vop_eopnotsupp },
91 static struct vnodeopv_desc default_vnodeop_opv_desc =
92 { &default_vnodeop_p, default_vnodeop_entries };
94 VNODEOP_SET(default_vnodeop_opv_desc);
97 vop_eopnotsupp(struct vop_generic_args *ap)
100 printf("vop_notsupp[%s]\n", ap->a_desc->vdesc_name);
107 vop_ebadf(struct vop_generic_args *ap)
114 vop_enotty(struct vop_generic_args *ap)
121 vop_einval(struct vop_generic_args *ap)
128 vop_null(struct vop_generic_args *ap)
135 vop_defaultop(struct vop_generic_args *ap)
138 return (VOCALL(default_vnodeop_p, ap->a_desc->vdesc_offset, ap));
142 vop_panic(struct vop_generic_args *ap)
145 printf("vop_panic[%s]\n", ap->a_desc->vdesc_name);
146 panic("Filesystem goof");
153 * Strategy routine for VFS devices that have none.
155 * B_ERROR and B_INVAL must be cleared prior to calling any strategy
156 * routine. Typically this is done for a BIO_READ strategy call.
157 * Typically B_INVAL is assumed to already be clear prior to a write
158 * and should not be cleared manually unless you just made the buffer
159 * invalid. B_ERROR should be cleared either way.
163 vop_nostrategy (struct vop_strategy_args *ap)
165 printf("No strategy for buffer at %p\n", ap->a_bp);
166 vprint("", ap->a_vp);
167 vprint("", ap->a_bp->b_vp);
168 ap->a_bp->b_flags |= B_ERROR;
169 ap->a_bp->b_error = EOPNOTSUPP;
176 struct vop_pathconf_args /* {
183 switch (ap->a_name) {
185 *ap->a_retval = LINK_MAX;
188 *ap->a_retval = MAX_CANON;
191 *ap->a_retval = MAX_INPUT;
194 *ap->a_retval = PIPE_BUF;
196 case _PC_CHOWN_RESTRICTED:
200 *ap->a_retval = _POSIX_VDISABLE;
209 * Standard lock, unlock and islocked functions.
211 * These depend on the lock structure being the first element in the
212 * inode, ie: vp->v_data points to the the lock!
216 struct vop_lock_args /* {
224 if ((l = (struct lock *)ap->a_vp->v_data) == NULL) {
225 if (ap->a_flags & LK_INTERLOCK)
226 simple_unlock(&ap->a_vp->v_interlock);
231 return (lockmgr(l, ap->a_flags, &ap->a_vp->v_interlock, ap->a_p));
233 return (debuglockmgr(l, ap->a_flags, &ap->a_vp->v_interlock, ap->a_p,
234 "vop_stdlock", ap->a_vp->filename, ap->a_vp->line));
240 struct vop_unlock_args /* {
248 if ((l = (struct lock *)ap->a_vp->v_data) == NULL) {
249 if (ap->a_flags & LK_INTERLOCK)
250 simple_unlock(&ap->a_vp->v_interlock);
254 return (lockmgr(l, ap->a_flags | LK_RELEASE, &ap->a_vp->v_interlock,
260 struct vop_islocked_args /* {
267 if ((l = (struct lock *)ap->a_vp->v_data) == NULL)
270 return (lockstatus(l, ap->a_p));
274 * Return true for select/poll.
278 struct vop_poll_args /* {
281 struct ucred *a_cred;
286 * Return true for read/write. If the user asked for something
287 * special, return POLLNVAL, so that clients have a way of
288 * determining reliably whether or not the extended
289 * functionality is present without hard-coding knowledge
290 * of specific filesystem implementations.
292 if (ap->a_events & ~POLLSTANDARD)
295 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
299 * Implement poll for local filesystems that support it.
303 struct vop_poll_args /* {
306 struct ucred *a_cred;
310 if ((ap->a_events & ~POLLSTANDARD) == 0)
311 return (ap->a_events & (POLLRDNORM|POLLWRNORM));
312 return (vn_pollrecord(ap->a_vp, ap->a_p, ap->a_events));
317 struct vop_bwrite_args *ap;
319 return (bwrite(ap->a_bp));
323 * Stubs to use when there is no locking to be done on the underlying object.
324 * A minimal shared lock is necessary to ensure that the underlying object
325 * is not revoked while an operation is in progress. So, an active shared
326 * count is maintained in an auxillary vnode lock structure.
330 struct vop_lock_args /* {
337 * This code cannot be used until all the non-locking filesystems
338 * (notably NFS) are converted to properly lock and release nodes.
339 * Also, certain vnode operations change the locking state within
340 * the operation (create, mknod, remove, link, rename, mkdir, rmdir,
341 * and symlink). Ideally these operations should not change the
342 * lock state, but should be changed to let the caller of the
343 * function unlock them. Otherwise all intermediate vnode layers
344 * (such as union, umapfs, etc) must catch these functions to do
345 * the necessary locking at their layer. Note that the inactive
346 * and lookup operations also change their lock state, but this
347 * cannot be avoided, so these two operations will always need
348 * to be handled in intermediate layers.
350 struct vnode *vp = ap->a_vp;
351 int vnflags, flags = ap->a_flags;
353 if (vp->v_vnlock == NULL) {
354 if ((flags & LK_TYPE_MASK) == LK_DRAIN)
356 MALLOC(vp->v_vnlock, struct lock *, sizeof(struct lock),
358 lockinit(vp->v_vnlock, PVFS, "vnlock", 0, LK_NOPAUSE);
360 switch (flags & LK_TYPE_MASK) {
365 #ifdef DEBUG_VFS_LOCKS
367 * Normally, we use shared locks here, but that confuses
368 * the locking assertions.
370 vnflags = LK_EXCLUSIVE;
382 panic("vop_sharedlock: bad operation %d", flags & LK_TYPE_MASK);
384 if (flags & LK_INTERLOCK)
385 vnflags |= LK_INTERLOCK;
387 return (lockmgr(vp->v_vnlock, vnflags, &vp->v_interlock, ap->a_p));
389 return (debuglockmgr(vp->v_vnlock, vnflags, &vp->v_interlock, ap->a_p,
390 "vop_sharedlock", vp->filename, vp->line));
395 * Stubs to use when there is no locking to be done on the underlying object.
396 * A minimal shared lock is necessary to ensure that the underlying object
397 * is not revoked while an operation is in progress. So, an active shared
398 * count is maintained in an auxillary vnode lock structure.
402 struct vop_lock_args /* {
410 * This code cannot be used until all the non-locking filesystems
411 * (notably NFS) are converted to properly lock and release nodes.
412 * Also, certain vnode operations change the locking state within
413 * the operation (create, mknod, remove, link, rename, mkdir, rmdir,
414 * and symlink). Ideally these operations should not change the
415 * lock state, but should be changed to let the caller of the
416 * function unlock them. Otherwise all intermediate vnode layers
417 * (such as union, umapfs, etc) must catch these functions to do
418 * the necessary locking at their layer. Note that the inactive
419 * and lookup operations also change their lock state, but this
420 * cannot be avoided, so these two operations will always need
421 * to be handled in intermediate layers.
423 struct vnode *vp = ap->a_vp;
424 int vnflags, flags = ap->a_flags;
426 if (vp->v_vnlock == NULL) {
427 if ((flags & LK_TYPE_MASK) == LK_DRAIN)
429 MALLOC(vp->v_vnlock, struct lock *, sizeof(struct lock),
431 lockinit(vp->v_vnlock, PVFS, "vnlock", 0, LK_NOPAUSE);
433 switch (flags & LK_TYPE_MASK) {
447 panic("vop_nolock: bad operation %d", flags & LK_TYPE_MASK);
449 if (flags & LK_INTERLOCK)
450 vnflags |= LK_INTERLOCK;
451 return(lockmgr(vp->v_vnlock, vnflags, &vp->v_interlock, ap->a_p));
454 * Since we are not using the lock manager, we must clear
455 * the interlock here.
457 if (ap->a_flags & LK_INTERLOCK)
458 simple_unlock(&ap->a_vp->v_interlock);
464 * Do the inverse of vop_nolock, handling the interlock in a compatible way.
468 struct vop_unlock_args /* {
474 struct vnode *vp = ap->a_vp;
476 if (vp->v_vnlock == NULL) {
477 if (ap->a_flags & LK_INTERLOCK)
478 simple_unlock(&ap->a_vp->v_interlock);
481 return (lockmgr(vp->v_vnlock, LK_RELEASE | ap->a_flags,
482 &ap->a_vp->v_interlock, ap->a_p));
486 * Return whether or not the node is in use.
490 struct vop_islocked_args /* {
495 struct vnode *vp = ap->a_vp;
497 if (vp->v_vnlock == NULL)
499 return (lockstatus(vp->v_vnlock, ap->a_p));
504 * used to fill the vfs fucntion table to get reasonable default return values.
507 vfs_stdmount (mp, path, data, ndp, p)
511 struct nameidata *ndp;
518 vfs_stdunmount (mp, mntflags, p)
527 vfs_stdroot (mp, vpp)
535 vfs_stdstatfs (mp, sbp, p)
544 vfs_stdvptofh (vp, fhp)
552 vfs_stdstart (mp, flags, p)
561 vfs_stdquotactl (mp, cmds, uid, arg, p)
572 vfs_stdsync (mp, waitfor, cred, p)
582 vfs_stdvget (mp, ino, vpp)
591 vfs_stdfhtovp (mp, fhp, vpp)
600 vfs_stdcheckexp (mp, nam, extflagsp, credanonp)
602 struct sockaddr *nam;
604 struct ucred **credanonp;
611 struct vfsconf *vfsp;
618 struct vfsconf *vfsp;
624 vfs_stdextattrctl(mp, cmd, attrname, arg, p)
627 const char *attrname;
634 /* end of vfs default ops */