#include "stdinc.h"
#include "dat.h"
#include "fns.h"
static void
usage(void)
{
fprint(2, "usage: %s [-c cachesize] [-h] file\n", argv0);
exits("usage");
}
void
main(int argc, char *argv[])
{
int csize;
int hflag;
Fs *fs;
u32int bused, btotal, bsize;
uvlong total, used, free;
csize = 1000;
hflag = 0;
ARGBEGIN{
case 'c':
csize = atoi(EARGF(usage()));
break;
case 'h':
hflag++;
break;
default:
usage();
}ARGEND
if(argc != 1)
usage();
vtAttach();
fmtinstall('R', vtErrFmt);
fs = fsOpen(argv[0], nil, csize, OReadOnly);
if(fs == nil)
vtFatal("could not open fs: %R");
cacheCountUsed(fs->cache, fs->elo, &bused, &btotal, &bsize);
total = (uvlong)btotal * bsize;
used = (uvlong)bused * bsize;
free = total - used;
if(hflag)
print("%,ulld used + %,ulld free = %,ulld (%.1f%% used)\n",
used, free, total, used*100.0/total);
else
print("%ulld\t%ulld\n", total, used);
fsClose(fs);
vtDetach();
exits(0);
}
|