Error messages altered.
[fsck.sofs09.git] / test_sbzones.c
blobae62c1551ee11f6cb514adef01fceb20621ee531
1 #include <stdio.h>
3 #include "fsck.h"
4 #include "fsck_helper.h"
5 #include "sofs09.h"
7 testresult_t test_sbzones (void)
9 testresult_t ret;
10 int r, s;
11 int nzones;
12 SOSuperBlock *sb;
14 fetch_superblock(&sb);
16 /* current position inside the disc, in blocks */
17 uint32_t cpos;
19 struct zone_s {
20 /* start position, in blocks, of this zone */
21 uint32_t start;
22 /* size, in blocks, of this zone */
23 uint32_t size;
24 /* zone name */
25 char *name;
27 struct zone_s zone[] = {
28 {sb->fctable_start, sb->fctable_size, "FCT"},
29 {sb->ciutable_start, sb->ciutable_size, "CIUT"},
30 {sb->itable_start, sb->itable_size, "IT"},
31 {sb->dzone_start, sb->dzone_size*BLOCKS_PER_CLUSTER, "DATA"},
33 struct zone_s tempzone;
35 ret = nice;
37 /* sort zones by start position (bubble sort) */
38 nzones = sizeof(zone)/sizeof(struct zone_s);
39 for (r = 0; r < nzones-1; ++r) {
40 for (s = r; s < nzones-1-r; ++s) {
41 if (zone[r].start > zone[r+1].start) {
42 tempzone = zone[r];
43 zone[r] = zone[r+1];
44 zone[r+1] = tempzone;
49 cpos = 0;
51 /* advance superblock */
52 cpos++;
54 for (r = 0; (r < nzones) && (ret != corrupt); ++r) {
55 if (cpos > zone[r].start) {
56 printf("Zones overlap.\n");
57 ret = corrupt;
58 } else {
59 if (cpos != zone[r].start) {
60 printf("Zones are not contiguous.\n");
61 cpos = zone[r].start;
62 ret = weird;
64 cpos += zone[r].size;
65 if (cpos > sb->ntotal) {
66 printf("Zones exceed disc size.\n");
67 ret = corrupt;
72 printf("Detected structure: ZONE_NAME (start,end)\n");
73 printf("0: SB (0,1) : ");
74 for (r = 0; r < nzones; ++r) {
75 printf("%s (%d,%d): ", zone[r].name, zone[r].start,
76 zone[r].start + zone[r].size);
78 printf("%d\n", sb->ntotal);
80 return ret;