/* -*- Mode: C++; tab-width: 8; c-basic-offset: 8 -*-
 *
 */

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "LFSFileSystem.h"
#include "Exception.h"

int
main(int /* argc */, char* argv[])
{
	int fd;
	if ((fd = open(argv[1], O_RDONLY)) < 0) {
		fprintf(stderr, "%s: unable to mount %s: %s\n",
			argv[0], argv[1], strerror(errno));

		return 1;
	}

	int error = 0;
	try {
		CLFSFileSystem fs(fd);
		fs.Mount();
		CLFSSMap* smap = fs.GetSMap();

		CIterator* it = smap->GetSegments();
		CLFSSegment* segment;
		while ((segment = (CLFSSegment*) it->NextElement()) != 0) {
			printf("%d,%d\n", segment->Number(), segment->UsedBlocks());
			delete segment;
		}
		delete it;
		delete smap;
	}
	catch (CException* ex) {
		fprintf(stderr, "%s: %s\n", argv[0], ex->GetMessage());
		delete ex;
	}
	close(fd);
	return error;
}

