handle case where fdesc is mounted twice or more
authorJan-Simon Pendry <pendry@ucbvax.Berkeley.EDU>
Thu, 6 Jan 1994 04:03:22 +0000 (20:03 -0800)
committerJan-Simon Pendry <pendry@ucbvax.Berkeley.EDU>
Thu, 6 Jan 1994 04:03:22 +0000 (20:03 -0800)
general cleanup, remove debug code, lint + KNF.

SCCS-vsn: sys/miscfs/fdesc/fdesc.h 8.4
SCCS-vsn: sys/miscfs/fdesc/fdesc_vfsops.c 8.3
SCCS-vsn: sys/miscfs/fdesc/fdesc_vnops.c 8.7

usr/src/sys/miscfs/fdesc/fdesc.h
usr/src/sys/miscfs/fdesc/fdesc_vfsops.c
usr/src/sys/miscfs/fdesc/fdesc_vnops.c

index 7071a5b..b318b90 100644 (file)
@@ -8,7 +8,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)fdesc.h     8.3 (Berkeley) %G%
+ *     @(#)fdesc.h     8.4 (Berkeley) %G%
  *
  * $Id: fdesc.h,v 1.8 1993/04/06 15:28:33 jsp Exp $
  */
  *
  * $Id: fdesc.h,v 1.8 1993/04/06 15:28:33 jsp Exp $
  */
@@ -36,6 +36,9 @@ typedef enum {
 } fdntype;
 
 struct fdescnode {
 } fdntype;
 
 struct fdescnode {
+       struct fdescnode *fd_forw;      /* Hash chain */
+       struct fdescnode *fd_back;
+       struct vnode    *fd_vnode;      /* Back ptr to vnode */
        fdntype         fd_type;        /* Type of this node */
        unsigned        fd_fd;          /* Fd to be dup'ed */
        char            *fd_link;       /* Link to fd/n */
        fdntype         fd_type;        /* Type of this node */
        unsigned        fd_fd;          /* Fd to be dup'ed */
        char            *fd_link;       /* Link to fd/n */
@@ -46,6 +49,8 @@ struct fdescnode {
 #define        VTOFDESC(vp) ((struct fdescnode *)(vp)->v_data)
 
 extern dev_t devctty;
 #define        VTOFDESC(vp) ((struct fdescnode *)(vp)->v_data)
 
 extern dev_t devctty;
+extern int fdesc_init __P((void));
+extern int fdesc_root __P((struct mount *, struct vnode **));
 extern int fdesc_allocvp __P((fdntype, int, struct mount *, struct vnode **));
 extern int (**fdesc_vnodeop_p)();
 extern struct vfsops fdesc_vfsops;
 extern int fdesc_allocvp __P((fdntype, int, struct mount *, struct vnode **));
 extern int (**fdesc_vnodeop_p)();
 extern struct vfsops fdesc_vfsops;
index cb85075..de7fc79 100644 (file)
@@ -8,7 +8,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)fdesc_vfsops.c      8.2 (Berkeley) %G%
+ *     @(#)fdesc_vfsops.c      8.3 (Berkeley) %G%
  *
  * $Id: fdesc_vfsops.c,v 1.9 1993/04/06 15:28:33 jsp Exp $
  */
  *
  * $Id: fdesc_vfsops.c,v 1.9 1993/04/06 15:28:33 jsp Exp $
  */
 #include <sys/malloc.h>
 #include <miscfs/fdesc/fdesc.h>
 
 #include <sys/malloc.h>
 #include <miscfs/fdesc/fdesc.h>
 
-dev_t devctty;
-
-fdesc_init()
-{
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_init\n");         /* printed during system boot */
-#endif
-       devctty = makedev(nchrdev, 0);
-}
-
 /*
  * Mount the per-process file descriptors (/dev/fd)
  */
 /*
  * Mount the per-process file descriptors (/dev/fd)
  */
+int
 fdesc_mount(mp, path, data, ndp, p)
        struct mount *mp;
        char *path;
 fdesc_mount(mp, path, data, ndp, p)
        struct mount *mp;
        char *path;
@@ -55,10 +46,6 @@ fdesc_mount(mp, path, data, ndp, p)
        struct fdescmount *fmp;
        struct vnode *rvp;
 
        struct fdescmount *fmp;
        struct vnode *rvp;
 
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_mount(mp = %x)\n", mp);
-#endif
-
        /*
         * Update is a no-op
         */
        /*
         * Update is a no-op
         */
@@ -73,9 +60,6 @@ fdesc_mount(mp, path, data, ndp, p)
                                M_UFSMNT, M_WAITOK);    /* XXX */
        rvp->v_type = VDIR;
        rvp->v_flag |= VROOT;
                                M_UFSMNT, M_WAITOK);    /* XXX */
        rvp->v_type = VDIR;
        rvp->v_flag |= VROOT;
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_mount: root vp = %x\n", rvp);
-#endif
        fmp->f_root = rvp;
        /* XXX -- don't mark as local to work around fts() problems */
        /*mp->mnt_flag |= MNT_LOCAL;*/
        fmp->f_root = rvp;
        /* XXX -- don't mark as local to work around fts() problems */
        /*mp->mnt_flag |= MNT_LOCAL;*/
@@ -86,12 +70,10 @@ fdesc_mount(mp, path, data, ndp, p)
        bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
        bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
        bcopy("fdesc", mp->mnt_stat.f_mntfromname, sizeof("fdesc"));
        bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
        bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
        bcopy("fdesc", mp->mnt_stat.f_mntfromname, sizeof("fdesc"));
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_mount: at %s\n", mp->mnt_stat.f_mntonname);
-#endif
        return (0);
 }
 
        return (0);
 }
 
+int
 fdesc_start(mp, flags, p)
        struct mount *mp;
        int flags;
 fdesc_start(mp, flags, p)
        struct mount *mp;
        int flags;
@@ -100,6 +82,7 @@ fdesc_start(mp, flags, p)
        return (0);
 }
 
        return (0);
 }
 
+int
 fdesc_unmount(mp, mntflags, p)
        struct mount *mp;
        int mntflags;
 fdesc_unmount(mp, mntflags, p)
        struct mount *mp;
        int mntflags;
@@ -110,10 +93,6 @@ fdesc_unmount(mp, mntflags, p)
        extern int doforce;
        struct vnode *rootvp = VFSTOFDESC(mp)->f_root;
 
        extern int doforce;
        struct vnode *rootvp = VFSTOFDESC(mp)->f_root;
 
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_unmount(mp = %x)\n", mp);
-#endif
-
        if (mntflags & MNT_FORCE) {
                /* fdesc can never be rootfs so don't check for it */
                if (!doforce)
        if (mntflags & MNT_FORCE) {
                /* fdesc can never be rootfs so don't check for it */
                if (!doforce)
@@ -126,28 +105,11 @@ fdesc_unmount(mp, mntflags, p)
         * ever get anything cached at this level at the
         * moment, but who knows...
         */
         * ever get anything cached at this level at the
         * moment, but who knows...
         */
-#if 0
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_unmount: calling mntflushbuf\n");
-#endif
-       mntflushbuf(mp, 0); 
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_unmount: calling mntinvalbuf\n");
-#endif
-       if (mntinvalbuf(mp, 1))
-               return (EBUSY);
-#endif
        if (rootvp->v_usecount > 1)
                return (EBUSY);
        if (rootvp->v_usecount > 1)
                return (EBUSY);
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_unmount: calling vflush\n");
-#endif
        if (error = vflush(mp, rootvp, flags))
                return (error);
 
        if (error = vflush(mp, rootvp, flags))
                return (error);
 
-#ifdef FDESC_DIAGNOSTIC
-       vprint("fdesc root", rootvp);
-#endif  
        /*
         * Release reference on underlying root vnode
         */
        /*
         * Release reference on underlying root vnode
         */
@@ -161,19 +123,17 @@ fdesc_unmount(mp, mntflags, p)
         */
        free(mp->mnt_data, M_UFSMNT);   /* XXX */
        mp->mnt_data = 0;
         */
        free(mp->mnt_data, M_UFSMNT);   /* XXX */
        mp->mnt_data = 0;
-       return 0;
+
+       return (0);
 }
 
 }
 
+int
 fdesc_root(mp, vpp)
        struct mount *mp;
        struct vnode **vpp;
 {
        struct vnode *vp;
 
 fdesc_root(mp, vpp)
        struct mount *mp;
        struct vnode **vpp;
 {
        struct vnode *vp;
 
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_root(mp = %x)\n", mp);
-#endif
-
        /*
         * Return locked reference to root.
         */
        /*
         * Return locked reference to root.
         */
@@ -184,6 +144,7 @@ fdesc_root(mp, vpp)
        return (0);
 }
 
        return (0);
 }
 
+int
 fdesc_quotactl(mp, cmd, uid, arg, p)
        struct mount *mp;
        int cmd;
 fdesc_quotactl(mp, cmd, uid, arg, p)
        struct mount *mp;
        int cmd;
@@ -191,9 +152,11 @@ fdesc_quotactl(mp, cmd, uid, arg, p)
        caddr_t arg;
        struct proc *p;
 {
        caddr_t arg;
        struct proc *p;
 {
+
        return (EOPNOTSUPP);
 }
 
        return (EOPNOTSUPP);
 }
 
+int
 fdesc_statfs(mp, sbp, p)
        struct mount *mp;
        struct statfs *sbp;
 fdesc_statfs(mp, sbp, p)
        struct mount *mp;
        struct statfs *sbp;
@@ -205,10 +168,6 @@ fdesc_statfs(mp, sbp, p)
        int last;
        int freefd;
 
        int last;
        int freefd;
 
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_statfs(mp = %x)\n", mp);
-#endif
-
        /*
         * Compute number of free file descriptors.
         * [ Strange results will ensue if the open file
        /*
         * Compute number of free file descriptors.
         * [ Strange results will ensue if the open file
@@ -247,10 +206,12 @@ fdesc_statfs(mp, sbp, p)
        return (0);
 }
 
        return (0);
 }
 
+int
 fdesc_sync(mp, waitfor)
        struct mount *mp;
        int waitfor;
 {
 fdesc_sync(mp, waitfor)
        struct mount *mp;
        int waitfor;
 {
+
        return (0);
 }
 
        return (0);
 }
 
@@ -258,6 +219,7 @@ fdesc_sync(mp, waitfor)
  * Fdesc flat namespace lookup.
  * Currently unsupported.
  */
  * Fdesc flat namespace lookup.
  * Currently unsupported.
  */
+int
 fdesc_vget(mp, ino, vpp)
        struct mount *mp;
        ino_t ino;
 fdesc_vget(mp, ino, vpp)
        struct mount *mp;
        ino_t ino;
@@ -267,7 +229,7 @@ fdesc_vget(mp, ino, vpp)
        return (EOPNOTSUPP);
 }
 
        return (EOPNOTSUPP);
 }
 
-
+int
 fdesc_fhtovp(mp, fhp, setgen, vpp)
        struct mount *mp;
        struct fid *fhp;
 fdesc_fhtovp(mp, fhp, setgen, vpp)
        struct mount *mp;
        struct fid *fhp;
@@ -277,10 +239,12 @@ fdesc_fhtovp(mp, fhp, setgen, vpp)
        return (EOPNOTSUPP);
 }
 
        return (EOPNOTSUPP);
 }
 
+int
 fdesc_vptofh(vp, fhp)
        struct vnode *vp;
        struct fid *fhp;
 {
 fdesc_vptofh(vp, fhp)
        struct vnode *vp;
        struct fid *fhp;
 {
+
        return (EOPNOTSUPP);
 }
 
        return (EOPNOTSUPP);
 }
 
index 7091dba..1dedf84 100644 (file)
@@ -8,7 +8,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)fdesc_vnops.c       8.6 (Berkeley) %G%
+ *     @(#)fdesc_vnops.c       8.7 (Berkeley) %G%
  *
  * $Id: fdesc_vnops.c,v 1.12 1993/04/06 16:17:17 jsp Exp $
  */
  *
  * $Id: fdesc_vnops.c,v 1.12 1993/04/06 16:17:17 jsp Exp $
  */
 
 #define FDL_WANT       0x01
 #define FDL_LOCKED     0x02
 
 #define FDL_WANT       0x01
 #define FDL_LOCKED     0x02
-static int fdescvplock;
-static struct vnode *fdescvp[FD_MAX];
+static int fdcache_lock;
+
+dev_t devctty;
 
 #if (FD_STDIN != FD_STDOUT-1) || (FD_STDOUT != FD_STDERR-1)
 FD_STDIN, FD_STDOUT, FD_STDERR must be a sequence n, n+1, n+2
 #endif
 
 
 #if (FD_STDIN != FD_STDOUT-1) || (FD_STDOUT != FD_STDERR-1)
 FD_STDIN, FD_STDOUT, FD_STDERR must be a sequence n, n+1, n+2
 #endif
 
+#define        NFDCACHE 3
+#define        FD_NHASH(ix) ((ix) & NFDCACHE)
+
+/*
+ * Cache head
+ */
+struct fdcache {
+       struct fdescnode        *fc_forw;
+       struct fdescnode        *fc_back;
+};
+
+static struct fdcache fdcache[NFDCACHE];
+
+/*
+ * Initialise cache headers
+ */
+fdesc_init()
+{
+       struct fdcache *fc;
+
+       devctty = makedev(nchrdev, 0);
+
+       for (fc = fdcache; fc < fdcache + NFDCACHE; fc++)
+               fc->fc_forw = fc->fc_back = (struct fdescnode *) fc;
+}
+
+/*
+ * Compute hash list for given target vnode
+ */
+static struct fdcache *
+fdesc_hash(ix)
+       int ix;
+{
+
+       return (&fdcache[FD_NHASH(ix)]);
+}
+
+int
 fdesc_allocvp(ftype, ix, mp, vpp)
        fdntype ftype;
        int ix;
        struct mount *mp;
        struct vnode **vpp;
 {
 fdesc_allocvp(ftype, ix, mp, vpp)
        fdntype ftype;
        int ix;
        struct mount *mp;
        struct vnode **vpp;
 {
-       struct vnode **nvpp = 0;
+       struct fdcache *fc;
+       struct fdescnode *fd;
        int error = 0;
 
 loop:
        int error = 0;
 
 loop:
-       /* get stashed copy of the vnode */
-       if (ix >= 0 && ix < FD_MAX) {
-               nvpp = &fdescvp[ix];
-               if (*nvpp) {
-                       if (vget(*nvpp, 1))
+       fc = fdesc_hash(ix);
+       for (fd = fc->fc_forw; fd != (struct fdescnode *) fc; fd = fd->fd_forw) {
+               if (fd->fd_ix == ix && fd->fd_vnode->v_mount == mp) {
+                       if (vget(fd->fd_vnode, 0))
                                goto loop;
                                goto loop;
-                       VOP_UNLOCK(*nvpp);
-                       *vpp = *nvpp;
+                       *vpp = fd->fd_vnode;
                        return (error);
                }
        }
                        return (error);
                }
        }
@@ -72,30 +110,32 @@ loop:
         * otherwise lock the array while we call getnewvnode
         * since that can block.
         */ 
         * otherwise lock the array while we call getnewvnode
         * since that can block.
         */ 
-       if (fdescvplock & FDL_LOCKED) {
-               fdescvplock |= FDL_WANT;
-               sleep((caddr_t) &fdescvplock, PINOD);
+       if (fdcache_lock & FDL_LOCKED) {
+               fdcache_lock |= FDL_WANT;
+               sleep((caddr_t) &fdcache_lock, PINOD);
                goto loop;
        }
                goto loop;
        }
-       fdescvplock |= FDL_LOCKED;
+       fdcache_lock |= FDL_LOCKED;
 
        error = getnewvnode(VT_FDESC, mp, fdesc_vnodeop_p, vpp);
        if (error)
                goto out;
 
        error = getnewvnode(VT_FDESC, mp, fdesc_vnodeop_p, vpp);
        if (error)
                goto out;
-       MALLOC((*vpp)->v_data, void *, sizeof(struct fdescnode), M_TEMP, M_WAITOK);
-       if (nvpp)
-               *nvpp = *vpp;
-       VTOFDESC(*vpp)->fd_type = ftype;
-       VTOFDESC(*vpp)->fd_fd = -1;
-       VTOFDESC(*vpp)->fd_link = 0;
-       VTOFDESC(*vpp)->fd_ix = ix;
+       MALLOC(fd, void *, sizeof(struct fdescnode), M_TEMP, M_WAITOK);
+       (*vpp)->v_data = fd;
+       fd->fd_vnode = *vpp;
+       fd->fd_type = ftype;
+       fd->fd_fd = -1;
+       fd->fd_link = 0;
+       fd->fd_ix = ix;
+       fc = fdesc_hash(ix);
+       insque(fd, fc);
 
 out:;
 
 out:;
-       fdescvplock &= ~FDL_LOCKED;
+       fdcache_lock &= ~FDL_LOCKED;
 
 
-       if (fdescvplock & FDL_WANT) {
-               fdescvplock &= ~FDL_WANT;
-               wakeup((caddr_t) &fdescvplock);
+       if (fdcache_lock & FDL_WANT) {
+               fdcache_lock &= ~FDL_WANT;
+               wakeup((caddr_t) &fdcache_lock);
        }
 
        return (error);
        }
 
        return (error);
@@ -105,6 +145,7 @@ out:;
  * vp is the current namei directory
  * ndp is the name to locate in that directory...
  */
  * vp is the current namei directory
  * ndp is the name to locate in that directory...
  */
+int
 fdesc_lookup(ap)
        struct vop_lookup_args /* {
                struct vnode * a_dvp;
 fdesc_lookup(ap)
        struct vop_lookup_args /* {
                struct vnode * a_dvp;
@@ -122,14 +163,7 @@ fdesc_lookup(ap)
        struct vnode *fvp;
        char *ln;
 
        struct vnode *fvp;
        char *ln;
 
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_lookup(%x)\n", ap);
-       printf("fdesc_lookup(dp = %x, vpp = %x, cnp = %x)\n", dvp, vpp, ap->a_cnp);
-#endif
        pname = ap->a_cnp->cn_nameptr;
        pname = ap->a_cnp->cn_nameptr;
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_lookup(%s)\n", pname);
-#endif
        if (ap->a_cnp->cn_namelen == 1 && *pname == '.') {
                *vpp = dvp;
                VREF(dvp);      
        if (ap->a_cnp->cn_namelen == 1 && *pname == '.') {
                *vpp = dvp;
                VREF(dvp);      
@@ -156,9 +190,6 @@ fdesc_lookup(ap)
                        *vpp = fvp;
                        fvp->v_type = VDIR;
                        VOP_LOCK(fvp);
                        *vpp = fvp;
                        fvp->v_type = VDIR;
                        VOP_LOCK(fvp);
-#ifdef FDESC_DIAGNOSTIC
-                       printf("fdesc_lookup: newvp = %x\n", fvp);
-#endif
                        return (0);
                }
 
                        return (0);
                }
 
@@ -174,9 +205,6 @@ fdesc_lookup(ap)
                        *vpp = fvp;
                        fvp->v_type = VFIFO;
                        VOP_LOCK(fvp);
                        *vpp = fvp;
                        fvp->v_type = VFIFO;
                        VOP_LOCK(fvp);
-#ifdef FDESC_DIAGNOSTIC
-                       printf("fdesc_lookup: ttyvp = %x\n", fvp);
-#endif
                        return (0);
                }
 
                        return (0);
                }
 
@@ -201,9 +229,6 @@ fdesc_lookup(ap)
                }
 
                if (ln) {
                }
 
                if (ln) {
-#ifdef FDESC_DIAGNOSTIC
-                       printf("fdesc_lookup: link -> %s\n", ln);
-#endif
                        error = fdesc_allocvp(Flink, fd, dvp->v_mount, &fvp);
                        if (error)
                                goto bad;
                        error = fdesc_allocvp(Flink, fd, dvp->v_mount, &fvp);
                        if (error)
                                goto bad;
@@ -211,16 +236,13 @@ fdesc_lookup(ap)
                        *vpp = fvp;
                        fvp->v_type = VLNK;
                        VOP_LOCK(fvp);
                        *vpp = fvp;
                        fvp->v_type = VLNK;
                        VOP_LOCK(fvp);
-#ifdef FDESC_DIAGNOSTIC
-                       printf("fdesc_lookup: newvp = %x\n", fvp);
-#endif
                        return (0);
                } else {
                        error = ENOENT;
                        goto bad;
                }
 
                        return (0);
                } else {
                        error = ENOENT;
                        goto bad;
                }
 
-               /* fall through */
+               /* FALL THROUGH */
 
        case Fdevfd:
                if (ap->a_cnp->cn_namelen == 2 && bcmp(pname, "..", 2) == 0) {
 
        case Fdevfd:
                if (ap->a_cnp->cn_namelen == 2 && bcmp(pname, "..", 2) == 0) {
@@ -235,9 +257,6 @@ fdesc_lookup(ap)
                                break;
                }
 
                                break;
                }
 
-#ifdef FDESC_DIAGNOSTIC
-               printf("fdesc_lookup: fd = %d, *pname = %x\n", fd, *pname);
-#endif
                if (*pname != '\0') {
                        error = ENOENT;
                        goto bad;
                if (*pname != '\0') {
                        error = ENOENT;
                        goto bad;
@@ -248,28 +267,20 @@ fdesc_lookup(ap)
                        goto bad;
                }
 
                        goto bad;
                }
 
-#ifdef FDESC_DIAGNOSTIC
-               printf("fdesc_lookup: allocate new vnode\n");
-#endif
                error = fdesc_allocvp(Fdesc, FD_DESC+fd, dvp->v_mount, &fvp);
                if (error)
                        goto bad;
                VTOFDESC(fvp)->fd_fd = fd;
                *vpp = fvp;
                error = fdesc_allocvp(Fdesc, FD_DESC+fd, dvp->v_mount, &fvp);
                if (error)
                        goto bad;
                VTOFDESC(fvp)->fd_fd = fd;
                *vpp = fvp;
-#ifdef FDESC_DIAGNOSTIC
-               printf("fdesc_lookup: newvp = %x\n", fvp);
-#endif
                return (0);
        }
 
 bad:;
        *vpp = NULL;
                return (0);
        }
 
 bad:;
        *vpp = NULL;
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_lookup: error = %d\n", error);
-#endif
        return (error);
 }
 
        return (error);
 }
 
+int
 fdesc_open(ap)
        struct vop_open_args /* {
                struct vnode *a_vp;
 fdesc_open(ap)
        struct vop_open_args /* {
                struct vnode *a_vp;
@@ -315,15 +326,8 @@ fdesc_attr(fd, vap, cred, p)
        struct stat stb;
        int error;
 
        struct stat stb;
        int error;
 
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_attr: fd = %d, nfiles = %d\n", fd, fdp->fd_nfiles);
-#endif
-       if (fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[fd]) == NULL) {
-#ifdef FDESC_DIAGNOSTIC
-               printf("fdesc_attr: fp = %x (EBADF)\n", fp);
-#endif
+       if (fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[fd]) == NULL)
                return (EBADF);
                return (EBADF);
-       }
 
        switch (fp->f_type) {
        case DTYPE_VNODE:
 
        switch (fp->f_type) {
        case DTYPE_VNODE:
@@ -365,12 +369,10 @@ fdesc_attr(fd, vap, cred, p)
                break;
        }
 
                break;
        }
 
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_attr: returns error %d\n", error);
-#endif
        return (error);
 }
 
        return (error);
 }
 
+int
 fdesc_getattr(ap)
        struct vop_getattr_args /* {
                struct vnode *a_vp;
 fdesc_getattr(ap)
        struct vop_getattr_args /* {
                struct vnode *a_vp;
@@ -384,10 +386,6 @@ fdesc_getattr(ap)
        unsigned fd;
        int error = 0;
 
        unsigned fd;
        int error = 0;
 
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_getattr: stat type = %d\n", VTOFDESC(vp)->fd_type);
-#endif
-
        switch (VTOFDESC(vp)->fd_type) {
        case Froot:
        case Fdevfd:
        switch (VTOFDESC(vp)->fd_type) {
        case Froot:
        case Fdevfd:
@@ -402,7 +400,6 @@ fdesc_getattr(ap)
                        vap->va_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
                        vap->va_type = VLNK;
                        vap->va_nlink = 1;
                        vap->va_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
                        vap->va_type = VLNK;
                        vap->va_nlink = 1;
-                       /* vap->va_qsize = strlen(VTOFDESC(vp)->fd_link); */
                        vap->va_size = strlen(VTOFDESC(vp)->fd_link);
                        break;
 
                        vap->va_size = strlen(VTOFDESC(vp)->fd_link);
                        break;
 
@@ -410,7 +407,6 @@ fdesc_getattr(ap)
                        vap->va_mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
                        vap->va_type = VFIFO;
                        vap->va_nlink = 1;
                        vap->va_mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
                        vap->va_type = VFIFO;
                        vap->va_nlink = 1;
-                       /* vap->va_qsize = 0; */
                        vap->va_size = 0;
                        break;
 
                        vap->va_size = 0;
                        break;
 
@@ -418,7 +414,6 @@ fdesc_getattr(ap)
                        vap->va_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
                        vap->va_type = VDIR;
                        vap->va_nlink = 2;
                        vap->va_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
                        vap->va_type = VDIR;
                        vap->va_nlink = 2;
-                       /* vap->va_qsize = 0; */
                        vap->va_size = DEV_BSIZE;
                        break;
                }
                        vap->va_size = DEV_BSIZE;
                        break;
                }
@@ -433,14 +428,10 @@ fdesc_getattr(ap)
                vap->va_gen = 0;
                vap->va_flags = 0;
                vap->va_rdev = 0;
                vap->va_gen = 0;
                vap->va_flags = 0;
                vap->va_rdev = 0;
-               /* vap->va_qbytes = 0; */
                vap->va_bytes = 0;
                break;
 
        case Fdesc:
                vap->va_bytes = 0;
                break;
 
        case Fdesc:
-#ifdef FDESC_DIAGNOSTIC
-               printf("fdesc_getattr: stat desc #%d\n", VTOFDESC(vp)->fd_fd);
-#endif
                fd = VTOFDESC(vp)->fd_fd;
                error = fdesc_attr(fd, vap, ap->a_cred, ap->a_p);
                break;
                fd = VTOFDESC(vp)->fd_fd;
                error = fdesc_attr(fd, vap, ap->a_cred, ap->a_p);
                break;
@@ -453,12 +444,10 @@ fdesc_getattr(ap)
        if (error == 0)
                vp->v_type = vap->va_type;
 
        if (error == 0)
                vp->v_type = vap->va_type;
 
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_getattr: stat returns 0\n");
-#endif
        return (error);
 }
 
        return (error);
 }
 
+int
 fdesc_setattr(ap)
        struct vop_setattr_args /* {
                struct vnode *a_vp;
 fdesc_setattr(ap)
        struct vop_setattr_args /* {
                struct vnode *a_vp;
@@ -487,13 +476,7 @@ fdesc_setattr(ap)
        }
 
        fd = VTOFDESC(ap->a_vp)->fd_fd;
        }
 
        fd = VTOFDESC(ap->a_vp)->fd_fd;
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_setattr: fd = %d, nfiles = %d\n", fd, fdp->fd_nfiles);
-#endif
        if (fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[fd]) == NULL) {
        if (fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[fd]) == NULL) {
-#ifdef FDESC_DIAGNOSTIC
-               printf("fdesc_setattr: fp = %x (EBADF)\n", fp);
-#endif
                return (EBADF);
        }
 
                return (EBADF);
        }
 
@@ -514,9 +497,6 @@ fdesc_setattr(ap)
                break;
        }
 
                break;
        }
 
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_setattr: returns error %d\n", error);
-#endif
        return (error);
 }
 
        return (error);
 }
 
@@ -536,6 +516,7 @@ static struct dirtmp {
        { 0 }
 };
 
        { 0 }
 };
 
+int
 fdesc_readdir(ap)
        struct vop_readdir_args /* {
                struct vnode *a_vp;
 fdesc_readdir(ap)
        struct vop_readdir_args /* {
                struct vnode *a_vp;
@@ -609,19 +590,16 @@ fdesc_readdir(ap)
        i = uio->uio_offset / UIO_MX;
        error = 0;
        while (uio->uio_resid > 0) {
        i = uio->uio_offset / UIO_MX;
        error = 0;
        while (uio->uio_resid > 0) {
-               if (i >= fdp->fd_nfiles) {
-                       /* *ap->a_eofflagp = 1; */
+               if (i >= fdp->fd_nfiles)
                        break;
                        break;
-               }
+
                if (fdp->fd_ofiles[i] != NULL) {
                        struct dirent d;
                        struct dirent *dp = &d;
                if (fdp->fd_ofiles[i] != NULL) {
                        struct dirent d;
                        struct dirent *dp = &d;
+
                        bzero((caddr_t) dp, UIO_MX);
 
                        dp->d_namlen = sprintf(dp->d_name, "%d", i);
                        bzero((caddr_t) dp, UIO_MX);
 
                        dp->d_namlen = sprintf(dp->d_name, "%d", i);
-                       /*
-                        * Fill in the remaining fields
-                        */
                        dp->d_reclen = UIO_MX;
                        dp->d_type = DT_UNKNOWN;
                        dp->d_fileno = i + FD_STDIN;
                        dp->d_reclen = UIO_MX;
                        dp->d_type = DT_UNKNOWN;
                        dp->d_fileno = i + FD_STDIN;
@@ -647,7 +625,7 @@ fdesc_readlink(ap)
                struct ucred *a_cred;
        } */ *ap;
 {
                struct ucred *a_cred;
        } */ *ap;
 {
-       register struct vnode *vp = ap->a_vp;
+       struct vnode *vp = ap->a_vp;
        int error;
 
        if (vp->v_type != VLNK)
        int error;
 
        if (vp->v_type != VLNK)
@@ -663,6 +641,7 @@ fdesc_readlink(ap)
        return (error);
 }
 
        return (error);
 }
 
+int
 fdesc_read(ap)
        struct vop_read_args /* {
                struct vnode *a_vp;
 fdesc_read(ap)
        struct vop_read_args /* {
                struct vnode *a_vp;
@@ -686,6 +665,7 @@ fdesc_read(ap)
        return (error);
 }
 
        return (error);
 }
 
+int
 fdesc_write(ap)
        struct vop_write_args /* {
                struct vnode *a_vp;
 fdesc_write(ap)
        struct vop_write_args /* {
                struct vnode *a_vp;
@@ -709,6 +689,7 @@ fdesc_write(ap)
        return (error);
 }
 
        return (error);
 }
 
+int
 fdesc_ioctl(ap)
        struct vop_ioctl_args /* {
                struct vnode *a_vp;
 fdesc_ioctl(ap)
        struct vop_ioctl_args /* {
                struct vnode *a_vp;
@@ -721,10 +702,6 @@ fdesc_ioctl(ap)
 {
        int error = EOPNOTSUPP;
 
 {
        int error = EOPNOTSUPP;
 
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_ioctl: type = %d, command = %x\n",
-                       VTOFDESC(ap->a_vp)->fd_type, ap->a_command);
-#endif
        switch (VTOFDESC(ap->a_vp)->fd_type) {
        case Fctty:
                error = cttyioctl(devctty, ap->a_command, ap->a_data,
        switch (VTOFDESC(ap->a_vp)->fd_type) {
        case Fctty:
                error = cttyioctl(devctty, ap->a_command, ap->a_data,
@@ -739,6 +716,7 @@ fdesc_ioctl(ap)
        return (error);
 }
 
        return (error);
 }
 
+int
 fdesc_select(ap)
        struct vop_select_args /* {
                struct vnode *a_vp;
 fdesc_select(ap)
        struct vop_select_args /* {
                struct vnode *a_vp;
@@ -763,6 +741,7 @@ fdesc_select(ap)
        return (error);
 }
 
        return (error);
 }
 
+int
 fdesc_inactive(ap)
        struct vop_inactive_args /* {
                struct vnode *a_vp;
 fdesc_inactive(ap)
        struct vop_inactive_args /* {
                struct vnode *a_vp;
@@ -775,33 +754,21 @@ fdesc_inactive(ap)
         * nasty things happening in vgone().
         */
        vp->v_type = VNON;
         * nasty things happening in vgone().
         */
        vp->v_type = VNON;
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_inactive(%x)\n", vp);
-#endif
        return (0);
 }
 
        return (0);
 }
 
+int
 fdesc_reclaim(ap)
        struct vop_reclaim_args /* {
                struct vnode *a_vp;
        } */ *ap;
 {
        struct vnode *vp = ap->a_vp;
 fdesc_reclaim(ap)
        struct vop_reclaim_args /* {
                struct vnode *a_vp;
        } */ *ap;
 {
        struct vnode *vp = ap->a_vp;
-       int ix;
 
 
-#ifdef FDESC_DIAGNOSTIC
-       printf("fdesc_reclaim(%x)\n", vp);
-#endif
-       ix = VTOFDESC(vp)->fd_ix;
-       if (ix >= 0 && ix < FD_MAX) {
-               if (fdescvp[ix] != vp)
-                       panic("fdesc_reclaim");
-               fdescvp[ix] = 0;
-       }
-       if (vp->v_data) {
-               FREE(vp->v_data, M_TEMP);
-               vp->v_data = 0;
-       }
+       remque(VTOFDESC(vp));
+       FREE(vp->v_data, M_TEMP);
+       vp->v_data = 0;
+
        return (0);
 }
 
        return (0);
 }
 
@@ -809,6 +776,7 @@ fdesc_reclaim(ap)
  * Print out the contents of a /dev/fd vnode.
  */
 /* ARGSUSED */
  * Print out the contents of a /dev/fd vnode.
  */
 /* ARGSUSED */
+int
 fdesc_print(ap)
        struct vop_print_args /* {
                struct vnode *a_vp;
 fdesc_print(ap)
        struct vop_print_args /* {
                struct vnode *a_vp;
@@ -820,6 +788,7 @@ fdesc_print(ap)
 }
 
 /*void*/
 }
 
 /*void*/
+int
 fdesc_vfree(ap)
        struct vop_vfree_args /* {
                struct vnode *a_pvp;
 fdesc_vfree(ap)
        struct vop_vfree_args /* {
                struct vnode *a_pvp;
@@ -834,6 +803,7 @@ fdesc_vfree(ap)
 /*
  * /dev/fd vnode unsupported operation
  */
 /*
  * /dev/fd vnode unsupported operation
  */
+int
 fdesc_enotsupp()
 {
 
 fdesc_enotsupp()
 {
 
@@ -843,6 +813,7 @@ fdesc_enotsupp()
 /*
  * /dev/fd "should never get here" operation
  */
 /*
  * /dev/fd "should never get here" operation
  */
+int
 fdesc_badop()
 {
 
 fdesc_badop()
 {
 
@@ -853,6 +824,7 @@ fdesc_badop()
 /*
  * /dev/fd vnode null operation
  */
 /*
  * /dev/fd vnode null operation
  */
+int
 fdesc_nullop()
 {
 
 fdesc_nullop()
 {