installer: Make function to determine the amount of system memory.

This commit is contained in:
Michael Tremer
2014-07-20 16:48:59 +02:00
parent d7dd283b89
commit c4e966746e
3 changed files with 23 additions and 10 deletions

View File

@@ -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;
}

View File

@@ -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 */

View File

@@ -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