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

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

CVSweb <webmaster@jp.NetBSD.org>