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

Annotation of src/sys/miscfs/fdesc/fdesc_vfsops.c, Revision 1.33

1.33    ! mrg         1: /*     $NetBSD: fdesc_vfsops.c,v 1.32 2001/01/22 12:17:37 jdolecek Exp $       */
1.13      cgd         2:
1.1       cgd         3: /*
1.24      fvdl        4:  * Copyright (c) 1992, 1993, 1995
1.12      mycroft     5:  *     The Regents of the University of California.  All rights reserved.
1.1       cgd         6:  *
1.6       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.6       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.24      fvdl       38:  *     @(#)fdesc_vfsops.c      8.10 (Berkeley) 5/14/95
1.15      mycroft    39:  *
                     40:  * #Id: fdesc_vfsops.c,v 1.9 1993/04/06 15:28:33 jsp Exp #
1.1       cgd        41:  */
                     42:
                     43: /*
                     44:  * /dev/fd Filesystem
                     45:  */
1.25      jonathan   46:
1.33    ! mrg        47: #if defined(_KERNEL_OPT)
1.25      jonathan   48: #include "opt_compat_netbsd.h"
                     49: #endif
1.1       cgd        50:
1.6       cgd        51: #include <sys/param.h>
                     52: #include <sys/systm.h>
                     53: #include <sys/time.h>
                     54: #include <sys/types.h>
                     55: #include <sys/proc.h>
                     56: #include <sys/resourcevar.h>
                     57: #include <sys/filedesc.h>
                     58: #include <sys/vnode.h>
                     59: #include <sys/mount.h>
                     60: #include <sys/namei.h>
                     61: #include <sys/malloc.h>
                     62: #include <miscfs/fdesc/fdesc.h>
1.1       cgd        63:
1.22      cgd        64: int    fdesc_mount __P((struct mount *, const char *, void *,
1.21      christos   65:                         struct nameidata *, struct proc *));
                     66: int    fdesc_start __P((struct mount *, int, struct proc *));
                     67: int    fdesc_unmount __P((struct mount *, int, struct proc *));
                     68: int    fdesc_quotactl __P((struct mount *, int, uid_t, caddr_t,
                     69:                            struct proc *));
                     70: int    fdesc_statfs __P((struct mount *, struct statfs *, struct proc *));
                     71: int    fdesc_sync __P((struct mount *, int, struct ucred *, struct proc *));
                     72: int    fdesc_vget __P((struct mount *, ino_t, struct vnode **));
1.27      wrstuden   73: int    fdesc_fhtovp __P((struct mount *, struct fid *, struct vnode **));
                     74: int    fdesc_checkexp __P((struct mount *, struct mbuf *, int *,
                     75:                            struct ucred **));
1.21      christos   76: int    fdesc_vptofh __P((struct vnode *, struct fid *));
1.24      fvdl       77: int    fdesc_sysctl __P((int *, u_int, void *, size_t *, void *, size_t,
                     78:                          struct proc *));
1.21      christos   79:
1.1       cgd        80: /*
                     81:  * Mount the per-process file descriptors (/dev/fd)
                     82:  */
1.12      mycroft    83: int
1.1       cgd        84: fdesc_mount(mp, path, data, ndp, p)
                     85:        struct mount *mp;
1.22      cgd        86:        const char *path;
                     87:        void *data;
1.1       cgd        88:        struct nameidata *ndp;
                     89:        struct proc *p;
                     90: {
                     91:        int error = 0;
1.19      mycroft    92:        size_t size;
1.1       cgd        93:        struct fdescmount *fmp;
                     94:        struct vnode *rvp;
                     95:
                     96:        /*
                     97:         * Update is a no-op
                     98:         */
                     99:        if (mp->mnt_flag & MNT_UPDATE)
                    100:                return (EOPNOTSUPP);
                    101:
1.6       cgd       102:        error = fdesc_allocvp(Froot, FD_ROOT, mp, &rvp);
1.1       cgd       103:        if (error)
                    104:                return (error);
                    105:
1.6       cgd       106:        MALLOC(fmp, struct fdescmount *, sizeof(struct fdescmount),
1.12      mycroft   107:                                M_UFSMNT, M_WAITOK);    /* XXX */
1.1       cgd       108:        rvp->v_type = VDIR;
                    109:        rvp->v_flag |= VROOT;
                    110:        fmp->f_root = rvp;
1.14      mycroft   111:        mp->mnt_flag |= MNT_LOCAL;
                    112:        mp->mnt_data = (qaddr_t)fmp;
1.31      assar     113:        vfs_getnewfsid(mp);
1.1       cgd       114:
                    115:        (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
1.26      perry     116:        memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN - size);
                    117:        memset(mp->mnt_stat.f_mntfromname, 0, MNAMELEN);
                    118:        memcpy(mp->mnt_stat.f_mntfromname, "fdesc", sizeof("fdesc"));
1.28      wrstuden  119:        VOP_UNLOCK(rvp, 0);
1.1       cgd       120:        return (0);
                    121: }
                    122:
1.12      mycroft   123: int
1.1       cgd       124: fdesc_start(mp, flags, p)
                    125:        struct mount *mp;
                    126:        int flags;
                    127:        struct proc *p;
                    128: {
                    129:        return (0);
                    130: }
                    131:
1.12      mycroft   132: int
1.1       cgd       133: fdesc_unmount(mp, mntflags, p)
                    134:        struct mount *mp;
                    135:        int mntflags;
                    136:        struct proc *p;
                    137: {
                    138:        int error;
                    139:        int flags = 0;
                    140:        struct vnode *rootvp = VFSTOFDESC(mp)->f_root;
                    141:
1.24      fvdl      142:        if (mntflags & MNT_FORCE)
1.1       cgd       143:                flags |= FORCECLOSE;
                    144:
                    145:        /*
                    146:         * Clear out buffer cache.  I don't think we
                    147:         * ever get anything cached at this level at the
                    148:         * moment, but who knows...
                    149:         */
                    150:        if (rootvp->v_usecount > 1)
                    151:                return (EBUSY);
1.21      christos  152:        if ((error = vflush(mp, rootvp, flags)) != 0)
1.1       cgd       153:                return (error);
                    154:
                    155:        /*
                    156:         * Release reference on underlying root vnode
                    157:         */
                    158:        vrele(rootvp);
                    159:        /*
                    160:         * And blow it away for future re-use
                    161:         */
                    162:        vgone(rootvp);
                    163:        /*
                    164:         * Finally, throw away the fdescmount structure
                    165:         */
1.12      mycroft   166:        free(mp->mnt_data, M_UFSMNT);   /* XXX */
1.1       cgd       167:        mp->mnt_data = 0;
1.12      mycroft   168:
                    169:        return (0);
1.1       cgd       170: }
                    171:
1.12      mycroft   172: int
1.1       cgd       173: fdesc_root(mp, vpp)
                    174:        struct mount *mp;
                    175:        struct vnode **vpp;
                    176: {
                    177:        struct vnode *vp;
                    178:
                    179:        /*
                    180:         * Return locked reference to root.
                    181:         */
                    182:        vp = VFSTOFDESC(mp)->f_root;
                    183:        VREF(vp);
1.24      fvdl      184:        vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
1.1       cgd       185:        *vpp = vp;
                    186:        return (0);
                    187: }
                    188:
1.12      mycroft   189: int
1.1       cgd       190: fdesc_quotactl(mp, cmd, uid, arg, p)
                    191:        struct mount *mp;
                    192:        int cmd;
                    193:        uid_t uid;
                    194:        caddr_t arg;
                    195:        struct proc *p;
                    196: {
1.12      mycroft   197:
1.1       cgd       198:        return (EOPNOTSUPP);
                    199: }
                    200:
1.12      mycroft   201: int
1.1       cgd       202: fdesc_statfs(mp, sbp, p)
                    203:        struct mount *mp;
                    204:        struct statfs *sbp;
                    205:        struct proc *p;
                    206: {
                    207:        struct filedesc *fdp;
                    208:        int lim;
                    209:        int i;
                    210:        int last;
                    211:        int freefd;
                    212:
                    213:        /*
                    214:         * Compute number of free file descriptors.
                    215:         * [ Strange results will ensue if the open file
                    216:         * limit is ever reduced below the current number
                    217:         * of open files... ]
                    218:         */
1.5       mycroft   219:        lim = p->p_rlimit[RLIMIT_NOFILE].rlim_cur;
1.1       cgd       220:        fdp = p->p_fd;
                    221:        last = min(fdp->fd_nfiles, lim);
                    222:        freefd = 0;
                    223:        for (i = fdp->fd_freefile; i < last; i++)
                    224:                if (fdp->fd_ofiles[i] == NULL)
                    225:                        freefd++;
                    226:
                    227:        /*
                    228:         * Adjust for the fact that the fdesc array may not
                    229:         * have been fully allocated yet.
                    230:         */
                    231:        if (fdp->fd_nfiles < lim)
                    232:                freefd += (lim - fdp->fd_nfiles);
                    233:
                    234:        sbp->f_bsize = DEV_BSIZE;
1.10      cgd       235:        sbp->f_iosize = DEV_BSIZE;
1.1       cgd       236:        sbp->f_blocks = 2;              /* 1K to keep df happy */
                    237:        sbp->f_bfree = 0;
                    238:        sbp->f_bavail = 0;
                    239:        sbp->f_files = lim + 1;         /* Allow for "." */
                    240:        sbp->f_ffree = freefd;          /* See comments above */
1.24      fvdl      241: #ifdef COMPAT_09
                    242:        sbp->f_type = 6;
                    243: #else
                    244:        sbp->f_type = 0;
                    245: #endif
1.1       cgd       246:        if (sbp != &mp->mnt_stat) {
1.26      perry     247:                memcpy(&sbp->f_fsid, &mp->mnt_stat.f_fsid, sizeof(sbp->f_fsid));
                    248:                memcpy(sbp->f_mntonname, mp->mnt_stat.f_mntonname, MNAMELEN);
                    249:                memcpy(sbp->f_mntfromname, mp->mnt_stat.f_mntfromname, MNAMELEN);
1.1       cgd       250:        }
1.17      mycroft   251:        strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name, MFSNAMELEN);
1.1       cgd       252:        return (0);
                    253: }
                    254:
1.21      christos  255: /*ARGSUSED*/
1.12      mycroft   256: int
1.21      christos  257: fdesc_sync(mp, waitfor, uc, p)
1.1       cgd       258:        struct mount *mp;
                    259:        int waitfor;
1.21      christos  260:        struct ucred *uc;
                    261:        struct proc *p;
1.1       cgd       262: {
1.12      mycroft   263:
1.1       cgd       264:        return (0);
                    265: }
                    266:
1.12      mycroft   267: /*
                    268:  * Fdesc flat namespace lookup.
                    269:  * Currently unsupported.
                    270:  */
                    271: int
                    272: fdesc_vget(mp, ino, vpp)
                    273:        struct mount *mp;
                    274:        ino_t ino;
                    275:        struct vnode **vpp;
                    276: {
                    277:
                    278:        return (EOPNOTSUPP);
                    279: }
                    280:
1.21      christos  281:
                    282: /*ARGSUSED*/
1.12      mycroft   283: int
1.27      wrstuden  284: fdesc_fhtovp(mp, fhp, vpp)
1.1       cgd       285:        struct mount *mp;
                    286:        struct fid *fhp;
1.27      wrstuden  287:        struct vnode **vpp;
                    288: {
                    289:
                    290:        return (EOPNOTSUPP);
                    291: }
                    292:
                    293: /*ARGSUSED*/
                    294: int
                    295: fdesc_checkexp(mp, nam, exflagsp, credanonp)
                    296:        struct mount *mp;
1.21      christos  297:        struct mbuf *nam;
                    298:        int *exflagsp;
                    299:        struct ucred **credanonp;
1.1       cgd       300: {
1.21      christos  301:
1.1       cgd       302:        return (EOPNOTSUPP);
                    303: }
                    304:
1.21      christos  305: /*ARGSUSED*/
1.12      mycroft   306: int
1.1       cgd       307: fdesc_vptofh(vp, fhp)
                    308:        struct vnode *vp;
                    309:        struct fid *fhp;
                    310: {
                    311:        return (EOPNOTSUPP);
                    312: }
                    313:
1.24      fvdl      314: int
                    315: fdesc_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
                    316:        int *name;
                    317:        u_int namelen;
                    318:        void *oldp;
                    319:        size_t *oldlenp;
                    320:        void *newp;
                    321:        size_t newlen;
                    322:        struct proc *p;
                    323: {
                    324:        return (EOPNOTSUPP);
                    325: }
                    326:
1.32      jdolecek  327: extern const struct vnodeopv_desc fdesc_vnodeop_opv_desc;
1.23      thorpej   328:
1.32      jdolecek  329: const struct vnodeopv_desc * const fdesc_vnodeopv_descs[] = {
1.23      thorpej   330:        &fdesc_vnodeop_opv_desc,
                    331:        NULL,
                    332: };
                    333:
1.1       cgd       334: struct vfsops fdesc_vfsops = {
1.9       cgd       335:        MOUNT_FDESC,
1.1       cgd       336:        fdesc_mount,
                    337:        fdesc_start,
                    338:        fdesc_unmount,
                    339:        fdesc_root,
                    340:        fdesc_quotactl,
                    341:        fdesc_statfs,
                    342:        fdesc_sync,
1.12      mycroft   343:        fdesc_vget,
1.1       cgd       344:        fdesc_fhtovp,
                    345:        fdesc_vptofh,
                    346:        fdesc_init,
1.29      jdolecek  347:        fdesc_done,
1.24      fvdl      348:        fdesc_sysctl,
1.23      thorpej   349:        NULL,                           /* vfs_mountroot */
1.27      wrstuden  350:        fdesc_checkexp,
1.23      thorpej   351:        fdesc_vnodeopv_descs,
1.1       cgd       352: };

CVSweb <webmaster@jp.NetBSD.org>