+ /* calculate first device on which this falls */
+ i = (s / dmmax) % nswdev;
+ while (s < e) { /* XXX this is inefficient */
+ int bound = roundup(s+1, dmmax);
+
+ if (bound > e)
+ bound = e;
+ perdev[i] += bound - s;
+ if (++i >= nswdev)
+ i = 0;
+ s = bound;
+ }
+ }
+
+ header = getbsize(&hlen, &blocksize);
+ if (!totalflag)
+ (void)printf("%-10s %*s %10s %10s %10s\n",
+ "Device", hlen, header, "Used", "Available", "Capacity");
+ div = blocksize / 512;
+ avail = npfree = 0;
+ for (i = 0; i < nswdev; i++) {
+ int xsize, xfree;
+
+ if (!totalflag)
+ (void)printf("/dev/%-5s %*d ",
+ devname(sw[i].sw_dev, S_IFBLK),
+ hlen, sw[i].sw_nblks / div);
+
+ /*
+ * Don't report statistics for partitions which have not
+ * yet been activated via swapon(8).
+ */
+ if (!sw[i].sw_freed) {
+ if (totalflag)
+ continue;
+ (void)printf(" *** not available for swapping ***\n");
+ continue;
+ }
+ xsize = sw[i].sw_nblks;
+ xfree = perdev[i];
+ used = xsize - xfree;
+ npfree++;
+ avail += xsize;
+ if (totalflag)
+ continue;
+ (void)printf("%10d %10d %7.0f%%\n",
+ used / div, xfree / div,
+ (double)used / (double)xsize * 100.0);
+ }
+
+ /*
+ * If only one partition has been set up via swapon(8), we don't
+ * need to bother with totals.
+ */
+ used = avail - nfree;
+ if (totalflag) {
+ (void)printf("%dM/%dM swap space\n", used / 2048, avail / 2048);
+ return;
+ }
+ if (npfree > 1) {
+ (void)printf("%-10s %*d %10d %10d %7.0f%%\n",
+ "Total", hlen, avail / div, used / div, nfree / div,
+ (double)used / (double)avail * 100.0);
+ }