MCPcopy Create free account
hub / github.com/bfbbdecomp/bfbb / VerifyFAT

Function VerifyFAT

src/dolphin/src/card/CARDCheck.c:131–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129}
130
131static s32 VerifyFAT(CARDControl* card, int* outCurrent)
132{
133 u16* fat[2];
134 u16* fatp;
135 u16 nBlock;
136 u16 cFree;
137 int i;
138 u16 checkSum;
139 u16 checkSumInv;
140 int errors;
141 int current;
142
143 current = errors = 0;
144 for (i = 0; i < 2; i++)
145 {
146 fatp = fat[i] = (u16*)((u8*)card->workArea + (3 + i) * CARD_SYSTEM_BLOCK_SIZE);
147
148 __CARDCheckSum(&fatp[CARD_FAT_CHECKCODE], CARD_SYSTEM_BLOCK_SIZE - sizeof(u32), &checkSum,
149 &checkSumInv);
150 if (fatp[CARD_FAT_CHECKSUM] != checkSum || fatp[CARD_FAT_CHECKSUMINV] != checkSumInv)
151 {
152 ++errors;
153 current = i;
154 card->currentFat = 0;
155 continue;
156 }
157
158 cFree = 0;
159 for (nBlock = CARD_NUM_SYSTEM_BLOCK; nBlock < card->cBlock; nBlock++)
160 {
161 if (fatp[nBlock] == CARD_FAT_AVAIL)
162 {
163 cFree++;
164 }
165 }
166 if (cFree != fatp[CARD_FAT_FREEBLOCKS])
167 {
168 ++errors;
169 current = i;
170 card->currentFat = 0;
171 continue;
172 }
173 }
174
175 if (0 == errors)
176 {
177 if (card->currentFat == 0)
178 {
179 if (((s16)fat[0][CARD_FAT_CHECKCODE] - (s16)fat[1][CARD_FAT_CHECKCODE]) < 0)
180 {
181 current = 0;
182 }
183 else
184 {
185 current = 1;
186 }
187 card->currentFat = fat[current];
188 memcpy(fat[current], fat[current ^ 1], CARD_SYSTEM_BLOCK_SIZE);

Callers 2

__CARDVerifyFunction · 0.85
CARDCheckExAsyncFunction · 0.85

Calls 2

__CARDCheckSumFunction · 0.85
memcpyFunction · 0.85

Tested by

no test coverage detected