2013-08-06 07:16:27 -04:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#include <sys/statvfs.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2013-08-14 09:19:05 -04:00
|
|
|
#include "grabmntinfo.h"
|
2013-08-06 07:16:27 -04:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
static void mnt_show(const char *fsname, const char *dir);
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2013-09-01 12:53:21 -04:00
|
|
|
eprintf("usage: %s [-a]\n", argv0);
|
2013-08-06 07:16:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct mntinfo *minfo = NULL;
|
|
|
|
int siz, i;
|
|
|
|
|
|
|
|
ARGBEGIN {
|
|
|
|
case 'a':
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
case 'h':
|
|
|
|
case 'i':
|
|
|
|
eprintf("not implemented\n");
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
|
|
|
|
|
|
|
printf("Filesystem 512-blocks Used Avail Capacity Mounted on\n");
|
|
|
|
siz = grabmntinfo(&minfo);
|
|
|
|
if (!siz)
|
|
|
|
eprintf("grabmntinfo:");
|
|
|
|
|
2014-01-25 17:34:05 -05:00
|
|
|
for (i = 0; i < siz; i++) {
|
2013-08-06 07:16:27 -04:00
|
|
|
mnt_show(minfo[i].fsname, minfo[i].mntdir);
|
2014-01-25 17:34:05 -05:00
|
|
|
free(minfo[i].fsname);
|
|
|
|
free(minfo[i].mntdir);
|
|
|
|
}
|
2013-08-06 07:16:27 -04:00
|
|
|
free(minfo);
|
|
|
|
|
2013-10-07 14:11:40 -04:00
|
|
|
return EXIT_SUCCESS;
|
2013-08-06 07:16:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mnt_show(const char *fsname, const char *dir)
|
|
|
|
{
|
|
|
|
struct statvfs s;
|
|
|
|
unsigned long long total, used, avail;
|
|
|
|
int capacity = 0;
|
|
|
|
int bs;
|
|
|
|
|
|
|
|
statvfs(dir, &s);
|
|
|
|
|
|
|
|
bs = s.f_frsize / 512;
|
|
|
|
total = s.f_blocks * bs;
|
|
|
|
avail = s.f_bfree * bs;
|
|
|
|
used = total - avail;
|
|
|
|
|
|
|
|
if (used + avail) {
|
|
|
|
capacity = (used * 100) / (used + avail);
|
|
|
|
if (used * 100 != capacity * (used + avail))
|
|
|
|
capacity++;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("%-12s %9llu %9llu %9llu %7d%% %s\n",
|
|
|
|
fsname, total, used, avail, capacity,
|
|
|
|
dir);
|
|
|
|
}
|