1 /* This module implements functions that allow a controlled access to vital
4 * No function from this module returns if failure occurs.
5 * When something wrong occurs, the function aborts the program, immediately.
15 #include "fsck_helper.h"
18 void printError (int errcode
, char *cmd_name
)
20 fprintf(stderr
, "%s: error #%d: %s\n", cmd_name
, errcode
,\
24 /* Fetch current disc superblock.
25 * If the superblock was not read, it is read from disk.
26 * No changes to the superblock are monitored. It is assumed the superblock is
29 * argument sb is the address of a pointer to a SOSuperBlock
31 * The address to the superblock is placed in (*sb).
33 void fetch_superblock(SOSuperBlock
**sb
)
35 assert(&(*sb
) != NULL
);
37 static SOSuperBlock localsb
;
38 static bool localsb_valid
= 0;
41 if (localsb_valid
== false) {
42 fret
= soReadRawBlock(0, &localsb
);
43 if (fret
< 0) FABORT(fret
, "fetch_superblock");
50 /* Inode control table */
53 static bool ictable_valid
= false;
54 static uint32_t ictable_size
= 0;
56 void ictable_free(void)
58 assert(ictable_valid
== true);
61 ictable_valid
= false;
64 void ictable_create(void)
66 assert (ictable_valid
== false);
70 fetch_superblock(&sb
);
72 ictable
= malloc(sizeof(ic_t
)*(sb
->itotal
));
73 if (ictable
== NULL
) FABORT(errno
, "ictable_init");
75 ictable_size
= sb
->itotal
;
76 for (r
= 0; r
< ictable_size
; ++r
) {
83 void ictable_set(uint32_t index
, ic_t value
)
85 assert(ictable_valid
== true);
86 assert(index
< ictable_size
);
88 ictable
[index
] = value
;
91 void ictable_get(uint32_t index
, ic_t
*value
)
93 assert(value
!= NULL
);
94 assert(ictable_valid
== true);
95 assert(index
< ictable_size
);
97 (*value
) = ictable
[index
];
100 void ictable_print(void)
102 assert(ictable_valid
== true);
110 printf("\nInode control table contents (\e[42mfree\e[m \e[44mbusy\e[m "
111 "\e[41munknown\e[m)\n");
112 for (r
= 0; r
< ictable_size
; ++r
) {
113 ictable_get(r
, &icstat
);
125 printf("\e[m\nBUM!\n");
127 if (((r
+1)%ncols
) == 0) printf("\e[m\n");
132 /* Cluster control table */
133 static cc_t
*cctable
;
134 static bool cctable_valid
= false;
135 static uint32_t cctable_size
= 0;
137 void cctable_free(void)
139 assert(cctable_valid
== true);
142 cctable_valid
= false;
145 void cctable_create(void)
147 assert (cctable_valid
== false);
151 fetch_superblock(&sb
);
153 cctable
= malloc(sizeof(cc_t
)*(sb
->dzone_size
));
154 if (cctable
== NULL
) FABORT(errno
, "cctable_init");
156 cctable_size
= sb
->dzone_size
;
157 for (r
= 0; r
< cctable_size
; ++r
) {
161 cctable_valid
= true;
164 void cctable_set(uint32_t index
, cc_t value
)
166 assert(cctable_valid
== true);
167 assert(index
< cctable_size
);
169 cctable
[index
] = value
;
172 void cctable_get(uint32_t index
, cc_t
*value
)
174 assert(value
!= NULL
);
175 assert(cctable_valid
== true);
176 assert(index
< cctable_size
);
178 (*value
) = cctable
[index
];
181 void cctable_print(void)
183 assert(cctable_valid
== true);
191 printf("\nCluster control table contents (\e[42mfree\e[m \e[44mbusy\e[m "
192 "\e[41munknown\e[m)\n");
193 for (r
= 0; r
< cctable_size
; ++r
) {
194 cctable_get(r
, &ccstat
);
206 if (((r
+1)%ncols
) == 0) printf("\e[m\n");
211 /* inode refcount table */
213 static uint32_t *irtable
;
214 static bool irtable_valid
= false;
215 static uint32_t irtable_size
= 0;
217 void irtable_free(void)
219 assert(irtable_valid
== true);
222 irtable_valid
= false;
225 void irtable_create(void)
227 assert (irtable_valid
== false);
231 fetch_superblock(&sb
);
233 irtable
= malloc(sizeof(uint32_t)*(sb
->itotal
));
234 if (irtable
== NULL
) FABORT(errno
, "irtable_init");
236 irtable_size
= sb
->itotal
;
237 for (r
= 0; r
< irtable_size
; ++r
) {
241 irtable_valid
= true;
244 void irtable_inc(uint32_t index
)
246 assert(irtable_valid
== true);
247 assert(index
< irtable_size
);
252 void irtable_get(uint32_t index
, uint32_t *value
)
254 assert(value
!= NULL
);
255 assert(irtable_valid
== true);
256 assert(index
< irtable_size
);
258 (*value
) = irtable
[index
];