diff options
author | Ales Kozumplik <akozumpl@redhat.com> | 2010-05-24 16:20:44 +0200 |
---|---|---|
committer | Ales Kozumplik <akozumpl@redhat.com> | 2010-05-27 09:46:25 +0200 |
commit | 07801894d2fd2924b69ccc1075426bd3c529ca9a (patch) | |
tree | 462dc47727288916c7a0714fb37f59799a08505e /isys | |
parent | 743bb68fda8b4b60b5ea397afb243c1b8e075149 (diff) | |
download | anaconda-07801894d2fd2924b69ccc1075426bd3c529ca9a.tar.gz anaconda-07801894d2fd2924b69ccc1075426bd3c529ca9a.tar.xz anaconda-07801894d2fd2924b69ccc1075426bd3c529ca9a.zip |
refactoring: put totalMemory() into isys.
so the python implementation in iutil.py can be removed.
Diffstat (limited to 'isys')
-rw-r--r-- | isys/Makefile.am | 2 | ||||
-rw-r--r-- | isys/isys.c | 7 | ||||
-rw-r--r-- | isys/isys.h | 11 | ||||
-rwxr-xr-x | isys/isys.py | 1 | ||||
-rw-r--r-- | isys/mem.c | 94 | ||||
-rw-r--r-- | isys/mem.h | 37 |
6 files changed, 140 insertions, 12 deletions
diff --git a/isys/Makefile.am b/isys/Makefile.am index 1a7ca81e8..978df72c1 100644 --- a/isys/Makefile.am +++ b/isys/Makefile.am @@ -21,7 +21,7 @@ pkgpyexecdir = $(pyexecdir)/py$(PACKAGE_NAME) ISYS_SRCS = devices.c imount.c cpio.c uncpio.c lang.c \ isofs.c linkdetect.c vio.c ethtool.c eddsupport.c iface.c \ - auditd.c log.c + auditd.c log.c mem.c dist_noinst_HEADERS = *.h diff --git a/isys/isys.c b/isys/isys.c index 6aeb72f78..eddc2d4d2 100644 --- a/isys/isys.c +++ b/isys/isys.c @@ -78,6 +78,7 @@ #include "auditd.h" #include "imount.h" #include "log.h" +#include "mem.h" #ifndef CDROMEJECT #define CDROMEJECT 0x5309 @@ -114,6 +115,7 @@ static PyObject * doGetLinkStatus(PyObject * s, PyObject * args); static PyObject * doGetAnacondaVersion(PyObject * s, PyObject * args); static PyObject * doInitLog(PyObject * s); static PyObject * doIsWirelessDevice(PyObject * s, PyObject * args); +static PyObject * doTotalMemory(PyObject * s); static PyMethodDef isysModuleMethods[] = { { "ejectcdrom", (PyCFunction) doEjectCdrom, METH_VARARGS, NULL }, @@ -147,6 +149,7 @@ static PyMethodDef isysModuleMethods[] = { { "getAnacondaVersion", (PyCFunction) doGetAnacondaVersion, METH_VARARGS, NULL }, { "initLog", (PyCFunction) doInitLog, METH_VARARGS, NULL }, { "isWirelessDevice", (PyCFunction) doIsWirelessDevice, METH_VARARGS, NULL }, + { "total_memory", (PyCFunction) doTotalMemory, METH_NOARGS, NULL }, { NULL, NULL, 0, NULL } } ; @@ -713,6 +716,10 @@ static PyObject * doIsWirelessDevice(PyObject * s, PyObject * args) { } return PyBool_FromLong(0); + +static PyObject * doTotalMemory(PyObject * s) { + int tm = totalMemory(); + return PyInt_FromLong(tm); } /* vim:set shiftwidth=4 softtabstop=4: */ diff --git a/isys/isys.h b/isys/isys.h index 659e3d611..980a872f4 100644 --- a/isys/isys.h +++ b/isys/isys.h @@ -20,17 +20,6 @@ #ifndef H_ISYS #define H_ISYS -#if defined(__powerpc64__) || defined(__sparc__) - #define MIN_RAM 1024*1024 // 1 GB - #define GUI_INSTALL_EXTRA_RAM 512*1024 // 512 MB -#else - #define MIN_RAM 256 * 1024 // 256 MB - #define GUI_INSTALL_EXTRA_RAM 128 * 1024 // 128 MB -#endif -#define URL_INSTALL_EXTRA_RAM 128 * 1024 // 128 MB -#define MIN_GUI_RAM MIN_RAM + GUI_INSTALL_EXTRA_RAM -#define EARLY_SWAP_RAM 512 * 1024 // 512 MB - #define OUTPUT_TERMINAL "/dev/tty5" int insmod(char * modName, char * path, char ** args); diff --git a/isys/isys.py b/isys/isys.py index 537f32d6f..9eef97be6 100755 --- a/isys/isys.py +++ b/isys/isys.py @@ -544,3 +544,4 @@ printObject = _isys.printObject bind_textdomain_codeset = _isys.bind_textdomain_codeset isVioConsole = _isys.isVioConsole initLog = _isys.initLog +total_memory = _isys.total_memory diff --git a/isys/mem.c b/isys/mem.c new file mode 100644 index 000000000..3003ba055 --- /dev/null +++ b/isys/mem.c @@ -0,0 +1,94 @@ +/* + * mem.c - memory checking + * + * Copyright (C) 2010 + * Red Hat, Inc. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <ctype.h> +#include <fcntl.h> +#include <string.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> + +#include "mem.h" +#include "log.h" + +/* look for available memory. note: won't ever report more than the + * 900 megs or so supported by the -BOOT kernel due to not using e820 */ +int totalMemory(void) { + int fd; + int bytesRead; + char buf[4096]; + char * chptr, * start; + int total = 0; + + fd = open("/proc/meminfo", O_RDONLY); + if (fd < 0) { + logMessage(ERROR, "failed to open /proc/meminfo: %m"); + return 0; + } + + bytesRead = read(fd, buf, sizeof(buf) - 1); + if (bytesRead < 0) { + logMessage(ERROR, "failed to read from /proc/meminfo: %m"); + close(fd); + return 0; + } + + close(fd); + buf[bytesRead] = '\0'; + + chptr = buf; + while (*chptr && !total) { + if (strncmp(chptr, "MemTotal:", 9)) { + chptr++; + continue; + } + + start = ++chptr ; + while (*chptr && *chptr != '\n') chptr++; + + *chptr = '\0'; + + while (!isdigit(*start) && *start) start++; + if (!*start) { + logMessage(WARNING, "no number appears after MemTotal tag"); + return 0; + } + + chptr = start; + while (*chptr && isdigit(*chptr)) { + total = (total * 10) + (*chptr - '0'); + chptr++; + } + } + + /*Because /proc/meminfo only gives us the MemTotal (total physical RAM minus + the kernel binary code), we need to round this up. Assuming every machine + has the total RAM MB number divisible by 128. */ + total /= 1024; + total = (total / 128 + 1) * 128; + total *= 1024; + + logMessage(INFO, "%d kB are available", total); + + return total; +} + + +/* vim:set shiftwidth=4 softtabstop=4: */ diff --git a/isys/mem.h b/isys/mem.h new file mode 100644 index 000000000..1a715d400 --- /dev/null +++ b/isys/mem.h @@ -0,0 +1,37 @@ +/* + * mem.h + * + * Copyright (C) 2010 + * Red Hat, Inc. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef _MEM_H_ +#define _MEM_H_ + +#if defined(__powerpc64__) || defined(__sparc__) + #define MIN_RAM 1024*1024 // 1 GB + #define GUI_INSTALL_EXTRA_RAM 512*1024 // 512 MB +#else + #define MIN_RAM 256 * 1024 // 256 MB + #define GUI_INSTALL_EXTRA_RAM 128 * 1024 // 128 MB +#endif +#define URL_INSTALL_EXTRA_RAM 128 * 1024 // 128 MB +#define MIN_GUI_RAM MIN_RAM + GUI_INSTALL_EXTRA_RAM +#define EARLY_SWAP_RAM 512 * 1024 // 512 MB + +int totalMemory(void); + +#endif /* _MEM_H_ */ |