[BACK]Return to kernfs_vfsops.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / miscfs / kernfs

Annotation of src/sys/miscfs/kernfs/kernfs_vfsops.c, Revision 1.48

1.48    ! christos    1: /*     $NetBSD: kernfs_vfsops.c,v 1.47 2003/02/01 06:23:46 thorpej Exp $       */
1.18      cgd         2:
1.1       cgd         3: /*
1.32      fvdl        4:  * Copyright (c) 1992, 1993, 1995
1.15      mycroft     5:  *     The Regents of the University of California.  All rights reserved.
1.1       cgd         6:  *
1.11      cgd         7:  * This code is derived from software donated to Berkeley by
1.1       cgd         8:  * Jan-Simon Pendry.
                      9:  *
1.2       cgd        10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     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:
1.11      cgd        20:  *     This product includes software developed by the University of
                     21:  *     California, Berkeley and its contributors.
1.2       cgd        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.
1.1       cgd        25:  *
1.2       cgd        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
                     36:  * SUCH DAMAGE.
1.1       cgd        37:  *
1.32      fvdl       38:  *     @(#)kernfs_vfsops.c     8.10 (Berkeley) 5/14/95
1.1       cgd        39:  */
                     40:
                     41: /*
                     42:  * Kernel params Filesystem
                     43:  */
1.42      lukem      44:
                     45: #include <sys/cdefs.h>
1.48    ! christos   46: __KERNEL_RCSID(0, "$NetBSD: kernfs_vfsops.c,v 1.47 2003/02/01 06:23:46 thorpej Exp $");
1.33      jonathan   47:
1.40      mrg        48: #if defined(_KERNEL_OPT)
1.33      jonathan   49: #include "opt_compat_netbsd.h"
                     50: #endif
1.1       cgd        51:
1.9       mycroft    52: #include <sys/param.h>
                     53: #include <sys/systm.h>
1.15      mycroft    54: #include <sys/conf.h>
1.9       mycroft    55: #include <sys/proc.h>
                     56: #include <sys/vnode.h>
                     57: #include <sys/mount.h>
                     58: #include <sys/namei.h>
                     59: #include <sys/malloc.h>
1.15      mycroft    60:
                     61: #include <miscfs/specfs/specdev.h>
1.9       mycroft    62: #include <miscfs/kernfs/kernfs.h>
1.1       cgd        63:
1.47      thorpej    64: MALLOC_DEFINE(M_KERNFSMNT, "kernfs mount", "kernfs mount structures");
                     65:
1.15      mycroft    66: dev_t rrootdev = NODEV;
                     67:
1.25      christos   68: void   kernfs_init __P((void));
1.36      jdolecek   69: void   kernfs_done __P((void));
1.25      christos   70: void   kernfs_get_rrootdev __P((void));
1.29      cgd        71: int    kernfs_mount __P((struct mount *, const char *, void *,
                     72:            struct nameidata *, struct proc *));
1.25      christos   73: int    kernfs_start __P((struct mount *, int, struct proc *));
                     74: int    kernfs_unmount __P((struct mount *, int, struct proc *));
                     75: int    kernfs_root __P((struct mount *, struct vnode **));
                     76: int    kernfs_statfs __P((struct mount *, struct statfs *, struct proc *));
                     77: int    kernfs_quotactl __P((struct mount *, int, uid_t, caddr_t,
                     78:                             struct proc *));
                     79: int    kernfs_sync __P((struct mount *, int, struct ucred *, struct proc *));
                     80: int    kernfs_vget __P((struct mount *, ino_t, struct vnode **));
1.35      wrstuden   81: int    kernfs_fhtovp __P((struct mount *, struct fid *, struct vnode **));
                     82: int    kernfs_checkexp __P((struct mount *, struct mbuf *, int *,
                     83:                           struct ucred **));
1.25      christos   84: int    kernfs_vptofh __P((struct vnode *, struct fid *));
1.32      fvdl       85: int    kernfs_sysctl __P((int *, u_int, void *, size_t *, void *, size_t,
                     86:                           struct proc *));
1.25      christos   87:
                     88: void
1.1       cgd        89: kernfs_init()
                     90: {
1.10      cgd        91: }
                     92:
1.11      cgd        93: void
1.36      jdolecek   94: kernfs_done()
                     95: {
                     96: }
                     97:
                     98: void
1.15      mycroft    99: kernfs_get_rrootdev()
1.10      cgd       100: {
1.16      mycroft   101:        static int tried = 0;
1.10      cgd       102:
1.16      mycroft   103:        if (tried) {
1.15      mycroft   104:                /* Already did it once. */
                    105:                return;
                    106:        }
1.16      mycroft   107:        tried = 1;
                    108:
                    109:        if (rootdev == NODEV)
                    110:                return;
1.45      gehenna   111:        rrootdev = devsw_blk2chr(rootdev);
                    112:        if (rrootdev != NODEV) {
1.39      mrg       113: #ifdef KERNFS_DIAGNOSTIC
                    114:        printf("kernfs_mount: rootdev = %u.%u; rrootdev = %u.%u\n",
                    115:            major(rootdev), minor(rootdev), major(rrootdev), minor(rrootdev));
                    116: #endif
1.45      gehenna   117:                return;
1.10      cgd       118:        }
1.16      mycroft   119:        rrootdev = NODEV;
1.28      christos  120:        printf("kernfs_get_rrootdev: no raw root device\n");
1.1       cgd       121: }
                    122:
                    123: /*
1.15      mycroft   124:  * Mount the Kernel params filesystem
1.1       cgd       125:  */
1.25      christos  126: int
1.1       cgd       127: kernfs_mount(mp, path, data, ndp, p)
                    128:        struct mount *mp;
1.29      cgd       129:        const char *path;
                    130:        void *data;
1.1       cgd       131:        struct nameidata *ndp;
                    132:        struct proc *p;
                    133: {
                    134:        int error = 0;
                    135:        struct kernfs_mount *fmp;
                    136:        struct vnode *rvp;
                    137:
                    138: #ifdef KERNFS_DIAGNOSTIC
1.30      christos  139:        printf("kernfs_mount(mp = %p)\n", mp);
1.1       cgd       140: #endif
                    141:
1.46      christos  142:        if (mp->mnt_flag & MNT_GETARGS)
                    143:                return 0;
1.1       cgd       144:        /*
                    145:         * Update is a no-op
                    146:         */
                    147:        if (mp->mnt_flag & MNT_UPDATE)
                    148:                return (EOPNOTSUPP);
                    149:
1.25      christos  150:        error = getnewvnode(VT_KERNFS, mp, kernfs_vnodeop_p, &rvp);
                    151:        if (error)
1.1       cgd       152:                return (error);
                    153:
1.15      mycroft   154:        MALLOC(fmp, struct kernfs_mount *, sizeof(struct kernfs_mount),
1.47      thorpej   155:            M_KERNFSMNT, M_WAITOK);
1.1       cgd       156:        rvp->v_type = VDIR;
                    157:        rvp->v_flag |= VROOT;
                    158: #ifdef KERNFS_DIAGNOSTIC
1.30      christos  159:        printf("kernfs_mount: root vp = %p\n", rvp);
1.1       cgd       160: #endif
                    161:        fmp->kf_root = rvp;
                    162:        mp->mnt_flag |= MNT_LOCAL;
1.44      soren     163:        mp->mnt_data = fmp;
1.37      assar     164:        vfs_getnewfsid(mp);
1.1       cgd       165:
1.48    ! christos  166:        error = set_statfs_info(path, UIO_USERSPACE, "kernfs", UIO_SYSSPACE,
        !           167:            mp, p);
1.1       cgd       168: #ifdef KERNFS_DIAGNOSTIC
1.28      christos  169:        printf("kernfs_mount: at %s\n", mp->mnt_stat.f_mntonname);
1.1       cgd       170: #endif
1.10      cgd       171:
1.15      mycroft   172:        kernfs_get_rrootdev();
1.48    ! christos  173:        return error;
1.1       cgd       174: }
                    175:
1.25      christos  176: int
1.1       cgd       177: kernfs_start(mp, flags, p)
                    178:        struct mount *mp;
                    179:        int flags;
                    180:        struct proc *p;
                    181: {
1.15      mycroft   182:
1.1       cgd       183:        return (0);
                    184: }
                    185:
1.25      christos  186: int
1.1       cgd       187: kernfs_unmount(mp, mntflags, p)
                    188:        struct mount *mp;
                    189:        int mntflags;
                    190:        struct proc *p;
                    191: {
                    192:        int error;
                    193:        int flags = 0;
                    194:        struct vnode *rootvp = VFSTOKERNFS(mp)->kf_root;
                    195:
                    196: #ifdef KERNFS_DIAGNOSTIC
1.30      christos  197:        printf("kernfs_unmount(mp = %p)\n", mp);
1.1       cgd       198: #endif
                    199:
1.32      fvdl      200:         if (mntflags & MNT_FORCE)
1.1       cgd       201:                flags |= FORCECLOSE;
                    202:
                    203:        /*
                    204:         * Clear out buffer cache.  I don't think we
                    205:         * ever get anything cached at this level at the
                    206:         * moment, but who knows...
                    207:         */
                    208:        if (rootvp->v_usecount > 1)
                    209:                return (EBUSY);
                    210: #ifdef KERNFS_DIAGNOSTIC
1.28      christos  211:        printf("kernfs_unmount: calling vflush\n");
1.1       cgd       212: #endif
1.25      christos  213:        if ((error = vflush(mp, rootvp, flags)) != 0)
1.1       cgd       214:                return (error);
                    215:
                    216: #ifdef KERNFS_DIAGNOSTIC
                    217:        vprint("kernfs root", rootvp);
1.15      mycroft   218: #endif
1.1       cgd       219:        /*
1.15      mycroft   220:         * Clean out the old root vnode for reuse.
1.1       cgd       221:         */
                    222:        vrele(rootvp);
                    223:        vgone(rootvp);
                    224:        /*
                    225:         * Finally, throw away the kernfs_mount structure
                    226:         */
1.47      thorpej   227:        free(mp->mnt_data, M_KERNFSMNT);
1.1       cgd       228:        mp->mnt_data = 0;
1.15      mycroft   229:        return (0);
1.1       cgd       230: }
                    231:
1.25      christos  232: int
1.1       cgd       233: kernfs_root(mp, vpp)
                    234:        struct mount *mp;
                    235:        struct vnode **vpp;
                    236: {
                    237:        struct vnode *vp;
                    238:
                    239: #ifdef KERNFS_DIAGNOSTIC
1.30      christos  240:        printf("kernfs_root(mp = %p)\n", mp);
1.1       cgd       241: #endif
                    242:
                    243:        /*
                    244:         * Return locked reference to root.
                    245:         */
                    246:        vp = VFSTOKERNFS(mp)->kf_root;
                    247:        VREF(vp);
1.32      fvdl      248:        vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
1.1       cgd       249:        *vpp = vp;
                    250:        return (0);
                    251: }
                    252:
1.25      christos  253: int
1.1       cgd       254: kernfs_quotactl(mp, cmd, uid, arg, p)
                    255:        struct mount *mp;
                    256:        int cmd;
                    257:        uid_t uid;
                    258:        caddr_t arg;
                    259:        struct proc *p;
                    260: {
1.15      mycroft   261:
1.1       cgd       262:        return (EOPNOTSUPP);
                    263: }
                    264:
1.25      christos  265: int
1.1       cgd       266: kernfs_statfs(mp, sbp, p)
                    267:        struct mount *mp;
                    268:        struct statfs *sbp;
                    269:        struct proc *p;
                    270: {
                    271:
                    272: #ifdef KERNFS_DIAGNOSTIC
1.30      christos  273:        printf("kernfs_statfs(mp = %p)\n", mp);
1.1       cgd       274: #endif
                    275:
                    276:        sbp->f_bsize = DEV_BSIZE;
1.13      cgd       277:        sbp->f_iosize = DEV_BSIZE;
1.1       cgd       278:        sbp->f_blocks = 2;              /* 1K to keep df happy */
                    279:        sbp->f_bfree = 0;
                    280:        sbp->f_bavail = 0;
1.15      mycroft   281:        sbp->f_files = 0;
                    282:        sbp->f_ffree = 0;
1.32      fvdl      283: #ifdef COMPAT_09
                    284:        sbp->f_type = 7;
                    285: #else
                    286:        sbp->f_type = 0;
                    287: #endif
1.48    ! christos  288:        copy_statfs_info(sbp, mp);
1.1       cgd       289:        return (0);
                    290: }
                    291:
1.25      christos  292: /*ARGSUSED*/
                    293: int
                    294: kernfs_sync(mp, waitfor, uc, p)
1.1       cgd       295:        struct mount *mp;
                    296:        int waitfor;
1.25      christos  297:        struct ucred *uc;
                    298:        struct proc *p;
1.1       cgd       299: {
1.15      mycroft   300:
1.1       cgd       301:        return (0);
                    302: }
                    303:
1.15      mycroft   304: /*
                    305:  * Kernfs flat namespace lookup.
                    306:  * Currently unsupported.
                    307:  */
1.25      christos  308: int
1.15      mycroft   309: kernfs_vget(mp, ino, vpp)
                    310:        struct mount *mp;
                    311:        ino_t ino;
                    312:        struct vnode **vpp;
                    313: {
                    314:
                    315:        return (EOPNOTSUPP);
                    316: }
                    317:
1.25      christos  318: /*ARGSUSED*/
                    319: int
1.35      wrstuden  320: kernfs_fhtovp(mp, fhp, vpp)
1.1       cgd       321:        struct mount *mp;
                    322:        struct fid *fhp;
1.35      wrstuden  323:        struct vnode **vpp;
                    324: {
                    325:
                    326:        return (EOPNOTSUPP);
                    327: }
                    328:
                    329: /*ARGSUSED*/
                    330: int
                    331: kernfs_checkexp(mp, mb, what, anon)
                    332:        struct mount *mp;
1.25      christos  333:        struct mbuf *mb;
                    334:        int *what;
                    335:        struct ucred **anon;
1.1       cgd       336: {
1.15      mycroft   337:
1.1       cgd       338:        return (EOPNOTSUPP);
                    339: }
                    340:
1.25      christos  341: /*ARGSUSED*/
                    342: int
1.1       cgd       343: kernfs_vptofh(vp, fhp)
                    344:        struct vnode *vp;
                    345:        struct fid *fhp;
                    346: {
1.15      mycroft   347:
1.1       cgd       348:        return (EOPNOTSUPP);
                    349: }
                    350:
1.32      fvdl      351: int
                    352: kernfs_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
                    353:        int *name;
                    354:        u_int namelen;
                    355:        void *oldp;
                    356:        size_t *oldlenp;
                    357:        void *newp;
                    358:        size_t newlen;
                    359:        struct proc *p;
                    360: {
                    361:        return (EOPNOTSUPP);
                    362: }
                    363:
1.38      jdolecek  364: extern const struct vnodeopv_desc kernfs_vnodeop_opv_desc;
1.31      thorpej   365:
1.38      jdolecek  366: const struct vnodeopv_desc * const kernfs_vnodeopv_descs[] = {
1.31      thorpej   367:        &kernfs_vnodeop_opv_desc,
                    368:        NULL,
                    369: };
                    370:
1.1       cgd       371: struct vfsops kernfs_vfsops = {
1.12      cgd       372:        MOUNT_KERNFS,
1.1       cgd       373:        kernfs_mount,
                    374:        kernfs_start,
                    375:        kernfs_unmount,
                    376:        kernfs_root,
                    377:        kernfs_quotactl,
                    378:        kernfs_statfs,
                    379:        kernfs_sync,
1.15      mycroft   380:        kernfs_vget,
1.1       cgd       381:        kernfs_fhtovp,
                    382:        kernfs_vptofh,
                    383:        kernfs_init,
1.41      chs       384:        NULL,
1.36      jdolecek  385:        kernfs_done,
1.32      fvdl      386:        kernfs_sysctl,
1.31      thorpej   387:        NULL,                           /* vfs_mountroot */
1.35      wrstuden  388:        kernfs_checkexp,
1.31      thorpej   389:        kernfs_vnodeopv_descs,
1.1       cgd       390: };

CVSweb <webmaster@jp.NetBSD.org>