Package: linuxinfo / 1.1.8-34

20_highmem Patch series | download
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Description: Support highmem configurations
#  On ia64, mips and sparc /proc/kcore cannot be trusted, always use alternate 
#  method
#  Improve regular expression for himem detection
#  Sometimes the value for switching to the alternative method is differing
# Author: Helge Kreutzmann <debian@helgefjell.de>
# Last-Update: 2009-05-24

Index: linuxinfo-1.1.8-29/linuxinfo_common.c
===================================================================
--- linuxinfo-1.1.8-29.orig/linuxinfo_common.c	2010-02-01 21:39:10.201495549 +0100
+++ linuxinfo-1.1.8-29/linuxinfo_common.c	2010-02-01 21:38:18.394280000 +0100
@@ -21,6 +21,7 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/utsname.h>
+#include <fcntl.h>
 
 #include "linuxinfo.h"
 
@@ -121,14 +122,54 @@
 {
 	LONGLONG memory;
         struct stat st_buf;
+	int meminfo_fd;
+	char temp_string[BUFSIZ], temp_string2[BUFSIZ];
+	int found;
 
+#if !defined(system_ia64) && !defined(system_mips) && !defined(system_sparc)
         if (stat("/proc/kcore", &st_buf) < 0)
 	{
-		printf("Could not stat /proc/kcore, failing\n");
+		memory = 0;
 	}
 
         memory = (LONGLONG)st_buf.st_size;
         memory /= 1024; memory /= 1024;
+
+	// Highmem machines on x86 (at least) have a /proc/kcore of 896 MB
+	// so we have to check a second source: /proc/meminfo (which is
+	// less acurate, i.e., usually a few MB too small)
+#if defined(system_intel)
+	// Sometimes /proc/kcore seems to differ a few MB from 896 in this case
+	// and we don't trust values >\approx 4 GB ...
+	if (memory==887||memory==889||memory==896||memory==0||memory>3500)
+#else
+	if (memory==896||memory==0)
+#endif
+	{
+#endif
+	    meminfo_fd = open(MEMINFO_FILE, O_RDONLY);
+	    found=0;
+            if (meminfo_fd < 0)
+	    {
+		printf("Could not stat /proc/meminfo, result can be inaccurate\n");
+	    }
+	    else
+	    { while (read_line(meminfo_fd, temp_string, BUFSIZ) != 0)
+		{
+		    if (splitstring(temp_string, temp_string2))
+		    {
+			if ((strncmp(temp_string, "MemTota", strlen("MemTota")) == 0)&&!found)
+			{
+			    found=1;
+			    memory = (LONGLONG)atol(temp_string2);
+			    memory /= 1024; 
+			}
+		    }
+		}
+	    }
+#if !defined(system_ia64) && !defined(system_mips) && !defined(system_sparc)
+	}
+#endif
 	return memory;
 }
 
Index: linuxinfo-1.1.8-29/linuxinfo.h
===================================================================
--- linuxinfo-1.1.8-29.orig/linuxinfo.h	2010-02-01 21:38:48.213828330 +0100
+++ linuxinfo-1.1.8-29/linuxinfo.h	2010-02-01 21:38:18.394280000 +0100
@@ -20,6 +20,7 @@
 	1.1.4	AIB	20000405	Moved strstr() to linuxinfo_common.h
         1.1.5   OPAL	20021225	Added hppa
 	1.1.8   KRE     20040429        Added mips
+	1.1.8   KRE     20040807        Add support for HIGHMEM
 
 */
 
@@ -110,5 +111,6 @@
 LONGLONG getphysicalmemory(void);
 
 #define CPUINFO_FILE	"/proc/cpuinfo"
+#define MEMINFO_FILE	"/proc/meminfo"
 
 #endif /* _LINUXINFO_H_ */