Magellan Linux

Contents of /trunk/mkinitrd-magellan/busybox/procps/free.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 1753 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

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 *
7 * Licensed under the GPL version 2, see the file LICENSE in this tarball.
8 */
9
10 /* getopt not needed */
11
12 #include "busybox.h"
13
14 int free_main(int argc, char **argv)
15 {
16 struct sysinfo info;
17 sysinfo(&info);
18
19 /* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */
20 if (info.mem_unit==0) {
21 info.mem_unit=1;
22 }
23 if ( info.mem_unit == 1 ) {
24 info.mem_unit=1024;
25
26 /* TODO: Make all this stuff not overflow when mem >= 4 Gib */
27 info.totalram/=info.mem_unit;
28 info.freeram/=info.mem_unit;
29 #ifndef __uClinux__
30 info.totalswap/=info.mem_unit;
31 info.freeswap/=info.mem_unit;
32 #endif
33 info.sharedram/=info.mem_unit;
34 info.bufferram/=info.mem_unit;
35 } else {
36 info.mem_unit/=1024;
37 /* TODO: Make all this stuff not overflow when mem >= 4 Gib */
38 info.totalram*=info.mem_unit;
39 info.freeram*=info.mem_unit;
40 #ifndef __uClinux__
41 info.totalswap*=info.mem_unit;
42 info.freeswap*=info.mem_unit;
43 #endif
44 info.sharedram*=info.mem_unit;
45 info.bufferram*=info.mem_unit;
46 }
47
48 if (argc > 1 && **(argv + 1) == '-')
49 bb_show_usage();
50
51 printf("%6s%13s%13s%13s%13s%13s\n", "", "total", "used", "free",
52 "shared", "buffers");
53
54 printf("%6s%13ld%13ld%13ld%13ld%13ld\n", "Mem:", info.totalram,
55 info.totalram-info.freeram, info.freeram,
56 info.sharedram, info.bufferram);
57
58 #ifndef __uClinux__
59 printf("%6s%13ld%13ld%13ld\n", "Swap:", info.totalswap,
60 info.totalswap-info.freeswap, info.freeswap);
61
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);
65 #endif
66 return EXIT_SUCCESS;
67 }
68