Plan 9 from Bell Labs’s /usr/web/sources/contrib/stallion/src/fossil/df.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#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);
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.