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 static const int NCOLS
= 80;
26 /* Fetch current disc superblock.
27 * If the superblock was not read, it is read from disk.
28 * No changes to the superblock are monitored. It is assumed the superblock is
31 * argument sb is the address of a pointer to a SOSuperBlock
33 * The address to the superblock is placed in (*sb).
35 void fetch_superblock(SOSuperBlock
**sb
)
37 assert(&(*sb
) != NULL
);
39 static SOSuperBlock localsb
;
40 static bool localsb_valid
= 0;
43 if (localsb_valid
== false) {
44 fret
= soReadRawBlock(0, &localsb
);
45 if (fret
< 0) FABORT(fret
, "fetch_superblock");
52 /* Inode control table */
55 static bool ictable_valid
= false;
56 static uint32_t ictable_size
= 0;
58 void ictable_free(void)
60 assert(ictable_valid
== true);
63 ictable_valid
= false;
66 void ictable_create(void)
68 assert (ictable_valid
== false);
72 fetch_superblock(&sb
);
74 ictable
= malloc(sizeof(ic_t
)*(sb
->itotal
));
75 if (ictable
== NULL
) FABORT(errno
, "ictable_init");
77 ictable_size
= sb
->itotal
;
78 for (r
= 0; r
< ictable_size
; ++r
) {
85 void ictable_set(uint32_t index
, ic_t value
)
87 assert(ictable_valid
== true);
88 assert(index
< ictable_size
);
90 ictable
[index
] = value
;
93 void ictable_get(uint32_t index
, ic_t
*value
)
95 assert(value
!= NULL
);
96 assert(ictable_valid
== true);
97 assert(index
< ictable_size
);
99 (*value
) = ictable
[index
];
102 /* Cluster control table */
103 static cc_t
*cctable
;
104 static bool cctable_valid
= false;
105 static uint32_t cctable_size
= 0;
107 void cctable_free(void)
109 assert(cctable_valid
== true);
112 cctable_valid
= false;
115 void cctable_create(void)
117 assert (cctable_valid
== false);
121 fetch_superblock(&sb
);
123 cctable
= malloc(sizeof(cc_t
)*(sb
->dzone_size
));
124 if (cctable
== NULL
) FABORT(errno
, "cctable_init");
126 cctable_size
= sb
->dzone_size
;
127 for (r
= 0; r
< cctable_size
; ++r
) {
131 cctable_valid
= true;
134 void cctable_set(uint32_t index
, cc_t value
)
136 assert(cctable_valid
== true);
137 assert(index
< cctable_size
);
139 cctable
[index
] = value
;
142 void cctable_get(uint32_t index
, cc_t
*value
)
144 assert(value
!= NULL
);
145 assert(cctable_valid
== true);
146 assert(index
< cctable_size
);
148 (*value
) = cctable
[index
];
151 void cctable_print(void)
153 assert(cctable_valid
== true);
161 printf("\nCluster control table contents (\e[42mfree\e[m \e[44mbusy\e[m "
162 "\e[41munknown\e[m)\n");
163 for (r
= 0; r
< cctable_size
; ++r
) {
164 cctable_get(r
, &ccstat
);
176 if (((r
+1)%ncols
) == 0) printf("\e[m\n");
181 /* inode refcount table */
183 static uint32_t *irtable
;
184 static bool irtable_valid
= false;
185 static uint32_t irtable_size
= 0;
187 void irtable_free(void)
189 assert(irtable_valid
== true);
192 irtable_valid
= false;
195 void irtable_create(void)
197 assert (irtable_valid
== false);
201 fetch_superblock(&sb
);
203 irtable
= malloc(sizeof(uint32_t)*(sb
->itotal
));
204 if (irtable
== NULL
) FABORT(errno
, "irtable_init");
206 irtable_size
= sb
->itotal
;
207 for (r
= 0; r
< irtable_size
; ++r
) {
211 irtable_valid
= true;
214 void irtable_inc(uint32_t index
)
216 assert(irtable_valid
== true);
217 assert(index
< irtable_size
);
222 void irtable_get(uint32_t index
, uint32_t *value
)
224 assert(value
!= NULL
);
225 assert(irtable_valid
== true);
226 assert(index
< irtable_size
);
228 (*value
) = irtable
[index
];
231 void itable_print(void)
233 assert(ictable_valid
== true);
242 printf("\nInode control table contents (\e[42mfree\e[m \e[44mbusy\e[m "
243 "\e[41munknown\e[m)\n");
244 for (r
= 0; r
< ictable_size
; ++r
) {
245 ictable_get(r
, &icstat
);
246 irtable_get(r
, &refcount
);
249 printf("\e[42m%d", refcount
);
252 printf("\e[44m%d", refcount
);
255 printf("\e[41m%d", refcount
);
258 printf("\e[m\nBUM!\n");
260 if (((r
+1)%ncols
) == 0) printf("\e[m\n");