1 /* vi: set sw=4 ts=4: */
3 * Mini free implementation for busybox
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7 * Licensed under the GPL version 2, see the file LICENSE in this tarball.
10 /* getopt not needed */
14 int free_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
15 int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM))
21 if (argv[1] && argv[1][0] == '-')
27 /* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */
29 if (info.mem_unit != 0) {
30 mem_unit = info.mem_unit;
33 /* Convert values to kbytes */
38 info.totalswap >>= 10;
41 info.sharedram >>= 10;
42 info.bufferram >>= 10;
45 /* TODO: Make all this stuff not overflow when mem >= 4 Tb */
46 info.totalram *= mem_unit;
47 info.freeram *= mem_unit;
49 info.totalswap *= mem_unit;
50 info.freeswap *= mem_unit;
52 info.sharedram *= mem_unit;
53 info.bufferram *= mem_unit;
56 printf(" %13s%13s%13s%13s%13s\n",
60 "shared", "buffers" /* swap and total don't have these columns */
62 printf("%6s%13lu%13lu%13lu%13lu%13lu\n", "Mem:",
64 info.totalram - info.freeram,
66 info.sharedram, info.bufferram
69 printf("%6s%13lu%13lu%13lu\n", "Swap:",
71 info.totalswap - info.freeswap,
74 printf("%6s%13lu%13lu%13lu\n", "Total:",
75 info.totalram + info.totalswap,
76 (info.totalram - info.freeram) + (info.totalswap - info.freeswap),
77 info.freeram + info.freeswap