From b4c0c39b6e51cd4882757285e80ffdc32bf53e00 Mon Sep 17 00:00:00 2001 From: phk Date: Sun, 13 Jun 1999 20:53:16 +0000 Subject: Eliminate the bogus procfs private almost struct dirent structure. Spotted by: Lars Hamren Reviewed by: bde --- sys/fs/procfs/procfs.h | 16 ++------------- sys/fs/procfs/procfs_vfsops.c | 7 +------ sys/fs/procfs/procfs_vnops.c | 47 ++++++++++++++++++++++--------------------- 3 files changed, 27 insertions(+), 43 deletions(-) (limited to 'sys/fs') diff --git a/sys/fs/procfs/procfs.h b/sys/fs/procfs/procfs.h index b758d06..b38ed87 100644 --- a/sys/fs/procfs/procfs.h +++ b/sys/fs/procfs/procfs.h @@ -37,7 +37,7 @@ * @(#)procfs.h 8.9 (Berkeley) 5/14/95 * * From: - * $Id: procfs.h,v 1.24 1999/04/30 13:04:20 phk Exp $ + * $Id: procfs.h,v 1.25 1999/05/04 08:00:10 phk Exp $ */ /* @@ -77,6 +77,7 @@ struct pfsnode { #define PROCFS_NOTELEN 64 /* max length of a note (/proc/$pid/note) */ #define PROCFS_CTLLEN 8 /* max length of a ctl msg (/proc/$pid/ctl */ +#define PROCFS_NAMELEN 8 /* max length of a filename component */ /* * Kernel stuff follows @@ -100,19 +101,6 @@ struct pfsnode { ((p2)->p_flag & P_SUGID) == 0) || \ (suser_xxx(0, (p1), PRISON_ROOT) == 0))) -/* - * Format of a directory entry in /proc, ... - * This must map onto struct dirent (see ) - */ -#define PROCFS_NAMELEN 8 -struct pfsdent { - u_int32_t d_fileno; - u_int16_t d_reclen; - u_int8_t d_type; - u_int8_t d_namlen; - char d_name[PROCFS_NAMELEN]; -}; -#define UIO_MX sizeof(struct pfsdent) #define PROCFS_FILENO(pid, type) \ (((type) < Pproc) ? \ ((type) + 2) : \ diff --git a/sys/fs/procfs/procfs_vfsops.c b/sys/fs/procfs/procfs_vfsops.c index ac1ab53..2c22020 100644 --- a/sys/fs/procfs/procfs_vfsops.c +++ b/sys/fs/procfs/procfs_vfsops.c @@ -36,7 +36,7 @@ * * @(#)procfs_vfsops.c 8.7 (Berkeley) 5/10/95 * - * $Id: procfs_vfsops.c,v 1.25 1998/07/27 22:47:17 alex Exp $ + * $Id: procfs_vfsops.c,v 1.26 1998/09/07 13:17:01 bde Exp $ */ /* @@ -78,11 +78,6 @@ procfs_mount(mp, path, data, ndp, p) size_t size; int error; - if (UIO_MX & (UIO_MX-1)) { - log(LOG_ERR, "procfs: invalid directory entry size\n"); - return (EINVAL); - } - if (mp->mnt_flag & MNT_UPDATE) return (EOPNOTSUPP); diff --git a/sys/fs/procfs/procfs_vnops.c b/sys/fs/procfs/procfs_vnops.c index d6f2185..d421bac 100644 --- a/sys/fs/procfs/procfs_vnops.c +++ b/sys/fs/procfs/procfs_vnops.c @@ -36,7 +36,7 @@ * * @(#)procfs_vnops.c 8.18 (Berkeley) 5/21/95 * - * $Id: procfs_vnops.c,v 1.67 1999/04/30 13:04:21 phk Exp $ + * $Id: procfs_vnops.c,v 1.68 1999/05/04 08:01:55 phk Exp $ */ /* @@ -784,16 +784,10 @@ procfs_validfile(p) } /* - * readdir returns directory entries from pfsnode (vp). + * readdir() returns directory entries from pfsnode (vp). * - * the strategy here with procfs is to generate a single - * directory entry at a time (struct pfsdent) and then - * copy that out to userland using uiomove. a more efficent - * though more complex implementation, would try to minimize - * the number of calls to uiomove(). for procfs, this is - * hardly worth the added code complexity. - * - * this should just be done through read() + * We generate just one directory entry at a time, as it would probably + * not pay off to buffer several entries locally to save uiomove calls. */ static int procfs_readdir(ap) @@ -807,21 +801,28 @@ procfs_readdir(ap) } */ *ap; { struct uio *uio = ap->a_uio; - struct pfsdent d; - struct pfsdent *dp = &d; + struct dirent d; + struct dirent *dp = &d; struct pfsnode *pfs; int count, error, i, off; + static u_int delen; + + if (!delen) { + + d.d_namlen = PROCFS_NAMELEN; + delen = GENERIC_DIRSIZ(&d); + } pfs = VTOPFS(ap->a_vp); off = (int)uio->uio_offset; - if (off != uio->uio_offset || off < 0 || (u_int)off % UIO_MX != 0 || - uio->uio_resid < UIO_MX) + if (off != uio->uio_offset || off < 0 || + off % delen != 0 || uio->uio_resid < delen) return (EINVAL); error = 0; count = 0; - i = (u_int)off / UIO_MX; + i = off / delen; switch (pfs->pfs_type) { /* @@ -840,17 +841,17 @@ procfs_readdir(ap) break; for (pt = &proc_targets[i]; - uio->uio_resid >= UIO_MX && i < nproc_targets; pt++, i++) { + uio->uio_resid >= delen && i < nproc_targets; pt++, i++) { if (pt->pt_valid && (*pt->pt_valid)(p) == 0) continue; - dp->d_reclen = UIO_MX; + dp->d_reclen = delen; dp->d_fileno = PROCFS_FILENO(pfs->pfs_pid, pt->pt_pfstype); dp->d_namlen = pt->pt_namlen; bcopy(pt->pt_name, dp->d_name, pt->pt_namlen + 1); dp->d_type = pt->pt_type; - if ((error = uiomove((caddr_t)dp, UIO_MX, uio)) != 0) + if ((error = uiomove((caddr_t)dp, delen, uio)) != 0) break; } @@ -873,9 +874,9 @@ procfs_readdir(ap) int pcnt = 0; volatile struct proc *p = allproc.lh_first; - for (; p && uio->uio_resid >= UIO_MX; i++, pcnt++) { - bzero((char *) dp, UIO_MX); - dp->d_reclen = UIO_MX; + for (; p && uio->uio_resid >= delen; i++, pcnt++) { + bzero((char *) dp, delen); + dp->d_reclen = delen; switch (i) { case 0: /* `.' */ @@ -916,7 +917,7 @@ procfs_readdir(ap) break; } - if ((error = uiomove((caddr_t)dp, UIO_MX, uio)) != 0) + if ((error = uiomove((caddr_t)dp, delen, uio)) != 0) break; } done: @@ -938,7 +939,7 @@ procfs_readdir(ap) break; } - uio->uio_offset = i * UIO_MX; + uio->uio_offset = i * delen; return (error); } -- cgit v1.1