Skip to content

SDFS File::flush() appears to do nothing #1293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
everslick opened this issue Apr 5, 2018 · 14 comments
Closed

SDFS File::flush() appears to do nothing #1293

everslick opened this issue Apr 5, 2018 · 14 comments

Comments

@everslick
Copy link
Contributor

I have a long running process that regularly appends data to a file on SD card and calls flush() on it afterwards. Still when I open the very same file and read its content it has no data appended nor its file size updated. When I close the file between writes, the data is there though. The exact same code works as expected when the file lifes on SPIFFS. So I assume that SD flush() is either not implemented or is buggy.

@everslick
Copy link
Contributor Author

everslick commented Apr 5, 2018

Or do I just see this behaviour mentioned here: #514 (comment) ?

why should a file handle be closed if another one is opened for the same file? this is completely not to be expected, is it?

@everslick
Copy link
Contributor Author

I see there have been reports about this issue, putting them here for reference: #1173 and #1169

@psykokwak-com
Copy link

I had the same issue.
I fixed it by adding fsync(fileno(_f)); after fflush(_f); in the void VFSFileImpl::flush() in file vfs_api.cpp

@k8C
Copy link

k8C commented Jan 27, 2019

I confirm that File.flush() does not work as expected. For example instead of file.print(text); file.flush(); I have to open and close everytime: file = SD.open(fileName, FILE_APPEND); file.print(text); file.close();. Please fix this soon

@ericlangel
Copy link

Same Problem with Flash (FFAT) File write.

This works...but its to slow
loop(){
File Data = FFat.open("/Data.txt", FILE_APPEND);
Data.write(Buffer,18);
Data.close();
}

And this doesn't work... nothing is written
loop(){
File Data = FFat.open("/Data.txt", FILE_APPEND);
while(1){
Data.write(Buffer,18);
Data.flush
}
}

I have to write 18 Bytes every 1ms.
How can i get it working?
FFat.open() needs 8ms.

@psykokwak-com
Copy link

Just use the POSIX implementation : fopen, fwrite, fsync, fclose.

@rrroonn
Copy link

rrroonn commented Mar 19, 2019

fsync(fileno(myFileDesc)); does indeed work around the problem.

@Bascy
Copy link
Contributor

Bascy commented Apr 14, 2019

I'm getting a 'fileno' was not declared in this scope when compiling
Where should this method be living?

@everslick
Copy link
Contributor Author

@Bascy : the workaround has already been merged 5 days ago. I think it will land in the stable release sooner or later. fileno() is an internal function, you cannot use it in a sketch.

@Bascy
Copy link
Contributor

Bascy commented Apr 14, 2019

I'm getting the compile error when compiling FS library through my script, not using fileno() myself
Definition of fileno() is disabled in esp32\tools\sdk\include\newlib\stdio.h

#if 0 /*ndef STRICT_ANSI - FIXME: must initialize stdio first, use fn */
#define fileno(p) __sfileno(p)
#endif

@Bascy
Copy link
Contributor

Bascy commented Apr 14, 2019

Solved, was caused by a stray compiler option

@ArosPrince
Copy link

For me. the error is caused by -std=c++17. But I wouldn't call that a stray compiler option. There are libraries that require this option.

@davefiddes
Copy link
Contributor

@ArosPrince If you are looking to use a newer standard from the one defined in the platform.txt you need to use the GNU extension variant. So the ESP32 Arduino project currently uses -std=gnu++11 if you wanted to use C++17 you change this to -std=gnu++17. Using a newer C++ standard should probably be raised as a separate issue.

@ArosPrince
Copy link

@davefiddes OK, thanks. Good to know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants