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

Annotation of src/sys/miscfs/kernfs/kernfs_vnops.c, Revision 1.37

1.37    ! mycroft     1: /*     $NetBSD: kernfs_vnops.c,v 1.36 1995/04/15 01:56:43 cgd Exp $    */
1.27      cgd         2:
1.1       cgd         3: /*
1.23      mycroft     4:  * Copyright (c) 1992, 1993
                      5:  *     The Regents of the University of California.  All rights reserved.
1.1       cgd         6:  *
1.17      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.17      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.27      cgd        38:  *     @(#)kernfs_vnops.c      8.9 (Berkeley) 6/15/94
1.1       cgd        39:  */
                     40:
                     41: /*
1.23      mycroft    42:  * Kernel parameter filesystem (/kern)
1.1       cgd        43:  */
                     44:
1.14      mycroft    45: #include <sys/param.h>
                     46: #include <sys/systm.h>
                     47: #include <sys/kernel.h>
1.23      mycroft    48: #include <sys/vmmeter.h>
1.14      mycroft    49: #include <sys/types.h>
                     50: #include <sys/time.h>
                     51: #include <sys/proc.h>
1.23      mycroft    52: #include <sys/vnode.h>
                     53: #include <sys/malloc.h>
1.14      mycroft    54: #include <sys/file.h>
                     55: #include <sys/stat.h>
                     56: #include <sys/mount.h>
                     57: #include <sys/namei.h>
                     58: #include <sys/buf.h>
1.23      mycroft    59: #include <sys/dirent.h>
1.28      mycroft    60: #include <sys/msgbuf.h>
1.17      cgd        61: #include <miscfs/kernfs/kernfs.h>
1.1       cgd        62:
1.17      cgd        63: #define KSTRING        256             /* Largest I/O available via this filesystem */
                     64: #define        UIO_MX 32
1.1       cgd        65:
1.23      mycroft    66: #define        READ_MODE       (S_IRUSR|S_IRGRP|S_IROTH)
                     67: #define        WRITE_MODE      (S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH)
                     68: #define DIR_MODE       (S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
                     69:
1.17      cgd        70: struct kern_target {
1.23      mycroft    71:        u_char kt_type;
                     72:        u_char kt_namlen;
1.17      cgd        73:        char *kt_name;
                     74:        void *kt_data;
1.23      mycroft    75: #define        KTT_NULL         1
                     76: #define        KTT_TIME         5
                     77: #define KTT_INT                17
                     78: #define        KTT_STRING      31
                     79: #define KTT_HOSTNAME   47
                     80: #define KTT_AVENRUN    53
                     81: #define KTT_DEVICE     71
1.28      mycroft    82: #define        KTT_MSGBUF      89
1.23      mycroft    83:        u_char kt_tag;
                     84:        u_char kt_vtype;
                     85:        mode_t kt_mode;
1.17      cgd        86: } kern_targets[] = {
1.1       cgd        87: /* NOTE: The name must be less than UIO_MX-16 chars in length */
1.23      mycroft    88: #define N(s) sizeof(s)-1, s
                     89:      /*        name            data          tag           type  ro/rw */
                     90:      { DT_DIR, N("."),         0,            KTT_NULL,     VDIR, DIR_MODE   },
                     91:      { DT_DIR, N(".."),        0,            KTT_NULL,     VDIR, DIR_MODE   },
                     92:      { DT_REG, N("boottime"),  &boottime.tv_sec, KTT_INT,  VREG, READ_MODE  },
                     93:      { DT_REG, N("copyright"), copyright,    KTT_STRING,   VREG, READ_MODE  },
                     94:      { DT_REG, N("hostname"),  0,            KTT_HOSTNAME, VREG, WRITE_MODE },
                     95:      { DT_REG, N("hz"),        &hz,          KTT_INT,      VREG, READ_MODE  },
                     96:      { DT_REG, N("loadavg"),   0,            KTT_AVENRUN,  VREG, READ_MODE  },
1.28      mycroft    97:      { DT_REG, N("msgbuf"),    0,           KTT_MSGBUF,   VREG, READ_MODE  },
1.23      mycroft    98:      { DT_REG, N("pagesize"),  &cnt.v_page_size, KTT_INT,  VREG, READ_MODE  },
                     99:      { DT_REG, N("physmem"),   &physmem,     KTT_INT,      VREG, READ_MODE  },
1.17      cgd       100: #if 0
1.23      mycroft   101:      { DT_DIR, N("root"),      0,            KTT_NULL,     VDIR, DIR_MODE   },
1.17      cgd       102: #endif
1.23      mycroft   103:      { DT_BLK, N("rootdev"),   &rootdev,     KTT_DEVICE,   VBLK, READ_MODE  },
                    104:      { DT_CHR, N("rrootdev"),  &rrootdev,    KTT_DEVICE,   VCHR, READ_MODE  },
                    105:      { DT_REG, N("time"),      0,            KTT_TIME,     VREG, READ_MODE  },
                    106:      { DT_REG, N("version"),   version,      KTT_STRING,   VREG, READ_MODE  },
                    107: #undef N
1.1       cgd       108: };
1.17      cgd       109: static int nkern_targets = sizeof(kern_targets) / sizeof(kern_targets[0]);
1.1       cgd       110:
1.28      mycroft   111: int
                    112: kernfs_xread(kt, off, bufp, len)
1.17      cgd       113:        struct kern_target *kt;
1.28      mycroft   114:        int off;
                    115:        char **bufp;
1.1       cgd       116:        int len;
                    117: {
                    118:
                    119:        switch (kt->kt_tag) {
                    120:        case KTT_TIME: {
                    121:                struct timeval tv;
1.28      mycroft   122:
1.1       cgd       123:                microtime(&tv);
1.28      mycroft   124:                sprintf(*bufp, "%d %d\n", tv.tv_sec, tv.tv_usec);
1.1       cgd       125:                break;
                    126:        }
                    127:
                    128:        case KTT_INT: {
                    129:                int *ip = kt->kt_data;
1.28      mycroft   130:
                    131:                sprintf(*bufp, "%d\n", *ip);
1.1       cgd       132:                break;
                    133:        }
                    134:
                    135:        case KTT_STRING: {
                    136:                char *cp = kt->kt_data;
                    137:
1.28      mycroft   138:                *bufp = cp;
                    139:                break;
                    140:        }
1.1       cgd       141:
1.28      mycroft   142:        case KTT_MSGBUF: {
                    143:                extern struct msgbuf *msgbufp;
                    144:                long n;
                    145:
                    146:                if (off >= MSG_BSIZE)
                    147:                        return (0);
                    148:                n = msgbufp->msg_bufx + off;
                    149:                if (n >= MSG_BSIZE)
                    150:                        n -= MSG_BSIZE;
                    151:                len = min(MSG_BSIZE - n, MSG_BSIZE - off);
                    152:                *bufp = msgbufp->msg_bufc + n;
                    153:                return (len);
1.1       cgd       154:        }
                    155:
                    156:        case KTT_HOSTNAME: {
                    157:                char *cp = hostname;
                    158:                int xlen = hostnamelen;
                    159:
1.17      cgd       160:                if (xlen >= (len-2))
1.1       cgd       161:                        return (EINVAL);
                    162:
1.28      mycroft   163:                bcopy(cp, *bufp, xlen);
                    164:                (*bufp)[xlen] = '\n';
                    165:                (*bufp)[xlen+1] = '\0';
1.1       cgd       166:                break;
                    167:        }
                    168:
                    169:        case KTT_AVENRUN:
1.31      mycroft   170:                averunnable.fscale = FSCALE;
1.28      mycroft   171:                sprintf(*bufp, "%ld %ld %ld %ld\n",
1.23      mycroft   172:                    averunnable.ldavg[0], averunnable.ldavg[1],
                    173:                    averunnable.ldavg[2], averunnable.fscale);
1.1       cgd       174:                break;
                    175:
                    176:        default:
1.28      mycroft   177:                return (0);
1.1       cgd       178:        }
                    179:
1.28      mycroft   180:        len = strlen(*bufp);
                    181:        if (len <= off)
                    182:                return (0);
                    183:        *bufp += off;
                    184:        return (len - off);
1.1       cgd       185: }
                    186:
1.28      mycroft   187: int
1.1       cgd       188: kernfs_xwrite(kt, buf, len)
1.17      cgd       189:        struct kern_target *kt;
1.1       cgd       190:        char *buf;
                    191:        int len;
                    192: {
1.23      mycroft   193:
1.1       cgd       194:        switch (kt->kt_tag) {
1.23      mycroft   195:        case KTT_HOSTNAME:
1.1       cgd       196:                if (buf[len-1] == '\n')
                    197:                        --len;
                    198:                bcopy(buf, hostname, len);
1.17      cgd       199:                hostname[len] = '\0';
1.6       cgd       200:                hostnamelen = len;
1.1       cgd       201:                return (0);
                    202:
                    203:        default:
                    204:                return (EIO);
                    205:        }
                    206: }
                    207:
1.17      cgd       208:
                    209: /*
1.1       cgd       210:  * vp is the current namei directory
                    211:  * ndp is the name to locate in that directory...
                    212:  */
1.23      mycroft   213: kernfs_lookup(ap)
                    214:        struct vop_lookup_args /* {
                    215:                struct vnode * a_dvp;
                    216:                struct vnode ** a_vpp;
                    217:                struct componentname * a_cnp;
                    218:        } */ *ap;
                    219: {
                    220:        struct componentname *cnp = ap->a_cnp;
                    221:        struct vnode **vpp = ap->a_vpp;
                    222:        struct vnode *dvp = ap->a_dvp;
                    223:        char *pname = cnp->cn_nameptr;
                    224:        struct kern_target *kt;
1.1       cgd       225:        struct vnode *fvp;
1.23      mycroft   226:        int error, i;
1.1       cgd       227:
                    228: #ifdef KERNFS_DIAGNOSTIC
1.23      mycroft   229:        printf("kernfs_lookup(%x)\n", ap);
                    230:        printf("kernfs_lookup(dp = %x, vpp = %x, cnp = %x)\n", dvp, vpp, ap->a_cnp);
1.1       cgd       231:        printf("kernfs_lookup(%s)\n", pname);
                    232: #endif
1.23      mycroft   233:
1.35      mycroft   234:        *vpp = NULLVP;
                    235:
                    236:        if (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)
                    237:                return (EROFS);
                    238:
1.23      mycroft   239:        if (cnp->cn_namelen == 1 && *pname == '.') {
                    240:                *vpp = dvp;
1.1       cgd       241:                VREF(dvp);
                    242:                /*VOP_LOCK(dvp);*/
                    243:                return (0);
                    244:        }
1.13      cgd       245:
1.17      cgd       246: #if 0
1.23      mycroft   247:        if (cnp->cn_namelen == 4 && bcmp(pname, "root", 4) == 0) {
                    248:                *vpp = rootdir;
1.17      cgd       249:                VREF(rootdir);
1.1       cgd       250:                VOP_LOCK(rootdir);
                    251:                return (0);
                    252:        }
1.13      cgd       253: #endif
1.25      mycroft   254:
1.35      mycroft   255:        for (kt = kern_targets, i = 0; i < nkern_targets; kt++, i++) {
1.26      mycroft   256:                if (cnp->cn_namelen == kt->kt_namlen &&
1.35      mycroft   257:                    bcmp(kt->kt_name, pname, cnp->cn_namelen) == 0)
                    258:                        goto found;
1.1       cgd       259:        }
                    260:
                    261: #ifdef KERNFS_DIAGNOSTIC
1.35      mycroft   262:        printf("kernfs_lookup: i = %d, failed", i);
1.1       cgd       263: #endif
                    264:
1.35      mycroft   265:        return (cnp->cn_nameiop == LOOKUP ? ENOENT : EROFS);
1.23      mycroft   266:
1.35      mycroft   267: found:
1.23      mycroft   268:        if (kt->kt_tag == KTT_DEVICE) {
                    269:                dev_t *dp = kt->kt_data;
1.24      mycroft   270:        loop:
1.23      mycroft   271:                if (*dp == NODEV || !vfinddev(*dp, kt->kt_vtype, &fvp))
1.24      mycroft   272:                        return (ENOENT);
1.23      mycroft   273:                *vpp = fvp;
1.24      mycroft   274:                if (vget(fvp, 1))
                    275:                        goto loop;
1.23      mycroft   276:                return (0);
                    277:        }
1.1       cgd       278:
                    279: #ifdef KERNFS_DIAGNOSTIC
                    280:        printf("kernfs_lookup: allocate new vnode\n");
                    281: #endif
1.23      mycroft   282:        if (error = getnewvnode(VT_KERNFS, dvp->v_mount, kernfs_vnodeop_p,
                    283:            &fvp))
                    284:                return (error);
                    285:
                    286:        MALLOC(fvp->v_data, void *, sizeof(struct kernfs_node), M_TEMP,
                    287:            M_WAITOK);
                    288:        VTOKERN(fvp)->kf_kt = kt;
                    289:        fvp->v_type = kt->kt_vtype;
                    290:        *vpp = fvp;
                    291:
1.1       cgd       292: #ifdef KERNFS_DIAGNOSTIC
                    293:        printf("kernfs_lookup: newvp = %x\n", fvp);
                    294: #endif
                    295:        return (0);
                    296: }
                    297:
1.23      mycroft   298: kernfs_open(ap)
                    299:        struct vop_open_args /* {
                    300:                struct vnode *a_vp;
                    301:                int  a_mode;
                    302:                struct ucred *a_cred;
                    303:                struct proc *a_p;
                    304:        } */ *ap;
1.1       cgd       305: {
                    306:
1.23      mycroft   307:        /* Only need to check access permissions. */
                    308:        return (0);
                    309: }
1.1       cgd       310:
1.28      mycroft   311: int
1.23      mycroft   312: kernfs_access(ap)
                    313:        struct vop_access_args /* {
                    314:                struct vnode *a_vp;
1.34      mycroft   315:                int a_mode;
1.23      mycroft   316:                struct ucred *a_cred;
                    317:                struct proc *a_p;
                    318:        } */ *ap;
                    319: {
1.26      mycroft   320:        struct vnode *vp = ap->a_vp;
1.23      mycroft   321:        mode_t fmode =
                    322:            (vp->v_flag & VROOT) ? DIR_MODE : VTOKERN(vp)->kf_kt->kt_mode;
1.17      cgd       323:
1.33      ws        324:        return (vaccess(fmode, (uid_t)0, (gid_t)0, ap->a_mode, ap->a_cred));
1.23      mycroft   325: }
                    326:
                    327: kernfs_getattr(ap)
                    328:        struct vop_getattr_args /* {
                    329:                struct vnode *a_vp;
                    330:                struct vattr *a_vap;
                    331:                struct ucred *a_cred;
                    332:                struct proc *a_p;
                    333:        } */ *ap;
1.1       cgd       334: {
1.23      mycroft   335:        struct vnode *vp = ap->a_vp;
                    336:        struct vattr *vap = ap->a_vap;
1.36      cgd       337:        struct timeval tv;
1.1       cgd       338:        int error = 0;
1.28      mycroft   339:        char strbuf[KSTRING], *buf;
1.1       cgd       340:
                    341:        bzero((caddr_t) vap, sizeof(*vap));
                    342:        vattr_null(vap);
1.17      cgd       343:        vap->va_uid = 0;
                    344:        vap->va_gid = 0;
1.1       cgd       345:        vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0];
1.23      mycroft   346:        vap->va_size = 0;
1.1       cgd       347:        vap->va_blocksize = DEV_BSIZE;
1.36      cgd       348:        microtime(&tv);
                    349:        TIMEVAL_TO_TIMESPEC(&tv, &vap->va_atime);
1.1       cgd       350:        vap->va_mtime = vap->va_atime;
                    351:        vap->va_ctime = vap->va_ctime;
                    352:        vap->va_gen = 0;
                    353:        vap->va_flags = 0;
                    354:        vap->va_rdev = 0;
                    355:        vap->va_bytes = 0;
                    356:
                    357:        if (vp->v_flag & VROOT) {
                    358: #ifdef KERNFS_DIAGNOSTIC
                    359:                printf("kernfs_getattr: stat rootdir\n");
                    360: #endif
1.17      cgd       361:                vap->va_type = VDIR;
1.23      mycroft   362:                vap->va_mode = DIR_MODE;
1.1       cgd       363:                vap->va_nlink = 2;
                    364:                vap->va_fileid = 2;
                    365:                vap->va_size = DEV_BSIZE;
                    366:        } else {
1.23      mycroft   367:                struct kern_target *kt = VTOKERN(vp)->kf_kt;
1.28      mycroft   368:                int nbytes, total;
1.1       cgd       369: #ifdef KERNFS_DIAGNOSTIC
                    370:                printf("kernfs_getattr: stat target %s\n", kt->kt_name);
                    371: #endif
1.17      cgd       372:                vap->va_type = kt->kt_vtype;
1.23      mycroft   373:                vap->va_mode = kt->kt_mode;
1.1       cgd       374:                vap->va_nlink = 1;
1.23      mycroft   375:                vap->va_fileid = 1 + (kt - kern_targets) / sizeof(*kt);
1.28      mycroft   376:                total = 0;
                    377:                while (buf = strbuf,
                    378:                       nbytes = kernfs_xread(kt, total, &buf, sizeof(strbuf)))
                    379:                        total += nbytes;
                    380:                vap->va_size = total;
1.1       cgd       381:        }
                    382:
                    383: #ifdef KERNFS_DIAGNOSTIC
                    384:        printf("kernfs_getattr: return error %d\n", error);
                    385: #endif
                    386:        return (error);
                    387: }
                    388:
1.23      mycroft   389: kernfs_setattr(ap)
                    390:        struct vop_setattr_args /* {
                    391:                struct vnode *a_vp;
                    392:                struct vattr *a_vap;
                    393:                struct ucred *a_cred;
                    394:                struct proc *a_p;
                    395:        } */ *ap;
1.1       cgd       396: {
                    397:
                    398:        /*
1.17      cgd       399:         * Silently ignore attribute changes.
                    400:         * This allows for open with truncate to have no
                    401:         * effect until some data is written.  I want to
                    402:         * do it this way because all writes are atomic.
1.1       cgd       403:         */
1.17      cgd       404:        return (0);
1.1       cgd       405: }
                    406:
1.28      mycroft   407: int
1.23      mycroft   408: kernfs_read(ap)
                    409:        struct vop_read_args /* {
                    410:                struct vnode *a_vp;
                    411:                struct uio *a_uio;
                    412:                int  a_ioflag;
                    413:                struct ucred *a_cred;
                    414:        } */ *ap;
1.1       cgd       415: {
1.23      mycroft   416:        struct vnode *vp = ap->a_vp;
                    417:        struct uio *uio = ap->a_uio;
                    418:        struct kern_target *kt;
1.28      mycroft   419:        char strbuf[KSTRING], *buf;
                    420:        int off, len;
                    421:        int error;
1.23      mycroft   422:
                    423:        if (vp->v_type == VDIR)
                    424:                return (EOPNOTSUPP);
                    425:
                    426:        kt = VTOKERN(vp)->kf_kt;
                    427:
1.1       cgd       428: #ifdef KERNFS_DIAGNOSTIC
                    429:        printf("kern_read %s\n", kt->kt_name);
                    430: #endif
1.18      cgd       431:
1.28      mycroft   432:        off = uio->uio_offset;
                    433: #if 0
                    434:        while (buf = strbuf,
                    435: #else
                    436:        if (buf = strbuf,
                    437: #endif
                    438:            len = kernfs_xread(kt, off, &buf, sizeof(strbuf))) {
                    439:                if (error = uiomove(buf, len, uio))
                    440:                        return (error);
                    441:                off += len;
                    442:        }
                    443:        return (0);
1.1       cgd       444: }
                    445:
1.28      mycroft   446: int
1.23      mycroft   447: kernfs_write(ap)
                    448:        struct vop_write_args /* {
                    449:                struct vnode *a_vp;
                    450:                struct uio *a_uio;
                    451:                int  a_ioflag;
                    452:                struct ucred *a_cred;
                    453:        } */ *ap;
1.1       cgd       454: {
1.23      mycroft   455:        struct vnode *vp = ap->a_vp;
                    456:        struct uio *uio = ap->a_uio;
                    457:        struct kern_target *kt;
                    458:        int error, xlen;
1.1       cgd       459:        char strbuf[KSTRING];
1.23      mycroft   460:
                    461:        if (vp->v_type == VDIR)
                    462:                return (EOPNOTSUPP);
                    463:
                    464:        kt = VTOKERN(vp)->kf_kt;
1.1       cgd       465:
                    466:        if (uio->uio_offset != 0)
                    467:                return (EINVAL);
                    468:
                    469:        xlen = min(uio->uio_resid, KSTRING-1);
1.23      mycroft   470:        if (error = uiomove(strbuf, xlen, uio))
1.1       cgd       471:                return (error);
                    472:
                    473:        if (uio->uio_resid != 0)
                    474:                return (EIO);
                    475:
                    476:        strbuf[xlen] = '\0';
1.17      cgd       477:        xlen = strlen(strbuf);
1.1       cgd       478:        return (kernfs_xwrite(kt, strbuf, xlen));
                    479: }
                    480:
1.23      mycroft   481: kernfs_readdir(ap)
                    482:        struct vop_readdir_args /* {
                    483:                struct vnode *a_vp;
                    484:                struct uio *a_uio;
                    485:                struct ucred *a_cred;
1.26      mycroft   486:                int *a_eofflag;
                    487:                u_long *a_cookies;
                    488:                int a_ncookies;
1.23      mycroft   489:        } */ *ap;
                    490: {
                    491:        struct uio *uio = ap->a_uio;
1.37    ! mycroft   492:        struct dirent d;
1.26      mycroft   493:        struct kern_target *kt;
1.37    ! mycroft   494:        off_t off;
1.1       cgd       495:        int i;
                    496:        int error;
1.37    ! mycroft   497:        u_long *cookies = ap->a_cookies;
        !           498:        int ncookies = ap->a_ncookies;
1.1       cgd       499:
1.23      mycroft   500:        if (ap->a_vp->v_type != VDIR)
                    501:                return (ENOTDIR);
                    502:
1.37    ! mycroft   503:        if (uio->uio_resid < UIO_MX)
        !           504:                return (EINVAL);
        !           505:        off = uio->uio_offset;
        !           506:        if (off & (UIO_MX - 1) || off < 0)
        !           507:                return (EINVAL);
1.26      mycroft   508:
1.1       cgd       509:        error = 0;
1.37    ! mycroft   510:        i = off / UIO_MX;
        !           511:        bzero((caddr_t)&d, UIO_MX);
        !           512:        d.d_reclen = UIO_MX;
        !           513:
1.23      mycroft   514:        for (kt = &kern_targets[i];
                    515:             uio->uio_resid >= UIO_MX && i < nkern_targets; kt++, i++) {
1.1       cgd       516: #ifdef KERNFS_DIAGNOSTIC
                    517:                printf("kernfs_readdir: i = %d\n", i);
                    518: #endif
1.26      mycroft   519:
1.23      mycroft   520:                if (kt->kt_tag == KTT_DEVICE) {
1.26      mycroft   521:                        dev_t *dp = kt->kt_data;
1.23      mycroft   522:                        struct vnode *fvp;
1.26      mycroft   523:
1.23      mycroft   524:                        if (*dp == NODEV || !vfinddev(*dp, kt->kt_vtype, &fvp))
                    525:                                continue;
                    526:                }
1.26      mycroft   527:
1.37    ! mycroft   528:                d.d_fileno = i + 3;
        !           529:                d.d_namlen = kt->kt_namlen;
        !           530:                bcopy(kt->kt_name, d.d_name, kt->kt_namlen + 1);
        !           531:                d.d_type = kt->kt_type;
1.26      mycroft   532:
1.37    ! mycroft   533:                if (error = uiomove((caddr_t)&d, UIO_MX, uio))
1.1       cgd       534:                        break;
1.37    ! mycroft   535:                if (ncookies-- > 0)
        !           536:                        *cookies++ = (i + 1) * UIO_MX;
1.1       cgd       537:        }
                    538:
1.37    ! mycroft   539:        uio->uio_offset = (i + 1) * UIO_MX;
1.1       cgd       540:        return (error);
                    541: }
                    542:
1.23      mycroft   543: kernfs_inactive(ap)
                    544:        struct vop_inactive_args /* {
                    545:                struct vnode *a_vp;
                    546:        } */ *ap;
1.1       cgd       547: {
1.23      mycroft   548:        struct vnode *vp = ap->a_vp;
                    549:
                    550: #ifdef KERNFS_DIAGNOSTIC
                    551:        printf("kernfs_inactive(%x)\n", vp);
                    552: #endif
1.1       cgd       553:        /*
                    554:         * Clear out the v_type field to avoid
                    555:         * nasty things happening in vgone().
                    556:         */
                    557:        vp->v_type = VNON;
1.23      mycroft   558:        return (0);
                    559: }
                    560:
                    561: kernfs_reclaim(ap)
                    562:        struct vop_reclaim_args /* {
                    563:                struct vnode *a_vp;
                    564:        } */ *ap;
                    565: {
                    566:        struct vnode *vp = ap->a_vp;
                    567:
1.1       cgd       568: #ifdef KERNFS_DIAGNOSTIC
1.23      mycroft   569:        printf("kernfs_reclaim(%x)\n", vp);
1.1       cgd       570: #endif
1.23      mycroft   571:        if (vp->v_data) {
                    572:                FREE(vp->v_data, M_TEMP);
                    573:                vp->v_data = 0;
                    574:        }
1.1       cgd       575:        return (0);
                    576: }
                    577:
                    578: /*
1.23      mycroft   579:  * Return POSIX pathconf information applicable to special devices.
                    580:  */
                    581: kernfs_pathconf(ap)
                    582:        struct vop_pathconf_args /* {
                    583:                struct vnode *a_vp;
                    584:                int a_name;
1.29      cgd       585:                register_t *a_retval;
1.23      mycroft   586:        } */ *ap;
                    587: {
                    588:
                    589:        switch (ap->a_name) {
                    590:        case _PC_LINK_MAX:
                    591:                *ap->a_retval = LINK_MAX;
                    592:                return (0);
                    593:        case _PC_MAX_CANON:
                    594:                *ap->a_retval = MAX_CANON;
                    595:                return (0);
                    596:        case _PC_MAX_INPUT:
                    597:                *ap->a_retval = MAX_INPUT;
                    598:                return (0);
                    599:        case _PC_PIPE_BUF:
                    600:                *ap->a_retval = PIPE_BUF;
                    601:                return (0);
                    602:        case _PC_CHOWN_RESTRICTED:
                    603:                *ap->a_retval = 1;
                    604:                return (0);
                    605:        case _PC_VDISABLE:
                    606:                *ap->a_retval = _POSIX_VDISABLE;
                    607:                return (0);
                    608:        default:
                    609:                return (EINVAL);
                    610:        }
                    611:        /* NOTREACHED */
                    612: }
                    613:
                    614: /*
                    615:  * Print out the contents of a /dev/fd vnode.
1.1       cgd       616:  */
                    617: /* ARGSUSED */
1.23      mycroft   618: kernfs_print(ap)
                    619:        struct vop_print_args /* {
                    620:                struct vnode *a_vp;
                    621:        } */ *ap;
                    622: {
                    623:
                    624:        printf("tag VT_KERNFS, kernfs vnode\n");
                    625:        return (0);
                    626: }
                    627:
                    628: /*void*/
                    629: kernfs_vfree(ap)
                    630:        struct vop_vfree_args /* {
                    631:                struct vnode *a_pvp;
                    632:                ino_t a_ino;
                    633:                int a_mode;
                    634:        } */ *ap;
1.1       cgd       635: {
1.23      mycroft   636:
                    637:        return (0);
1.1       cgd       638: }
                    639:
                    640: /*
1.23      mycroft   641:  * /dev/fd vnode unsupported operation
1.1       cgd       642:  */
                    643: kernfs_enotsupp()
                    644: {
1.23      mycroft   645:
1.1       cgd       646:        return (EOPNOTSUPP);
                    647: }
                    648:
                    649: /*
1.23      mycroft   650:  * /dev/fd "should never get here" operation
1.1       cgd       651:  */
                    652: kernfs_badop()
                    653: {
1.23      mycroft   654:
1.1       cgd       655:        panic("kernfs: bad op");
                    656:        /* NOTREACHED */
                    657: }
                    658:
                    659: /*
                    660:  * kernfs vnode null operation
                    661:  */
                    662: kernfs_nullop()
                    663: {
1.23      mycroft   664:
1.1       cgd       665:        return (0);
                    666: }
                    667:
1.23      mycroft   668: #define kernfs_create ((int (*) __P((struct  vop_create_args *)))kernfs_enotsupp)
                    669: #define kernfs_mknod ((int (*) __P((struct  vop_mknod_args *)))kernfs_enotsupp)
                    670: #define kernfs_close ((int (*) __P((struct  vop_close_args *)))nullop)
                    671: #define kernfs_ioctl ((int (*) __P((struct  vop_ioctl_args *)))kernfs_enotsupp)
                    672: #define kernfs_select ((int (*) __P((struct  vop_select_args *)))kernfs_enotsupp)
                    673: #define kernfs_mmap ((int (*) __P((struct  vop_mmap_args *)))kernfs_enotsupp)
                    674: #define kernfs_fsync ((int (*) __P((struct  vop_fsync_args *)))nullop)
                    675: #define kernfs_seek ((int (*) __P((struct  vop_seek_args *)))nullop)
                    676: #define kernfs_remove ((int (*) __P((struct  vop_remove_args *)))kernfs_enotsupp)
                    677: #define kernfs_link ((int (*) __P((struct  vop_link_args *)))kernfs_enotsupp)
                    678: #define kernfs_rename ((int (*) __P((struct  vop_rename_args *)))kernfs_enotsupp)
                    679: #define kernfs_mkdir ((int (*) __P((struct  vop_mkdir_args *)))kernfs_enotsupp)
                    680: #define kernfs_rmdir ((int (*) __P((struct  vop_rmdir_args *)))kernfs_enotsupp)
                    681: #define kernfs_symlink ((int (*) __P((struct vop_symlink_args *)))kernfs_enotsupp)
                    682: #define kernfs_readlink \
                    683:        ((int (*) __P((struct  vop_readlink_args *)))kernfs_enotsupp)
                    684: #define kernfs_abortop ((int (*) __P((struct  vop_abortop_args *)))nullop)
                    685: #define kernfs_lock ((int (*) __P((struct  vop_lock_args *)))nullop)
                    686: #define kernfs_unlock ((int (*) __P((struct  vop_unlock_args *)))nullop)
                    687: #define kernfs_bmap ((int (*) __P((struct  vop_bmap_args *)))kernfs_badop)
                    688: #define kernfs_strategy ((int (*) __P((struct  vop_strategy_args *)))kernfs_badop)
                    689: #define kernfs_islocked ((int (*) __P((struct  vop_islocked_args *)))nullop)
                    690: #define kernfs_advlock ((int (*) __P((struct vop_advlock_args *)))kernfs_enotsupp)
                    691: #define kernfs_blkatoff \
                    692:        ((int (*) __P((struct  vop_blkatoff_args *)))kernfs_enotsupp)
                    693: #define kernfs_valloc ((int(*) __P(( \
                    694:                struct vnode *pvp, \
                    695:                int mode, \
1.1       cgd       696:                struct ucred *cred, \
1.23      mycroft   697:                struct vnode **vpp))) kernfs_enotsupp)
                    698: #define kernfs_truncate \
                    699:        ((int (*) __P((struct  vop_truncate_args *)))kernfs_enotsupp)
                    700: #define kernfs_update ((int (*) __P((struct  vop_update_args *)))kernfs_enotsupp)
                    701: #define kernfs_bwrite ((int (*) __P((struct  vop_bwrite_args *)))kernfs_enotsupp)
                    702:
                    703: int (**kernfs_vnodeop_p)();
                    704: struct vnodeopv_entry_desc kernfs_vnodeop_entries[] = {
                    705:        { &vop_default_desc, vn_default_error },
                    706:        { &vop_lookup_desc, kernfs_lookup },    /* lookup */
                    707:        { &vop_create_desc, kernfs_create },    /* create */
                    708:        { &vop_mknod_desc, kernfs_mknod },      /* mknod */
                    709:        { &vop_open_desc, kernfs_open },        /* open */
                    710:        { &vop_close_desc, kernfs_close },      /* close */
                    711:        { &vop_access_desc, kernfs_access },    /* access */
                    712:        { &vop_getattr_desc, kernfs_getattr },  /* getattr */
                    713:        { &vop_setattr_desc, kernfs_setattr },  /* setattr */
                    714:        { &vop_read_desc, kernfs_read },        /* read */
                    715:        { &vop_write_desc, kernfs_write },      /* write */
                    716:        { &vop_ioctl_desc, kernfs_ioctl },      /* ioctl */
                    717:        { &vop_select_desc, kernfs_select },    /* select */
                    718:        { &vop_mmap_desc, kernfs_mmap },        /* mmap */
                    719:        { &vop_fsync_desc, kernfs_fsync },      /* fsync */
                    720:        { &vop_seek_desc, kernfs_seek },        /* seek */
                    721:        { &vop_remove_desc, kernfs_remove },    /* remove */
                    722:        { &vop_link_desc, kernfs_link },        /* link */
                    723:        { &vop_rename_desc, kernfs_rename },    /* rename */
                    724:        { &vop_mkdir_desc, kernfs_mkdir },      /* mkdir */
                    725:        { &vop_rmdir_desc, kernfs_rmdir },      /* rmdir */
                    726:        { &vop_symlink_desc, kernfs_symlink },  /* symlink */
                    727:        { &vop_readdir_desc, kernfs_readdir },  /* readdir */
                    728:        { &vop_readlink_desc, kernfs_readlink },/* readlink */
                    729:        { &vop_abortop_desc, kernfs_abortop },  /* abortop */
                    730:        { &vop_inactive_desc, kernfs_inactive },/* inactive */
                    731:        { &vop_reclaim_desc, kernfs_reclaim },  /* reclaim */
                    732:        { &vop_lock_desc, kernfs_lock },        /* lock */
                    733:        { &vop_unlock_desc, kernfs_unlock },    /* unlock */
                    734:        { &vop_bmap_desc, kernfs_bmap },        /* bmap */
                    735:        { &vop_strategy_desc, kernfs_strategy },/* strategy */
                    736:        { &vop_print_desc, kernfs_print },      /* print */
                    737:        { &vop_islocked_desc, kernfs_islocked },/* islocked */
                    738:        { &vop_pathconf_desc, kernfs_pathconf },/* pathconf */
                    739:        { &vop_advlock_desc, kernfs_advlock },  /* advlock */
                    740:        { &vop_blkatoff_desc, kernfs_blkatoff },/* blkatoff */
                    741:        { &vop_valloc_desc, kernfs_valloc },    /* valloc */
                    742:        { &vop_vfree_desc, kernfs_vfree },      /* vfree */
                    743:        { &vop_truncate_desc, kernfs_truncate },/* truncate */
                    744:        { &vop_update_desc, kernfs_update },    /* update */
                    745:        { &vop_bwrite_desc, kernfs_bwrite },    /* bwrite */
                    746:        { (struct vnodeop_desc*)NULL, (int(*)())NULL }
1.1       cgd       747: };
1.23      mycroft   748: struct vnodeopv_desc kernfs_vnodeop_opv_desc =
                    749:        { &kernfs_vnodeop_p, kernfs_vnodeop_entries };

CVSweb <webmaster@jp.NetBSD.org>