From: Erik Andersen <andersen@codepoet.org>
To: Christoph Rohland <cr@sap.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [Patch] sysinfo compatibility
Date: Tue, 21 Aug 2001 11:46:41 -0600 [thread overview]
Message-ID: <20010821114640.A25151@codepoet.org> (raw)
In-Reply-To: <Pine.LNX.4.21.0108211137340.1320-100000@localhost.localdomain> <m34rr12ueb.fsf@linux.local>
In-Reply-To: <m34rr12ueb.fsf@linux.local>
On Tue Aug 21, 2001 at 07:30:04PM +0200, Christoph Rohland wrote:
> And I have somewhat harder feelings since we get a lot of bug reports
> that our installer only detects 0M RAM when running on a 2.4 machine
> while it works with the 2.2 kernel. We are talking about an ABI which
> is directly imported into user space programs.
Its your lucky day. Put something like this in your installer,
and your problems will go away:
/* Include our own copy of struct sysinfo to avoid binary compatibility
* problems with Linux 2.4, which changed things. Grumble, grumble. */
struct sysinfo {
long uptime; /* Seconds since boot */
unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
unsigned long totalram; /* Total usable main memory size */
unsigned long freeram; /* Available memory size */
unsigned long sharedram; /* Amount of shared memory */
unsigned long bufferram; /* Memory used by buffers */
unsigned long totalswap; /* Total swap space size */
unsigned long freeswap; /* swap space still available */
unsigned short procs; /* Number of current processes */
unsigned short pad; /* Padding needed for m68k */
unsigned long totalhigh; /* Total high memory size */
unsigned long freehigh; /* Available high memory size */
unsigned int mem_unit; /* Memory unit size in bytes */
char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
};
extern int sysinfo (struct sysinfo* info);
/* How much memory does this machine have?
Units are kBytes to avoid overflow on 4GB machines */
static int check_free_memory()
{
struct sysinfo info;
unsigned int result, u, s=10;
if (sysinfo(&info) != 0) {
fprintf(stderr,"Error checking free memory");
return -1;
}
/* Kernels 2.0.x and 2.2.x return info.mem_unit==0 with values in bytes.
* Kernels 2.4.0 return info.mem_unit in bytes. */
u = info.mem_unit;
if (u==0) u=1;
while ( (u&1) == 0 && s > 0 ) { u>>=1; s--; }
result = (info.totalram>>s) + (info.totalswap>>s);
result = result*u;
if (result < 0) result = INT_MAX;
return result;
}
-Erik
--
Erik B. Andersen email: andersee@debian.org, andersen@lineo.com
--This message was written using 73% post-consumer electrons--
next prev parent reply other threads:[~2001-08-21 17:46 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-21 8:03 [Patch] sysinfo compatibility Christoph Rohland
2001-08-21 10:59 ` Hugh Dickins
2001-08-21 13:50 ` Alan Cox
2001-08-21 17:30 ` Christoph Rohland
2001-08-21 18:40 ` Alan Cox
2001-08-22 6:40 ` Christoph Rohland
2001-08-21 17:30 ` Christoph Rohland
2001-08-21 17:46 ` Erik Andersen [this message]
2001-08-22 6:44 ` Christoph Rohland
2001-08-22 15:45 ` Erik Andersen
2001-08-22 16:04 ` Christoph Rohland
2001-08-21 18:40 ` Hugh Dickins
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20010821114640.A25151@codepoet.org \
--to=andersen@codepoet.org \
--cc=cr@sap.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.