code: mafs

ref: eef0fe67ee4bb8c254f0f9e61c24ef5d34d05a4f
dir: /tests/testextents.c/

View raw version
#include <u.h>
#include <libc.h>
#include "../dat.h"
#include "../extents.h"
#include <bio.h>

/*
	test the extents functionality
	{ echo 2 3 ; echo 100 3; } | ./6.testextents
 */

int chatty9p = 0;

static void
usage(void)
{
	fprint(2, "usage: testextents [-D ]\n");
	exits("usage");
}

void
main(int argc, char *argv[])
{
	Extents es;
	s8 *line, *p;
	Biobuf *bp;
	u64 bno, len;

	ARGBEGIN{
	default:	usage();
	case 'D':	chatty9p=6; break;
	}ARGEND

	if(argc != 0)
		usage();

	bp = Bfdopen(0, OREAD);
	Blethal(bp, nil);

	while((line = Brdstr(bp, '\n', 1)) != nil) {
		bno = strtoull(line, &p, 10);
		p++;	/* for the space */
		len = strtoull(p, nil, 10);
		bfree(&es, bno, len);
		free(line);
	}

	showextents(1, "", &es);

	/* why bother? just exits(nil) as cinap suggests */
	Bterm(bp);
	exits(nil);
}