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)
19 /* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */
20 if (info.mem_unit==0) {
23 if ( info.mem_unit == 1 ) {
26 /* TODO: Make all this stuff not overflow when mem >= 4 Gib */
27 info.totalram/=info.mem_unit;
28 info.freeram/=info.mem_unit;
30 info.totalswap/=info.mem_unit;
31 info.freeswap/=info.mem_unit;
33 info.sharedram/=info.mem_unit;
34 info.bufferram/=info.mem_unit;
37 /* TODO: Make all this stuff not overflow when mem >= 4 Gib */
38 info.totalram*=info.mem_unit;
39 info.freeram*=info.mem_unit;
41 info.totalswap*=info.mem_unit;
42 info.freeswap*=info.mem_unit;
44 info.sharedram*=info.mem_unit;
45 info.bufferram*=info.mem_unit;
48 if (argc > 1 && **(argv + 1) == '-')
51 printf("%6s%13s%13s%13s%13s%13s\n", "", "total", "used", "free",
54 printf("%6s%13ld%13ld%13ld%13ld%13ld\n", "Mem:", info.totalram,
55 info.totalram-info.freeram, info.freeram,
56 info.sharedram, info.bufferram);
59 printf("%6s%13ld%13ld%13ld\n", "Swap:", info.totalswap,
60 info.totalswap-info.freeswap, info.freeswap);
62 printf("%6s%13ld%13ld%13ld\n", "Total:", info.totalram+info.totalswap,
63 (info.totalram-info.freeram)+(info.totalswap-info.freeswap),
64 info.freeram+info.freeswap);