SdFat icon indicating copy to clipboard operation
SdFat copied to clipboard

SdFat conflict with SPIFFS/fs

Open williamesp2015 opened this issue 4 years ago • 8 comments

I am using SPIFFS to read and write SPIFFS on ESP32 using Arduino platform. I have seriouse problem with File definitions; File logFile = SPIFFS.open(FILENAME_DATALOG, FILE_WRITE); LowLatencyLogger.cpp:658:56: error: invalid conversion from 'int' to 'const char*' [-fpermissive] I did try this but did not help me. fs::File logFile = SPIFFS.open(FILENAME_DATALOG, FILE_WRITE);

williamesp2015 avatar Apr 08 '20 13:04 williamesp2015

I have no idea since I don't use esp32.

greiman avatar Apr 08 '20 18:04 greiman

@williamesp2015 please paste rest of error

uzi18 avatar Apr 08 '20 20:04 uzi18

Hi @uzi18. If FS.h change class File name it will solve the problem. I tried to change in my project but other files like WebServer.cpp uses FS.h too. Complete errors: src\FatLib/ArduinoFiles.h:122:7: error: redefinition of 'class fs::File' C:/users/am/.platformio/packages/framework-arduinoespressif32/libraries/FS/src/FS.h:47:7: error: previous definition of 'class fs::File' src\FatLib/FatFileSystem.h:95:13: error: 'class fs::File' has no member named 'open'

Finally, I changed File to File_ in SdFat: typedef File32 File_; and similar definitions

williamesp2015 avatar Apr 09 '20 02:04 williamesp2015

What are the exact definitions ? I have the same problem.

Thanks. Marc.

nodoubtman avatar Jan 30 '22 04:01 nodoubtman

File is only defined here in SdFat.h at about line 450

//
// Only define File if FS.h is not included.
// Line with test for __has_include must not have operators or parentheses.
#if defined __has_include
#if __has_include(<FS.h>)
#define HAS_INCLUDE_FS_H
#warning File not defined because __has_include(FS.h)
#endif  // __has_include(<FS.h>)
#endif  // defined __has_include
#ifndef HAS_INCLUDE_FS_H
#if SDFAT_FILE_TYPE == 1 || defined(DOXYGEN)
/** Select type for File. */
typedef File32 File;
#elif SDFAT_FILE_TYPE == 2
typedef ExFile File;
#elif SDFAT_FILE_TYPE == 3
typedef FsFile File;
#endif  // SDFAT_FILE_TYPE
#endif  // HAS_INCLUDE_FS_H

You can just use File32, ExFile, or FsFile and never define File by disabling or removing this section.

File was added to the Arduino port of SdFat in 2009 so I added a typedef to be backward compatible.

greiman avatar Jan 30 '22 12:01 greiman

Thanks for answering. I dont understand. What i have to do to use spiffs with sdfat ? Thanks. Have a good day. Marc.

nodoubtman avatar Jan 30 '22 15:01 nodoubtman

What i have to do to use spiffs with sdfat ?

The simplest thing is to do what @williamesp2015 did.

Change File to File_ in the above section of SdFat.h and use File_ in your app.

You can also delete the above section of SdFat.h and use the appropriate class name, File32, ExFile, or FsFile.

greiman avatar Jan 30 '22 19:01 greiman

If fs::FS compatibility is needed, this can be acchieved by writing an adapter: see https://github.com/greiman/SdFat/issues/148#issuecomment-1464448806

ockernuts avatar Mar 10 '23 22:03 ockernuts