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

Stanislav Sedov stas at FreeBSD.org
Wed Jul 15 22:27:36 UTC 2009


Author: stas
Date: Wed Jul 15 22:27:36 2009
New Revision: 195713
URL: http://svn.freebsd.org/changeset/base/195713

Log:
  - Fix file flags processing.

Modified:
  projects/libprocstat/usr.bin/fstat/libprocstat.c
  projects/libprocstat/usr.bin/fstat/libprocstat.h

Modified: projects/libprocstat/usr.bin/fstat/libprocstat.c
==============================================================================
--- projects/libprocstat/usr.bin/fstat/libprocstat.c	Wed Jul 15 17:29:05 2009	(r195712)
+++ projects/libprocstat/usr.bin/fstat/libprocstat.c	Wed Jul 15 22:27:36 2009	(r195713)
@@ -78,26 +78,41 @@ static struct {
 };
 #define NVFTYPES (sizeof(vt2fst) / sizeof(*vt2fst))
 
-char *getmnton(kvm_t *kd, struct mount *m);
-void
-socktrans(kvm_t *kd, struct socket *sock, int fd, int flags, struct filestat *fst);
+static struct {
+	int flag;
+	int fst_flag;
+} fstflags[] = {
+	{ FREAD, PS_FST_FFLAG_READ },
+	{ FWRITE, PS_FST_FFLAG_WRITE },
+	{ O_NONBLOCK, PS_FST_FFLAG_NONBLOCK },
+	{ O_APPEND, PS_FST_FFLAG_APPEND },
+	{ O_SHLOCK, PS_FST_FFLAG_SHLOCK },
+	{ O_EXLOCK, PS_FST_FFLAG_EXLOCK },
+	{ O_ASYNC, PS_FST_FFLAG_ASYNC },
+	{ O_SYNC, PS_FST_FFLAG_SYNC },
+	{ O_NOFOLLOW, PS_FST_FFLAG_NOFOLLOW },
+	{ O_CREAT, PS_FST_FFLAG_CREAT },
+	{ O_TRUNC, PS_FST_FFLAG_TRUNC },
+	{ O_EXCL, PS_FST_FFLAG_EXCL }
+};
+#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,
+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,
+int	procstat_get_pipe_info_sysctl(struct filestat *fst,
     struct pipestat *pipe, char *errbuf);
-int
-procstat_get_pts_info_sysctl(struct filestat *fst, struct ptsstat *pts,
+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,
+int	procstat_get_pts_info_kvm(kvm_t *kd, struct filestat *fst,
     struct ptsstat *pts, char *errbuf);
+static int	to_filestat_flags(int flags);
 
 
 /*
@@ -378,7 +393,7 @@ procstat_getfiles_kvm(kvm_t *kd, struct 
 			continue;
 		}
 		entry = filestat_new_entry(data, type, i,
-		    PS_FST_FFLAG_READ);
+		    to_filestat_flags(file.f_flag));
 		if (entry != NULL)
 			STAILQ_INSERT_TAIL(head, entry, next);
 	}
@@ -387,6 +402,19 @@ 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 *
 procstat_getfiles_sysctl(struct kinfo_proc *kp __unused)
 {

Modified: projects/libprocstat/usr.bin/fstat/libprocstat.h
==============================================================================
--- projects/libprocstat/usr.bin/fstat/libprocstat.h	Wed Jul 15 17:29:05 2009	(r195712)
+++ projects/libprocstat/usr.bin/fstat/libprocstat.h	Wed Jul 15 22:27:36 2009	(r195713)
@@ -27,8 +27,18 @@ struct procstat {
 #define	PS_FST_FD_TEXT -5
 #define	PS_FST_FD_MMAP -6
 
-#define PS_FST_FFLAG_READ 0x01
-#define PS_FST_FFLAG_WRITE 0x02
+#define PS_FST_FFLAG_READ	0x0001
+#define PS_FST_FFLAG_WRITE	0x0002
+#define	PS_FST_FFLAG_NONBLOCK	0x0004
+#define	PS_FST_FFLAG_APPEND	0x0008
+#define	PS_FST_FFLAG_SHLOCK	0x0010
+#define	PS_FST_FFLAG_EXLOCK	0x0020
+#define	PS_FST_FFLAG_ASYNC	0x0040
+#define	PS_FST_FFLAG_SYNC	0x0080
+#define	PS_FST_FFLAG_NOFOLLOW	0x0100
+#define	PS_FST_FFLAG_CREAT	0x0200
+#define	PS_FST_FFLAG_TRUNC	0x0400
+#define	PS_FST_FFLAG_EXCL	0x0800
 
 #define	PS_FST_FLAG_ERROR 0x01
 #define	PS_FST_FLAG_UNKNOWNFS 0x02


More information about the svn-src-projects mailing list