maxfiles.c
1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#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);
}