Annotation of /trunk/mkinitrd-magellan/busybox/procps/free.c
Parent Directory | Revision Log
Revision 1520 -
(hide annotations)
(download)
Wed Sep 7 18:39:43 2011 UTC (12 years, 8 months ago) by niro
File MIME type: text/plain
File size: 1862 byte(s)
Wed Sep 7 18:39:43 2011 UTC (12 years, 8 months ago) by niro
File MIME type: text/plain
File size: 1862 byte(s)
-fixed build against linux-3.0
1 | niro | 532 | /* 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 | * | ||
7 | * Licensed under the GPL version 2, see the file LICENSE in this tarball. | ||
8 | */ | ||
9 | |||
10 | /* getopt not needed */ | ||
11 | |||
12 | niro | 816 | #include "libbb.h" |
13 | niro | 1520 | #include <sys/sysinfo.h> |
14 | niro | 532 | |
15 | niro | 816 | int free_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
16 | niro | 1123 | int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM)) |
17 | niro | 532 | { |
18 | struct sysinfo info; | ||
19 | niro | 1123 | unsigned mem_unit; |
20 | |||
21 | #if ENABLE_DESKTOP | ||
22 | if (argv[1] && argv[1][0] == '-') | ||
23 | bb_show_usage(); | ||
24 | #endif | ||
25 | |||
26 | niro | 532 | sysinfo(&info); |
27 | |||
28 | /* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */ | ||
29 | niro | 1123 | mem_unit = 1; |
30 | if (info.mem_unit != 0) { | ||
31 | mem_unit = info.mem_unit; | ||
32 | niro | 532 | } |
33 | |||
34 | niro | 1123 | /* Convert values to kbytes */ |
35 | if (mem_unit == 1) { | ||
36 | info.totalram >>= 10; | ||
37 | info.freeram >>= 10; | ||
38 | #if BB_MMU | ||
39 | info.totalswap >>= 10; | ||
40 | info.freeswap >>= 10; | ||
41 | niro | 532 | #endif |
42 | niro | 1123 | info.sharedram >>= 10; |
43 | info.bufferram >>= 10; | ||
44 | niro | 532 | } else { |
45 | niro | 1123 | mem_unit >>= 10; |
46 | /* TODO: Make all this stuff not overflow when mem >= 4 Tb */ | ||
47 | info.totalram *= mem_unit; | ||
48 | info.freeram *= mem_unit; | ||
49 | #if BB_MMU | ||
50 | info.totalswap *= mem_unit; | ||
51 | info.freeswap *= mem_unit; | ||
52 | niro | 532 | #endif |
53 | niro | 1123 | info.sharedram *= mem_unit; |
54 | info.bufferram *= mem_unit; | ||
55 | niro | 532 | } |
56 | |||
57 | niro | 1123 | printf(" %13s%13s%13s%13s%13s\n", |
58 | "total", | ||
59 | "used", | ||
60 | "free", | ||
61 | "shared", "buffers" /* swap and total don't have these columns */ | ||
62 | ); | ||
63 | printf("%6s%13lu%13lu%13lu%13lu%13lu\n", "Mem:", | ||
64 | info.totalram, | ||
65 | info.totalram - info.freeram, | ||
66 | info.freeram, | ||
67 | info.sharedram, info.bufferram | ||
68 | ); | ||
69 | #if BB_MMU | ||
70 | printf("%6s%13lu%13lu%13lu\n", "Swap:", | ||
71 | info.totalswap, | ||
72 | info.totalswap - info.freeswap, | ||
73 | info.freeswap | ||
74 | ); | ||
75 | printf("%6s%13lu%13lu%13lu\n", "Total:", | ||
76 | info.totalram + info.totalswap, | ||
77 | (info.totalram - info.freeram) + (info.totalswap - info.freeswap), | ||
78 | info.freeram + info.freeswap | ||
79 | ); | ||
80 | niro | 532 | #endif |
81 | return EXIT_SUCCESS; | ||
82 | } |