summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Cottenceau <gc@mandriva.com>2001-02-08 12:49:56 +0000
committerGuillaume Cottenceau <gc@mandriva.com>2001-02-08 12:49:56 +0000
commita0f295c6837be1282b3b7ecca13f08a3c8d99175 (patch)
treed4901671674a9803520fc3a06c42bef0ac006edd
parentdd565d0c93639079355387546e55a9c615662760 (diff)
downloaddrakx-a0f295c6837be1282b3b7ecca13f08a3c8d99175.tar
drakx-a0f295c6837be1282b3b7ecca13f08a3c8d99175.tar.gz
drakx-a0f295c6837be1282b3b7ecca13f08a3c8d99175.tar.bz2
drakx-a0f295c6837be1282b3b7ecca13f08a3c8d99175.tar.xz
drakx-a0f295c6837be1282b3b7ecca13f08a3c8d99175.zip
better memory detection (from wonderful drakx)
-rw-r--r--mdk-stage1/config-stage1.h4
-rw-r--r--mdk-stage1/network.c4
-rw-r--r--mdk-stage1/tools.c38
3 files changed, 12 insertions, 34 deletions
diff --git a/mdk-stage1/config-stage1.h b/mdk-stage1/config-stage1.h
index d2503d642..4bfa3896a 100644
--- a/mdk-stage1/config-stage1.h
+++ b/mdk-stage1/config-stage1.h
@@ -18,8 +18,8 @@
#define _GNU_SOURCE 1
-/* If we have more than that amount of memory, we assume we can load the second stage as a ramdisk */
-#define MEM_LIMIT_RAMDISK 52 * 1024
+/* If we have more than that amount of memory (in Mbytes), we assume we can load the second stage as a ramdisk */
+#define MEM_LIMIT_RAMDISK 52
#define DISTRIB_NAME "Linux-Mandrake"
diff --git a/mdk-stage1/network.c b/mdk-stage1/network.c
index f961df17f..7c4207c36 100644
--- a/mdk-stage1/network.c
+++ b/mdk-stage1/network.c
@@ -642,7 +642,7 @@ enum return_type ftp_prepare(void)
if (!ramdisk_possible()) {
error_message("FTP install needs more than %d Mbytes of memory (detected %d Mbytes).",
- MEM_LIMIT_RAMDISK >> 10, total_memory() >> 10);
+ MEM_LIMIT_RAMDISK, total_memory());
return RETURN_ERROR;
}
@@ -726,7 +726,7 @@ enum return_type http_prepare(void)
if (!ramdisk_possible()) {
error_message("HTTP install needs more than %d Mbytes of memory (detected %d Mbytes).",
- MEM_LIMIT_RAMDISK >> 10, total_memory() >> 10);
+ MEM_LIMIT_RAMDISK, total_memory());
return RETURN_ERROR;
}
diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c
index 9acabdb5f..8b2931ad2 100644
--- a/mdk-stage1/tools.c
+++ b/mdk-stage1/tools.c
@@ -183,38 +183,16 @@ int charstar_to_int(char * s)
int total_memory(void)
{
- int fd;
- int i;
- char buf[4096];
- char * memtotal_tag = "MemTotal:";
- int memtotal = 0;
-
- fd = open("/proc/meminfo", O_RDONLY);
- if (fd == -1)
- fatal_error("could not open /proc/meminfo");
-
- i = read(fd, buf, sizeof(buf));
- if (i < 0)
- fatal_error("could not read /proc/meminfo");
-
- close(fd);
- buf[i] = 0;
-
- i = 0;
- while (buf[i] != 0 && strncmp(&buf[i], memtotal_tag, strlen(memtotal_tag)))
- i++;
-
- while (buf[i] != 0 && buf[i] != '\n' && !isdigit(buf[i]))
- i++;
-
- if (buf[i] == 0 || buf[i] == '\n')
- fatal_error("could not read MemTotal");
+ int value;
+ struct stat statr;
+ if (stat("/proc/kcore", &statr))
+ return 0;
- memtotal = charstar_to_int(&(buf[i]));
-
- log_message("%s %d kB", memtotal_tag, memtotal);
+ /* drakx powered: use /proc/kcore and rounds every 4 Mbytes */
+ value = 4 * ((int)((float)statr.st_size / 1024 / 1024 / 4 + 0.5));
+ log_message("Total Memory: %d Mbytes", value);
- return memtotal;
+ return value;
}