MCPcopy Create free account
hub / github.com/Gregwar/fatcat / nextCluster

Method nextCluster

src/core/FatSystem.cpp:199–259  ·  view source on GitHub ↗

* Returns the 32-bit fat value for the given cluster number */

Source from the content-addressed store, hash-verified

197 * Returns the 32-bit fat value for the given cluster number
198 */
199unsigned int FatSystem::nextCluster(unsigned int cluster, int fat)
200{
201 int bytes = (bits == 32 ? 4 : 2);
202#ifndef __WIN__
203 char buffer[bytes];
204#else
205 char *buffer = new char[bytes];
206 __try
207 {
208#endif
209
210 if (!validCluster(cluster)) {
211 return 0;
212 }
213
214 if (cacheEnabled) {
215 return cache[cluster];
216 }
217
218 readData(fatStart+fatSize*fat+(bits*cluster)/8, buffer, sizeof(buffer));
219
220 unsigned int next;
221
222 if (type == FAT32) {
223 next = FAT_READ_LONG(buffer, 0)&0x0fffffff;
224
225 if (next >= 0x0ffffff0) {
226 return FAT_LAST;
227 } else {
228 return next;
229 }
230 } else {
231 next = FAT_READ_SHORT(buffer,0)&0xffff;
232
233 if (bits == 12) {
234 int bit = cluster*bits;
235 if (bit%8 != 0) {
236 next = next >> 4;
237 }
238 next &= 0xfff;
239 if (next >= 0xff0) {
240 return FAT_LAST;
241 } else {
242 return next;
243 }
244 } else {
245 if (next >= 0xfff0) {
246 return FAT_LAST;
247 } else {
248 return next;
249 }
250 }
251 }
252#ifdef __WIN__
253}
254__finally
255{
256 delete[] buffer;

Callers 6

mainFunction · 0.80
compareMethod · 0.80
mergeMethod · 0.80
recursiveExplorationMethod · 0.80
findChainsMethod · 0.80
chainSizeMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected