svn commit: r195720 - projects/libprocstat/usr.bin/fstat

Stanislav Sedov stas at FreeBSD.org
Thu Jul 16 15:39:55 UTC 2009


Author: stas
Date: Thu Jul 16 15:39:54 2009
New Revision: 195720
URL: http://svn.freebsd.org/changeset/base/195720

Log:
  - Cleanup.

Added:
  projects/libprocstat/usr.bin/fstat/common_kvm.c
     - copied, changed from r195718, projects/libprocstat/usr.bin/fstat/common.c
  projects/libprocstat/usr.bin/fstat/common_kvm.h
     - copied, changed from r195718, projects/libprocstat/usr.bin/fstat/common.h
Deleted:
  projects/libprocstat/usr.bin/fstat/common.c
  projects/libprocstat/usr.bin/fstat/common.h
Modified:
  projects/libprocstat/usr.bin/fstat/Makefile
  projects/libprocstat/usr.bin/fstat/cd9660.c
  projects/libprocstat/usr.bin/fstat/fstat.c
  projects/libprocstat/usr.bin/fstat/libprocstat.c
  projects/libprocstat/usr.bin/fstat/libprocstat.h
  projects/libprocstat/usr.bin/fstat/main.c
  projects/libprocstat/usr.bin/fstat/msdosfs.c
  projects/libprocstat/usr.bin/fstat/zfs.c

Modified: projects/libprocstat/usr.bin/fstat/Makefile
==============================================================================
--- projects/libprocstat/usr.bin/fstat/Makefile	Thu Jul 16 14:24:06 2009	(r195719)
+++ projects/libprocstat/usr.bin/fstat/Makefile	Thu Jul 16 15:39:54 2009	(r195720)
@@ -4,7 +4,7 @@
 .include <bsd.own.mk>
 
 PROG=	fstat
-SRCS=	common.c fstat.c main.c libprocstat.c cd9660.c msdosfs.c
+SRCS=	cd9660.c common_kvm.c fstat.c libprocstat.c main.c msdosfs.c
 LINKS=	${BINDIR}/fstat ${BINDIR}/fuser
 DPADD=	${LIBKVM}
 LDADD=	-lkvm -lutil

Modified: projects/libprocstat/usr.bin/fstat/cd9660.c
==============================================================================
--- projects/libprocstat/usr.bin/fstat/cd9660.c	Thu Jul 16 14:24:06 2009	(r195719)
+++ projects/libprocstat/usr.bin/fstat/cd9660.c	Thu Jul 16 15:39:54 2009	(r195720)
@@ -59,7 +59,7 @@ __FBSDID("$FreeBSD$");
 #include <kvm.h>
 #include <stdio.h>
 
-#include "common.h"
+#include "common_kvm.h"
 
 int
 isofs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn)

Copied and modified: projects/libprocstat/usr.bin/fstat/common_kvm.c (from r195718, projects/libprocstat/usr.bin/fstat/common.c)
==============================================================================
--- projects/libprocstat/usr.bin/fstat/common.c	Thu Jul 16 13:26:03 2009	(r195718, copy source)
+++ projects/libprocstat/usr.bin/fstat/common_kvm.c	Thu Jul 16 15:39:54 2009	(r195720)
@@ -1,4 +1,5 @@
 /*-
+ * Copyright (c) 2009 Stanislav Sedov <stas at FreeBSD.org>
  * Copyright (c) 1988, 1993
  *	The Regents of the University of California.  All rights reserved.
  *
@@ -35,23 +36,9 @@
 __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
-#include <sys/time.h>
-#include <sys/proc.h>
 #include <sys/user.h>
 #include <sys/stat.h>
 #include <sys/vnode.h>
-#include <sys/socket.h>
-#include <sys/socketvar.h>
-#include <sys/domain.h>
-#include <sys/protosw.h>
-#include <sys/un.h>
-#include <sys/unpcb.h>
-#include <sys/sysctl.h>
-#include <sys/tty.h>
-#include <sys/filedesc.h>
-#include <sys/queue.h>
-#define	_WANT_FILE
-#include <sys/file.h>
 #include <sys/conf.h>
 #define	_KERNEL
 #include <sys/pipe.h>
@@ -65,48 +52,13 @@ __FBSDID("$FreeBSD$");
 #include <nfsclient/nfs.h>
 #include <nfsclient/nfsnode.h>
 
-
-#include <vm/vm.h>
-#include <vm/vm_map.h>
-#include <vm/vm_object.h>
-
-#include <net/route.h>
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <netinet/in_pcb.h>
-
 #include <assert.h>
-#include <ctype.h>
 #include <err.h>
-#include <fcntl.h>
 #include <kvm.h>
-#include <limits.h>
-#include <nlist.h>
-#include <paths.h>
-#include <pwd.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
 #include <stddef.h>
 #include <string.h>
-#include <unistd.h>
-#include <netdb.h>
-
-#include "common.h"
-
-int vflg = 0;
 
-void
-dprintf(FILE *file, const char *fmt, ...) {
-	va_list ap;
-
-	if (vflg != 0) {
-		va_start(ap, fmt);
-		vfprintf(file, fmt, ap);
-		va_end(ap);
-	}
-}
+#include "common_kvm.h"
 
 int
 kvm_read_all(kvm_t *kd, unsigned long addr, void *buf, size_t nbytes)
@@ -236,8 +188,8 @@ dev2udev(kvm_t *kd, struct cdev *dev)
 	    sizeof(priv))) {
 		return ((dev_t)priv.cdp_inode);
 	} else {
-		dprintf(stderr, "can't convert cdev *%p to a dev_t\n", dev);
-		return -1;
+		warnx("can't convert cdev *%p to a dev_t\n", dev);
+		return (-1);
 	}
 }
 

Copied and modified: projects/libprocstat/usr.bin/fstat/common_kvm.h (from r195718, projects/libprocstat/usr.bin/fstat/common.h)
==============================================================================
--- projects/libprocstat/usr.bin/fstat/common.h	Thu Jul 16 13:26:03 2009	(r195718, copy source)
+++ projects/libprocstat/usr.bin/fstat/common_kvm.h	Thu Jul 16 15:39:54 2009	(r195720)
@@ -1,6 +1,6 @@
 /*-
- * Copyright (c) 1988, 1993
- *	The Regents of the University of California.  All rights reserved.
+ * Copyright (c) 2009 Stanislav Sedov <stas at FreeBSD.org>
+ * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -10,13 +10,6 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -33,8 +26,8 @@
  * $FreeBSD$
  */
 
-#ifndef	__COMMON_H__
-#define	__COMMON_H__
+#ifndef	__COMMON_KVM_H__
+#define	__COMMON_KVM_H__
 
 struct filestat {
 	int	fs_type;	/* Descriptor type. */
@@ -82,10 +75,7 @@ struct sockstat {
 
 STAILQ_HEAD(filestat_list, filestat);
 
-extern int vflg;
-
 dev_t	dev2udev(kvm_t *kd, struct cdev *dev);
-void	dprintf(FILE *file, const char *fmt, ...);
 int	kdevtoname(kvm_t *kd, struct cdev *dev, char *);
 int	kvm_read_all(kvm_t *kd, unsigned long addr, void *buf,
     size_t nbytes);
@@ -104,4 +94,4 @@ void	*getvnodedata(struct vnode *vp);
 struct mount	*getvnodemount(struct vnode *vp);
 #endif
 
-#endif /* __COMMON_H__ */
+#endif	/* __COMMON_KVM_H__ */

Modified: projects/libprocstat/usr.bin/fstat/fstat.c
==============================================================================
--- projects/libprocstat/usr.bin/fstat/fstat.c	Thu Jul 16 14:24:06 2009	(r195719)
+++ projects/libprocstat/usr.bin/fstat/fstat.c	Thu Jul 16 15:39:54 2009	(r195720)
@@ -1,4 +1,5 @@
 /*-
+ * Copyright (c) 2009 Stanislav Sedov <stas at FreeBSD.org>
  * Copyright (c) 1988, 1993
  *	The Regents of the University of California.  All rights reserved.
  *
@@ -31,17 +32,6 @@
  * SUCH DAMAGE.
  */
 
-#ifndef lint
-static const char copyright[] =
-"@(#) Copyright (c) 1988, 1993\n\
-	The Regents of the University of California.  All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)fstat.c	8.3 (Berkeley) 5/2/95";
-#endif
-#endif /* not lint */
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
@@ -103,7 +93,7 @@ __FBSDID("$FreeBSD$");
 #include <unistd.h>
 #include <netdb.h>
 
-#include "common.h"
+#include "common_kvm.h"
 #include "functions.h"
 #include "libprocstat.h"
 
@@ -113,6 +103,7 @@ int 	fsflg,	/* show files on same filesy
 int 	checkfile; /* true if restricting to particular files or filesystems */
 int	nflg;	/* (numerical) display f.s. and rdev as dev_t */
 int	mflg;	/* include memory-mapped files */
+int	vflg;	/* be verbose */
 
 typedef struct devs {
 	struct devs	*next;
@@ -366,9 +357,10 @@ print_file_info(struct procstat *procsta
 		print_pts_info(procstat, fst);
 		break;
 	default:	
-		dprintf(stderr,
-		    "unknown file type %d for file %d of pid %d\n",
-		    fst->fs_type, fst->fs_fd, pid);
+		if (vflg)
+			fprintf(stderr,
+			    "unknown file type %d for file %d of pid %d\n",
+			    fst->fs_type, fst->fs_fd, pid);
 	}
 	if (filename && !fsflg)
 		printf("  %s", filename);

Modified: projects/libprocstat/usr.bin/fstat/libprocstat.c
==============================================================================
--- projects/libprocstat/usr.bin/fstat/libprocstat.c	Thu Jul 16 14:24:06 2009	(r195719)
+++ projects/libprocstat/usr.bin/fstat/libprocstat.c	Thu Jul 16 15:39:54 2009	(r195720)
@@ -1,3 +1,37 @@
+/*-
+ * Copyright (c) 2009 Stanislav Sedov <stas at FreeBSD.org>
+ * Copyright (c) 1988, 1993
+ *      The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by the University of
+ *      California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
@@ -32,7 +66,6 @@ __FBSDID("$FreeBSD$");
 #include <nfsclient/nfs.h>
 #include <nfsclient/nfsnode.h>
 
-
 #include <vm/vm.h>
 #include <vm/vm_map.h>
 #include <vm/vm_object.h>
@@ -59,9 +92,12 @@ __FBSDID("$FreeBSD$");
 #include <unistd.h>
 #include <netdb.h>
 
-#include "common.h"
+#include "common_kvm.h"
 #include "libprocstat.h"
 
+/*
+ * Vnode-to-filestat types translation table.
+ */
 static struct {
         int     vtype; 
         int     fst_vtype;
@@ -78,6 +114,9 @@ static struct {
 };
 #define NVFTYPES (sizeof(vt2fst) / sizeof(*vt2fst))
 
+/*
+ * Descriptor-to-filestat flags translation table.
+ */
 static struct {
 	int flag;
 	int fst_flag;
@@ -97,28 +136,6 @@ static struct {
 };
 #define NFSTFLAGS	(sizeof(fstflags) / sizeof(*fstflags))
 
-char	*getmnton(kvm_t *kd, struct mount *m);
-void	socktrans(kvm_t *kd, struct socket *sock, int fd, int flags,
-    struct filestat *fst);
-int	procstat_get_vnode_info_kvm(kvm_t *kd, struct filestat *fst,
-    struct vnstat *vn, char *errbuf);
-int	procstat_get_vnode_info_sysctl(struct filestat *fst, struct vnstat *vn,
-    char *errbuf);
-int	procstat_get_pipe_info_sysctl(struct filestat *fst,
-    struct pipestat *pipe, char *errbuf);
-int	procstat_get_pipe_info_kvm(kvm_t *kd, struct filestat *fst,
-    struct pipestat *pipe, char *errbuf);
-int	procstat_get_pts_info_sysctl(struct filestat *fst, struct ptsstat *pts,
-    char *errbuf);
-int	procstat_get_pts_info_kvm(kvm_t *kd, struct filestat *fst,
-    struct ptsstat *pts, char *errbuf);
-int	procstat_get_socket_info_sysctl(struct filestat *fst, struct sockstat *sock,
-    char *errbuf);
-int	procstat_get_socket_info_kvm(kvm_t *kd, struct filestat *fst,
-    struct sockstat *sock, char *errbuf);
-static int	to_filestat_flags(int flags);
-
-
 /*
  * Filesystem specific handlers.
  */
@@ -145,8 +162,32 @@ struct {
 };
 #define NTYPES  (sizeof(fstypes) / sizeof(*fstypes))
 
-#define	PROCSTAT_KVM 1
-#define	PROCSTAT_SYSCTL 2
+#define	PROCSTAT_KVM	1
+#define	PROCSTAT_SYSCTL	2
+
+static char	*getmnton(kvm_t *kd, struct mount *m);
+static struct filestat_list	*procstat_getfiles_kvm(kvm_t *kd,
+    struct kinfo_proc *kp);
+static struct filestat_list	*procstat_getfiles_sysctl(
+    struct kinfo_proc *kp);
+static int	procstat_get_pipe_info_sysctl(struct filestat *fst,
+    struct pipestat *pipe, char *errbuf);
+static int	procstat_get_pipe_info_kvm(kvm_t *kd, struct filestat *fst,
+    struct pipestat *pipe, char *errbuf);
+static int	procstat_get_pts_info_sysctl(struct filestat *fst,
+    struct ptsstat *pts, char *errbuf);
+static int	procstat_get_pts_info_kvm(kvm_t *kd, struct filestat *fst,
+    struct ptsstat *pts, char *errbuf);
+static int	procstat_get_socket_info_sysctl(struct filestat *fst,
+    struct sockstat *sock, char *errbuf);
+static int	procstat_get_socket_info_kvm(kvm_t *kd, struct filestat *fst,
+    struct sockstat *sock, char *errbuf);
+static int	to_filestat_flags(int flags);
+static int	procstat_get_vnode_info_kvm(kvm_t *kd, struct filestat *fst,
+    struct vnstat *vn, char *errbuf);
+static int	procstat_get_vnode_info_sysctl(struct filestat *fst,
+    struct vnstat *vn, char *errbuf);
+static int	vntype2psfsttype(int type);
 
 void
 procstat_close(struct procstat *procstat)
@@ -279,7 +320,7 @@ filestat_new_entry(struct vnode *vp, int
 	return (entry);
 }
 
-struct filestat_list *
+static struct filestat_list *
 procstat_getfiles_kvm(kvm_t *kd, struct kinfo_proc *kp)
 {
 	int i;
@@ -406,68 +447,12 @@ exit:
 	return (head);
 }
 
-static int
-to_filestat_flags(int flags)
-{
-	int fst_flags;
-	unsigned int i;
-
-	fst_flags = 0;
-	for (i = 0; i < NFSTFLAGS; i++)
-		if (flags & fstflags[i].flag)
-			fst_flags |= fstflags[i].fst_flag;
-	return (fst_flags);
-}
-
-struct filestat_list *
+static struct filestat_list *
 procstat_getfiles_sysctl(struct kinfo_proc *kp __unused)
 {
 	return (NULL);
 }
 
-static int
-vntype2psfsttype(int type)
-{
-	unsigned int i, fst_type;
-
-	fst_type = PS_FST_VTYPE_UNKNOWN;
-	for (i = 0; i < NVFTYPES; i++) {
-		if (type == vt2fst[i].vtype) {
-			fst_type = vt2fst[i].fst_vtype;
-			break;
-		}
-	}
-	return (fst_type);
-}
-
-char *
-getmnton(kvm_t *kd, struct mount *m)
-{
-	static struct mount mnt;
-	static struct mtab {
-		struct mtab *next;
-		struct mount *m;
-		char mntonname[MNAMELEN + 1];
-	} *mhead = NULL;
-	struct mtab *mt;
-
-	for (mt = mhead; mt != NULL; mt = mt->next)
-		if (m == mt->m)
-			return (mt->mntonname);
-	if (!kvm_read_all(kd, (unsigned long)m, &mnt, sizeof(struct mount))) {
-		warnx("can't read mount table at %p", (void *)m);
-		return (NULL);
-	}
-	if ((mt = malloc(sizeof (struct mtab))) == NULL)
-		err(1, NULL);
-	mt->m = m;
-	bcopy(&mnt.mnt_stat.f_mntonname[0], &mt->mntonname[0], MNAMELEN);
-	mnt.mnt_stat.f_mntonname[MNAMELEN] = '\0';
-	mt->next = mhead;
-	mhead = mt;
-	return (mt->mntonname);
-}
-
 int
 procstat_get_pipe_info(struct procstat *procstat, struct filestat *fst,
     struct pipestat *pipe, char *errbuf)
@@ -485,7 +470,8 @@ procstat_get_pipe_info(struct procstat *
 		return (1);
 	}
 }
-int
+
+static int
 procstat_get_pipe_info_kvm(kvm_t *kd, struct filestat *fst,
     struct pipestat *pipe, char *errbuf)
 {
@@ -513,7 +499,7 @@ fail:
 	return (1);
 }
 
-int
+static int
 procstat_get_pipe_info_sysctl(struct filestat *fst, struct pipestat *pipe,
     char *errbuf)
 {
@@ -540,7 +526,8 @@ procstat_get_pts_info(struct procstat *p
 		return (1);
 	}
 }
-int
+
+static int
 procstat_get_pts_info_kvm(kvm_t *kd, struct filestat *fst,
     struct ptsstat *pts, char *errbuf)
 {
@@ -567,7 +554,7 @@ fail:
 	return (1);
 }
 
-int
+static int
 procstat_get_pts_info_sysctl(struct filestat *fst, struct ptsstat *pts,
     char *errbuf)
 {
@@ -595,7 +582,7 @@ procstat_get_vnode_info(struct procstat 
 	}
 }
 
-int
+static int
 procstat_get_vnode_info_kvm(kvm_t *kd, struct filestat *fst,
     struct vnstat *vn, char *errbuf)
 {
@@ -647,6 +634,8 @@ procstat_get_vnode_info_kvm(kvm_t *kd, s
 	    vnode.v_rdev != NULL){
 		vn->vn_dev = dev2udev(kd, vnode.v_rdev);
 		(void)kdevtoname(kd, vnode.v_rdev, vn->vn_devname);
+	} else {
+		vn->vn_dev = -1;
 	}
 	return (0);
 
@@ -655,7 +644,7 @@ fail:
 	return (1);
 }
 
-int
+static int
 procstat_get_vnode_info_sysctl(struct filestat *fst, struct vnstat *vn,
     char *errbuf)
 {
@@ -682,7 +671,8 @@ procstat_get_socket_info(struct procstat
 		return (1);
 	}
 }
-int
+
+static int
 procstat_get_socket_info_kvm(kvm_t *kd, struct filestat *fst,
     struct sockstat *sock, char *errbuf)
 {
@@ -779,7 +769,7 @@ fail:
 	return (1);
 }
 
-int
+static int
 procstat_get_socket_info_sysctl(struct filestat *fst, struct sockstat *sock,
     char *errbuf)
 {
@@ -788,3 +778,59 @@ procstat_get_socket_info_sysctl(struct f
 	snprintf(errbuf, _POSIX2_LINE_MAX, "error");
 	return (1);
 }
+
+static int
+to_filestat_flags(int flags)
+{
+	int fst_flags;
+	unsigned int i;
+
+	fst_flags = 0;
+	for (i = 0; i < NFSTFLAGS; i++)
+		if (flags & fstflags[i].flag)
+			fst_flags |= fstflags[i].fst_flag;
+	return (fst_flags);
+}
+
+static int
+vntype2psfsttype(int type)
+{
+	unsigned int i, fst_type;
+
+	fst_type = PS_FST_VTYPE_UNKNOWN;
+	for (i = 0; i < NVFTYPES; i++) {
+		if (type == vt2fst[i].vtype) {
+			fst_type = vt2fst[i].fst_vtype;
+			break;
+		}
+	}
+	return (fst_type);
+}
+
+static char *
+getmnton(kvm_t *kd, struct mount *m)
+{
+	static struct mount mnt;
+	static struct mtab {
+		struct mtab *next;
+		struct mount *m;
+		char mntonname[MNAMELEN + 1];
+	} *mhead = NULL;
+	struct mtab *mt;
+
+	for (mt = mhead; mt != NULL; mt = mt->next)
+		if (m == mt->m)
+			return (mt->mntonname);
+	if (!kvm_read_all(kd, (unsigned long)m, &mnt, sizeof(struct mount))) {
+		warnx("can't read mount table at %p", (void *)m);
+		return (NULL);
+	}
+	if ((mt = malloc(sizeof (struct mtab))) == NULL)
+		err(1, NULL);
+	mt->m = m;
+	bcopy(&mnt.mnt_stat.f_mntonname[0], &mt->mntonname[0], MNAMELEN);
+	mnt.mnt_stat.f_mntonname[MNAMELEN] = '\0';
+	mt->next = mhead;
+	mhead = mt;
+	return (mt->mntonname);
+}

Modified: projects/libprocstat/usr.bin/fstat/libprocstat.h
==============================================================================
--- projects/libprocstat/usr.bin/fstat/libprocstat.h	Thu Jul 16 14:24:06 2009	(r195719)
+++ projects/libprocstat/usr.bin/fstat/libprocstat.h	Thu Jul 16 15:39:54 2009	(r195720)
@@ -1,3 +1,37 @@
+/*-
+ * Copyright (c) 2009 Stanislav Sedov <stas at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef __LIBPROCSTAT_H__
+#define	__LIBPROCSTAT_H__
+
+/*
+ * Vnode types.
+ */
 #define	PS_FST_VTYPE_VNON	1
 #define	PS_FST_VTYPE_VREG	2
 #define	PS_FST_VTYPE_VDIR	3
@@ -9,24 +43,28 @@
 #define	PS_FST_VTYPE_VBAD	9
 #define	PS_FST_VTYPE_UNKNOWN	255
 
+/*
+ * Descriptor types.
+ */
 #define	PS_FST_TYPE_VNODE	1
 #define	PS_FST_TYPE_FIFO	2
 #define	PS_FST_TYPE_SOCKET	3
 #define	PS_FST_TYPE_PIPE	4
 #define	PS_FST_TYPE_PTS		5
 
-struct procstat {
-        int     type;
-        kvm_t   *kd;
-};
-
-#define	PS_FST_FD_RDIR -1
-#define	PS_FST_FD_CDIR -2
-#define	PS_FST_FD_JAIL -3
-#define	PS_FST_FD_TRACE -4
-#define	PS_FST_FD_TEXT -5
-#define	PS_FST_FD_MMAP -6
-
+/*
+ * Special descriptor numbers.
+ */
+#define	PS_FST_FD_RDIR		-1
+#define	PS_FST_FD_CDIR		-2
+#define	PS_FST_FD_JAIL		-3
+#define	PS_FST_FD_TRACE		-4
+#define	PS_FST_FD_TEXT		-5
+#define	PS_FST_FD_MMAP		-6
+
+/*
+ * Descriptor flags.
+ */
 #define PS_FST_FFLAG_READ	0x0001
 #define PS_FST_FFLAG_WRITE	0x0002
 #define	PS_FST_FFLAG_NONBLOCK	0x0004
@@ -40,25 +78,24 @@ struct procstat {
 #define	PS_FST_FFLAG_TRUNC	0x0400
 #define	PS_FST_FFLAG_EXCL	0x0800
 
-#define	PS_FST_FLAG_ERROR 0x01
-#define	PS_FST_FLAG_UNKNOWNFS 0x02
+struct procstat {
+        int     type;
+        kvm_t   *kd;
+};
 
 void	procstat_close(struct procstat *procstat);
-struct procstat	*procstat_open(const char *nlistf, const char *memf);
-struct kinfo_proc	*procstat_getprocs(struct procstat *procstat,
-    int what, int arg, unsigned int *count);
 struct filestat_list	*procstat_getfiles(struct procstat *procstat,
     struct kinfo_proc *kp);
-struct filestat_list	*procstat_getfiles_sysctl(struct kinfo_proc *kp);
-struct filestat_list	*procstat_getfiles_kvm(kvm_t *kd, struct kinfo_proc *kp);
-int	vtrans_kvm(kvm_t *kd, struct vnode *vp, int fd, int flags, struct filestat *fst);
-char *procstat_kdevtoname(struct procstat *procstat, struct cdev *cdev);
-dev_t procstat_dev2udev(struct procstat *procstat, struct cdev *cdev);
-int	procstat_get_vnode_info(struct procstat *procstat, struct filestat *fst,
-    struct vnstat *vn, char *errbuf);
-int	procstat_get_pts_info(struct procstat *procstat, struct filestat *fst,
-    struct ptsstat *pts, char *errbuf);
+struct kinfo_proc	*procstat_getprocs(struct procstat *procstat,
+    int what, int arg, unsigned int *count);
 int	procstat_get_pipe_info(struct procstat *procstat, struct filestat *fst,
     struct pipestat *pipe, char *errbuf);
+int	procstat_get_pts_info(struct procstat *procstat, struct filestat *fst,
+    struct ptsstat *pts, char *errbuf);
 int	procstat_get_socket_info(struct procstat *procstat, struct filestat *fst,
     struct sockstat *sock, char *errbuf);
+int	procstat_get_vnode_info(struct procstat *procstat, struct filestat *fst,
+    struct vnstat *vn, char *errbuf);
+struct procstat	*procstat_open(const char *nlistf, const char *memf);
+
+#endif	/* !__LIBPROCSTAT_H__ */

Modified: projects/libprocstat/usr.bin/fstat/main.c
==============================================================================
--- projects/libprocstat/usr.bin/fstat/main.c	Thu Jul 16 14:24:06 2009	(r195719)
+++ projects/libprocstat/usr.bin/fstat/main.c	Thu Jul 16 15:39:54 2009	(r195720)
@@ -32,8 +32,7 @@ __FBSDID("$FreeBSD$");
 #include <stdlib.h>
 #include <string.h>
 
-int	do_fstat(int argc, char *argv[]);
-int	do_fuser(int argc, char *argv[]);
+#include "functions.h"
 
 int
 main(int argc, char *argv[])

Modified: projects/libprocstat/usr.bin/fstat/msdosfs.c
==============================================================================
--- projects/libprocstat/usr.bin/fstat/msdosfs.c	Thu Jul 16 14:24:06 2009	(r195719)
+++ projects/libprocstat/usr.bin/fstat/msdosfs.c	Thu Jul 16 15:39:54 2009	(r195720)
@@ -64,7 +64,7 @@ __FBSDID("$FreeBSD$");
  */
 #define VTODE(vp) ((struct denode *)(vp)->v_data)
 
-#include "common.h"
+#include "common_kvm.h"
 
 struct dosmount {
 	struct dosmount *next;

Modified: projects/libprocstat/usr.bin/fstat/zfs.c
==============================================================================
--- projects/libprocstat/usr.bin/fstat/zfs.c	Thu Jul 16 14:24:06 2009	(r195719)
+++ projects/libprocstat/usr.bin/fstat/zfs.c	Thu Jul 16 15:39:54 2009	(r195720)
@@ -50,8 +50,7 @@
 #include <stdlib.h>
 
 #define ZFS
-#undef dprintf
-#include "common.h"
+#include "common_kvm.h"
 
 /* 
  * Offset calculations that are used to get data from znode without having the


More information about the svn-src-projects mailing list