Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/miscfs/procfs use fd_getfile() in procfs_getfp(), and FI...



details:   https://anonhg.NetBSD.org/src/rev/2d447956b1a1
branches:  trunk
changeset: 545910:2d447956b1a1
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Thu Apr 17 19:04:25 2003 +0000

description:
use fd_getfile() in procfs_getfp(), and FILE_USE()/FILE_UNUSE() the
returned file descriptor pointer appropriately

diffstat:

 sys/miscfs/procfs/procfs.h       |   4 ++--
 sys/miscfs/procfs/procfs_fd.c    |  18 +++++++++++++-----
 sys/miscfs/procfs/procfs_subr.c  |  17 ++++++++++++-----
 sys/miscfs/procfs/procfs_vnops.c |  10 +++++++---
 4 files changed, 34 insertions(+), 15 deletions(-)

diffs (178 lines):

diff -r fba2f09cc8b5 -r 2d447956b1a1 sys/miscfs/procfs/procfs.h
--- a/sys/miscfs/procfs/procfs.h        Thu Apr 17 18:51:23 2003 +0000
+++ b/sys/miscfs/procfs/procfs.h        Thu Apr 17 19:04:25 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs.h,v 1.41 2003/02/25 21:00:31 jrf Exp $  */
+/*     $NetBSD: procfs.h,v 1.42 2003/04/17 19:04:25 jdolecek Exp $     */
 
 /*
  * Copyright (c) 1993 Jan-Simon Pendry
@@ -168,7 +168,7 @@
 void procfs_hashinit __P((void));
 void procfs_hashreinit __P((void));
 void procfs_hashdone __P((void));
-int procfs_getfp __P((struct pfsnode *, struct file **));
+int procfs_getfp __P((struct pfsnode *, struct proc **, struct file **));
 
 /* functions to check whether or not files should be displayed */
 int procfs_validfile __P((struct proc *, struct mount *));
diff -r fba2f09cc8b5 -r 2d447956b1a1 sys/miscfs/procfs/procfs_fd.c
--- a/sys/miscfs/procfs/procfs_fd.c     Thu Apr 17 18:51:23 2003 +0000
+++ b/sys/miscfs/procfs/procfs_fd.c     Thu Apr 17 19:04:25 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_fd.c,v 1.1 2003/01/03 13:21:18 christos Exp $   */
+/*     $NetBSD: procfs_fd.c,v 1.2 2003/04/17 19:04:25 jdolecek Exp $   */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_fd.c,v 1.1 2003/01/03 13:21:18 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_fd.c,v 1.2 2003/04/17 19:04:25 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -45,6 +45,7 @@
 #include <sys/proc.h>
 #include <sys/vnode.h>
 #include <sys/file.h>
+#include <sys/filedesc.h>
 #include <miscfs/procfs/procfs.h>
 
 int
@@ -56,19 +57,26 @@
 {
        int error;
        struct file *fp;
+       struct proc *pown;
        off_t offs;
 
-       if ((error = procfs_getfp(pfs, &fp)) != 0)
+       if ((error = procfs_getfp(pfs, &pown, &fp)) != 0)
                return error;
 
+       FILE_USE(fp);
+
        offs = fp->f_offset;
 
        switch (uio->uio_rw) {
        case UIO_READ:
-               return (*fp->f_ops->fo_read)(fp, &offs, uio, curp->p_ucred, 0);
+               error = (*fp->f_ops->fo_read)(fp, &offs, uio, curp->p_ucred, 0);
        case UIO_WRITE:
-               return (*fp->f_ops->fo_write)(fp, &offs, uio, curp->p_ucred, 0);
+               error = (*fp->f_ops->fo_write)(fp, &offs, uio, curp->p_ucred,0);
        default:
                panic("bad uio op");
        }
+
+       FILE_UNUSE(fp, pown);
+
+       return (error);
 }
diff -r fba2f09cc8b5 -r 2d447956b1a1 sys/miscfs/procfs/procfs_subr.c
--- a/sys/miscfs/procfs/procfs_subr.c   Thu Apr 17 18:51:23 2003 +0000
+++ b/sys/miscfs/procfs/procfs_subr.c   Thu Apr 17 19:04:25 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_subr.c,v 1.48 2003/03/15 00:22:47 enami Exp $   */
+/*     $NetBSD: procfs_subr.c,v 1.49 2003/04/17 19:04:25 jdolecek Exp $        */
 
 /*
  * Copyright (c) 1994 Christopher G. Demetriou.  All rights reserved.
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.48 2003/03/15 00:22:47 enami Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.49 2003/04/17 19:04:25 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -150,10 +150,12 @@
                } else {        /* /proc/N/fd/M = [ps-]rw------- */
                        struct file *fp;
                        struct vnode *vxp;
+                       struct proc *pown;
 
                        /* XXX can procfs_getfp() ever fail here? */
-                       if ((error = procfs_getfp(pfs, &fp)) != 0)
+                       if ((error = procfs_getfp(pfs, &pown, &fp)) != 0)
                                goto bad;
+                       FILE_USE(fp);
 
                        pfs->pfs_mode = S_IRUSR|S_IWUSR;
                        switch (fp->f_type) {
@@ -169,8 +171,10 @@
                                break;
                        default:
                                error = EOPNOTSUPP;
+                               FILE_UNUSE(fp, pown);
                                goto bad;
                        }
+                       FILE_UNUSE(fp, pown);
                }
                break;
 
@@ -522,8 +526,9 @@
 }
 
 int
-procfs_getfp(pfs, fp)
+procfs_getfp(pfs, pown, fp)
        struct pfsnode *pfs;
+       struct proc **pown;
        struct file **fp;
 {
        struct proc *p = PFIND(pfs->pfs_pid);
@@ -534,7 +539,9 @@
        if (pfs->pfs_fd == -1)
                return EINVAL;
 
-       if ((*fp = p->p_fd->fd_ofiles[pfs->pfs_fd]) == NULL)
+       if ((*fp = fd_getfile(p->p_fd, pfs->pfs_fd)) == NULL)
                return EBADF;
+
+       *pown = p;
        return 0;
 }
diff -r fba2f09cc8b5 -r 2d447956b1a1 sys/miscfs/procfs/procfs_vnops.c
--- a/sys/miscfs/procfs/procfs_vnops.c  Thu Apr 17 18:51:23 2003 +0000
+++ b/sys/miscfs/procfs/procfs_vnops.c  Thu Apr 17 19:04:25 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_vnops.c,v 1.97 2003/04/17 18:08:28 jdolecek Exp $       */
+/*     $NetBSD: procfs_vnops.c,v 1.98 2003/04/17 19:04:25 jdolecek Exp $       */
 
 /*
  * Copyright (c) 1993 Jan-Simon Pendry
@@ -44,7 +44,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.97 2003/04/17 18:08:28 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.98 2003/04/17 19:04:25 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -593,8 +593,11 @@
        case Pfd:
                if (pfs->pfs_fd != -1) {
                        struct file *fp;
-                       if ((error = procfs_getfp(pfs, &fp)) != 0)
+                       struct proc *pown;
+
+                       if ((error = procfs_getfp(pfs, &pown, &fp)) != 0)
                                return error;
+                       FILE_USE(fp);
                        vap->va_nlink = 1;
                        vap->va_uid = fp->f_cred->cr_uid;
                        vap->va_gid = fp->f_cred->cr_gid;
@@ -607,6 +610,7 @@
                                vap->va_bytes = vap->va_size = 0;
                                break;
                        }
+                       FILE_UNUSE(fp, pown);
                        break;
                }
                /*FALLTHROUGH*/



Home | Main Index | Thread Index | Old Index