2000-02-08 19:58:47 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
1999-12-08 23:19:36 +00:00
|
|
|
/*
|
|
|
|
* Mini free implementation for busybox
|
|
|
|
*
|
2004-03-15 08:29:22 +00:00
|
|
|
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
1999-12-08 23:19:36 +00:00
|
|
|
*
|
2006-09-22 02:52:41 +00:00
|
|
|
* Licensed under the GPL version 2, see the file LICENSE in this tarball.
|
1999-12-08 23:19:36 +00:00
|
|
|
*/
|
|
|
|
|
2001-03-09 23:59:51 +00:00
|
|
|
/* getopt not needed */
|
|
|
|
|
2006-06-02 20:56:16 +00:00
|
|
|
#include "busybox.h"
|
2000-06-26 10:45:52 +00:00
|
|
|
|
2007-02-03 17:28:39 +00:00
|
|
|
int free_main(int argc, char **argv);
|
2006-03-06 20:47:33 +00:00
|
|
|
int free_main(int argc, char **argv)
|
1999-12-08 23:19:36 +00:00
|
|
|
{
|
2000-02-21 21:26:32 +00:00
|
|
|
struct sysinfo info;
|
|
|
|
sysinfo(&info);
|
2000-09-10 16:10:41 +00:00
|
|
|
|
|
|
|
/* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */
|
2007-03-24 15:40:16 +00:00
|
|
|
if (info.mem_unit == 0) {
|
2000-09-10 16:10:41 +00:00
|
|
|
info.mem_unit=1;
|
2000-06-26 10:45:52 +00:00
|
|
|
}
|
2007-03-24 15:40:16 +00:00
|
|
|
if (info.mem_unit == 1) {
|
2003-01-11 20:40:49 +00:00
|
|
|
info.mem_unit=1024;
|
|
|
|
|
|
|
|
/* TODO: Make all this stuff not overflow when mem >= 4 Gib */
|
|
|
|
info.totalram/=info.mem_unit;
|
|
|
|
info.freeram/=info.mem_unit;
|
|
|
|
#ifndef __uClinux__
|
|
|
|
info.totalswap/=info.mem_unit;
|
|
|
|
info.freeswap/=info.mem_unit;
|
|
|
|
#endif
|
|
|
|
info.sharedram/=info.mem_unit;
|
|
|
|
info.bufferram/=info.mem_unit;
|
|
|
|
} else {
|
|
|
|
info.mem_unit/=1024;
|
|
|
|
/* TODO: Make all this stuff not overflow when mem >= 4 Gib */
|
|
|
|
info.totalram*=info.mem_unit;
|
|
|
|
info.freeram*=info.mem_unit;
|
|
|
|
#ifndef __uClinux__
|
|
|
|
info.totalswap*=info.mem_unit;
|
|
|
|
info.freeswap*=info.mem_unit;
|
|
|
|
#endif
|
|
|
|
info.sharedram*=info.mem_unit;
|
|
|
|
info.bufferram*=info.mem_unit;
|
|
|
|
}
|
2000-09-10 16:10:41 +00:00
|
|
|
|
2007-03-24 15:40:16 +00:00
|
|
|
if (argc > 1 && *argv[1] == '-')
|
2003-03-19 09:13:01 +00:00
|
|
|
bb_show_usage();
|
2000-02-21 21:26:32 +00:00
|
|
|
|
2004-03-15 08:29:22 +00:00
|
|
|
printf("%6s%13s%13s%13s%13s%13s\n", "", "total", "used", "free",
|
2000-02-21 21:26:32 +00:00
|
|
|
"shared", "buffers");
|
|
|
|
|
2004-03-15 08:29:22 +00:00
|
|
|
printf("%6s%13ld%13ld%13ld%13ld%13ld\n", "Mem:", info.totalram,
|
|
|
|
info.totalram-info.freeram, info.freeram,
|
2000-02-21 21:26:32 +00:00
|
|
|
info.sharedram, info.bufferram);
|
|
|
|
|
2003-01-11 20:40:49 +00:00
|
|
|
#ifndef __uClinux__
|
2000-02-21 21:26:32 +00:00
|
|
|
printf("%6s%13ld%13ld%13ld\n", "Swap:", info.totalswap,
|
|
|
|
info.totalswap-info.freeswap, info.freeswap);
|
2000-02-08 19:58:47 +00:00
|
|
|
|
2000-02-21 21:26:32 +00:00
|
|
|
printf("%6s%13ld%13ld%13ld\n", "Total:", info.totalram+info.totalswap,
|
|
|
|
(info.totalram-info.freeram)+(info.totalswap-info.freeswap),
|
|
|
|
info.freeram+info.freeswap);
|
2003-01-11 20:40:49 +00:00
|
|
|
#endif
|
2000-12-01 02:55:13 +00:00
|
|
|
return EXIT_SUCCESS;
|
1999-12-08 23:19:36 +00:00
|
|
|
}
|