mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-28 11:43:25 +02:00
installer: Make function to determine the amount of system memory.
This commit is contained in:
@@ -315,3 +315,23 @@ struct hw_destination* hw_make_destination(int part_type, struct hw_disk** disks
|
|||||||
|
|
||||||
return dest;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -77,4 +77,6 @@ void hw_free_disks(struct hw_disk** disks);
|
|||||||
unsigned int hw_count_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);
|
struct hw_disk** hw_select_disks(struct hw_disk** disks, int* selection);
|
||||||
|
|
||||||
|
unsigned long long hw_memory();
|
||||||
|
|
||||||
#endif /* HEADER_HW_H */
|
#endif /* HEADER_HW_H */
|
||||||
|
|||||||
@@ -410,16 +410,7 @@ int main(int argc, char *argv[]) {
|
|||||||
if (rc == 2)
|
if (rc == 2)
|
||||||
goto EXIT;
|
goto EXIT;
|
||||||
|
|
||||||
/* Calculate amount of memory in machine */
|
memory = hw_memory() / 1024 / 1024;
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Partition, mkswp, mkfs.
|
/* Partition, mkswp, mkfs.
|
||||||
* before partitioning, first determine the sizes of each
|
* before partitioning, first determine the sizes of each
|
||||||
|
|||||||
Reference in New Issue
Block a user