File: 20_highmem.dpatch

package info (click to toggle)
linuxinfo 1.1.8-21
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 348 kB
  • ctags: 49
  • sloc: sh: 1,729; ansic: 564; makefile: 80
file content (104 lines) | stat: -rw-r--r-- 3,052 bytes parent folder | 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
96
97
98
99
100
101
102
103
104
#! /bin/sh -e
## 20-highmem.dpatch by Helge Kreutzmann <debian@helgefjell.de>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Support highmem configurations
## DP: On ia64, mips and sparc /proc/kcore cannot be trusted, always use
## DP: alternate method
## DP: Improve regular expression for himem detection

[ -f debian/patches/00patch-opts ] && . debian/patches/00patch-opts
patch_opts="${patch_opts:--f --no-backup-if-mismatch ${2:+-d $2}}"

if [ $# -lt 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
       -patch) patch $patch_opts -p1 < $0;;
       -unpatch) patch $patch_opts -p1 -R < $0;;
        *)
                echo >&2 "`basename $0`: script expects -patch|-unpatch as argum&ent"
                exit 1;;
esac

exit 0
@DPATCH@
diff -urN linuxinfo-1.1.8-8/linuxinfo.h linuxinfo-1.1.8-local/linuxinfo.h
--- linuxinfo-1.1.8-8/linuxinfo.h	2004-08-07 22:23:59.000000000 +0200
+++ linuxinfo-1.1.8-local/linuxinfo.h	2004-08-07 22:26:20.000000000 +0200
@@ -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_ */
--- linuxinfo-1.1.8.upstream/linuxinfo_common.c	2002-02-04 23:43:07.000000000 +0100
+++ linuxinfo-1.1.8-19/linuxinfo_common.c	2006-07-22 18:18:05.929588750 +0200
@@ -21,6 +21,7 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/utsname.h>
+#include <fcntl.h>
 
 #include "linuxinfo.h"
 
@@ -121,14 +122,48 @@
 {
 	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 (memory==896||memory==0)
+	{
+#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;
 }