summaryrefslogtreecommitdiff
path: root/sysutils/xosview/patches/patch-aa
blob: 1686744a36fc0190bfe62a809df7ea780e70f55e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
$NetBSD: patch-aa,v 1.14 2006/06/05 20:20:26 christos Exp $

--- bsd/kernel.cc.orig	2006-02-18 02:36:06.000000000 -0500
+++ bsd/kernel.cc	2006-06-05 16:17:01.000000000 -0400
@@ -21,6 +21,8 @@
 /*  NetBSD pulls in stdio.h via one of the other includes, but
  *  the other BSDs don't.  */
 # include <stdio.h>
+#else
+# define UVM
 #endif
 
 #include <fcntl.h>
@@ -115,6 +117,13 @@
 // in __NetBSD_Version__ for us if needed.
 #if defined(XOSVIEW_NETBSD) && defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 106010000)
 #define NETBSD_1_6A
+#ifdef HW_DISKSTATS
+static int dmib[3] = {CTL_HW, HW_DISKSTATS, sizeof(struct disk_sysctl)};
+#endif
+#ifdef HW_IOSTATS
+static int dmib[3] = {CTL_HW, HW_IOSTATS, sizeof(struct io_sysctl)};
+#include <sys/iostat.h>
+#endif
 #endif
 
 #include "general.h"
@@ -773,13 +782,12 @@
 #ifdef NETBSD_1_6A
   // Do a sysctl with a NULL data pointer to get the size that would
   // have been returned, and use that to figure out # drives.
-  int mib[3] = {CTL_HW, HW_DISKSTATS, sizeof(struct disk_sysctl)};
   size_t size;
-  if (sysctl(mib, 3, NULL, &size, NULL, 0) < 0) {
+  if (sysctl(dmib, 3, NULL, &size, NULL, 0) < 0) {
     warnx("!!! The DiskMeter sysctl failed.  Disabling DiskMeter.");
     return 0;
   }
-  NetBSD_N_Drives = size / sizeof(struct disk_sysctl);
+  NetBSD_N_Drives = size / dmib[2];
   return 1;
 #endif
   return ValidSymbol(DISKLIST_SYM_INDEX);
@@ -816,19 +824,29 @@
 #else
 #if defined(NETBSD_1_6A)
   // Use the new sysctl to do this for us.
-  int mib[3] = {CTL_HW, HW_DISKSTATS, sizeof(struct disk_sysctl)};
-  size_t sysctl_sz = NetBSD_N_Drives * sizeof(struct disk_sysctl);
+  size_t sysctl_sz = NetBSD_N_Drives * dmib[2];
+#ifdef HW_DISKSTATS
   struct disk_sysctl drive_stats[NetBSD_N_Drives];
+#endif
+#ifdef HW_IOSTATS
+  struct io_sysctl drive_stats[NetBSD_N_Drives];
+#endif
 
   // Do the sysctl.
-  if (sysctl(mib, 3, drive_stats, &sysctl_sz, NULL, 0) < 0) {
+  if (sysctl(dmib, 3, drive_stats, &sysctl_sz, NULL, 0) < 0) {
     err(1, "sysctl hw.diskstats failed");
   }
 
   // Now accumulate the total.
   unsigned long long xferred = 0;
   for (unsigned int i = 0; i < NetBSD_N_Drives; i++) {
+#ifdef HW_DISKSTATS
     xferred += drive_stats[i].dk_rbytes + drive_stats[i].dk_wbytes;
+#endif
+#ifdef HW_IOSTATS
+    if (drive_stats[i].type == IOSTAT_DISK)
+	xferred += drive_stats[i].rbytes + drive_stats[i].wbytes;
+#endif
   }
   *bytesXferred = xferred;
 #else