code: mafs

ref: fb53d7e68bcb2108fb304c81dccb1d7ff50ffa1f
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=8; break;
	}ARGEND

	if(argc != 0)
		usage();

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

	initextents(&es, "testextents", 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);
}