MCPcopy Create free account
hub / github.com/Duet3D/RepRapFirmware / Read

Method Read

src/Storage/FileStore.cpp:383–432  ·  view source on GitHub ↗

Returns the number of bytes read or -1 if the read process failed

Source from the content-addressed store, hash-verified

381
382// Returns the number of bytes read or -1 if the read process failed
383int FileStore::Read(char *_ecv_array extBuf, size_t nBytes) noexcept
384{
385 switch (usageMode)
386 {
387 case FileUseMode::free:
388 REPORT_INTERNAL_ERROR;
389 return -1;
390
391 case FileUseMode::readOnly:
392 case FileUseMode::readWrite:
393#if HAS_SBC_INTERFACE
394 if (reprap.UsingSbcInterface())
395 {
396 int bytesRead = reprap.GetSbcInterface().ReadFile(handle, extBuf, nBytes);
397 if (bytesRead > 0)
398 {
399 offset += bytesRead;
400 }
401 return bytesRead;
402 }
403#endif
404#if HAS_MASS_STORAGE
405 {
406 UINT bytes_read;
407 const FRESULT readStatus = f_read(&file, extBuf, nBytes, &bytes_read);
408 if (readStatus != FR_OK)
409 {
410 reprap.GetPlatform().MessageF(ErrorMessage, "Cannot read file, error code %d\n", (int)readStatus);
411 return -1;
412 }
413 return (int)bytes_read;
414 }
415#elif HAS_EMBEDDED_FILES
416 {
417 const int ret = EmbeddedFiles::Read(fileIndex, offset, extBuf, nBytes);
418 if (ret > 0)
419 {
420 offset += ret;
421 }
422 return ret;
423 }
424#else
425 return -1;
426#endif
427
428 case FileUseMode::invalidated:
429 default:
430 return -1;
431 }
432}
433
434// As Read but stop after '\n' or '\r\n' and null-terminate the string.
435// If the next line is too long to fit in the buffer then the line will be split.

Callers 14

ReadFromFileMethod · 0.45
SendFileCredentialMethod · 0.45
flashWriteBlockMethod · 0.45
AdvanceHashMethod · 0.45
RunStateMachineMethod · 0.45
ReadFromFileMethod · 0.45
GCodes2.cppFile · 0.45
ReadCharMethod · 0.45
preMethod · 0.45
RecordSimulationTimeMethod · 0.45

Calls 3

UsingSbcInterfaceMethod · 0.80
ReadFileMethod · 0.80
MessageFMethod · 0.45

Tested by

no test coverage detected