I'm writing a bit of software that uses the fsync()
system call to ensure a file is persisted to disk. I've done this before, and I'm aware of various "gotchas" you need to be aware of (i.e., when replacing a file, you need to fsync()
the file, issue a rename()
, then fsync()
the containing directory. Coding the software that durably writes files to disk is fine.
Testing the software is another matter. I want to verify that it operates correctly in the face of, e.g., power outages. My physical reflexes are pretty good, but not quite good enough to unplug the power cable between two CPU instructions.
How should I test the durability of a C program that writes to disk?
(As implied by the title, I'm assuming you use some sort of debugger-like software, perhaps using ptrace()
, to automatically kill your program at particular files/lines, as listed in the debugging information of the executable.)