In my program there is a function to frequently call stat()
to get the attributes of a file in flash storage. Sometimes after power off and reboot the contents of the file lost. I noticed that the stat()
finally calls the file system driver in the Linux kernel.
My questions are: will the Linux kernel fs open or read the file to get the file attributes? Is it possible for the power off during stat() or fstat() corrupt the file in flash?
All the stat() call does is to retrieve the contents of the file's i-node; the file itself isn't touched. However, the file's i-node will be in memory, and it the file was updated in any way [even by being held open by this or another process], the file mtime and such will need to be updated and the i-node will get updated, perhaps wrongly. Poof! No file.
But this behavior is not unique to flash.