add ext4,vfat and tar.bz2
[u-tools.git] / u-tools / apps / busybox / procps / free.c
blobe76dd21a5f06a1e05c8ac12e48746562c61c70cc
1 /* vi: set sw=4 ts=4: */
2 /*
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.
8 */
10 /* getopt not needed */
12 #include "libbb.h"
14 int free_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
15 int free_main(int argc, char **argv)
17 struct sysinfo info;
18 sysinfo(&info);
20 /* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */
21 if (info.mem_unit == 0) {
22 info.mem_unit=1;
24 if (info.mem_unit == 1) {
25 info.mem_unit=1024;
27 /* TODO: Make all this stuff not overflow when mem >= 4 Gib */
28 info.totalram/=info.mem_unit;
29 info.freeram/=info.mem_unit;
30 #ifndef __uClinux__
31 info.totalswap/=info.mem_unit;
32 info.freeswap/=info.mem_unit;
33 #endif
34 info.sharedram/=info.mem_unit;
35 info.bufferram/=info.mem_unit;
36 } else {
37 info.mem_unit/=1024;
38 /* TODO: Make all this stuff not overflow when mem >= 4 Gib */
39 info.totalram*=info.mem_unit;
40 info.freeram*=info.mem_unit;
41 #ifndef __uClinux__
42 info.totalswap*=info.mem_unit;
43 info.freeswap*=info.mem_unit;
44 #endif
45 info.sharedram*=info.mem_unit;
46 info.bufferram*=info.mem_unit;
49 if (argc > 1 && *argv[1] == '-')
50 bb_show_usage();
52 printf("%6s%13s%13s%13s%13s%13s\n", "", "total", "used", "free",
53 "shared", "buffers");
55 printf("%6s%13ld%13ld%13ld%13ld%13ld\n", "Mem:", info.totalram,
56 info.totalram-info.freeram, info.freeram,
57 info.sharedram, info.bufferram);
59 #ifndef __uClinux__
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);
66 #endif
67 return EXIT_SUCCESS;