Some messages altered.
[fsck.sofs09.git] / test_clusterused.c
blob349a1704a4cb83233b2193c8e64fbede81a3f857
1 #include "sofs09.h"
2 #include "fsck.h"
3 #include "fsck_helper.h"
5 /* this function is nasty. almost had to buy a bigger screen */
6 bool parse_clusters(uint32_t inodeidx)
8 bool ret;
9 uint32_t cn;
10 uint32_t clucount;
11 uint32_t pcn;
12 uint32_t cidx;
13 uint32_t ciurefs[RPB];
14 cc_t ccstat;
15 uint32_t fret;
16 SOSuperBlock *sb;
18 fetch_superblock(&sb);
19 ret = true;
21 for (cn = 0; cn < MAX_FILE_CLUSTERS; cn++) {
22 fret = soHandleFileCluster(inodeidx, cn, OP_GET, &pcn);
23 if (fret < 0) FABORT(fret, "parse_cluster");
24 if (pcn != NULL_BLOCK) {
25 clucount++;
26 /* check alignment */
27 if ((pcn-(sb->dzone_start))%(BLOCKS_PER_CLUSTER)) {
28 printf("Cluster number %d of inode number %d points to "
29 "unaligned block.\n", cn, inodeidx);
30 ret = false;
31 } else {
32 /* overflow is irrelevant here */
33 cidx = (pcn-(sb->dzone_start))/(BLOCKS_PER_CLUSTER);
34 if (cidx >= sb->dzone_size) {
35 printf("Cluster number %d of inode number %d points to"
36 "a place outside data zone.\n", cn, inodeidx);
37 ret = false;
38 } else {
39 soReadRawBlock(sb->ciutable_start+(cidx/RPB), ciurefs);
40 if (ciurefs[cidx%RPB] != inodeidx) {
41 printf("Entry in CIUT for cluster number %d points to "
42 "inode %d, bot it is used by inode %d.\n", cidx,
43 ciurefs[cidx%RPB], inodeidx);
44 ret = false;
45 } else {
46 cctable_get(cidx, &ccstat);
47 if (ccstat == idle) {
48 printf("Cluster number %d is used by inode %d but "
49 "is also a free cluster.\n", cidx, inodeidx);
50 ret = false;
51 } else if (ccstat == bah) {
52 cctable_set(cidx, busy);
53 } else {
54 printf("BUM! ERROR, trying to mark cluster number "
55 "%d serveral times in cctable when all else "
56 "is good.\n", cidx);
57 ret = false;
65 return ret;
68 /* assumes inodes are sane */
69 testresult_t test_clusterused(void)
71 testresult_t ret;
72 ic_t icstat;
73 SOSuperBlock *sb;
74 SOInode inode;
75 uint32_t r;
77 fetch_superblock(&sb);
78 ret = nice;
80 for (r = 0; (r < sb->itotal) && (ret != corrupt); ++r) {
81 ictable_get(r, &icstat);
82 soReadInode(&inode, r);
83 switch (icstat) {
84 case idle:
85 if ((inode.mode & INODE_TYPE_MASK & !INODE_FREE) != 0) {
86 /* inode is dirty - check */
87 if (parse_clusters(r) == false) ret = corrupt;
89 break;
90 case busy:
91 if (parse_clusters(r) == false) ret = corrupt;
92 break;
93 default:
94 printf("BUM! test_clusterused assumes inodes are sane.\n");
95 ret = corrupt;
96 break;
100 return ret;