1 /* $NetBSD: df.c,v 1.3 2005/08/01 02:38:03 xtraeme Exp $ */
4 * Copyright (c) 1980, 1992, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Hubert Feyrer <hubert@feyrer.de>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/cdefs.h>
36 __RCSID("$NetBSD: df.c,v 1.3 2005/08/01 02:38:03 xtraeme Exp $");
39 #include <sys/param.h>
41 #include <sys/mount.h>
53 static struct statvfs
*fss
;
54 static const char *nodisplay
[] = {"procfs", "kernfs", "ptyfs", "null", NULL
};
55 static int displayall
=0;
61 return (subwin(stdscr
, -1, 0, 5, 0));
82 int64_t used
, bsize
, bavail
, availblks
;
85 y
=2; /* at what line to start displaying */
86 for (i
=0; i
<nfss
; i
++) {
88 for(j
=0; nodisplay
[j
] != NULL
; j
++) {
89 if (strcmp(nodisplay
[j
],
90 fss
[i
].f_fstypename
) == 0) {
96 if (displayall
|| !skip
) {
100 snprintf(s
, sizeof(s
), "%s", fss
[i
].f_mntonname
);
101 mvwaddstr(wnd
, y
, 0, s
);
103 used
= fss
[i
].f_blocks
- fss
[i
].f_bfree
;
104 bavail
= fss
[i
].f_bavail
;
105 availblks
= bavail
+ used
;
106 bsize
= fss
[i
].f_frsize
;
108 if (availblks
== 0) {
109 pct
= 1.0; /* full pseudo-disk */
111 pct
= (1.0 * used
) / availblks
;
115 humanize_number(s2
, FREELEN
, bavail
*bsize
,
117 HN_B
| HN_NOSPACE
| HN_DECIMAL
);
118 snprintf(s
, sizeof(s
), "%*s", FREELEN
, s2
);
119 mvwaddstr(wnd
, y
, 25-FREELEN
, s
);
122 mvwhline(wnd
, y
, 25, 'X', (int)(51*pct
));
134 nfss
= getmntinfo(&fss
, MNT_NOWAIT
);
136 error("init: getmntinfo error");
140 mvwaddstr(wnd
, 0, 0, "Disk free %age:");
147 nfss
= getmntinfo(&fss
, MNT_NOWAIT
);
149 error("fetch: getmntinfo error");
159 mvwaddstr(wnd
, 0, 0, "Filesystem");
160 mvwaddstr(wnd
, 0, 18, "Avail");
161 mvwaddstr(wnd
, 0, 26, "Capacity");
162 mvwaddstr(wnd
, 1, 25, "/0% /10% /20% /30% /40% /50% /60% /70% /80% /90% /100%");