From: Michael Tremer Date: Sun, 20 Jul 2014 14:48:59 +0000 (+0200) Subject: installer: Make function to determine the amount of system memory. X-Git-Tag: v2.17-core87~103^2~51^2~138 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c4e966746ecb172767186c094a67b68907831da5;p=ipfire-2.x.git installer: Make function to determine the amount of system memory. --- diff --git a/src/install+setup/install/hw.c b/src/install+setup/install/hw.c index 1fca9fdfa9..f26c63836f 100644 --- a/src/install+setup/install/hw.c +++ b/src/install+setup/install/hw.c @@ -315,3 +315,23 @@ struct hw_destination* hw_make_destination(int part_type, struct hw_disk** disks return dest; } + +unsigned long long hw_memory() { + FILE* handle = NULL; + char line[STRING_SIZE]; + + unsigned long long memory = 0; + + /* Calculate amount of memory in machine */ + if ((handle = fopen("/proc/meminfo", "r"))) { + while (fgets(line, sizeof(line), handle)) { + if (!sscanf (line, "MemTotal: %llu kB", memory)) { + memory = 0; + } + } + + fclose(handle); + } + + return memory * 1024; +} diff --git a/src/install+setup/install/hw.h b/src/install+setup/install/hw.h index d5549a4c7a..2823a91ea4 100644 --- a/src/install+setup/install/hw.h +++ b/src/install+setup/install/hw.h @@ -77,4 +77,6 @@ void hw_free_disks(struct hw_disk** disks); unsigned int hw_count_disks(struct hw_disk** disks); struct hw_disk** hw_select_disks(struct hw_disk** disks, int* selection); +unsigned long long hw_memory(); + #endif /* HEADER_HW_H */ diff --git a/src/install+setup/install/main.c b/src/install+setup/install/main.c index 0386cf5cdd..affdd75e4c 100644 --- a/src/install+setup/install/main.c +++ b/src/install+setup/install/main.c @@ -410,16 +410,7 @@ int main(int argc, char *argv[]) { if (rc == 2) goto EXIT; - /* Calculate amount of memory in machine */ - if ((handle = fopen("/proc/meminfo", "r"))) - { - while (fgets(line, STRING_SIZE-1, handle)) { - if (sscanf (line, "MemTotal: %s kB", string)) { - memory = atoi(string) / 1024 ; - } - } - fclose(handle); - } + memory = hw_memory() / 1024 / 1024; /* Partition, mkswp, mkfs. * before partitioning, first determine the sizes of each