[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.88

1.88    ! dsl         1: /*     $NetBSD: kernfs_vfsops.c,v 1.87 2008/12/17 20:51:36 cegger 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.
1.53      agc        18:  * 3. Neither the name of the University nor the names of its contributors
1.2       cgd        19:  *    may be used to endorse or promote products derived from this software
                     20:  *    without specific prior written permission.
1.1       cgd        21:  *
1.2       cgd        22:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     23:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     24:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     25:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     26:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     27:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     28:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     29:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     30:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     31:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     32:  * SUCH DAMAGE.
1.1       cgd        33:  *
1.32      fvdl       34:  *     @(#)kernfs_vfsops.c     8.10 (Berkeley) 5/14/95
1.1       cgd        35:  */
                     36:
                     37: /*
                     38:  * Kernel params Filesystem
                     39:  */
1.42      lukem      40:
                     41: #include <sys/cdefs.h>
1.88    ! dsl        42: __KERNEL_RCSID(0, "$NetBSD: kernfs_vfsops.c,v 1.87 2008/12/17 20:51:36 cegger Exp $");
1.33      jonathan   43:
1.54      itojun     44: #ifdef _KERNEL_OPT
1.33      jonathan   45: #include "opt_compat_netbsd.h"
                     46: #endif
1.1       cgd        47:
1.9       mycroft    48: #include <sys/param.h>
                     49: #include <sys/systm.h>
1.57      atatat     50: #include <sys/sysctl.h>
1.15      mycroft    51: #include <sys/conf.h>
1.9       mycroft    52: #include <sys/proc.h>
                     53: #include <sys/vnode.h>
                     54: #include <sys/mount.h>
                     55: #include <sys/namei.h>
1.60      christos   56: #include <sys/dirent.h>
1.9       mycroft    57: #include <sys/malloc.h>
1.54      itojun     58: #include <sys/syslog.h>
1.71      elad       59: #include <sys/kauth.h>
1.85      rumble     60: #include <sys/module.h>
1.15      mycroft    61:
1.83      dholland   62: #include <miscfs/genfs/genfs.h>
1.15      mycroft    63: #include <miscfs/specfs/specdev.h>
1.9       mycroft    64: #include <miscfs/kernfs/kernfs.h>
1.1       cgd        65:
1.85      rumble     66: MODULE(MODULE_CLASS_VFS, kernfs, NULL);
                     67:
1.77      pooka      68: MALLOC_JUSTDEFINE(M_KERNFSMNT, "kernfs mount", "kernfs mount structures");
1.47      thorpej    69:
1.15      mycroft    70: dev_t rrootdev = NODEV;
                     71:
1.81      pooka      72: VFS_PROTOS(kernfs);
                     73:
1.68      xtraeme    74: void   kernfs_get_rrootdev(void);
1.25      christos   75:
1.86      rumble     76: static struct sysctllog *kernfs_sysctl_log;
                     77:
1.25      christos   78: void
1.1       cgd        79: kernfs_init()
                     80: {
1.77      pooka      81:
1.49      christos   82:        malloc_type_attach(M_KERNFSMNT);
1.54      itojun     83:        kernfs_hashinit();
                     84: }
                     85:
                     86: void
                     87: kernfs_reinit()
                     88: {
                     89:        kernfs_hashreinit();
1.10      cgd        90: }
                     91:
1.11      cgd        92: void
1.36      jdolecek   93: kernfs_done()
                     94: {
1.77      pooka      95:
                     96:        kernfs_hashdone();
1.49      christos   97:        malloc_type_detach(M_KERNFSMNT);
1.36      jdolecek   98: }
                     99:
                    100: void
1.15      mycroft   101: kernfs_get_rrootdev()
1.10      cgd       102: {
1.16      mycroft   103:        static int tried = 0;
1.10      cgd       104:
1.16      mycroft   105:        if (tried) {
1.15      mycroft   106:                /* Already did it once. */
                    107:                return;
                    108:        }
1.16      mycroft   109:        tried = 1;
                    110:
                    111:        if (rootdev == NODEV)
                    112:                return;
1.45      gehenna   113:        rrootdev = devsw_blk2chr(rootdev);
1.54      itojun    114:        if (rrootdev != NODEV)
1.45      gehenna   115:                return;
1.16      mycroft   116:        rrootdev = NODEV;
1.28      christos  117:        printf("kernfs_get_rrootdev: no raw root device\n");
1.1       cgd       118: }
                    119:
                    120: /*
1.15      mycroft   121:  * Mount the Kernel params filesystem
1.1       cgd       122:  */
1.25      christos  123: int
1.82      pooka     124: kernfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
1.1       cgd       125: {
1.82      pooka     126:        struct lwp *l = curlwp;
1.1       cgd       127:        int error = 0;
                    128:        struct kernfs_mount *fmp;
                    129:
1.54      itojun    130:        if (UIO_MX & (UIO_MX - 1)) {
                    131:                log(LOG_ERR, "kernfs: invalid directory entry size");
                    132:                return (EINVAL);
                    133:        }
1.1       cgd       134:
1.78      dsl       135:        if (mp->mnt_flag & MNT_GETARGS) {
                    136:                *data_len = 0;
1.46      christos  137:                return 0;
1.78      dsl       138:        }
1.1       cgd       139:        /*
                    140:         * Update is a no-op
                    141:         */
                    142:        if (mp->mnt_flag & MNT_UPDATE)
                    143:                return (EOPNOTSUPP);
                    144:
1.87      cegger    145:        fmp = malloc(sizeof(struct kernfs_mount), M_KERNFSMNT, M_WAITOK|M_ZERO);
1.54      itojun    146:        TAILQ_INIT(&fmp->nodelist);
                    147:
1.65      jdolecek  148:        mp->mnt_stat.f_namemax = MAXNAMLEN;
                    149:        mp->mnt_flag |= MNT_LOCAL;
1.54      itojun    150:        mp->mnt_data = fmp;
1.37      assar     151:        vfs_getnewfsid(mp);
1.1       cgd       152:
1.64      tron      153:        if ((error = set_statvfs_info(path, UIO_USERSPACE, "kernfs",
1.79      pooka     154:            UIO_SYSSPACE, mp->mnt_op->vfs_name, mp, l)) != 0) {
1.64      tron      155:                free(fmp, M_KERNFSMNT);
                    156:                return error;
                    157:        }
1.10      cgd       158:
1.15      mycroft   159:        kernfs_get_rrootdev();
1.64      tron      160:        return 0;
1.1       cgd       161: }
                    162:
1.25      christos  163: int
1.82      pooka     164: kernfs_start(struct mount *mp, int flags)
1.1       cgd       165: {
1.15      mycroft   166:
1.1       cgd       167:        return (0);
                    168: }
                    169:
1.25      christos  170: int
1.82      pooka     171: kernfs_unmount(struct mount *mp, int mntflags)
1.1       cgd       172: {
                    173:        int error;
                    174:        int flags = 0;
                    175:
1.54      itojun    176:        if (mntflags & MNT_FORCE)
1.1       cgd       177:                flags |= FORCECLOSE;
                    178:
1.54      itojun    179:        if ((error = vflush(mp, 0, flags)) != 0)
1.1       cgd       180:                return (error);
                    181:
                    182:        /*
                    183:         * Finally, throw away the kernfs_mount structure
                    184:         */
1.47      thorpej   185:        free(mp->mnt_data, M_KERNFSMNT);
1.64      tron      186:        mp->mnt_data = NULL;
1.15      mycroft   187:        return (0);
1.1       cgd       188: }
                    189:
1.25      christos  190: int
1.88    ! dsl       191: kernfs_root(struct mount *mp, struct vnode **vpp)
1.1       cgd       192: {
                    193:
1.54      itojun    194:        /* setup "." */
1.56      darcy     195:        return (kernfs_allocvp(mp, vpp, KFSkern, &kern_targets[0], 0));
1.1       cgd       196: }
                    197:
1.25      christos  198: int
1.82      pooka     199: kernfs_statvfs(struct mount *mp, struct statvfs *sbp)
1.1       cgd       200: {
                    201:
                    202:        sbp->f_bsize = DEV_BSIZE;
1.59      christos  203:        sbp->f_frsize = DEV_BSIZE;
1.13      cgd       204:        sbp->f_iosize = DEV_BSIZE;
1.1       cgd       205:        sbp->f_blocks = 2;              /* 1K to keep df happy */
                    206:        sbp->f_bfree = 0;
                    207:        sbp->f_bavail = 0;
1.59      christos  208:        sbp->f_bresvd = 0;
1.54      itojun    209:        sbp->f_files = 1024;    /* XXX lie */
                    210:        sbp->f_ffree = 128;     /* XXX lie */
1.59      christos  211:        sbp->f_favail = 128;    /* XXX lie */
                    212:        sbp->f_fresvd = 0;
                    213:        copy_statvfs_info(sbp, mp);
1.1       cgd       214:        return (0);
                    215: }
                    216:
1.25      christos  217: /*ARGSUSED*/
                    218: int
1.74      christos  219: kernfs_sync(struct mount *mp, int waitfor,
1.82      pooka     220:     kauth_cred_t uc)
1.1       cgd       221: {
1.15      mycroft   222:
1.1       cgd       223:        return (0);
                    224: }
                    225:
1.15      mycroft   226: /*
                    227:  * Kernfs flat namespace lookup.
                    228:  * Currently unsupported.
                    229:  */
1.25      christos  230: int
1.74      christos  231: kernfs_vget(struct mount *mp, ino_t ino,
                    232:     struct vnode **vpp)
1.15      mycroft   233: {
                    234:
                    235:        return (EOPNOTSUPP);
                    236: }
                    237:
1.38      jdolecek  238: extern const struct vnodeopv_desc kernfs_vnodeop_opv_desc;
1.31      thorpej   239:
1.38      jdolecek  240: const struct vnodeopv_desc * const kernfs_vnodeopv_descs[] = {
1.31      thorpej   241:        &kernfs_vnodeop_opv_desc,
                    242:        NULL,
                    243: };
                    244:
1.1       cgd       245: struct vfsops kernfs_vfsops = {
1.12      cgd       246:        MOUNT_KERNFS,
1.78      dsl       247:        0,
1.1       cgd       248:        kernfs_mount,
                    249:        kernfs_start,
                    250:        kernfs_unmount,
                    251:        kernfs_root,
1.82      pooka     252:        (void *)eopnotsupp,             /* vfs_quotactl */
1.59      christos  253:        kernfs_statvfs,
1.1       cgd       254:        kernfs_sync,
1.15      mycroft   255:        kernfs_vget,
1.75      chs       256:        (void *)eopnotsupp,             /* vfs_fhtovp */
                    257:        (void *)eopnotsupp,             /* vfs_vptofh */
1.1       cgd       258:        kernfs_init,
1.54      itojun    259:        kernfs_reinit,
1.36      jdolecek  260:        kernfs_done,
1.31      thorpej   261:        NULL,                           /* vfs_mountroot */
1.63      hannken   262:        (int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
1.66      thorpej   263:        vfs_stdextattrctl,
1.80      pooka     264:        (void *)eopnotsupp,             /* vfs_suspendctl */
1.83      dholland  265:        genfs_renamelock_enter,
                    266:        genfs_renamelock_exit,
1.84      ad        267:        (void *)eopnotsupp,
1.31      thorpej   268:        kernfs_vnodeopv_descs,
1.72      christos  269:        0,
                    270:        { NULL, NULL },
1.1       cgd       271: };
1.85      rumble    272:
                    273: static int
                    274: kernfs_modcmd(modcmd_t cmd, void *arg)
                    275: {
1.86      rumble    276:        int error;
1.85      rumble    277:
                    278:        switch (cmd) {
                    279:        case MODULE_CMD_INIT:
1.86      rumble    280:                error = vfs_attach(&kernfs_vfsops);
                    281:                if (error != 0)
                    282:                        break;
                    283:                sysctl_createv(&kernfs_sysctl_log, 0, NULL, NULL,
                    284:                               CTLFLAG_PERMANENT,
                    285:                               CTLTYPE_NODE, "vfs", NULL,
                    286:                               NULL, 0, NULL, 0,
                    287:                               CTL_VFS, CTL_EOL);
                    288:                sysctl_createv(&kernfs_sysctl_log, 0, NULL, NULL,
                    289:                               CTLFLAG_PERMANENT,
                    290:                               CTLTYPE_NODE, "kernfs",
                    291:                               SYSCTL_DESCR("/kern file system"),
                    292:                               NULL, 0, NULL, 0,
                    293:                               CTL_VFS, 11, CTL_EOL);
                    294:                /*
                    295:                 * XXX the "11" above could be dynamic, thereby eliminating one
                    296:                 * more instance of the "number to vfs" mapping problem, but
                    297:                 * "11" is the order as taken from sys/mount.h
                    298:                 */
                    299:                break;
1.85      rumble    300:        case MODULE_CMD_FINI:
1.86      rumble    301:                error = vfs_detach(&kernfs_vfsops);
                    302:                if (error != 0)
                    303:                        break;
                    304:                sysctl_teardown(&kernfs_sysctl_log);
                    305:                break;
1.85      rumble    306:        default:
1.86      rumble    307:                error = ENOTTY;
                    308:                break;
1.85      rumble    309:        }
1.86      rumble    310:
                    311:        return (error);
1.85      rumble    312: }

CVSweb <webmaster@jp.NetBSD.org>