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

1.61    ! christos    1: /*     $NetBSD: fdesc_vfsops.c,v 1.60 2006/08/30 01:28:53 christos 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.
1.44      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.24      fvdl       34:  *     @(#)fdesc_vfsops.c      8.10 (Berkeley) 5/14/95
1.15      mycroft    35:  *
                     36:  * #Id: fdesc_vfsops.c,v 1.9 1993/04/06 15:28:33 jsp Exp #
1.1       cgd        37:  */
                     38:
                     39: /*
                     40:  * /dev/fd Filesystem
                     41:  */
1.35      lukem      42:
                     43: #include <sys/cdefs.h>
1.61    ! christos   44: __KERNEL_RCSID(0, "$NetBSD: fdesc_vfsops.c,v 1.60 2006/08/30 01:28:53 christos Exp $");
1.25      jonathan   45:
1.33      mrg        46: #if defined(_KERNEL_OPT)
1.25      jonathan   47: #include "opt_compat_netbsd.h"
                     48: #endif
1.1       cgd        49:
1.6       cgd        50: #include <sys/param.h>
                     51: #include <sys/systm.h>
1.45      atatat     52: #include <sys/sysctl.h>
1.6       cgd        53: #include <sys/time.h>
                     54: #include <sys/proc.h>
                     55: #include <sys/resourcevar.h>
                     56: #include <sys/filedesc.h>
                     57: #include <sys/vnode.h>
                     58: #include <sys/mount.h>
1.48      christos   59: #include <sys/dirent.h>
1.6       cgd        60: #include <sys/namei.h>
                     61: #include <sys/malloc.h>
1.59      elad       62: #include <sys/kauth.h>
                     63:
1.6       cgd        64: #include <miscfs/fdesc/fdesc.h>
1.1       cgd        65:
1.56      xtraeme    66: int    fdesc_mount(struct mount *, const char *, void *,
1.58      christos   67:                         struct nameidata *, struct lwp *);
                     68: int    fdesc_start(struct mount *, int, struct lwp *);
                     69: int    fdesc_unmount(struct mount *, int, struct lwp *);
1.56      xtraeme    70: int    fdesc_quotactl(struct mount *, int, uid_t, void *,
1.58      christos   71:                            struct lwp *);
                     72: int    fdesc_statvfs(struct mount *, struct statvfs *, struct lwp *);
1.59      elad       73: int    fdesc_sync(struct mount *, int, kauth_cred_t, struct lwp *);
1.56      xtraeme    74: int    fdesc_vget(struct mount *, ino_t, struct vnode **);
1.21      christos   75:
1.1       cgd        76: /*
                     77:  * Mount the per-process file descriptors (/dev/fd)
                     78:  */
1.12      mycroft    79: int
1.61    ! christos   80: fdesc_mount(struct mount *mp, const char *path, void *data __unused,
        !            81:     struct nameidata *ndp __unused, struct lwp *l)
1.1       cgd        82: {
                     83:        int error = 0;
                     84:        struct fdescmount *fmp;
                     85:        struct vnode *rvp;
                     86:
1.38      christos   87:        if (mp->mnt_flag & MNT_GETARGS)
                     88:                return 0;
1.1       cgd        89:        /*
                     90:         * Update is a no-op
                     91:         */
                     92:        if (mp->mnt_flag & MNT_UPDATE)
                     93:                return (EOPNOTSUPP);
                     94:
1.6       cgd        95:        error = fdesc_allocvp(Froot, FD_ROOT, mp, &rvp);
1.1       cgd        96:        if (error)
                     97:                return (error);
                     98:
1.6       cgd        99:        MALLOC(fmp, struct fdescmount *, sizeof(struct fdescmount),
1.12      mycroft   100:                                M_UFSMNT, M_WAITOK);    /* XXX */
1.1       cgd       101:        rvp->v_type = VDIR;
                    102:        rvp->v_flag |= VROOT;
                    103:        fmp->f_root = rvp;
1.52      jdolecek  104:        mp->mnt_stat.f_namemax = MAXNAMLEN;
1.14      mycroft   105:        mp->mnt_flag |= MNT_LOCAL;
1.37      soren     106:        mp->mnt_data = fmp;
1.31      assar     107:        vfs_getnewfsid(mp);
1.1       cgd       108:
1.47      christos  109:        error = set_statvfs_info(path, UIO_USERSPACE, "fdesc", UIO_SYSSPACE,
1.58      christos  110:            mp, l);
1.28      wrstuden  111:        VOP_UNLOCK(rvp, 0);
1.39      christos  112:        return error;
1.1       cgd       113: }
                    114:
1.12      mycroft   115: int
1.61    ! christos  116: fdesc_start(struct mount *mp __unused, int flags __unused,
        !           117:     struct lwp *l __unused)
1.1       cgd       118: {
                    119:        return (0);
                    120: }
                    121:
1.12      mycroft   122: int
1.61    ! christos  123: fdesc_unmount(struct mount *mp, int mntflags, struct lwp *l __unused)
1.1       cgd       124: {
                    125:        int error;
                    126:        int flags = 0;
1.55      christos  127:        struct vnode *rtvp = VFSTOFDESC(mp)->f_root;
1.1       cgd       128:
1.24      fvdl      129:        if (mntflags & MNT_FORCE)
1.1       cgd       130:                flags |= FORCECLOSE;
                    131:
                    132:        /*
                    133:         * Clear out buffer cache.  I don't think we
                    134:         * ever get anything cached at this level at the
                    135:         * moment, but who knows...
                    136:         */
1.55      christos  137:        if (rtvp->v_usecount > 1)
1.1       cgd       138:                return (EBUSY);
1.55      christos  139:        if ((error = vflush(mp, rtvp, flags)) != 0)
1.1       cgd       140:                return (error);
                    141:
                    142:        /*
                    143:         * Release reference on underlying root vnode
                    144:         */
1.55      christos  145:        vrele(rtvp);
1.1       cgd       146:        /*
                    147:         * And blow it away for future re-use
                    148:         */
1.55      christos  149:        vgone(rtvp);
1.1       cgd       150:        /*
                    151:         * Finally, throw away the fdescmount structure
                    152:         */
1.12      mycroft   153:        free(mp->mnt_data, M_UFSMNT);   /* XXX */
1.1       cgd       154:        mp->mnt_data = 0;
1.12      mycroft   155:
                    156:        return (0);
1.1       cgd       157: }
                    158:
1.12      mycroft   159: int
1.42      thorpej   160: fdesc_root(mp, vpp)
1.1       cgd       161:        struct mount *mp;
                    162:        struct vnode **vpp;
                    163: {
                    164:        struct vnode *vp;
                    165:
                    166:        /*
                    167:         * Return locked reference to root.
                    168:         */
                    169:        vp = VFSTOFDESC(mp)->f_root;
                    170:        VREF(vp);
1.24      fvdl      171:        vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
1.1       cgd       172:        *vpp = vp;
                    173:        return (0);
                    174: }
                    175:
1.12      mycroft   176: int
1.61    ! christos  177: fdesc_quotactl(struct mount *mp __unused, int cmd __unused, uid_t uid __unused,
        !           178:     void *arg __unused, struct lwp *l __unused)
1.1       cgd       179: {
1.12      mycroft   180:
1.1       cgd       181:        return (EOPNOTSUPP);
                    182: }
                    183:
1.12      mycroft   184: int
1.58      christos  185: fdesc_statvfs(mp, sbp, l)
1.1       cgd       186:        struct mount *mp;
1.47      christos  187:        struct statvfs *sbp;
1.58      christos  188:        struct lwp *l;
1.1       cgd       189: {
                    190:        struct filedesc *fdp;
1.58      christos  191:        struct proc *p;
1.1       cgd       192:        int lim;
                    193:        int i;
                    194:        int last;
                    195:        int freefd;
                    196:
                    197:        /*
                    198:         * Compute number of free file descriptors.
                    199:         * [ Strange results will ensue if the open file
                    200:         * limit is ever reduced below the current number
                    201:         * of open files... ]
                    202:         */
1.58      christos  203:        p = l->l_proc;
1.5       mycroft   204:        lim = p->p_rlimit[RLIMIT_NOFILE].rlim_cur;
1.1       cgd       205:        fdp = p->p_fd;
                    206:        last = min(fdp->fd_nfiles, lim);
                    207:        freefd = 0;
                    208:        for (i = fdp->fd_freefile; i < last; i++)
                    209:                if (fdp->fd_ofiles[i] == NULL)
                    210:                        freefd++;
                    211:
                    212:        /*
                    213:         * Adjust for the fact that the fdesc array may not
                    214:         * have been fully allocated yet.
                    215:         */
                    216:        if (fdp->fd_nfiles < lim)
                    217:                freefd += (lim - fdp->fd_nfiles);
                    218:
                    219:        sbp->f_bsize = DEV_BSIZE;
1.47      christos  220:        sbp->f_frsize = DEV_BSIZE;
1.10      cgd       221:        sbp->f_iosize = DEV_BSIZE;
1.1       cgd       222:        sbp->f_blocks = 2;              /* 1K to keep df happy */
                    223:        sbp->f_bfree = 0;
                    224:        sbp->f_bavail = 0;
1.47      christos  225:        sbp->f_bresvd = 0;
1.1       cgd       226:        sbp->f_files = lim + 1;         /* Allow for "." */
                    227:        sbp->f_ffree = freefd;          /* See comments above */
1.47      christos  228:        sbp->f_favail = freefd;         /* See comments above */
                    229:        sbp->f_fresvd = 0;
                    230:        copy_statvfs_info(sbp, mp);
1.1       cgd       231:        return (0);
                    232: }
                    233:
1.21      christos  234: /*ARGSUSED*/
1.12      mycroft   235: int
1.61    ! christos  236: fdesc_sync(struct mount *mp __unused, int waitfor __unused,
        !           237:     kauth_cred_t uc __unused, struct lwp *l __unused)
1.1       cgd       238: {
1.12      mycroft   239:
1.1       cgd       240:        return (0);
                    241: }
                    242:
1.12      mycroft   243: /*
                    244:  * Fdesc flat namespace lookup.
                    245:  * Currently unsupported.
                    246:  */
                    247: int
1.61    ! christos  248: fdesc_vget(struct mount *mp __unused, ino_t ino __unused,
        !           249:     struct vnode **vpp __unused)
1.12      mycroft   250: {
                    251:
                    252:        return (EOPNOTSUPP);
                    253: }
                    254:
1.21      christos  255:
1.45      atatat    256: SYSCTL_SETUP(sysctl_vfs_fdesc_setup, "sysctl vfs.fdesc subtree setup")
1.24      fvdl      257: {
1.45      atatat    258:
1.46      atatat    259:        sysctl_createv(clog, 0, NULL, NULL,
                    260:                       CTLFLAG_PERMANENT,
1.45      atatat    261:                       CTLTYPE_NODE, "vfs", NULL,
                    262:                       NULL, 0, NULL, 0,
                    263:                       CTL_VFS, CTL_EOL);
1.46      atatat    264:        sysctl_createv(clog, 0, NULL, NULL,
                    265:                       CTLFLAG_PERMANENT,
1.50      atatat    266:                       CTLTYPE_NODE, "fdesc",
                    267:                       SYSCTL_DESCR("File-descriptor file system"),
1.45      atatat    268:                       NULL, 0, NULL, 0,
                    269:                       CTL_VFS, 7, CTL_EOL);
                    270:        /*
                    271:         * XXX the "7" above could be dynamic, thereby eliminating one
                    272:         * more instance of the "number to vfs" mapping problem, but
                    273:         * "7" is the order as taken from sys/mount.h
                    274:         */
1.24      fvdl      275: }
                    276:
1.32      jdolecek  277: extern const struct vnodeopv_desc fdesc_vnodeop_opv_desc;
1.23      thorpej   278:
1.32      jdolecek  279: const struct vnodeopv_desc * const fdesc_vnodeopv_descs[] = {
1.23      thorpej   280:        &fdesc_vnodeop_opv_desc,
                    281:        NULL,
                    282: };
                    283:
1.1       cgd       284: struct vfsops fdesc_vfsops = {
1.9       cgd       285:        MOUNT_FDESC,
1.1       cgd       286:        fdesc_mount,
                    287:        fdesc_start,
                    288:        fdesc_unmount,
                    289:        fdesc_root,
                    290:        fdesc_quotactl,
1.47      christos  291:        fdesc_statvfs,
1.1       cgd       292:        fdesc_sync,
1.12      mycroft   293:        fdesc_vget,
1.57      jmmv      294:        NULL,                           /* vfs_fhtovp */
                    295:        NULL,                           /* vfs_vptofh */
1.1       cgd       296:        fdesc_init,
1.34      chs       297:        NULL,
1.29      jdolecek  298:        fdesc_done,
1.23      thorpej   299:        NULL,                           /* vfs_mountroot */
1.51      hannken   300:        (int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
1.53      thorpej   301:        vfs_stdextattrctl,
1.23      thorpej   302:        fdesc_vnodeopv_descs,
1.60      christos  303:        0,
                    304:        { NULL, NULL},
1.1       cgd       305: };
1.54      thorpej   306: VFS_ATTACH(fdesc_vfsops);

CVSweb <webmaster@jp.NetBSD.org>