I have a similar type of issue to: Raspberry Pi: Filesystem writes files, but after reboot the old data is back but not quite the same.
I am using Armbian_23.02.2_Orangepizero_jammy_current_5.15.93
running on an OrangePi with an SD card for storage.
I built a race timer for a car using C++. It uses GPS and logs data at 10Hz to a file. It also runs a server and I can change some configuration on a webpage that is hosted and this configuration is then stored as JSON in a file so that it survives reboots. The OrangePi is powered from the car and when the car is turned off after a run the OrangePi loses power until the next time the car is started (could be problematic?)
The problem I am having is this: I can launch the server, change some configuration, ssh on, cat
the file and see that the new configuration is stored in the file. If I then pull the power, and plug it back in. The file returns to the state it was before the config was changed.
If I do sudo reboot now
instead of pull the power the new configuration persists. It seems like the new file data isn't actually being written and held in RAM.
Storing data like this:
void store(const config& c)
{
const nlohmann::json json = {
{"key1", c.val1},
{"key2", c.val1},
{"key2", c.val1}
};
std::ofstream f("/path/to/file.json");
f << json;
}
When logging data at 10Hz, I append to the end of the file with the new data at 10Hz, I have noticed that sometimes the end of the file is missing some "logs".
Also if the current run is faster, the log file for that run will be copied to a different location, I have noticed that the copied data can be "funky". For example I have seen it contain parts of the previous and new log and have the previous file name.
Copying files like:
std::filesystem::copy_file(
from_path,
to_path,
std::filesystem::copy_options::overwrite_existing,
ec);
Is there anything I can do to force the files to be written straight away?
Is appending roughly 100 characters to a file at 10Hz possibly too ambitious for a single-board computer running on an SD card?