infree simplified, irtable_get corrected and sbname added.
[fsck.sofs09.git] / fsck.c
blob556b08b76fdc965020b53d6dc4b6d351feb899c3
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <errno.h>
5 /* open and close disc */
6 #include "sofs_rawdisc.h"
7 #include "fsck.h"
8 #include "fsck_helper.h"
9 #include "tests.h"
11 struct test_s {
12 testfunction_t function;
13 char *name;
15 typedef struct test_s test_t;
17 void main (int argc, char *argv[])
19 int ret;
20 char *disc_path;
21 testresult_t testres;
22 int r;
23 int nfuncs;
25 /* functions containing the tests to be made */
26 test_t test[] =
28 {test_sbmagic, "sbmagic"},
29 {test_sbname, "sbname"},
30 {test_sbzones, "sbzones"},
31 {test_sbfctablesize, "sbfctablesize"},
32 {test_sbciutablesize, "sbciutablesize"},
33 {test_sbitotal, "sbitotal"},
34 {test_infree, "infree"},
35 {test_inused, "inused"},
36 {test_inlost, "inlost"},
37 {test_clusterfree, "clusterfree"},
38 {test_clusterused, "clusterused"},
39 {test_clusterlost, "clusterlost"},
42 if (argc != 2) ABORT(-EINVAL);
43 nfuncs = sizeof(test)/sizeof(test_t);
44 disc_path = argv[1];
46 printf("Opening file %s as disc.\n", disc_path);
47 ret = soOpenDevice(disc_path);
48 if (ret < 0) ABORT(ret);
49 atexit((void *)soCloseDevice);
51 for (r = 0; r < nfuncs; ++r) {
52 testres = test[r].function();
53 switch (testres) {
54 case corrupt:
55 printf("System file corrupted.\n");
56 exit(EXIT_FAILURE);
57 break;
58 case weird:
59 printf("System file is weird.\n");
60 break;
61 case nice:
62 printf("Test %s passed with success.\n", test[r].name);
63 break;
64 default:
65 printf("BUM!\n");
66 exit(EXIT_FAILURE);
67 break;
71 cctable_print();
72 ictable_print();
74 exit(EXIT_SUCCESS);