5 #include "fsck_helper.h"
7 static bool check_cluster(uint32_t cba
)
13 fetch_superblock(&sb
);
15 /* check if block address is inside data zone and if it is a valid
16 * cluster address (alignment) */
17 if (cba
< (sb
->dzone_start
) ||
18 cba
>= (sb
->dzone_start
) + (sb
->dzone_size
)*BLOCKS_PER_CLUSTER
||
19 ((cba
-(sb
->dzone_start
))%BLOCKS_PER_CLUSTER
) != 0)
21 printf("Member of free cluster list is not a valid cluster address, %u"
26 /* check if cluster was already marked */
27 ci
= (cba
-(sb
->dzone_start
))/BLOCKS_PER_CLUSTER
;
28 cctable_get(ci
, &ccstat
);
30 printf("Cluster number %u is used multiple times.\n", ci
);
35 cctable_set(ci
, idle
);
40 testresult_t
test_clusterfree (void)
44 uint32_t freeclusters
;
47 uint32_t cba
; /* cluster block address */
49 uint32_t cacheidx
, cachecnt
;
52 fetch_superblock(&sb
);
57 /* check fctable limits */
58 if ((sb
->fctable_head
) >= (sb
->fctable_size
)*RPB
) {
59 printf("fctable_head is out of bounds.\n");
62 if ((sb
->fctable_tail
) >= (sb
->fctable_size
)*RPB
) {
63 printf("fctable_tail is out of bounds.\n");
66 pos
= sb
->fctable_head
;
67 while (pos
!= sb
->fctable_tail
) {
68 fret
= soReadRawBlock((sb
->fctable_start
)+(pos
/RPB
), fcrefs
);
69 if (fret
< 0) FABORT(fret
, "sbfreeclusters");
71 cba
= fcrefs
[pos
%RPB
];
72 if (check_cluster(cba
) == true) {
75 printf("It was entry number %u of fctable.\n", pos
);
78 pos
= (pos
+1)%((sb
->fctable_size
)*RPB
);
81 /* check head cache */
82 cacheidx
= sb
->dzone_head
.cache_idx
;
83 cachecnt
= sb
->dzone_head
.cache_cnt
;
84 if (cacheidx
+ cachecnt
> DZONE_CACHE_SIZE
) {
85 printf("Head cache has incorrect information.\n");
88 for (r
= cacheidx
; r
< cacheidx
+ cachecnt
, ++r
) {
89 cba
= (sb
->dzone_head
.cache
)[r
];
90 if (check_cluster(cba
) == true) {
93 printf("It was entry number %u of dzone_head cache.\n", r
);
98 /* check tail cache */
100 cachecnt
= sb
->dzone_tail
.cache_cnt
;
101 if (cacheidx
+ cachecnt
>= DZONE_CACHE_SIZE
) {
102 printf("Tail cache has incorrect information.\n");
105 for (r
= cacheidx
; r
< cacheidx
+ cachecnt
; ++r
) {
106 cba
= (sb
->dzone_tail
.cache
)[r
];
107 if (check_cluster(cba
) == true) {
110 printf("It was entry number %u of dzone_tail cache.\n", r
);
115 if (freeclusters
!= sb
->dzone_free
) {
116 printf("donze_free is %u, should be %u.\n", sb
->dzone_free
,