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 */
|
|
|
|
|
2007-05-26 19:00:18 +00:00
|
|
|
#include "libbb.h"
|
2000-06-26 10:45:52 +00:00
|
|
|
|
2007-10-11 10:05:36 +00:00
|
|
|
int free_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2010-02-26 08:28:30 +00:00
|
|
|
int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM))
|
1999-12-08 23:19:36 +00:00
|
|
|
{
|
2000-02-21 21:26:32 +00:00
|
|
|
struct sysinfo info;
|
2010-02-21 04:39:59 +00:00
|
|
|
unsigned mem_unit;
|
|
|
|
|
|
|
|
#if ENABLE_DESKTOP
|
|
|
|
if (argv[1] && argv[1][0] == '-')
|
|
|
|
bb_show_usage();
|
|
|
|
#endif
|
|
|
|
|
2000-02-21 21:26:32 +00:00
|
|
|
sysinfo(&info);
|
2000-09-10 16:10:41 +00:00
|
|
|
|
|
|
|
/* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */
|
2010-02-21 04:39:59 +00:00
|
|
|
mem_unit = 1;
|
|
|
|
if (info.mem_unit != 0) {
|
|
|
|
mem_unit = info.mem_unit;
|
2000-06-26 10:45:52 +00:00
|
|
|
}
|
2003-01-11 20:40:49 +00:00
|
|
|
|
2010-02-21 04:39:59 +00:00
|
|
|
/* Convert values to kbytes */
|
|
|
|
if (mem_unit == 1) {
|
|
|
|
info.totalram >>= 10;
|
|
|
|
info.freeram >>= 10;
|
2010-02-21 04:17:41 +00:00
|
|
|
#if BB_MMU
|
2010-02-21 04:39:59 +00:00
|
|
|
info.totalswap >>= 10;
|
|
|
|
info.freeswap >>= 10;
|
2003-01-11 20:40:49 +00:00
|
|
|
#endif
|
2010-02-21 04:39:59 +00:00
|
|
|
info.sharedram >>= 10;
|
|
|
|
info.bufferram >>= 10;
|
2003-01-11 20:40:49 +00:00
|
|
|
} else {
|
2010-02-21 04:39:59 +00:00
|
|
|
mem_unit >>= 10;
|
|
|
|
/* TODO: Make all this stuff not overflow when mem >= 4 Tb */
|
|
|
|
info.totalram *= mem_unit;
|
|
|
|
info.freeram *= mem_unit;
|
2010-02-21 04:17:41 +00:00
|
|
|
#if BB_MMU
|
2010-02-21 04:39:59 +00:00
|
|
|
info.totalswap *= mem_unit;
|
|
|
|
info.freeswap *= mem_unit;
|
2003-01-11 20:40:49 +00:00
|
|
|
#endif
|
2010-02-21 04:39:59 +00:00
|
|
|
info.sharedram *= mem_unit;
|
|
|
|
info.bufferram *= mem_unit;
|
2003-01-11 20:40:49 +00:00
|
|
|
}
|
2000-09-10 16:10:41 +00:00
|
|
|
|
2010-02-21 04:39:59 +00:00
|
|
|
printf(" %13s%13s%13s%13s%13s\n",
|
|
|
|
"total",
|
|
|
|
"used",
|
|
|
|
"free",
|
|
|
|
"shared", "buffers" /* swap and total don't have these columns */
|
|
|
|
);
|
|
|
|
printf("%6s%13lu%13lu%13lu%13lu%13lu\n", "Mem:",
|
|
|
|
info.totalram,
|
|
|
|
info.totalram - info.freeram,
|
|
|
|
info.freeram,
|
|
|
|
info.sharedram, info.bufferram
|
|
|
|
);
|
2010-02-21 04:17:41 +00:00
|
|
|
#if BB_MMU
|
2010-02-21 04:39:59 +00:00
|
|
|
printf("%6s%13lu%13lu%13lu\n", "Swap:",
|
|
|
|
info.totalswap,
|
|
|
|
info.totalswap - info.freeswap,
|
|
|
|
info.freeswap
|
|
|
|
);
|
|
|
|
printf("%6s%13lu%13lu%13lu\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
|
|
|
}
|