alloctest.c 1.11 KB
#include "testlib.c"

char pname[256];
char *myname;
char *dname = DEVICE_NAME;

#include "fillcard.c"

int
main(int argc, char **argv)
{
	BBCHandle h;
	int loops = 0;
	int cardsize, freeblks, reservedblks, badblks;
	int rv;
	int i = 0;

	myname = argv[0];
	if (argc > 1)
		dname = argv[argc - 1];

	while (1) {
		sprintf(pname, "%s(%d)", myname, ++loops);
		h = BBCInit(dname, BBC_SYNC);
		printf("%s: BBCInit(%s) returns %d\n", pname, dname, h);
		if (h < 0) continue;
		while (!BBCCardPresent(h)) {
			if ((++i & 0x1ff) == 0)
				printf("%s: no card present ... wait\n", pname);
		}
		printf("%s: card is present\n", pname);
		if (BBCStats(h, &cardsize, &reservedblks, &freeblks, &badblks) < 0) {
			BBCClose(h);
			continue;
		}
		printf("%s: BBCStats cardsize %d, freeblks %d\n", pname, cardsize, freeblks);
		printf("%s: format card ...\n", pname);
		rv = BBCSetLed(h, BBC_LED_ORANGE);
		rv = BBCFormatCard(h);
		printf("%s: BBCFormatCard returns %d\n", pname, rv);
		if (h < 0) continue;
		do_fill_card(h);
		rv = BBCSetLed(h, BBC_LED_GREEN);
		rv = BBCClose(h);
		printf("%s: BBCClose returns %d\n", pname, rv);
	}

	exit(0);
}