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.\n");
25 /* check if cluster was already marked */
26 ci
= (cba
-(sb
->dzone_start
))/BLOCKS_PER_CLUSTER
;
27 cctable_get(ci
, &ccstat
);
29 printf("Cluster number %d is used multiple times.\n", ci
);
34 cctable_set(ci
, idle
);
39 testresult_t
test_clusterfree (void)
43 uint32_t freeclusters
;
46 uint32_t cba
; /* cluster block address */
48 uint32_t cacheidx
, cachecnt
;
51 fetch_superblock(&sb
);
56 /* check fctable limits */
57 if ((sb
->fctable_head
) >= (sb
->fctable_size
)*RPB
) {
58 printf("fctable_head is out of bounds.\n");
61 if ((sb
->fctable_tail
) >= (sb
->fctable_size
)*RPB
) {
62 printf("fctable_tail is out of bounds.\n");
65 pos
= sb
->fctable_head
;
66 while ((pos
!= sb
->fctable_tail
) && (ret
!= corrupt
)) {
67 fret
= soReadRawBlock((sb
->fctable_start
)+(pos
/RPB
), fcrefs
);
68 if (fret
< 0) FABORT(fret
, "sbfreeclusters");
70 cba
= fcrefs
[pos
%RPB
];
71 if (check_cluster(cba
) == true) {
76 pos
= (pos
+1)%((sb
->fctable_size
)*RPB
);
79 /* check head cache */
80 cacheidx
= sb
->dzone_head
.cache_idx
;
81 cachecnt
= sb
->dzone_head
.cache_cnt
;
82 if ((cacheidx
+ cachecnt
> DZONE_CACHE_SIZE
) && (ret
!= corrupt
)) {
83 printf("Head cache has incorrect information.\n");
86 for (r
= cacheidx
; (r
< cacheidx
+ cachecnt
) && (ret
!= corrupt
); ++r
) {
87 cba
= (sb
->dzone_head
.cache
)[r
];
88 if (check_cluster(cba
) == true) {
95 /* check tail cache */
97 cachecnt
= sb
->dzone_tail
.cache_cnt
;
98 if ((cacheidx
+ cachecnt
>= DZONE_CACHE_SIZE
) && (ret
!= corrupt
)) {
99 printf("Tail cache has incorrect information.\n");
102 for (r
= cacheidx
; (r
< cacheidx
+ cachecnt
) && (ret
!= corrupt
); ++r
) {
103 cba
= (sb
->dzone_head
.cache
)[r
];
104 if (check_cluster(cba
) == true) {
111 if ((ret
!= corrupt
) && (freeclusters
!= sb
->dzone_free
)) {
112 printf("donze_free is not correct.\n");