1 /* $NetBSD: swap.c,v 1.19 2006/03/18 11:02:48 dsl Exp $ */
4 * Copyright (c) 1997 Matthew R. Green.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * Copyright (c) 1980, 1992, 1993
31 * The Regents of the University of California. All rights reserved.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. Neither the name of the University nor the names of its contributors
42 * may be used to endorse or promote products derived from this software
43 * without specific prior written permission.
45 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 #include <sys/cdefs.h>
61 static char sccsid
[] = "@(#)swap.c 8.3 (Berkeley) 4/29/95";
63 __RCSID("$NetBSD: swap.c,v 1.19 2006/03/18 11:02:48 dsl Exp $");
66 #include <sys/param.h>
78 void showspace(char *header
, int hlen
, long blocksize
);
80 static long blocksize
;
81 static int hlen
, nswap
, rnswap
;
83 static struct swapent
*swap_devices
;
89 return (subwin(stdscr
, -1, 0, 5, 0));
114 int update_label
= 0;
117 nswap
= swapctl(SWAP_NSWAP
, 0, 0);
119 error("error: %s", strerror(errno
));
122 update_label
= (nswap
!= rnswap
);
125 (void)free(swap_devices
);
126 if ((swap_devices
= malloc(nswap
* sizeof(*swap_devices
))) == NULL
) {
127 error("malloc failed");
131 if ((rnswap
= swapctl(SWAP_STATS
, (void *)swap_devices
, nswap
)) != nswap
) {
132 error("swapctl failed");
152 mvwprintw(wnd
, row
++, 0, "No swap");
155 header
= getbsize(&hlen
, &blocksize
);
156 mvwprintw(wnd
, row
++, 0, "%-5s%*s%9s %55s",
157 "Disk", hlen
, header
, "Used",
158 "/0% /10% /20% /30% /40% /50% /60% /70% /80% /90% /100%");
164 int col
, blk_div
, i
, avail
, used
, xsize
, swp_free
;
168 blk_div
= blocksize
/ 512;
169 swp_free
= avail
= 0;
170 for (sep
= swap_devices
, i
= 0; i
< nswap
; i
++, sep
++) {
171 p
= strrchr(sep
->se_path
, '/');
172 p
= p
? p
+1 : sep
->se_path
;
174 mvwprintw(wnd
, i
+ 1, 0, "%-5s", p
);
177 mvwprintw(wnd
, i
+ 1, col
, "%*d", hlen
, sep
->se_nblks
/ blk_div
);
180 xsize
= sep
->se_nblks
;
181 used
= sep
->se_inuse
;
183 swp_free
+= xsize
- used
;
184 mvwprintw(wnd
, i
+ 1, col
, "%9d ", used
/ blk_div
);
186 whline(wnd
, 'X', (100 * used
/ xsize
+ 1) / 2);
188 /* do total if necessary */
190 used
= avail
- swp_free
;
191 mvwprintw(wnd
, i
+ 1, 0, "%-5s%*d%9d ",
192 "Total", hlen
, avail
/ blk_div
, used
/ blk_div
);
194 whline(wnd
, 'X', (100 * used
/ avail
+ 1) / 2);