3 #include "fsck_helper.h"
5 /* this function is nasty. almost had to buy a bigger screen */
6 bool parse_clusters(uint32_t inodeidx
)
13 uint32_t ciurefs
[RPB
];
18 fetch_superblock(&sb
);
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
) {
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
);
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
);
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
);
46 cctable_get(cidx
, &ccstat
);
48 printf("Cluster number %d is used by inode %d but "
49 "is also a free cluster.\n", cidx
, inodeidx
);
51 } else if (ccstat
== bah
) {
52 cctable_set(cidx
, busy
);
54 printf("BUM! ERROR, trying to mark cluster number "
55 "%d serveral times in cctable when all else "
68 /* assumes inodes are sane */
69 testresult_t
test_clusterused(void)
77 fetch_superblock(&sb
);
80 for (r
= 0; (r
< sb
->itotal
) && (ret
!= corrupt
); ++r
) {
81 ictable_get(r
, &icstat
);
82 soReadInode(&inode
, r
);
85 if ((inode
.mode
& INODE_TYPE_MASK
& !INODE_FREE
) != 0) {
86 /* inode is dirty - check */
87 if (parse_clusters(r
) == false) ret
= corrupt
;
91 if (parse_clusters(r
) == false) ret
= corrupt
;
94 printf("BUM! test_clusterused assumes inodes are sane.\n");