]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
installer: Make function to determine the amount of system memory.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 20 Jul 2014 14:48:59 +0000 (16:48 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 20 Jul 2014 14:48:59 +0000 (16:48 +0200)
src/install+setup/install/hw.c
src/install+setup/install/hw.h
src/install+setup/install/main.c

index 1fca9fdfa9d3d2dee5c471f517ebdcfd5d9aef4f..f26c63836f62dcc564b7d54e741a25479de25c70 100644 (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;
+}
index d5549a4c7a1f1957815ed590a73c9da6a9519a19..2823a91ea45b99169eca38b43162ec1b89269a56 100644 (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 */
index 0386cf5cdd460082df76d6e49272e03a4e5fbdc1..affdd75e4c8105d86365da8125570f60f2e0fd40 100644 (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