Subject: bin/175: swapinfo(1) doesn't respect BLOCKSIZE environment variable
To: None <gnats-admin>
From: None <thomas@mathematik.uni-Bremen.de>
List: netbsd-bugs
Date: 03/22/1994 16:05:02
>Number: 175
>Category: bin
>Synopsis: swapinfo(1) doesn't respect BLOCKSIZE environment variable
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: gnats-admin (Utility Bug People)
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Tue Mar 22 16:05:01 1994
>Originator: Thomas Eberhardt
>Organization:
CeVis, University of Bremen, Germany
>Release:
>Environment:
System: NetBSD ed209 0.9a ED209#0 i386
Machine: i386
>Description:
swapinfo(1) doesn't respect BLOCKSIZE environment variable since
it doesn't use getbsize(3).
>How-To-Repeat:
env BLOCKSIZE=2048 swapinfo
>Fix:
Below are patches for swapinfo(1) to use getbsize(3) and to make it's
output appear more like df(1).
*** swapinfo.1- Fri Dec 17 08:31:14 1993
--- swapinfo.1 Wed Mar 23 00:45:12 1994
***************
*** 6,14 ****
.Nd display free swap space
.Sh SYNOPSIS
.Nm swapinfo
! .Op Fl k
! .Op Fl m
! .Op Fl n
.Sh DESCRIPTION
.Nm Swapinfo
displays statistics about the amount of free swap space on all of the
--- 6,14 ----
.Nd display free swap space
.Sh SYNOPSIS
.Nm swapinfo
! .Op Fl kmn
! .Op Fl M Ar core
! .Op Fl N Ar system
.Sh DESCRIPTION
.Nm Swapinfo
displays statistics about the amount of free swap space on all of the
***************
*** 25,30 ****
--- 25,37 ----
Show the contents of the system swap map.
.It Fl n
Do not print swap device statistics.
+ .It Fl M
+ Extract values associated with the name list from the specified core
+ instead of the default
+ .Dq Pa /dev/kmem .
+ .It Fl N
+ Extract the name list from the specified system instead of the default
+ .Dq Pa /netbsd .
.El
.Sh STATISTICS
Statistics are reported for all swap partitions configured into the kernel.
***************
*** 32,38 ****
the total space available in the partition. The
.Ar Used
column indicates the total blocks used so far; the
! .Ar Available
column indicates how much space is remaining on each partition.
The
.Ar Capacity
--- 39,45 ----
the total space available in the partition. The
.Ar Used
column indicates the total blocks used so far; the
! .Ar Avail
column indicates how much space is remaining on each partition.
The
.Ar Capacity
***************
*** 55,60 ****
--- 62,76 ----
.Ar End
columns are the start and end of the entry, respectively. All values
are printed in units of blocks.
+ .Sh ENVIRONMENTAL VARIABLES
+ .Bl -tag -width BLOCKSIZE
+ .It Ev BLOCKSIZE
+ If the environmental variable
+ .Ev BLOCKSIZE
+ is set, and the
+ .Fl k
+ option is not specified, the block counts will be displayed in units of that
+ size block.
.Sh "BUGS AND CAVEATS"
Statistics are reported for all swap partitions compiled into the kernel,
regardless of whether those partitions are being used.
*** swapinfo.c- Fri Dec 17 08:31:14 1993
--- swapinfo.c Wed Mar 23 00:41:17 1994
***************
*** 27,33 ****
#include <unistd.h>
extern char *devname __P((int, int));
! void showspace __P((long blocksize));
int showmap; /* show the contents of the swap map */
int nosum; /* don't show totals */
--- 27,33 ----
#include <unistd.h>
extern char *devname __P((int, int));
! void showspace __P((int kflag));
int showmap; /* show the contents of the swap map */
int nosum; /* don't show totals */
***************
*** 53,68 ****
char **argv;
{
char *memf, *nlistf;
! int ch, i;
! long blocksize = 512;
char errbuf[256];
memf = nlistf = NULL;
while ((ch = getopt(argc, argv, "kmnM:N:")) != EOF) {
switch (ch) {
case 'k':
! blocksize = 1024;
break;
case 'm':
--- 53,68 ----
char **argv;
{
char *memf, *nlistf;
! int ch, i, kflag;
char errbuf[256];
memf = nlistf = NULL;
+ kflag = 0;
while ((ch = getopt(argc, argv, "kmnM:N:")) != EOF) {
switch (ch) {
case 'k':
! kflag = 1;
break;
case 'm':
***************
*** 83,89 ****
case '?':
default:
! errx(1, "usage: swapinfo [-M memfile] [-N kernel]\n");
}
}
argc -= optind;
--- 83,89 ----
case '?':
default:
! errx(1, "usage: swapinfo [-kmn] [-M memfile] [-N kernel]\n");
}
}
argc -= optind;
***************
*** 100,106 ****
(void)fprintf(stderr, "\n");
exit(1);
}
! showspace(blocksize);
exit(0);
}
--- 100,106 ----
(void)fprintf(stderr, "\n");
exit(1);
}
! showspace(kflag);
exit(0);
}
***************
*** 114,121 ****
errx(1, "cannot read %s: %s", msg, kvm_geterr())
void
! showspace(blocksize)
! long blocksize;
{
int nswap, nswdev, dmmax, nswapmap;
int s, e, div, i, ind, avail, nfree, npfree, used;
--- 114,121 ----
errx(1, "cannot read %s: %s", msg, kvm_geterr())
void
! showspace(kflag)
! int kflag;
{
int nswap, nswdev, dmmax, nswapmap;
int s, e, div, i, ind, avail, nfree, npfree, used;
***************
*** 123,128 ****
--- 123,138 ----
long *perdev;
struct map *swapmap, *kswapmap;
struct mapent *mp;
+ long blocksize;
+ int width, maxwidth, headerlen;
+ char *header;
+
+ if (kflag) {
+ blocksize = 1024;
+ header = "1K-blocks";
+ headerlen = strlen(header);
+ } else
+ header = getbsize(&headerlen, &blocksize);
div = blocksize / 512; /* printing routines use this */
***************
*** 196,210 ****
if (showmap)
printf("\n");
! (void)printf("%-10s %4d-blocks %10s %10s %10s\n",
! "Device", blocksize, "Used", "Available", "Capacity");
avail = npfree = 0;
for (i = 0; i < nswdev; i++) {
int xsize, xfree;
! (void)printf("/dev/%-5s %11d ",
devname(sw[i].sw_dev, S_IFBLK),
! sw[i].sw_nblks / div);
/*
* Don't report statistics for partitions which have not
--- 206,230 ----
if (showmap)
printf("\n");
! maxwidth = 0;
! for (i = 0; i < nswdev; i++) {
! width = strlen(devname(sw[i].sw_dev, S_IFBLK)) + 5;
! if (width > maxwidth)
! maxwidth = width;
! }
! if (maxwidth < 7)
! maxwidth = 7;
!
! (void)printf("%-*.*s %s Used Avail Capacity\n",
! maxwidth, maxwidth, "Device", header);
avail = npfree = 0;
for (i = 0; i < nswdev; i++) {
int xsize, xfree;
! (void)printf("/dev/%-*.*s %*d ",
! maxwidth - 5, maxwidth - 5,
devname(sw[i].sw_dev, S_IFBLK),
! headerlen, sw[i].sw_nblks / div);
/*
* Don't report statistics for partitions which have not
***************
*** 217,223 ****
xsize = sw[i].sw_nblks;
xfree = perdev[i];
used = xsize - xfree;
! (void)printf("%10d %10d %7.0f%%\n",
used / div, xfree / div,
(double)used / (double)xsize * 100.0);
npfree++;
--- 237,243 ----
xsize = sw[i].sw_nblks;
xfree = perdev[i];
used = xsize - xfree;
! (void)printf("%7d %7d %5.0f%%\n",
used / div, xfree / div,
(double)used / (double)xsize * 100.0);
npfree++;
***************
*** 231,238 ****
if (npfree > 1) {
used = avail - nfree;
! (void)printf("%-10s %11d %10d %10d %7.0f%%\n",
! "Total", avail / div, used / div, nfree / div,
(double)used / (double)avail * 100.0);
}
}
--- 251,258 ----
if (npfree > 1) {
used = avail - nfree;
! (void)printf("%-10s %*d %7d %7d %5.0f%%\n",
! "Total", headerlen, avail / div, used / div, nfree / div,
(double)used / (double)avail * 100.0);
}
}
>Audit-Trail:
>Unformatted:
------------------------------------------------------------------------------