MCPcopy Create free account
hub / github.com/PaulStoffregen/SerialFlash / readdir

Method readdir

SerialFlashDirectory.cpp:333–379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

331}
332
333bool SerialFlashChip::readdir(char *filename, uint32_t strsize, uint32_t &filesize)
334{
335 uint32_t maxfiles, index, straddr;
336 uint32_t i, n;
337 uint32_t buf[2];
338 uint16_t hash;
339 char str[16], *p=filename;
340
341 filename[0] = 0;
342 maxfiles = check_signature();
343 if (!maxfiles) return false;
344 maxfiles &= 0xFFFF;
345 index = dirindex;
346 while (1) {
347 if (index >= maxfiles) return false;
348 //Serial.printf("readdir, index = %u\n", index);
349 SerialFlash.read(8 + index * 2, &hash, 2);
350 if (hash != 0) break;
351 index++; // skip deleted entries
352 }
353 dirindex = index + 1;
354 buf[1] = 0;
355 SerialFlash.read(8 + 4 + maxfiles * 2 + index * 10, buf, 6);
356 if (buf[0] == 0xFFFFFFFF) return false;
357 filesize = buf[0];
358 straddr = 8 + maxfiles * 12 + buf[1] * 4;
359 //Serial.printf(" length = %u\n", buf[0]);
360 //Serial.printf(" straddr = %u\n", straddr);
361
362 while (strsize) {
363 n = strsize;
364 if (n > sizeof(str)) n = sizeof(str);
365 SerialFlash.read(straddr, str, n);
366 for (i=0; i < n; i++) {
367 *p++ = str[i];
368 if (str[i] == 0) {
369 //Serial.printf(" name = %s\n", filename);
370 return true;
371 }
372 }
373 strsize -= n;
374 straddr += n;
375 }
376 *(p - 1) = 0;
377 //Serial.printf(" name(overflow) = %s\n", filename);
378 return true;
379}
380
381
382void SerialFlashFile::erase()

Callers

nothing calls this directly

Calls 2

check_signatureFunction · 0.85
readMethod · 0.45

Tested by

no test coverage detected