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