mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-27 11:13:24 +02:00
installer: use sysinfo() for memory detection
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/swap.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <linux/fs.h>
|
||||
@@ -502,23 +503,13 @@ struct hw_destination* hw_make_destination(int part_type, struct hw_disk** disks
|
||||
}
|
||||
|
||||
unsigned long long hw_memory() {
|
||||
FILE* handle = NULL;
|
||||
char line[STRING_SIZE];
|
||||
struct sysinfo si;
|
||||
|
||||
unsigned long long memory = 0;
|
||||
int r = sysinfo(&si);
|
||||
if (r < 0)
|
||||
return 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;
|
||||
return si.totalram;
|
||||
}
|
||||
|
||||
static int hw_zero_out_device(const char* path, int bytes) {
|
||||
|
||||
@@ -494,6 +494,7 @@ int main(int argc, char *argv[]) {
|
||||
fprintf(flog, " swap : %s (%lluMB)\n", destination->part_swap, BYTES2MB(destination->size_swap));
|
||||
fprintf(flog, " root : %s (%lluMB)\n", destination->part_root, BYTES2MB(destination->size_root));
|
||||
fprintf(flog, " data : %s (%lluMB)\n", destination->part_data, BYTES2MB(destination->size_data));
|
||||
fprintf(flog, "Memory : %lluMB\n", BYTES2MB(hw_memory()));
|
||||
|
||||
// Warn the user if there is not enough space to create a swap partition
|
||||
if (!unattended && !*destination->part_swap) {
|
||||
|
||||
Reference in New Issue
Block a user