Hi,
I use an OrangePi Zero as a race timer for a car. It is powered from the car. So when the car starts the OrangePi gets power and boots and when the car is turned off the OrangePi loses power and "turns off". This isn't ideal but I don't have a lot of options. I feel like this is a fairly common use case for electronics in cars especially ones like race timers etc. Unless I have a battery as well.
I was wondering what are the best things to do to protect against the sudden power loss so that I don't corrupt anything? Is it possible to make parts of the file system read only maybe?
All I do with the OrangePi is run a C++ application, it uses two serial ports and runs a server on port 80. The application does read and write its own configuration files and log files. But these are not OS files, only files that the application created itself.
I have noticed that after writing or appending to a file from C++, if the power is pulled and then plugged back in the change to the file does not persist. I can ssh on before the power is pulled and `cat` the file and see that it is updated. Seems that the file data is held in RAM for a little while before actually writing. Is there anyway to force file writes to actually be flushed and written straight away?