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
, char **argv
)
20 /* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */
21 if (info
.mem_unit
== 0) {
24 if (info
.mem_unit
== 1) {
27 /* TODO: Make all this stuff not overflow when mem >= 4 Gib */
28 info
.totalram
/=info
.mem_unit
;
29 info
.freeram
/=info
.mem_unit
;
31 info
.totalswap
/=info
.mem_unit
;
32 info
.freeswap
/=info
.mem_unit
;
34 info
.sharedram
/=info
.mem_unit
;
35 info
.bufferram
/=info
.mem_unit
;
38 /* TODO: Make all this stuff not overflow when mem >= 4 Gib */
39 info
.totalram
*=info
.mem_unit
;
40 info
.freeram
*=info
.mem_unit
;
42 info
.totalswap
*=info
.mem_unit
;
43 info
.freeswap
*=info
.mem_unit
;
45 info
.sharedram
*=info
.mem_unit
;
46 info
.bufferram
*=info
.mem_unit
;
49 if (argc
> 1 && *argv
[1] == '-')
52 printf("%6s%13s%13s%13s%13s%13s\n", "", "total", "used", "free",
55 printf("%6s%13ld%13ld%13ld%13ld%13ld\n", "Mem:", info
.totalram
,
56 info
.totalram
-info
.freeram
, info
.freeram
,
57 info
.sharedram
, info
.bufferram
);
60 printf("%6s%13ld%13ld%13ld\n", "Swap:", info
.totalswap
,
61 info
.totalswap
-info
.freeswap
, info
.freeswap
);
63 printf("%6s%13ld%13ld%13ld\n", "Total:", info
.totalram
+info
.totalswap
,
64 (info
.totalram
-info
.freeram
)+(info
.totalswap
-info
.freeswap
),
65 info
.freeram
+info
.freeswap
);