maxfiles.c 1.94 KB
#include "testlib.c"

char *pname;
char *dname = "/dev/usb/bbrdb0";
char *uname = "user.sys";
char *tname = "tix.sys";

static void
do_fill_card(BBCHandle h)
{
	int rv;
	int cid;
	int errs = 0;
	char fname[32];
	char bbname[32];
	int len = 0;
	int cardsize, freeblks, reservedblks, badblks;

	for (cid = 0; ; cid++) {
		rv = BBCStats(h, &cardsize, &reservedblks, &freeblks, &badblks);
		printf("%s: BBCStats returns %d, cardsize %d, freeblks %d\n", pname, rv, cardsize, freeblks);
		if (rv < 0) break;
		if (freeblks == 0) {
		        printf("%s: card is full ... check files\n", pname);
			break;
		}
		len += BLK_SIZE;
		if (len > 8*BLK_SIZE)
			len = BLK_SIZE;
		sprintf(fname, "testfile.%d", cid);
		printf("%s: create content file %s, len %d\n", pname, fname, len);
		mkfile(fname, len);
		if ((rv = storecont(h, fname, cid)) < 0) {
			printf("%s: storecont %s fails: %d\n", pname, fname, rv);
			break;
		}
	}

	printf("%s: check all content files\n", pname);
	while (--cid >= 0) {
		sprintf(fname, "testfile.%d", cid);
		sprintf(bbname, "%08x.app", cid);
		rv = cmpfile(h, fname, bbname);
		if (rv != 0) {
			errs++;
			printf("%s: miscompare files %s, %s\n", pname, fname, bbname);
		}
	}
	if (errs > 0) {
		printf("%s: total %d miscompares, exiting\n", pname, errs);
		exit(1);
	}
	return;
}

int
main(int argc, char **argv)
{
	BBCHandle h;
	int rv;

	pname = argv[0];
	if (argc > 1)
		dname = argv[argc - 1];
	setbuf(stdout, NULL);
	setbuf(stderr, NULL);

	while (1) {
		h = BBCInit(dname, BBC_SYNC);
		printf("%s: BBCInit(%s) returns %d\n", pname, dname, h);
		if (h < 0) continue;
		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_OFF);
		rv = BBCClose(h);
		printf("%s: BBCClose returns %d\n", pname, rv);
#if 0
		printf("%s: exit to check status!\n", pname);
		exit(1);
#endif
	}

	exit(0);
}