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

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

CVSweb <webmaster@jp.NetBSD.org>