[821] | 1 | /* vi: set sw=4 ts=4: */
|
---|
| 2 | /*
|
---|
| 3 | * Mini free implementation for busybox
|
---|
| 4 | *
|
---|
| 5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
---|
| 6 | *
|
---|
[1770] | 7 | * Licensed under the GPL version 2, see the file LICENSE in this tarball.
|
---|
[821] | 8 | */
|
---|
| 9 |
|
---|
| 10 | /* getopt not needed */
|
---|
| 11 |
|
---|
[1770] | 12 | #include "libbb.h"
|
---|
[821] | 13 |
|
---|
[1770] | 14 | int free_main(int argc, char **argv);
|
---|
[821] | 15 | int free_main(int argc, char **argv)
|
---|
| 16 | {
|
---|
| 17 | struct sysinfo info;
|
---|
| 18 | sysinfo(&info);
|
---|
| 19 |
|
---|
| 20 | /* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */
|
---|
[1770] | 21 | if (info.mem_unit == 0) {
|
---|
[821] | 22 | info.mem_unit=1;
|
---|
| 23 | }
|
---|
[1770] | 24 | if (info.mem_unit == 1) {
|
---|
[821] | 25 | info.mem_unit=1024;
|
---|
| 26 |
|
---|
| 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;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
[1770] | 49 | if (argc > 1 && *argv[1] == '-')
|
---|
[821] | 50 | bb_show_usage();
|
---|
| 51 |
|
---|
| 52 | printf("%6s%13s%13s%13s%13s%13s\n", "", "total", "used", "free",
|
---|
| 53 | "shared", "buffers");
|
---|
| 54 |
|
---|
| 55 | printf("%6s%13ld%13ld%13ld%13ld%13ld\n", "Mem:", info.totalram,
|
---|
| 56 | info.totalram-info.freeram, info.freeram,
|
---|
| 57 | info.sharedram, info.bufferram);
|
---|
| 58 |
|
---|
| 59 | #ifndef __uClinux__
|
---|
| 60 | printf("%6s%13ld%13ld%13ld\n", "Swap:", info.totalswap,
|
---|
| 61 | info.totalswap-info.freeswap, info.freeswap);
|
---|
| 62 |
|
---|
| 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;
|
---|
| 68 | }
|
---|