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

1.80    ! pooka       1: /*     $NetBSD: kernfs_vfsops.c,v 1.79 2007/07/17 11:19:34 pooka 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.80    ! pooka      42: __KERNEL_RCSID(0, "$NetBSD: kernfs_vfsops.c,v 1.79 2007/07/17 11:19:34 pooka 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.15      mycroft    60:
                     61: #include <miscfs/specfs/specdev.h>
1.9       mycroft    62: #include <miscfs/kernfs/kernfs.h>
1.1       cgd        63:
1.77      pooka      64: MALLOC_JUSTDEFINE(M_KERNFSMNT, "kernfs mount", "kernfs mount structures");
1.47      thorpej    65:
1.15      mycroft    66: dev_t rrootdev = NODEV;
                     67:
1.68      xtraeme    68: void   kernfs_init(void);
                     69: void   kernfs_reinit(void);
                     70: void   kernfs_done(void);
                     71: void   kernfs_get_rrootdev(void);
1.78      dsl        72: int    kernfs_mount(struct mount *, const char *, void *, size_t *,
1.70      christos   73:            struct nameidata *, struct lwp *);
                     74: int    kernfs_start(struct mount *, int, struct lwp *);
                     75: int    kernfs_unmount(struct mount *, int, struct lwp *);
                     76: int    kernfs_statvfs(struct mount *, struct statvfs *, struct lwp *);
1.68      xtraeme    77: int    kernfs_quotactl(struct mount *, int, uid_t, void *,
1.70      christos   78:                             struct lwp *);
1.71      elad       79: int    kernfs_sync(struct mount *, int, kauth_cred_t, struct lwp *);
1.68      xtraeme    80: int    kernfs_vget(struct mount *, ino_t, struct vnode **);
1.25      christos   81:
                     82: void
1.1       cgd        83: kernfs_init()
                     84: {
1.77      pooka      85:
1.49      christos   86:        malloc_type_attach(M_KERNFSMNT);
1.54      itojun     87:        kernfs_hashinit();
                     88: }
                     89:
                     90: void
                     91: kernfs_reinit()
                     92: {
                     93:        kernfs_hashreinit();
1.10      cgd        94: }
                     95:
1.11      cgd        96: void
1.36      jdolecek   97: kernfs_done()
                     98: {
1.77      pooka      99:
                    100:        kernfs_hashdone();
1.49      christos  101:        malloc_type_detach(M_KERNFSMNT);
1.36      jdolecek  102: }
                    103:
                    104: void
1.15      mycroft   105: kernfs_get_rrootdev()
1.10      cgd       106: {
1.16      mycroft   107:        static int tried = 0;
1.10      cgd       108:
1.16      mycroft   109:        if (tried) {
1.15      mycroft   110:                /* Already did it once. */
                    111:                return;
                    112:        }
1.16      mycroft   113:        tried = 1;
                    114:
                    115:        if (rootdev == NODEV)
                    116:                return;
1.45      gehenna   117:        rrootdev = devsw_blk2chr(rootdev);
1.54      itojun    118:        if (rrootdev != NODEV)
1.45      gehenna   119:                return;
1.16      mycroft   120:        rrootdev = NODEV;
1.28      christos  121:        printf("kernfs_get_rrootdev: no raw root device\n");
1.1       cgd       122: }
                    123:
                    124: /*
1.15      mycroft   125:  * Mount the Kernel params filesystem
1.1       cgd       126:  */
1.25      christos  127: int
1.78      dsl       128: kernfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len,
1.74      christos  129:     struct nameidata *ndp, struct lwp *l)
1.1       cgd       130: {
                    131:        int error = 0;
                    132:        struct kernfs_mount *fmp;
                    133:
1.54      itojun    134:        if (UIO_MX & (UIO_MX - 1)) {
                    135:                log(LOG_ERR, "kernfs: invalid directory entry size");
                    136:                return (EINVAL);
                    137:        }
1.1       cgd       138:
1.78      dsl       139:        if (mp->mnt_flag & MNT_GETARGS) {
                    140:                *data_len = 0;
1.46      christos  141:                return 0;
1.78      dsl       142:        }
1.1       cgd       143:        /*
                    144:         * Update is a no-op
                    145:         */
                    146:        if (mp->mnt_flag & MNT_UPDATE)
                    147:                return (EOPNOTSUPP);
                    148:
1.15      mycroft   149:        MALLOC(fmp, struct kernfs_mount *, sizeof(struct kernfs_mount),
1.47      thorpej   150:            M_KERNFSMNT, M_WAITOK);
1.54      itojun    151:        memset(fmp, 0, sizeof(*fmp));
                    152:        TAILQ_INIT(&fmp->nodelist);
                    153:
1.65      jdolecek  154:        mp->mnt_stat.f_namemax = MAXNAMLEN;
                    155:        mp->mnt_flag |= MNT_LOCAL;
1.54      itojun    156:        mp->mnt_data = fmp;
1.37      assar     157:        vfs_getnewfsid(mp);
1.1       cgd       158:
1.64      tron      159:        if ((error = set_statvfs_info(path, UIO_USERSPACE, "kernfs",
1.79      pooka     160:            UIO_SYSSPACE, mp->mnt_op->vfs_name, mp, l)) != 0) {
1.64      tron      161:                free(fmp, M_KERNFSMNT);
                    162:                return error;
                    163:        }
1.10      cgd       164:
1.15      mycroft   165:        kernfs_get_rrootdev();
1.64      tron      166:        return 0;
1.1       cgd       167: }
                    168:
1.25      christos  169: int
1.74      christos  170: kernfs_start(struct mount *mp, int flags,
                    171:     struct lwp *l)
1.1       cgd       172: {
1.15      mycroft   173:
1.1       cgd       174:        return (0);
                    175: }
                    176:
1.25      christos  177: int
1.74      christos  178: kernfs_unmount(struct mount *mp, int mntflags, struct lwp *l)
1.1       cgd       179: {
                    180:        int error;
                    181:        int flags = 0;
                    182:
1.54      itojun    183:        if (mntflags & MNT_FORCE)
1.1       cgd       184:                flags |= FORCECLOSE;
                    185:
1.54      itojun    186:        if ((error = vflush(mp, 0, flags)) != 0)
1.1       cgd       187:                return (error);
                    188:
                    189:        /*
                    190:         * Finally, throw away the kernfs_mount structure
                    191:         */
1.47      thorpej   192:        free(mp->mnt_data, M_KERNFSMNT);
1.64      tron      193:        mp->mnt_data = NULL;
1.15      mycroft   194:        return (0);
1.1       cgd       195: }
                    196:
1.25      christos  197: int
1.51      thorpej   198: kernfs_root(mp, vpp)
1.1       cgd       199:        struct mount *mp;
                    200:        struct vnode **vpp;
                    201: {
                    202:
1.54      itojun    203:        /* setup "." */
1.56      darcy     204:        return (kernfs_allocvp(mp, vpp, KFSkern, &kern_targets[0], 0));
1.1       cgd       205: }
                    206:
1.25      christos  207: int
1.74      christos  208: kernfs_quotactl(struct mount *mp, int cmd, uid_t uid,
                    209:     void *arg, struct lwp *l)
1.1       cgd       210: {
1.15      mycroft   211:
1.1       cgd       212:        return (EOPNOTSUPP);
                    213: }
                    214:
1.25      christos  215: int
1.74      christos  216: kernfs_statvfs(struct mount *mp, struct statvfs *sbp, struct lwp *l)
1.1       cgd       217: {
                    218:
                    219:        sbp->f_bsize = DEV_BSIZE;
1.59      christos  220:        sbp->f_frsize = DEV_BSIZE;
1.13      cgd       221:        sbp->f_iosize = DEV_BSIZE;
1.1       cgd       222:        sbp->f_blocks = 2;              /* 1K to keep df happy */
                    223:        sbp->f_bfree = 0;
                    224:        sbp->f_bavail = 0;
1.59      christos  225:        sbp->f_bresvd = 0;
1.54      itojun    226:        sbp->f_files = 1024;    /* XXX lie */
                    227:        sbp->f_ffree = 128;     /* XXX lie */
1.59      christos  228:        sbp->f_favail = 128;    /* XXX lie */
                    229:        sbp->f_fresvd = 0;
                    230:        copy_statvfs_info(sbp, mp);
1.1       cgd       231:        return (0);
                    232: }
                    233:
1.25      christos  234: /*ARGSUSED*/
                    235: int
1.74      christos  236: kernfs_sync(struct mount *mp, int waitfor,
                    237:     kauth_cred_t uc, struct lwp *l)
1.1       cgd       238: {
1.15      mycroft   239:
1.1       cgd       240:        return (0);
                    241: }
                    242:
1.15      mycroft   243: /*
                    244:  * Kernfs flat namespace lookup.
                    245:  * Currently unsupported.
                    246:  */
1.25      christos  247: int
1.74      christos  248: kernfs_vget(struct mount *mp, ino_t ino,
                    249:     struct vnode **vpp)
1.15      mycroft   250: {
                    251:
                    252:        return (EOPNOTSUPP);
                    253: }
                    254:
1.58      atatat    255: SYSCTL_SETUP(sysctl_vfs_kernfs_setup, "sysctl vfs.kern subtree setup")
1.32      fvdl      256: {
1.57      atatat    257:
1.58      atatat    258:        sysctl_createv(clog, 0, NULL, NULL,
                    259:                       CTLFLAG_PERMANENT,
1.57      atatat    260:                       CTLTYPE_NODE, "vfs", NULL,
                    261:                       NULL, 0, NULL, 0,
                    262:                       CTL_VFS, CTL_EOL);
1.58      atatat    263:        sysctl_createv(clog, 0, NULL, NULL,
                    264:                       CTLFLAG_PERMANENT,
1.62      atatat    265:                       CTLTYPE_NODE, "kernfs",
                    266:                       SYSCTL_DESCR("/kern file system"),
1.57      atatat    267:                       NULL, 0, NULL, 0,
                    268:                       CTL_VFS, 11, CTL_EOL);
                    269:        /*
                    270:         * XXX the "11" above could be dynamic, thereby eliminating one
                    271:         * more instance of the "number to vfs" mapping problem, but
                    272:         * "11" is the order as taken from sys/mount.h
                    273:         */
1.32      fvdl      274: }
                    275:
1.38      jdolecek  276: extern const struct vnodeopv_desc kernfs_vnodeop_opv_desc;
1.31      thorpej   277:
1.38      jdolecek  278: const struct vnodeopv_desc * const kernfs_vnodeopv_descs[] = {
1.31      thorpej   279:        &kernfs_vnodeop_opv_desc,
                    280:        NULL,
                    281: };
                    282:
1.1       cgd       283: struct vfsops kernfs_vfsops = {
1.12      cgd       284:        MOUNT_KERNFS,
1.78      dsl       285:        0,
1.1       cgd       286:        kernfs_mount,
                    287:        kernfs_start,
                    288:        kernfs_unmount,
                    289:        kernfs_root,
                    290:        kernfs_quotactl,
1.59      christos  291:        kernfs_statvfs,
1.1       cgd       292:        kernfs_sync,
1.15      mycroft   293:        kernfs_vget,
1.75      chs       294:        (void *)eopnotsupp,             /* vfs_fhtovp */
                    295:        (void *)eopnotsupp,             /* vfs_vptofh */
1.1       cgd       296:        kernfs_init,
1.54      itojun    297:        kernfs_reinit,
1.36      jdolecek  298:        kernfs_done,
1.31      thorpej   299:        NULL,                           /* vfs_mountroot */
1.63      hannken   300:        (int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
1.66      thorpej   301:        vfs_stdextattrctl,
1.80    ! pooka     302:        (void *)eopnotsupp,             /* vfs_suspendctl */
1.31      thorpej   303:        kernfs_vnodeopv_descs,
1.72      christos  304:        0,
                    305:        { NULL, NULL },
1.1       cgd       306: };
1.67      thorpej   307: VFS_ATTACH(kernfs_vfsops);

CVSweb <webmaster@jp.NetBSD.org>