Unix’s file durability problem
A good solution is to use SQLite.  It addresses the issues (pretty much by doing all the fsync etc mentioned including on directories) and has a very comprehensive test suite.  It is also used very widely on desktops, mobile devices, applications etc.  https://www.sqlite.org/whentouse.htmlA notable quote: SQLite does not compete with client/server databases. SQLite competes with fopen().